From neolo12 at yandex.ru Tue May 1 00:39:42 2012 From: neolo12 at yandex.ru (jimmy970) Date: Mon, 30 Apr 2012 21:39:42 -0700 (PDT) Subject: porn-extreme In-Reply-To: <1335623703913-4936643.post@n6.nabble.com> References: <1334088832274-4776849.post@n6.nabble.com> <1334263544723-4864079.post@n6.nabble.com> <1334334574674-4879088.post@n6.nabble.com> <1334385003417-4880911.post@n6.nabble.com> <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> Message-ID: <1335847182281-4942868.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4942868.html Sent from the Python - python-list mailing list archive at Nabble.com. From deuteros at xrs.net Tue May 1 00:50:48 2012 From: deuteros at xrs.net (deuteros) Date: Tue, 1 May 2012 04:50:48 +0000 (UTC) Subject: Trouble splitting strings with consecutive delimiters Message-ID: I'm using regular expressions to split a string using multiple delimiters. But if two or more of my delimiters occur next to each other in the string, it puts an empty string in the resulting list. For example: re.split(':|;|px', "width:150px;height:50px;float:right") Results in ['width', '150', '', 'height', '50', '', 'float', 'right'] Is there any way to avoid getting '' in my list without adding px; as a delimiter? From drsalists at gmail.com Tue May 1 01:25:39 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 30 Apr 2012 22:25:39 -0700 Subject: Sort comparison Message-ID: A while back I did a sort algorithm runtime comparison for a variety of sorting algorithms, and then mostly sat on it. Recently, I got into a discussion with someone on stackoverflow about the running time of radix sort. I realize it's commonly said that radixsort is n*k rather than n*log(n). I've been making that case that in real life, frequently k==log(n). Anyway, here's the comparison, with code and graph: http://stromberg.dnsalias.org/~strombrg/sort-comparison/ (It's done in Pure python and Cython, with a little m4). Interesting, BTW, that an unstable quicksort in Cython was approaching timsort as a C extension module in performance, even though timsort in Cython wasn't that performant. It makes one wonder if a highly optimized quicksort as a C extension module wouldn't outperform timsort in the standard library. Yes, I know, we've committed to keeping list_.sort() stable now, and quicksort normally isn't stable. Also, before timsort, did CPython use quicksort? I'd be a little surprised if it hadn't, since people used to say quicksort was the best thing around in practice. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue May 1 01:54:04 2012 From: nagle at animats.com (John Nagle) Date: Mon, 30 Apr 2012 22:54:04 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: On 4/30/2012 8:19 AM, deltaquattro at gmail.com wrote: > Hi, > > I would like to automate the following task under Linux. I need to create a set of directories such as > > 075 > 095 > 100 > 125 > > The directory names may be read from a text file foobar, which also contains a number corresponding to each dir, like this: > > 075 1.818 > 095 2.181 > 100 2.579 > 125 3.019 > > > In each directory I must copy a text file input.in. This file contains two lines which need to be edited: Learn how to use a database. Creating and managing a big collection of directories to handle small data items is the wrong approach to data storage. John Nagle From frank at chagford.com Tue May 1 02:12:42 2012 From: frank at chagford.com (Frank Millman) Date: Mon, 30 Apr 2012 23:12:42 -0700 (PDT) Subject: Some posts do not show up in Google Groups References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> Message-ID: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> On Apr 30, 8:20?am, Frank Millman wrote: > Hi all > > For a while now I have been using Google Groups to read this group, but on the odd occasion when I want to post a message, I use Outlook Express, as I know that some people reject all messages from Google Groups due to the high spam ratio (which seems to have improved recently, BTW). > > From time to time I see a thread where the original post is missing, but the follow-ups do appear. My own posts have shown up with no problem. > > Now, in the last month, I have posted two messages using Outlook Express, and neither of them have shown up in Google Groups. I can see replies in OE, so they are being accepted. I send to the group gmane.comp.python.general. > > Does anyone know a reason for this, or have a solution? > > Frank Millman Thanks for the replies. I am also coming to the conclusion that Google Groups is no longer fit-for-purpose. Ironically, here are two replies that I can see in Outlook Express, but do not appear in Google Groups. Reply from Benjamin Kaplan - > I believe the mail-to-news gateway has trouble with HTML messages. Try sending everything as plain text and see if that works. I checked, and all my posts were sent in plain text. Reply from Terry Reedy - > Read and post through news.gmane.org I have had a look at this before, but there is one thing that Google Groups does that no other reader seems to do, and that is that messages are sorted according to thread-activity, not original posting date. This makes it easy to see what has changed since the last time I checked. All the other ones I have looked at - Outlook Express, Thunderbird, and gmane.org, sort by original posting date, so I have to go backwards to see if any threads have had any new postings. Maybe there is a setting that I am not aware of. Can anyone enlighten me? Thanks Frank From jpiitula at ling.helsinki.fi Tue May 1 02:14:54 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 01 May 2012 09:14:54 +0300 Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: deuteros writes: > I'm using regular expressions to split a string using multiple > delimiters. But if two or more of my delimiters occur next to each > other in the string, it puts an empty string in the resulting > list. For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; > as a delimiter? You could use a sequence of such delimiters. >>> re.split('(?::|;|px)+', "width:150px;height:50px;float:right") ['width', '150', 'height', '50', 'float', 'right'] Consider splitting twice instead: first into key-value substrings at semicolons, and those into key-value pairs at colons. Here as a dict. Better handle the units after that. >>> dict(kv.split(':') for kv in "width:150px;height:50px;float:right".split(';')) {'width': '150px', 'float': 'right', 'height': '50px'} You might also want to accept whitespace as part of the delimiters. (There might be a parser for such data formats somewhere in the library already. CSV?) From russ.paielli at gmail.com Tue May 1 02:56:48 2012 From: russ.paielli at gmail.com (Russ P.) Date: Mon, 30 Apr 2012 23:56:48 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> On Apr 29, 5:17?pm, someone wrote: > On 04/30/2012 12:39 AM, Kiuhnm wrote: > > >> So Matlab at least warns about "Matrix is close to singular or badly > >> scaled", which python (and I guess most other languages) does not... > > > A is not just close to singular: it's singular! > > Ok. When do you define it to be singular, btw? > > >> Which is the most accurate/best, even for such a bad matrix? Is it > >> possible to say something about that? Looks like python has a lot more > >> digits but maybe that's just a random result... I mean.... Element 1,1 = > >> 2.81e14 in Python, but something like 3e14 in Matlab and so forth - > >> there's a small difference in the results... > > > Both results are *wrong*: no inverse exists. > > What's the best solution of the two wrong ones? Best least-squares > solution or whatever? > > >> With python, I would also kindly ask about how to avoid this problem in > >> the future, I mean, this maybe means that I have to check the condition > >> number at all times before doing anything at all ? How to do that? > > > If cond(A) is high, you're trying to solve your problem the wrong way. > > So you're saying that in another language (python) I should check the > condition number, before solving anything? > > > You should try to avoid matrix inversion altogether if that's the case. > > For instance you shouldn't invert a matrix just to solve a linear system. > > What then? > > Cramer's rule? If you really want to know just about everything there is to know about a matrix, take a look at its Singular Value Decomposition (SVD). I've never used numpy, but I assume it can compute an SVD. From ian.g.kelly at gmail.com Tue May 1 03:21:50 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 May 2012 01:21:50 -0600 Subject: Sort comparison In-Reply-To: References: Message-ID: On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg wrote: > > A while back I did a sort algorithm runtime comparison for a variety of > sorting algorithms, and then mostly sat on it. > > Recently, I got into a discussion with someone on stackoverflow about the > running time of radix sort. > > I realize it's commonly said that radixsort is n*k rather than n*log(n). > I've been making that case that in real life, frequently k==log(n). > > Anyway, here's the comparison, with code and graph: > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ It can be difficult to distinguish O(n) from O(n log n) on a log-log plot, so I don't think that graph makes your point very well. > Interesting, BTW, that an unstable quicksort in Cython was approaching > timsort as a C extension module in performance, even though timsort in > Cython wasn't that performant.? It makes one wonder if a highly optimized > quicksort as a C extension module wouldn't outperform timsort in the > standard library. > > Yes, I know, we've committed to keeping list_.sort() stable now, and > quicksort normally isn't stable. > > Also, before timsort, did CPython use quicksort?? I'd be a little surprised > if it hadn't, since people used to say quicksort was the best thing around > in practice. Based on a little googling, it was quicksort prior to 1.5.2, then it was changed to a highly optimized samplesort (a quicksort variant) / insertion sort hybrid until the current timsort was implemented in 2.3. Cheers, Ian From jabba.laci at gmail.com Tue May 1 03:35:43 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 09:35:43 +0200 Subject: geoinfo with python Message-ID: Hi, I want to figure out where a host is located, in which country. There are sites that look up this information (e.g. http://geoip.flagfox.net/). Before writing a scraper, I would like to ask if you know a python API for this task. Thanks, Laszlo From albert at spenarnc.xs4all.nl Tue May 1 06:49:41 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 May 2012 10:49:41 GMT Subject: why () is () and [] is [] work in other way? References: <4f958600$0$1382$4fafbaef@reader1.news.tin.it> <7xvckq4c2j.fsf@ruckus.brouhaha.com> Message-ID: In article <7xvckq4c2j.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Kiuhnm writes: >> I can't think of a single case where 'is' is ill-defined. > >If I can't predict the output of > > print (20+30 is 30+20) # check whether addition is commutative > print (20*30 is 30*20) # check whether multiplication is commutative > >by just reading the language definition and the code, I'd have to say >"is" is ill-defined. The output depends whether the compiler is clever enough to realise that the outcome of the expressions is the same, such that only one object needs to be created. What is ill here is the users understanding of when it is appropriate to use "is". Asking about identity of temporary objects fully under control of the compiler is just sick. 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 deltaquattro at gmail.com Tue May 1 06:51:57 2012 From: deltaquattro at gmail.com (deltaquattro at gmail.com) Date: Tue, 1 May 2012 03:51:57 -0700 (PDT) Subject: Create directories and modify files with Python In-Reply-To: <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> Message-ID: <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Il giorno marted? 1 maggio 2012 01:57:12 UTC+2, Irmen de Jong ha scritto: > > Hi, 0 I would like to automate some simple tasks I'm doing by hand. Given a text file > > foobar.fo: > > [...] > > > At first, I tried to write a bash script to do this. However, when and if the script > > will work, I'll probably want to add more features to automate some other tasks. So I > > thought about using some other language, to have a more flexible and mantainable > > code. I've been told that both Python and perl are well suited for such tasks, but > > unfortunately I know neither of them. Can you show me how to write the script in > > Python? Thanks, > > Err.. if you don't know Python, why do you think a Python script will be more flexible > and maintainable for you? > Eheh :) good question. The point is that, when in the past I chose to use only languages that I know, I always ended up with one of these two solutions: 1) write a "simple" shell script, which three years from now will make me curse in Sumeric because I can't make heads or tails of it. Been there, done that. 2) with time, the shell script may become larger and require some mathematics. For example, the second column of foobar.fo consists of mass flows, which today I get from another code, but that I could compute in the script. At this point, I go for a Fortran/C code, which takes me longer to write. Now I'd like to try another road. The problem is that each time I stumble upon a good chance to learn Python, I never have enough time to learn the language from zero, and I end up with one of two solutions above. If you can provide me with a working solution or at least some code to start with, I should be able to solve my immediate problem, and then have time to learn some more (that's how I learned shell scripting). The (possibly wrong) underlying assumption is that the problem is simple enough for one of you Python experts to solve easily, without wasting too much of his/her time. Anyway, I'm willing to pay a reasonable fee for help, provided you have Paypal. > But if you really want to go this way (and hey, why not) then first you'll have to learn > some basic Python. A good resource for this might be: http://learnpythonthehardway.org/ Ehm...name's not exactly inspiring for a newbie who's short on time :) > > Focus on file input and output, string manipulation, and look in the os module for stuff > to help scanning directories (such as os.walk). > > Irmen Thanks for the directions. By the way, can you see my post in Google Groups? I'm not able to, and I don't know why. Sergio From jabba.laci at gmail.com Tue May 1 07:01:45 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 13:01:45 +0200 Subject: geoinfo with python In-Reply-To: References: Message-ID: I've found a web service for the task: http://www.geoplugin.com/webservices . It can produce JSON output too. Laszlo On Tue, May 1, 2012 at 09:35, Jabba Laci wrote: > Hi, > > I want to figure out where a host is located, in which country. There > are sites that look up this information (e.g. > http://geoip.flagfox.net/). Before writing a scraper, I would like to > ask if you know a python API for this task. > > Thanks, > > Laszlo From __peter__ at web.de Tue May 1 07:45:34 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 May 2012 13:45:34 +0200 Subject: Create directories and modify files with Python References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: deltaquattro at gmail.com wrote: > At this point, I go for a Fortran/C code, which takes me longer to write. If you already have a basic programming knowledge the tutorial that comes with Python should be an excellent starting point: http://docs.python.org/py3k/tutorial/index.html > Now I'd like to try another road. The problem is that each time I stumble > upon a good chance to learn Python, I never have enough time to learn the > language from zero, and I end up with one of two solutions above. If you > can provide me with a working solution or at least some code to start > with, I should be able to solve my immediate problem, and then have time > to learn some more (that's how I learned shell scripting). The (possibly > wrong) underlying assumption is that the problem is simple enough for one > of you Python experts to solve easily, without wasting too much of his/her > time. Anyway, I'm willing to pay a reasonable fee for help, provided you > have Paypal. While some people here might welcome a few extra bucks that's generally not the reason we are posting here. The idea is more about peers helping peers and sometimes learning something useful for themselves. In that spirit I'd like to make an alternative offer: put some effort into the job yourself, write a solution in bash and post it here. I (or someone else) will then help you translate it into basic Python. That will typically attract others who know how to make it shorter, simpler, or more general (or to turn it into a showcase for Python's more advanced features or their favourite programming paradigm). You'll end up with a usable starting point for further endeavours into the language, no money involved. From lkcl at lkcl.net Tue May 1 08:06:15 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Tue, 1 May 2012 13:06:15 +0100 Subject: pyjamas 0.8.1 - help requested for testing to reach stable release Message-ID: hi folks, got a small favour to ask of the python community - or, more specifically, i feel compelled to alert the python community to "a need" with which you may be able to help: we're due for another release, and it's becoming an increasingly-large task. given the number of examples requiring testing (75+) the number of browsers (15+) and desktop engines (3 so far, on 3 different OSes) that pyjamas supports is just... overwhelming for any one individual to even contemplate tackling. for the pyjamas 0.6 release, for example, i spent three weeks straight, just doing testing. from that experience i decided to set a rule, which is very straightforward: ask for help in testing, set a (reasonably firm) deadline for a release date, and then whatever has been tested by contributors by that time, that becomes the stable release. thus, in this way, the community receives a stable release that is of the quality that the *community* requires. the list of platforms tested already is quite long: however it's not long _enough_! and, also, on each task, there needs to be many more examples actually tested. here's what's been done so far: http://code.google.com/p/pyjamas/issues/list?can=2&q=milestone=Release0.8.1 we need more testing on opera, more testing on safari, more versions of firefox - more of everything basically! so, this is basically more of a "notification" than it is anything else, that if you'd like to help with the responsible task of ensuring that a python compiler and GUI toolkit has a release that the python community can be proud of, that i'm placing that responsibility directly into your hands: i'm just the gatekeeper, here. lastly, i'd like to leave you with this thought. i am doing a web site for a client (a general-purpose content management system which will be released as free software at some stage). the user management roles are stored as a comma-separated list in the database (kirbybase). i needed to split the string back into a list, and before i knew it i had typed this: import string roles = map(string.strip, user['roles'].split(",")) what struck me was that, although i've been working with pyjamas for over three years, it _still_ had me doing a double-take that this is *python*, yet this will end up running in *javascript* in the actual web site. the level of pain and awkwardness that would need to be gone through in order to do the same operation in javascript, and being completely unable to actually test and develop with confidence under pyjd directly at the python interpreter, i just... i can't imagine ever going back to that. and that's just... fricking awesome, but it highlights and underscores that there's a real reason why pyjamas is worthwhile helping out with (and using). you *do not* have to learn javascript, yet can still create comprehensive web sites that will work across all modern web browsers... *if* they're tested properly :) ok enough. thanks folks. l. From __peter__ at web.de Tue May 1 08:55:13 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 May 2012 14:55:13 +0200 Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: deuteros wrote: > I'm using regular expressions to split a string using multiple delimiters. > But if two or more of my delimiters occur next to each other in the > string, it puts an empty string in the resulting list. For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? That looks like a CSS style; to parse it you should use a tool that was built for the job. The first one I came across (because it is included in the linux distro I'm using and has "css" in its name, so this is not an endorsement) is http://packages.python.org/cssutils/ >>> import cssutils >>> style = cssutils.parseStyle("width:150px;height:50px;float:right") >>> for property in style.getProperties(): ... print property.name, "-->", property.value ... width --> 150px height --> 50px float --> right OK, so you still need to strip off the unit prefix manually: >>> def strip_suffix(s, *suffixes): ... for suffix in suffixes: ... if s.endswith(suffix): ... return s[:-len(suffix)] ... return s ... >>> strip_suffix(style.float, "pt", "px") u'right' >>> strip_suffix(style.width, "pt", "px") u'150' From hoogendoorn.eelco at gmail.com Tue May 1 09:26:16 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Tue, 1 May 2012 06:26:16 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: There is linalg.pinv, which computes a pseudoinverse based on SVD that works on all matrices, regardless of the rank of the matrix. It merely approximates A*A.I = I as well as A permits though, rather than being a true inverse, which may not exist. Anyway, there are no general answers for this kind of thing. In all non-textbook problems I can think of, the properties of your matrix are highly constrained by the problem you are working on; which additional tests are required to check for corner cases thus depends on the problem. Often, if you have found an elegant solution to your problem, no such corner cases exist. In that case, MATLAB is just wasting your time with its automated checks. From franck at ditter.org Tue May 1 09:54:31 2012 From: franck at ditter.org (Franck Ditter) Date: Tue, 01 May 2012 15:54:31 +0200 Subject: Installing pygame on MacOS-X Lion with Python 3.3 Message-ID: I can't get it working : "No pygame module"... Tried without success : pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg I am using Python 3 last version on MacOS-X Lion. Where is a step-by-step installation procedure ? Thanks, franck From chess at us.ibm.com Tue May 1 10:01:11 2012 From: chess at us.ibm.com (David M Chess) Date: Tue, 1 May 2012 10:01:11 -0400 Subject: bus errors when the network interface is reset? Message-ID: We have a system running Python 2.6.6 under RHEL 6.1. A bunch of processes spend most of their time sitting in a BaseHTTPServer.HTTPServer waiting for requests. Last night an update pushed out via xcat whimsically restarted all of the network interfaces, and at least some of our processes died with bus errors (i.e. no errors or exceptions reflected up to the Python level, just a crash). This is just my initial looking into this. Seeking opinions of the form, say: Yeah, that happens, don't reset the network interfaces. Yeah, that happens, and you can prevent the crash by doing X in your OS. Yeah, that happens, and you can prevent the crash by doing X in your Python code. That wouldn't happen if you upgraded S to version V. That sounds like a new bug and/or more information is needed; please provide copious details including at least X, Y, and Z. Any thoughts or advice greatly appreciated. DC David M. Chess IBM Watson Research Center -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Tue May 1 10:18:03 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 01 May 2012 16:18:03 +0200 Subject: syntax for code blocks In-Reply-To: <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> Message-ID: <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> On 5/1/2012 5:27, alex23 wrote: > On Apr 30, 2:05 am, Peter Pearson wrote: >> Hey, guys, am I the only one here who can't even guess what >> this code does? When did Python become so obscure? > > Thankfully it hasn't. The most Pythonic way to pass around a code > block is still to use a function. "Most Pythonic" doesn't mean better, unfortunately. For instance, assume that you want to write a function that accepts a dictionary of callbacks: func(some_args, callbacks) Pythonic way ------------ def when_odd(n): pass def when_prime(n): pass def before_check(): pass def after_check(): pass func(some_args, {'when_odd' : when_odd, 'when_prime' : when_prime, 'before_check' : before_check, 'after_check' : after_check}) def when_prime(n): pass def when_perfect(n): pass def before_reduction() pass def after_reduction(): pass func(some_args, {'when_prime' : when_prime, 'when_perfect' : when_perfect, 'before_reduction' : before_reduction, 'after_reduction' : after_reduction}) My way ------ with func(some_args) << ':dict': with when_odd as 'n': pass with when_prime as 'n': pass with before_check as '': pass with after_check as '': pass with func(some_args) << ':dict': with when_prime as 'n': pass with when_perfect as 'n': pass with before_reduction as '': pass with after_reduction as '': pass Kiuhnm From jabba.laci at gmail.com Tue May 1 10:23:11 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 16:23:11 +0200 Subject: For loop In-Reply-To: <4F9E7D14.1030708@kingdread.de> References: <4F9E7D14.1030708@kingdread.de> Message-ID: Hi, Try this: import sys for i in range (1, 5+1): for j in range (i): sys.stdout.write(str(i)) print "print" adds a newline character print "hi", notice the comma, it won't add newline, however it adds a space With sys.stdout.write you can print the way you want, it won't add any extra stuff (newline or space). Best, Laszlo On Mon, Apr 30, 2012 at 13:52, Daniel wrote: > You could also try http://docs.python.org/library/stdtypes.html#str.join > like this: > for i in range(5): > ? ?print "".join(str(i) for j in range(i)) > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue May 1 10:26:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 00:26:44 +1000 Subject: Create directories and modify files with Python In-Reply-To: References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: On Tue, May 1, 2012 at 9:45 PM, Peter Otten <__peter__ at web.de> wrote: > In that spirit I'd like to make an alternative offer: put some effort into > the job yourself, write a solution in bash and post it here. I (or someone > else) will then help you translate it into basic Python. That will typically > attract others who know how to make it shorter, simpler, or more general (or > to turn it into a showcase for Python's more advanced features or their > favourite programming paradigm). You'll end up with a usable starting point > for further endeavours into the language, no money involved. Seconded, and I'd recommend putting this into a FAQ. Dollars aren't the currency here, help and coding time are. Regarding the original problem: I would recommend you dedicate just one hour to learning Python. Most people should be able to find that much time, I think! As a programmer, you should be able to pick up most of Python's basics in an hour, using its own tutorial as Peter Otten posted ( http://docs.python.org/py3k/tutorial/index.html ); after that, you can probably write your script, or at very least will know which aspects of the language you love and which aspects you hate! ChrisA From rosuav at gmail.com Tue May 1 10:33:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 00:33:22 +1000 Subject: syntax for code blocks In-Reply-To: <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, May 2, 2012 at 12:18 AM, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. > > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ?pass > > def when_prime(n): > ? ?pass > > def before_check(): > ? ?pass > > def after_check(): > ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? 'after_check' : after_check}) My way: func(some_args, {'when_odd': lambda: 1, 'when_prime': lambda: 2, 'before_check': lambda: 3, 'after_check': lambda: 4}) In a language where lambda isn't restricted to a single expression (eg Javascript, Pike), this works even better, but it's still plausible for many situations. ChrisA From awilliam at whitemice.org Tue May 1 10:47:15 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 May 2012 10:47:15 -0400 Subject: Communication between C++ server and Python app In-Reply-To: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> References: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> Message-ID: <1335883635.4017.1.camel@linux-nysu.site> On Sat, 2012-04-28 at 17:45 -0700, kenk wrote: > I've got a server process written in C++ running on Unix machine. > On the same box I'd like to run multiple Python scripts that will > communicate with this server. > Can you please suggest what would be best was to achieve this ? Time to start using a message broker that can also grow to other applications. RabbitMQ. Simple, fast, and easy to manage. This allows each service to have outages without loosing information. -------------- 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 sg552 at hotmail.co.uk Tue May 1 11:09:25 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 01 May 2012 16:09:25 +0100 Subject: Some posts do not show up in Google Groups In-Reply-To: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> Message-ID: On 01/05/2012 07:12, Frank Millman wrote: > [...] > > I have had a look at this before, but there is one thing that Google > Groups does that no other reader seems to do, and that is that > messages are sorted according to thread-activity, not original posting > date. This makes it easy to see what has changed since the last time I > checked. > > All the other ones I have looked at - Outlook Express, Thunderbird, > and gmane.org, sort by original posting date, so I have to go > backwards to see if any threads have had any new postings. > > Maybe there is a setting that I am not aware of. Can anyone enlighten > me? In Thunderbird, in the list of articles, click on the box at the top right that says "Date". This will sort articles by date. If the arrow at the right hand side of the box points upwards, click the box again. This will sort articles by date with the newest at the top. Then click the leftmost box at the same height as the "Date" one, which has an icon that looks like a Tetris block; this will sort the articles into threads, with those threads that contain the most recent posts at the top of the list. At least that's how it works on my version of Thunderbird (11.0.1 and all previous versions I can remember). I don't know how one would get it to sort threads by OP date, so I don't know why it's doing that for you. Whenever I open a newsgroup in Thunderbird, I also find it useful to click the "Unread" button in the Quick Filter toolbar. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From steve+comp.lang.python at pearwood.info Tue May 1 11:11:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2012 15:11:03 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 16:18:03 +0200, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Perhaps. But this example is not one of those cases. > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > pass [snip multiple function definitions] > func(some_args, {'when_odd' : when_odd, > 'when_prime' : when_prime, > 'before_check' : before_check, > 'after_check' : after_check}) > My way > ------ > > with func(some_args) << ':dict': > with when_odd as 'n': > pass > with when_prime as 'n': > pass If you actually try that, you will see that it cannot work. You get: SyntaxError: can't assign to literal Have you actually tried to use these code blocks of yours? I asked you for a *working* example earlier, and you replied with examples that failed with multiple NameErrors and no hint as to how to fix them. And now you give an example that fails with SyntaxError. I'm reluctantly coming to the conclusion that these "code blocks" of yours simply do not work. > with before_check as '': > pass > with after_check as '': > pass You have a bug in one or more of those callbacks. Of course you do -- all non-trivial software has bugs. The question is, how are you going to find it? You can't unit-test the individual callbacks, because they don't exist in a form that can be tested. So in this case, even though Python is slightly more verbose, and forces you to have the discipline of writing named functions ahead of time, this is actually a *good* thing because it encourages you to test them. If the callbacks are trivial functions, the Pythonic way is to use lambdas: func(some_args, {'when_odd': lambda n: n-1, 'when_prime': lambda n: n**2 - 1, ...}) although I would discourage that unless they are *really* trivial. But for callbacks of any complexity, they will need to be tested, otherwise how do you know they do what you want them to do? Your code blocks make unit testing of the callbacks impossible, and for that reason the Pythonic way is better. -- Steven From steve+comp.lang.python at pearwood.info Tue May 1 11:12:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2012 15:12:46 GMT Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 04:50:48 +0000, deuteros wrote: > I'm using regular expressions to split a string using multiple > delimiters. But if two or more of my delimiters occur next to each other > in the string, it puts an empty string in the resulting list. As I would expect. After all, there *is* an empty string between two delimiters. > For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? Probably. But why not do it the easy way? items = re.split(':|;|px', "width:150px;height:50px;float:right") items = filter(None, item) In Python 3, the second line will need to be list(filter(None, item)). -- Steven From rosuav at gmail.com Tue May 1 11:28:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 01:28:51 +1000 Subject: syntax for code blocks In-Reply-To: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 2, 2012 at 1:11 AM, Steven D'Aprano wrote: > So in this case, even though Python is slightly more verbose, and forces > you to have the discipline of writing named functions ahead of time, this > is actually a *good* thing because it encourages you to test them. > > If the callbacks are trivial functions, the Pythonic way is to use > lambdas: > > func(some_args, {'when_odd': lambda n: n-1, > ? ? ? ? ? ? ? ? 'when_prime': lambda n: n**2 - 1, > ? ? ? ? ? ? ? ? ...}) > > although I would discourage that unless they are *really* trivial. But > for callbacks of any complexity, they will need to be tested, otherwise > how do you know they do what you want them to do? Agreed. At work, I'm currently shoveling through a pile of Javascript code (about 500KB of it, one file) that largely looks like this: FOO={} FOO.bar={ init:function() { // ... initialization code }, quux:function(a,b) { //code for this function }, ajaxrequest:function() { var blah,blah; blah; return { foo:function() { blah; } }; }(), bleh:blah } It's all anonymous functions assigned to member variables. It's not easy to debug, and refactoring the code into something simpler is a weeks-long job. I know it is because I've already spent two on it. Oh, and notice how ajaxrequest isn't actually declaring a function at all, it's calling a function and using its return value? Important information like that is buried away instead of being in the function signature. Plus, to make matters worse, many of the function and object names are reused, so FOO.bar.ajaxrequest.foo() is completely different from FOO.something.else.foo() and both have just "foo:function()" as their signature. Write your code out of line unless it REALLY wants to be inline. Name the functions unless they're trivial. And yes, I did say that I would do them as in-line lambdas. I don't really see much value in the callback system you have here unless either they ARE that trivial, or it's patently obvious that they need to be functions, so I still stand by what I said. ChrisA From rurpy at yahoo.com Tue May 1 11:34:57 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 1 May 2012 08:34:57 -0700 (PDT) Subject: Create directories and modify files with Python References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: On 04/30/2012 05:24 PM, deltaquattro at gmail.com wrote: > Hi, > > I would like to automate some simple tasks I'm doing by hand. Given a text file > foobar.fo: > > 073 1.819 > 085 2.132 > 100 2.456 > 115 2.789 > > I need to create the directories 073, 085, 100, 115, and copy in each directory a modified version of the text file input.in: > > . > . > . > foo = 1.5 ! edit this value > . > . > . > bar = 1.5 ! this one, too > . > . > . > > Tthe modification consists in substituting the number in the above lines with the value associated to the directory in the file foobar.fo. Thus, the input.in file in the directory 100 will be: > > . > . > . > foo = 2.456 ! edit this value > . > . > . > bar = 2.456 ! this one, too > . > . > . > > At first, I tried to write a bash script to do this. However, when and if the script will work, I'll probably want to add more features to automate some other tasks. So I thought about using some other language, to have a more flexible and mantainable code. I've been told that both Python and perl are well suited for such tasks, but unfortunately I know neither of them. Can you show me how to write the script in Python? Thanks, Perhaps something like this will get you started? To keep things simple (since this is illustrative code) there is little parameterization and no error handling. Apologies if Google screws up the formatting too bad. -------------------------------------------------------- from __future__ import print_function #1 import os def main(): listf = open ('foobar.fo') for line in listf: dirname, param = line.strip().split() #7 make_directory (dirname, param) def make_directory (dirname, param): os.mkdir (dirname) #11 tmplf = open ("input.in") newf = open (dirname + '/' + 'input.in', 'w') #13 for line in tmplf: if line.startswith ('foo = ') or line.startswith ('bar = '): #15 line = line.replace (' 1.5 ', ' '+param+' ') #16 print (line, file=newf, end='') #17 if __name__ == '__main__': main() #19 ------------------------------------------------------------ #1: Not sure whether you're using Python 2 or 3. I ran this on Python 2.7 and think it will run on Python 3 if you remove this line. #7:The strip() method removes the '\n' characters from the end of the lines as well as any other extraneous leading or trailing whitespace. The split() method here breaks the line into two pieces on the whitespace in the middle. See http://docs.python.org/library/stdtypes.html#string-methods #11: This will create subdirectory 'dirname' relative to the current directory of course. See http://docs.python.org/library/os.html#os.mkdir #13: Usually, is is more portable to use os.path.join() to concatenate path components but since you stated you are on Linux (and "/" works on Windows too), creating the path with "/" is easier to follow in this example. For open() see http://docs.python.org/library/functions.html#open #15: Depending on your data, you might want to use the re (regular expression) module here if the simple string substitution is not sufficient. #16: For simplicity I just blindly replaced the " 1.5 " text in the string. Depending of your files, you might want to parameterize this of do something more robust or sophisticated. #17: Since we did not strip the trailing '\n' of the lines we read from "input.in", we use "end=''" to prevent print from adding an additional '\n'. See http://docs.python.org/library/functions.html#print #19: This line is required to actually get your python file to do anything. :-) Hope this gets you started. I think you will find doing this kind of thing in Python is much easier in the long run than with bash scripts. A decent resource for learning the basics of Python is the standard Python tutorial: http://docs.python.org/tutorial/index.html From emile at fenx.com Tue May 1 13:06:32 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 01 May 2012 10:06:32 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: > re.split(':|;|px', "width:150px;height:50px;float:right") You could recognize that the delimiter you want to strip is in fact px; and not px in and of itself. So, try: re.split(':|px;', "width:150px;height:50px;float:right") Emile From kiuhnm03.4t.yahoo.it Tue May 1 13:07:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 01 May 2012 19:07:58 +0200 Subject: syntax for code blocks In-Reply-To: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> On 5/1/2012 17:11, Steven D'Aprano wrote: >> My way >> ------ >> >> with func(some_args)<< ':dict': >> with when_odd as 'n': >> pass >> with when_prime as 'n': >> pass > > > If you actually try that, you will see that it cannot work. You get: > > SyntaxError: can't assign to literal If you had read the module's docstring you would know that the public version uses with when_odd << 'n': pass > Have you actually tried to use these code blocks of yours? I asked you > for a *working* example earlier, and you replied with examples that > failed with multiple NameErrors and no hint as to how to fix them. And > now you give an example that fails with SyntaxError. The examples I gave you work perfectly. It's clear that you don't even have the vaguest idea of how my module works or, otherwise, you'd know what you're doing wrong. Again, the module's docstring is your friend. > You have a bug in one or more of those callbacks. > > Of course you do -- all non-trivial software has bugs. The question is, > how are you going to find it? You can't unit-test the individual > callbacks, because they don't exist in a form that can be tested. It's easy to come up with a solution, in fact those functions /do/ exist. You would know that if you had read the documentation or even my reply to a post of yours. > So in this case, even though Python is slightly more verbose, and forces > you to have the discipline of writing named functions ahead of time, this > is actually a *good* thing because it encourages you to test them. > > If the callbacks are trivial functions, the Pythonic way is to use > lambdas: > > func(some_args, {'when_odd': lambda n: n-1, > 'when_prime': lambda n: n**2 - 1, > ...}) > > although I would discourage that unless they are *really* trivial. But > for callbacks of any complexity, they will need to be tested, otherwise > how do you know they do what you want them to do? > > Your code blocks make unit testing of the callbacks impossible, and for > that reason the Pythonic way is better. Talking with you is a real pain. You're always partial in your opinions and this urge of yours to criticize other's work makes you look dumb or hopefully just lazy. I can't stand people like you who don't even have the decency of taking the time to read the documentation of a project and just run their mouth without any concern for facts. What I can't stand is that if I won't reply to your posts other lazy people will believe the nonsense you say, but I'll have to live with that because I've wasted enough time with you. Kiuhnm From lamialily at cleverpun.com Tue May 1 13:10:16 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:10:16 -0700 Subject: Installing pygame on MacOS-X Lion with Python 3.3 In-Reply-To: References: Message-ID: <0160q792v36ve6nlecvav2jdor392grfdq@4ax.com> >I can't get it working : "No pygame module"... >Tried without success : >pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip >pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg > >I am using Python 3 last version on MacOS-X Lion. > >Where is a step-by-step installation procedure ? > >Thanks, > > franck That'd likely be because package installations are limited to the major and minor version they were built for. Those two packages, for example, were built for Python 2.7, which is significantly different from Python 3.3. I'm not seeing any 3.3 builds for Pygame *at all*, even for Windows, so you'd probably be best off moving to Python 2.7. You should be able to use Pygame freely then. ~Temia -- When on earth, do as the earthlings do. From lamialily at cleverpun.com Tue May 1 13:13:55 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:13:55 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> >> re.split(':|;|px', "width:150px;height:50px;float:right") > >You could recognize that the delimiter you want to strip is in fact px; >and not px in and of itself. > >So, try: > >re.split(':|px;', "width:150px;height:50px;float:right") > >Emile That won't work at all outside of the example case. It'd choke on any attribute seperator that didn't end in px. Honestly I'd recommend recovering the size measurement anyway, since there are pretty huge differences between each form of measurement in CSS. Seperating it from the number itself is fine and all since you probably still need to turn it into a number Python can use, but I wouldn't discard it outright. ~Temia -- When on earth, do as the earthlings do. From lamialily at cleverpun.com Tue May 1 13:31:13 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:31:13 -0700 Subject: syntax for code blocks In-Reply-To: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: Holy crap. Easy there, tiger. I understand you're frustrated, but the people here are trying to help, even if they've decided the means of helping is trying to explain why they feel your style of development isn't the best way to do things. You're going to wear out your welcome and not get any help at all if you go ballistic like that. :/ ~Temia -- When on earth, do as the earthlings do. From emile at fenx.com Tue May 1 13:36:46 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 01 May 2012 10:36:46 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> Message-ID: On 5/1/2012 10:13 AM Temia Eszteri said... >> re.split(':|px;', "width:150px;height:50px;float:right") >> >> Emile > > That won't work at all outside of the example case. It'd choke on any > attribute seperator that didn't end in px. It would certainly choke on all delimeters that are not presented in the argument. You're free to flavor to taste... Emile From malaclypse2 at gmail.com Tue May 1 13:39:29 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 1 May 2012 13:39:29 -0400 Subject: syntax for code blocks In-Reply-To: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On Tue, May 1, 2012 at 1:07 PM, Kiuhnm wrote: > If you had read the module's docstring you would know that the public > version uses Are you aware that you've never posted a link to your module, nor it's docstrings? Are you also aware that your module is essentially unfindable on google? Certainly nothing on the first two pages of google results for 'python codeblocks' jumps out at me as a python module of that name. Perhaps you would have better luck if you either post the actual code you want people to critique, or posted a link to that code. -- Jerry From tjreedy at udel.edu Tue May 1 13:51:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 May 2012 13:51:31 -0400 Subject: Sort comparison In-Reply-To: References: Message-ID: On 5/1/2012 1:25 AM, Dan Stromberg wrote: > Anyway, here's the comparison, with code and graph: > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > > (It's done in Pure python and Cython, with a little m4). > > Interesting, BTW, that an unstable quicksort in Cython was approaching > timsort as a C extension module in performance, even though timsort in > Cython wasn't that performant. It makes one wonder if a highly > optimized quicksort as a C extension module wouldn't outperform timsort > in the standard library. Timsort is not only stable, but, by design, it is faster than quicksort for various structured data patterns, many of which are realistic in practice. For instance, you append k unordered items to n already sorted items, where k << n, so that k*log(k) is on the order of n. Timsort discovers the initial run of n sorted items, sorts the k items, and then merges. The practical time is O(n). Ditto for sorting an already sorted file in the reverse direction (timsort does an O(n) list reverse). -- Terry Jan Reedy From arnodel at gmail.com Tue May 1 13:55:40 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 1 May 2012 18:55:40 +0100 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: (sent from my phone) On May 1, 2012 6:42 PM, "Jerry Hill" wrote: > > On Tue, May 1, 2012 at 1:07 PM, Kiuhnm > wrote: > > If you had read the module's docstring you would know that the public > > version uses > > Are you aware that you've never posted a link to your module, nor it's > docstrings? Are you also aware that your module is essentially > unfindable on google? Certainly nothing on the first two pages of > google results for 'python codeblocks' jumps out at me as a python > module of that name. > > Perhaps you would have better luck if you either post the actual code > you want people to critique, or posted a link to that code. He did post a link to a blog post describing his module and also a link to the actual code, on bitbucket IIRC. Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue May 1 14:00:50 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 11:00:50 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 12:21 AM, Ian Kelly wrote: > On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg > wrote: > > > > A while back I did a sort algorithm runtime comparison for a variety of > > sorting algorithms, and then mostly sat on it. > > > > Recently, I got into a discussion with someone on stackoverflow about the > > running time of radix sort. > > > > I realize it's commonly said that radixsort is n*k rather than n*log(n). > > I've been making that case that in real life, frequently k==log(n). > > > > Anyway, here's the comparison, with code and graph: > > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > > It can be difficult to distinguish O(n) from O(n log n) on a log-log > plot, so I don't think that graph makes your point very well. > Thank you for your comment. Do you have a suggestion for a better type of graph - or other linearity/nonlinearity test? I thought that on a log-log graph, a straight line was still a straight line, but it's compressed at one end. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 1 14:15:34 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 01 May 2012 11:15:34 -0700 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4FA02846.7050701@stoneleaf.us> Arnaud Delobelle wrote: > On May 1, 2012 6:42 PM, "Jerry Hill" wrote: >> On Tue, May 1, 2012 at 1:07 PM, Kiuhnm wrote: >>> If you had read the module's docstring you would know that the public >>> version uses >> >> Are you aware that you've never posted a link to your module, nor it's >> docstrings? Are you also aware that your module is essentially >> unfindable on google? Certainly nothing on the first two pages of >> google results for 'python codeblocks' jumps out at me as a python >> module of that name. >> >> Perhaps you would have better luck if you either post the actual code >> you want people to critique, or posted a link to that code. > > He did post a link to a blog post describing his module and also a link > to the actual code, on bitbucket IIRC. Actually, it was Ian Kelly that posted the blog reference. ~Ethan~ From drsalists at gmail.com Tue May 1 14:24:12 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 11:24:12 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 10:51 AM, Terry Reedy wrote: > On 5/1/2012 1:25 AM, Dan Stromberg wrote: > > Anyway, here's the comparison, with code and graph: >> http://stromberg.dnsalias.org/**~strombrg/sort-comparison/ >> >> (It's done in Pure python and Cython, with a little m4). >> >> Interesting, BTW, that an unstable quicksort in Cython was approaching >> timsort as a C extension module in performance, even though timsort in >> Cython wasn't that performant. It makes one wonder if a highly >> optimized quicksort as a C extension module wouldn't outperform timsort >> in the standard library. >> > > Timsort is not only stable, but, by design, it is faster than quicksort > for various structured data patterns, many of which are realistic in > practice. For instance, you append k unordered items to n already sorted > items, where k << n, so that k*log(k) is on the order of n. Timsort > discovers the initial run of n sorted items, sorts the k items, and then > merges. The practical time is O(n). Ditto for sorting an already sorted > file in the reverse direction (timsort does an O(n) list reverse). > Yeah, I know, but thanks for making sure I did. Timsort is a quite impressive algorithm. I suspect that the "sorting a mostly-sorted list in near-linear time" attribute of Timsort tends to encourage sorting in a loop though. Usually sorting inside a loop gives a slow algorithm, even with something as nice as Timsort. -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsboost at gmail.com Tue May 1 14:43:05 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:43:05 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <7xd36qdojc.fsf@ruckus.brouhaha.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 04/30/2012 02:57 AM, Paul Rubin wrote: > someone writes: >>> A is not just close to singular: it's singular! >> Ok. When do you define it to be singular, btw? > > Singular means the determinant is zero, i.e. the rows or columns > are not linearly independent. Let's give names to the three rows: > > a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. > > Then notice that c = 2*b - a. So c is linearly dependent on a and b. > Geometrically this means the three vectors are in the same plane, > so the matrix doesn't have an inverse. Oh, thak you very much for a good explanation. >>>> Which is the most accurate/best, even for such a bad matrix? > > What are you trying to do? If you are trying to calculate stuff > with matrices, you really should know some basic linear algebra. Actually I know some... I just didn't think so much about, before writing the question this as I should, I know theres also something like singular value decomposition that I think can help solve otherwise illposed problems, although I'm not an expert like others in this forum, I know for sure :-) From newsboost at gmail.com Tue May 1 14:49:29 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:49:29 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: On 05/01/2012 08:56 AM, Russ P. wrote: > On Apr 29, 5:17 pm, someone wrote: >> On 04/30/2012 12:39 AM, Kiuhnm wrote: >>> You should try to avoid matrix inversion altogether if that's the case. >>> For instance you shouldn't invert a matrix just to solve a linear system. >> >> What then? >> >> Cramer's rule? > > If you really want to know just about everything there is to know > about a matrix, take a look at its Singular Value Decomposition (SVD). I know a bit about SVD - I used it for a short period of time in Matlab, though I'm definately not an expert in it and I don't understand the whole theory with orthogality behind making it work so elegant as it is/does work out. > I've never used numpy, but I assume it can compute an SVD. I'm making my first steps now with numpy, so there's a lot I don't know and haven't tried with numpy... From newsboost at gmail.com Tue May 1 14:52:49 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:52:49 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: Message-ID: On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > On 04/29/2012 07:59 PM, someone wrote: > I do not use python much myself, but a quick google showed that pyhton > scipy has API for linalg, so use, which is from the documentation, the > following code example > > X = scipy.linalg.solve(A, B) > > But you still need to check the cond(). If it is too large, not good. > How large and all that, depends on the problem itself. But the rule of > thumb, the lower the better. Less than 100 can be good in general, but I > really can't give you a fixed number to use, as I am not an expert in > this subjects, others who know more about it might have better > recommendations. Ok, that's a number... Anyone wants to participate and do I hear something better than "less than 100 can be good in general" ? If I don't hear anything better, the limit is now 100... What's the limit in matlab (on the condition number of the matrices), by the way, before it comes up with a warning ??? From ian.g.kelly at gmail.com Tue May 1 14:52:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 May 2012 12:52:53 -0600 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 12:00 PM, Dan Stromberg wrote: > > On Tue, May 1, 2012 at 12:21 AM, Ian Kelly wrote: >> >> On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg >> wrote: >> > >> > A while back I did a sort algorithm runtime comparison for a variety of >> > sorting algorithms, and then mostly sat on it. >> > >> > Recently, I got into a discussion with someone on stackoverflow about >> > the >> > running time of radix sort. >> > >> > I realize it's commonly said that radixsort is n*k rather than n*log(n). >> > I've been making that case that in real life, frequently k==log(n). >> > >> > Anyway, here's the comparison, with code and graph: >> > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ >> >> It can be difficult to distinguish O(n) from O(n log n) on a log-log >> plot, so I don't think that graph makes your point very well. > > Thank you for your comment. > > Do you have a suggestion for a better type of graph - or other > linearity/nonlinearity test? An ordinary linear-scale graph. It will only show the highest order of magnitude in any detail, but for determining asymptotic behavior that's the most interesting part anyway. O(n) should look like a straight line, and O(n log n) should curve up with a gradually increasing slope. Alternatively, calculate regressions and compare the goodness of fit. > I thought that on a log-log graph, a straight line was still a straight > line, but it's compressed at one end. The key characteristic of a log-log plot is that any curve y = ax ** b will appear as a straight line with a slope of b. So a linear curve will be a straight line with a slope of 1. A O(n log n) curve will converge to a straight line with a slope of 1 as n approaches infinity. From ramit.prasad at jpmorgan.com Tue May 1 15:04:08 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 1 May 2012 19:04:08 +0000 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409301757@SCACMX008.exchad.jpmchase.net> >I'm making my first steps now with numpy, so there's a lot I don't know >and haven't tried with numpy... An excellent reason to subscribe to the numpy mailing list and talk on there :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From georg at python.org Tue May 1 15:43:13 2012 From: georg at python.org (Georg Brandl) Date: Tue, 01 May 2012 21:43:13 +0200 Subject: [RELEASED] Python 3.3.0 alpha 3 Message-ID: <4FA03CD1.7020605@python.org> On behalf of the Python development team, I'm happy to announce the third alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) is based on importlib by default * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * The new "faulthandler" module that helps diagnosing crashes * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From cjw at ncf.ca Tue May 1 15:59:17 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 01 May 2012 15:59:17 -0400 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 01/05/2012 2:43 PM, someone wrote: [snip] >> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >> >> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >> Geometrically this means the three vectors are in the same plane, >> so the matrix doesn't have an inverse. > Does it not mean that there are three parallel planes? Consider the example in two dimensional space. Colin W. [snip] From kbsals5179 at gmail.com Tue May 1 16:07:13 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 13:07:13 -0700 (PDT) Subject: Converting a string to list for submission to easygui multenterbox Message-ID: Please help a newbe. I have a string returned from an esygui multchoicebox that looks like this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to this: ['ksals', '', 'alsdkfj', '3', ''] This is so I can submit this to a multchoicebox with 5 fields From kbsals5179 at gmail.com Tue May 1 16:18:20 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 13:18:20 -0700 (PDT) Subject: =?UTF-8?Q?Converting_a_string_to_list_for_submission_to_easygu?= =?UTF-8?Q?i_multenterb=E2=80=8Box?= Message-ID: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Please help a newbe. I have a string returned from an esygui multchoicebox that looks like this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to this: ['ksals', '', 'alsdkfj', '3', ''] This is so I can submit this to a multenterbox with 5 fields From gordon at panix.com Tue May 1 16:26:53 2012 From: gordon at panix.com (John Gordon) Date: Tue, 1 May 2012 20:26:53 +0000 (UTC) Subject: =?UTF-8?Q?Converting_a_string_to_list_for_submission_to_easygu?= =?UTF-8?Q?i_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: In <316efebe-7f54-4054-96b1-51c7bb7b7b25 at f5g2000vbt.googlegroups.com> ksals writes: > Please help a newbe. I have a string returned from an esygui > multchoicebox that looks like > this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to > this: ['ksals', '', 'alsdkfj', '3', ''] That looks like a tuple which contains five strings. But you said it's a string, so I'll believe you. >>> x = "('ksals', '', 'alsdkfj', '3', '')" >>> print x ('ksals', '', 'alsdkfj', '3', '') >>> y = "[%s]" % x[1:-1] >>> print y ['ksals', '', 'alsdkfj', '3', ''] -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From kroger at pedrokroger.net Tue May 1 16:32:05 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Tue, 1 May 2012 17:32:05 -0300 Subject: =?utf-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?utf-8?Q?sygui_multenterb=E2=80=8Box?= In-Reply-To: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: Have you tried to use the function list?: foo = (1,2,3) list(foo) Cheers, Pedro -- http://pedrokroger.net On May 1, 2012, at 5:18 PM, ksals wrote: > Please help a newbe. I have a string returned from an esygui > multchoicebox that looks like > this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to > this: ['ksals', '', 'alsdkfj', '3', ''] > > This is so I can submit this to a multenterbox with 5 fields > > -- > http://mail.python.org/mailman/listinfo/python-list From russ.paielli at gmail.com Tue May 1 16:54:41 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 13:54:41 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: Message-ID: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> On May 1, 11:52?am, someone wrote: > On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > > > On 04/29/2012 07:59 PM, someone wrote: > > I do not use python much myself, but a quick google showed that pyhton > > scipy has API for linalg, so use, which is from the documentation, the > > following code example > > > X = scipy.linalg.solve(A, B) > > > But you still need to check the cond(). If it is too large, not good. > > How large and all that, depends on the problem itself. But the rule of > > thumb, the lower the better. Less than 100 can be good in general, but I > > really can't give you a fixed number to use, as I am not an expert in > > this subjects, others who know more about it might have better > > recommendations. > > Ok, that's a number... > > Anyone wants to participate and do I hear something better than "less > than 100 can be good in general" ? > > If I don't hear anything better, the limit is now 100... > > What's the limit in matlab (on the condition number of the matrices), by > the way, before it comes up with a warning ??? The threshold of acceptability really depends on the problem you are trying to solve. I haven't solved linear equations for a long time, but off hand, I would say that a condition number over 10 is questionable. A high condition number suggests that the selection of independent variables for the linear function you are trying to fit is not quite right. For a poorly conditioned matrix, your modeling function will be very sensitive to measurement noise and other sources of error, if applicable. If the condition number is 100, then any input on one particular axis gets magnified 100 times more than other inputs. Unless your inputs are very precise, that is probably not what you want. Or something like that. From kbsals5179 at gmail.com Tue May 1 17:09:52 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 14:09:52 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> On May 1, 4:26?pm, John Gordon wrote: > In <316efebe-7f54-4054-96b1-51c7bb7b7... at f5g2000vbt.googlegroups.com> ksals writes: > > > Please help a newbe. ?I have a string returned from an esygui > > multchoicebox that looks like > > ? this: ?('ksals', '', 'alsdkfj', '3', '') I need to convert this to > > ? this: ?['ksals', '', 'alsdkfj', '3', ''] > > That looks like a tuple which contains five strings. ?But you said it's > a string, so I'll believe you. > > >>> x = "('ksals', '', 'alsdkfj', '3', '')" > >>> print x > > ('ksals', '', 'alsdkfj', '3', '')>>> y = "[%s]" % x[1:-1] > >>> print y > > ['ksals', '', 'alsdkfj', '3', ''] > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Edward Gorey, "The Gashlycrumb Tinies" > > The original choice looks like this when I print it: print(choice) ('ksals', '', 'alsdkfj', '3', '') I need to submit these as defaults to a multenterbox. Each entry above ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. I tried your suggestion so you must be right it is a tuple of 5 strings. But I need them to work in an instruction like fieldValues = eg.multenterbox(msg1,title, fieldNames, choice) fieldNames has 5 fields. From newsboost at gmail.com Tue May 1 17:18:08 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 23:18:08 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 05/01/2012 09:59 PM, Colin J. Williams wrote: > On 01/05/2012 2:43 PM, someone wrote: > [snip] >>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >>> >>> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >>> Geometrically this means the three vectors are in the same plane, >>> so the matrix doesn't have an inverse. >> > > Does it not mean that there are three parallel planes? > > Consider the example in two dimensional space. I actually drawed it and saw it... It means that you can construct a 2D plane and all 3 vectors are in this 2D-plane... From newsboost at gmail.com Tue May 1 17:21:19 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 23:21:19 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 05/01/2012 10:54 PM, Russ P. wrote: > On May 1, 11:52 am, someone wrote: >> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: >> What's the limit in matlab (on the condition number of the matrices), by >> the way, before it comes up with a warning ??? > > The threshold of acceptability really depends on the problem you are > trying to solve. I haven't solved linear equations for a long time, > but off hand, I would say that a condition number over 10 is > questionable. Anyone knows the threshold for Matlab for warning when solving x=A\b ? I tried "edit slash" but this seems to be internal so I cannot see what criteria the warning is based upon... > A high condition number suggests that the selection of independent > variables for the linear function you are trying to fit is not quite > right. For a poorly conditioned matrix, your modeling function will be > very sensitive to measurement noise and other sources of error, if > applicable. If the condition number is 100, then any input on one > particular axis gets magnified 100 times more than other inputs. > Unless your inputs are very precise, that is probably not what you > want. > > Or something like that. Ok. So it's like a frequency-response-function, output divided by input... From gordon at panix.com Tue May 1 17:29:09 2012 From: gordon at panix.com (John Gordon) Date: Tue, 1 May 2012 21:29:09 +0000 (UTC) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 at d20g2000vbh.googlegroups.com> ksals writes: > The original choice looks like this when I print it: > print(choice) > ('ksals', '', 'alsdkfj', '3', '') > I need to submit these as defaults to a multenterbox. Each entry above > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > I tried your suggestion so you must be right it is a tuple of 5 > strings. But I need them to work in an instruction like > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > fieldNames has 5 fields. If you just need to convert a tuple to a list, that's easy. Call the built-in function list() and pass the tuple as an intializer: >>> choice = ('ksals', '', 'alsdkfj', '3', '') >>> print choice ('ksals', '', 'alsdkfj', '3', '') >>> choice_list = list(choice) >>> print choice_list ['ksals', '', 'alsdkfj', '3', ''] -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ramit.prasad at jpmorgan.com Tue May 1 17:35:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 1 May 2012 21:35:29 +0000 Subject: =?utf-8?B?UkU6IENvbnZlcnRpbmcgYSBzdHJpbmcgdG8gbGlzdCBmb3Igc3VibWlzc2lv?= =?utf-8?B?biB0byBlYXN5Z3VpIG11bHRlbnRlcmLigItveA==?= In-Reply-To: <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409301A7F@SCACMX008.exchad.jpmchase.net> > > That looks like a tuple which contains five strings. > The original choice looks like this when I print it: > > print(choice) > ('ksals', '', 'alsdkfj', '3', '') Based on the print statement, choice is a tuple or a string. try doing `print(type(choice))`. On the assumption it is a tuple and not a string you can convert it by doing: choice = list(choice) If it actually is a string I would do: choice = list( ast.literal_eval( choice ) ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From robert.kern at gmail.com Tue May 1 17:45:16 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 01 May 2012 22:45:16 +0100 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 5/1/12 10:21 PM, someone wrote: > On 05/01/2012 10:54 PM, Russ P. wrote: >> On May 1, 11:52 am, someone wrote: >>> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > >>> What's the limit in matlab (on the condition number of the matrices), by >>> the way, before it comes up with a warning ??? >> >> The threshold of acceptability really depends on the problem you are >> trying to solve. I haven't solved linear equations for a long time, >> but off hand, I would say that a condition number over 10 is >> questionable. > > Anyone knows the threshold for Matlab for warning when solving x=A\b ? I tried > "edit slash" but this seems to be internal so I cannot see what criteria the > warning is based upon... The documentation for that operator is here: http://www.mathworks.co.uk/help/techdoc/ref/mldivide.html -- 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 lkcl at lkcl.net Tue May 1 17:48:27 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Tue, 1 May 2012 22:48:27 +0100 Subject: pyjamas pyjs.org domain has been hijacked Message-ID: i have an apology to make to the python community. about 3 or 4 months ago a number of the pyjamas users became unhappy that i was sticking to software (libre) principles on the pyjamas project. they saw the long-term policy that i had set, of developing python-based pyjamas-based infrastructure (such as pygit) for pyjamas to become a demonstration of its own technology, as being unnecessarily restrictive, and for their convenience, they requested the use of non-free hosting services such as github, google groups and so on. i patiently explained why this was not acceptable as i am software (libre) developer, and advised them that if they wanted such services, perhaps they could help themselves to learn pyjamas and python by helping to improve the existing infrastructure, and that i would be happy to help them do so. many of them did not understand or accept. what i did not realise was happening, until it was announced a few hours ago, was that in the intervening time a number of the pyjamas users had got together to develop alternative infrastructure which makes use of non-free hosting facilities such as github, and that they also planned to hijack the pyjs.org domain... *without* consulting the 650 or so members on the pyjamasdev mailing list, or the python community at large. so this is rather embarrassing because i had just put out a request for help to the wider python community, with the pyjamas 0.8.1 release, when it turns out that 12 hours later the domain has been hijacked. my first apology therefore is this: i apologise to the python community for being a cause of disruption. the second apology is - if priority can ever be applied to apologies at all - is i feel somewhat more important. i am a free (libre) software developer, and i am a teacher, as many of you will know from the talks that i have given on pyjamas at various conferences. i lead by example, and it is not just free software development itself that i teach, but also free software principles. this was why i set the long-term policy that pyjamas should migrate to running on python-based server infrastructure and pyjamas-based web front-end applications, *even* for its own development, because the most fundamental way to teach is to lead by example. my apology is therefore for the disruption caused to the pyjamas project - and to the python community - as a direct consequence of me wishing to uphold software (libre) principles, and for using the pyjamas project as a way to do that. that may sound incredibly strange, especially to those people for whom software (libre) principles are something that they just accept, but it is a genuine apology, recognising that there are people for whom free software principles are not of sufficient importance to have their day-to-day development made inconvenient. i don't know what else to say, so i'll leave it at that. sorry folks. l. From kbsals5179 at gmail.com Tue May 1 17:50:51 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 14:50:51 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> On May 1, 5:29?pm, John Gordon wrote: > In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> ksals writes: > > > The original choice looks like this when I print it: > > print(choice) > > ('ksals', '', 'alsdkfj', '3', '') > > I need to submit these as defaults to a multenterbox. Each entry above > > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > > I tried your suggestion so you must be right it is a tuple of 5 > > strings. ?But I need them to work in an instruction like > > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > > fieldNames has 5 fields. > > If you just need to convert a tuple to a list, that's easy. ?Call the > built-in function list() and pass the tuple as an intializer: > > >>> choice = ('ksals', '', 'alsdkfj', '3', '') > >>> print choice > > ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) > >>> print choice_list > > ['ksals', '', 'alsdkfj', '3', ''] > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Edward Gorey, "The Gashlycrumb Tinies" > > This is a small excert to show you what I get for choice in easygui.multchoicebox(msg1, title,qstack): if choice[0] == None: print ("No entries made") break print("CHOICE IS: ",choice) ..... CHOICE IS: ('', 'ksals', '', '', '') c=list(choice) print("C IS: ",c) ..... C IS: ['(', "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", "'", ',', ' ', "'", "'", ',', ' ', "'", "'", ')'] From kiuhnm03.4t.yahoo.it Tue May 1 18:04:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 00:04:59 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: <4fa05e0a$0$1380$4fafbaef@reader2.news.tin.it> On 5/1/2012 21:59, Colin J. Williams wrote: > On 01/05/2012 2:43 PM, someone wrote: > [snip] >>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >>> >>> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >>> Geometrically this means the three vectors are in the same plane, >>> so the matrix doesn't have an inverse. >> > > Does it not mean that there are three parallel planes? They're not parallel because our matrix has rank 2, not 1. Anyway, have a look at this: http://en.wikipedia.org/wiki/Parallelepiped#Volume It follows that our matrix A whose rows are a, b and c represents a parallelepiped. If our vectors are collinear or coplanar, the parallelepiped is degenerate, i.e. has volume 0. The converse is also true. Kiuhnm From drsalists at gmail.com Tue May 1 18:19:34 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 15:19:34 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 11:52 AM, Ian Kelly wrote: > On Tue, May 1, 2012 at 12:00 PM, Dan Stromberg > wrote: > > > > On Tue, May 1, 2012 at 12:21 AM, Ian Kelly > wrote: > >> > >> On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg > >> wrote: > >> > > >> > A while back I did a sort algorithm runtime comparison for a variety > of > >> > sorting algorithms, and then mostly sat on it. > >> > > >> > Recently, I got into a discussion with someone on stackoverflow about > >> > the > >> > running time of radix sort. > >> > > >> > I realize it's commonly said that radixsort is n*k rather than > n*log(n). > >> > I've been making that case that in real life, frequently k==log(n). > >> > > >> > Anyway, here's the comparison, with code and graph: > >> > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > >> > >> It can be difficult to distinguish O(n) from O(n log n) on a log-log > >> plot, so I don't think that graph makes your point very well. > > > > Thank you for your comment. > > > > Do you have a suggestion for a better type of graph - or other > > linearity/nonlinearity test? > > An ordinary linear-scale graph. It will only show the highest order > of magnitude in any detail, but for determining asymptotic behavior > that's the most interesting part anyway. O(n) should look like a > straight line, and O(n log n) should curve up with a gradually > increasing slope. Alternatively, calculate regressions and compare > the goodness of fit. > > > I thought that on a log-log graph, a straight line was still a straight > > line, but it's compressed at one end. > > The key characteristic of a log-log plot is that any curve y = ax ** b > will appear as a straight line with a slope of b. So a linear curve > will be a straight line with a slope of 1. A O(n log n) curve will > converge to a straight line with a slope of 1 as n approaches > infinity. > Thanks for the info. I actually feel like both the log-log graph and the linear-linear graph, tell an interesting but different part of the story, so I've kept the log-log graph and added a linear-linear graph. I also added a linear-line to the linear-linear graph, for the sake of comparison. You can see that radix sort is falling between mergesort and quicksort (both nlogn on average), and radix sort is coming up almost parallel to mergesort. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue May 1 19:05:22 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 01 May 2012 16:05:22 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: <7x62cfv6x9.fsf@ruckus.brouhaha.com> someone writes: > Actually I know some... I just didn't think so much about, before > writing the question this as I should, I know theres also something > like singular value decomposition that I think can help solve > otherwise illposed problems, You will probably get better advice if you are able to describe what problem (ill-posed or otherwise) you are actually trying to solve. SVD just separates out the orthogonal and scaling parts of the transformation induced by a matrix. Whether that is of any use to you is unclear since you don't say what you're trying to do. From irmen at -NOSPAM-razorvine.net Tue May 1 19:26:46 2012 From: irmen at -NOSPAM-razorvine.net (Irmen de Jong) Date: Wed, 02 May 2012 01:26:46 +0200 Subject: Create directories and modify files with Python In-Reply-To: <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> On 1-5-2012 12:51, deltaquattro at gmail.com wrote: >> But if you really want to go this way (and hey, why not) then first >> you'll have to learn some basic Python. A good resource for this >> might be: http://learnpythonthehardway.org/ > > Ehm...name's not exactly inspiring for a newbie who's short on time > :) It's just a name. That resource is generally regarded as one of the better books to learn Python for total beginners. If you can program already in another language, the standard Python tutorial might be more efficient to start from: http://docs.python.org/tutorial/ > Thanks for the directions. By the way, can you see my post in Google > Groups? I'm not able to, and I don't know why. I don't use Google groups. I much prefer a proper news agent to read my usenet newsgroups. Irmen From cs at zip.com.au Tue May 1 19:29:34 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 May 2012 09:29:34 +1000 Subject: Converting a string to =?utf-8?Q?list_?= =?utf-8?Q?for_submission_to_easygui_multenterb=E2=80=8Box?= In-Reply-To: References: Message-ID: <20120501232934.GA12072@cskk.homeip.net> Disclaimer: I have never used esygui. On 01May2012 21:29, John Gordon wrote: | In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 at d20g2000vbh.googlegroups.com> ksals writes: | > The original choice looks like this when I print it: | | > print(choice) | > ('ksals', '', 'alsdkfj', '3', '') That's just print() printing a tuple. | > I need to submit these as defaults to a multenterbox. Each entry above | > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. | > I tried your suggestion so you must be right it is a tuple of 5 | > strings. But I need them to work in an instruction like | > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) | > fieldNames has 5 fields. | | If you just need to convert a tuple to a list, that's easy. Call the | built-in function list() and pass the tuple as an intializer: Supposedly he should not need to. From: http://www.ferg.org/easygui/tutorial.html#contents_item_10.2 the sentence: "The choices are specified in a sequence (a tuple or a list)." I do not believe that ksals needs to change anything. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Uh, this is only temporary...unless it works. - Red Green From cs at zip.com.au Tue May 1 19:36:30 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 May 2012 09:36:30 +1000 Subject: Converting a string to =?utf-8?Q?list_?= =?utf-8?Q?for_submission_to_easygui_multenterb=E2=80=8Box?= In-Reply-To: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> References: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> Message-ID: <20120501233630.GA12405@cskk.homeip.net> The tutorial suggests multchoicebox returns an interable of chosen items, in fact probably a seqeunce. So... On 01May2012 14:50, ksals wrote: | This is a small excert to show you what I get | | for choice in easygui.multchoicebox(msg1, title,qstack): | if choice[0] == None: | print ("No entries made") | break This is the wrong test. "choice" is | print("CHOICE IS: ",choice) ..... CHOICE IS: | ('', 'ksals', '', '', '') Does this really happen? This code associated with the for loop? I'd expect easygui.multchoicebox to return a list (or tuple) and "choice" to be a single string from the list. Did your print() call happen after the quoted "for" loop or after a statement like this? choice = easygui.multchoicebox(msg1, title, qstack) | c=list(choice) | print("C IS: ",c) ..... C IS: ['(', | "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", | "'", ',', ' ', "'", "'", ',', ' ', "'", "'", | ')'] Ok, that really does look like "choice" is a string. I'm really very surprised. What does this do? choices = easygui.multchoicebox(msg1, title, qstack) print("type(choices) =", type(choices)) print("choices =", repr(choices)) Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you lie to the compiler, it will get its revenge. - Henry Spencer From russ.paielli at gmail.com Tue May 1 19:38:56 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 16:38:56 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> On May 1, 4:05?pm, Paul Rubin wrote: > someone writes: > > Actually I know some... I just didn't think so much about, before > > writing the question this as I should, I know theres also something > > like singular value decomposition that I think can help solve > > otherwise illposed problems, > > You will probably get better advice if you are able to describe what > problem (ill-posed or otherwise) you are actually trying to solve. ?SVD > just separates out the orthogonal and scaling parts of the > transformation induced by a matrix. ?Whether that is of any use to you > is unclear since you don't say what you're trying to do. I agree with the first sentence, but I take slight issue with the word "just" in the second. The "orthogonal" part of the transformation is non-distorting, but the "scaling" part essentially distorts the space. At least that's how I think about it. The larger the ratio between the largest and smallest singular value, the more distortion there is. SVD may or may not be the best choice for the final algorithm, but it is useful for visualizing the transformation you are applying. It can provide clues about the quality of the selection of independent variables, state variables, or inputs. From steve+comp.lang.python at pearwood.info Tue May 1 20:09:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 00:09:07 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 19:07:58 +0200, Kiuhnm wrote: > On 5/1/2012 17:11, Steven D'Aprano wrote: >>> My way >>> ------ >>> >>> with func(some_args)<< ':dict': >>> with when_odd as 'n': >>> pass >>> with when_prime as 'n': >>> pass >> >> >> If you actually try that, you will see that it cannot work. You get: >> >> SyntaxError: can't assign to literal > > If you had read the module's docstring What module? > you would know that the public version uses > with when_odd << 'n': > pass Then why didn't you write that instead of something that gives SyntaxError? Not once, but EIGHT times. >> Have you actually tried to use these code blocks of yours? I asked you >> for a *working* example earlier, and you replied with examples that >> failed with multiple NameErrors and no hint as to how to fix them. And >> now you give an example that fails with SyntaxError. > > The examples I gave you work perfectly. Except they don't. Look, this isn't difficult. I asked for *working* examples, you gave examples that give NameError. Some of those errors are easy to fix, e.g. by importing the random and re modules. Some of them aren't. What are "ris", "repl", "_return", "sorted1", "key"? Where do they come from? What value should I give them to make your code work? Code doesn't magically start to work because you declare that it does. Anyone who takes the time to copy and paste your examples into a fresh Python interactive session will see that they don't. Here's one of your earlier examples. I've removed the unnecessary indentation and made the obvious import, so all it takes to run it is to copy it and paste into the Python prompt: import random numbers = [random.randint(1, 100) for i in range(30)] with sorted1 << sorted(numbers) << key << 'x': if x <= 50: _return(-x) else: _return(x) print(sorted1) If you try it, you get NameError: name 'sorted1' is not defined Fix that (how?) and you'll get another NameError, for 'key', and then a third, for '_return'. The syntax isn't very clear. If I had to guess what it does, I'd predict that maybe it sorts the random list and negates everything <= 50, e.g. given input [5, 99, 34, 88, 70, 2] it returns [-2, -5, -34, 70, 88, 99]. Obviously that's wrong. You say it should return [34, 5, 2, 70, 88, 99]. The Pythonic way to get that result is: import random numbers = [random.randint(1, 100) for i in range(30)] sorted(numbers, key=lambda x: -x if x <= 50 else x) which is much more straightforward and obvious than yours, and presumably much faster. So even if I could get your example working, it would not be very persuasive. > It's clear that you don't even > have the vaguest idea of how my module works or, otherwise, you'd know > what you're doing wrong. Well duh. What module? Where do I find it? How am I supposed to know what this module is when you haven't mentioned it? Believe it or not, the world does not revolve around you. We cannot see what is in your head. If we ask for a WORKING EXAMPLE, you need to give an example that includes EVERYTHING necessary to make it work. [...] > Talking with you is a real pain. You're always partial in your opinions > and this urge of yours to criticize other's work makes you look dumb or > hopefully just lazy. > I can't stand people like you who don't even have the decency of taking > the time to read the documentation of a project and just run their mouth > without any concern for facts. What project? You're the one who doesn't tell us what project we're supposed to use, and yet *I'm* the dumb one. This is comedy gold. > What I can't stand is that if I won't reply to your posts other lazy > people will believe the nonsense you say, but I'll have to live with > that because I've wasted enough time with you. Whatever man. It's no skin off my nose. I've tried really hard to give your proposal a fair go, but my care factor is rapidly running out if you can't even be bothered to ensure your examples use legal Python syntax. -- Steven From lkcl at lkcl.net Tue May 1 21:29:03 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 2 May 2012 02:29:03 +0100 Subject: pyjamas pyjs.org domain has been hijacked In-Reply-To: References: Message-ID: ... i'm reeally really sorry about this, but it suddenly dawned on me that, under UK law, a breach of the UK's data protection act has occurred, and that the people responsible for setting up the hijacked services have committed a criminal offense under UK law. ordinarily, a free software mailing list would be transferred to alternative services through the process of soliciting the users to enter into an implicit contract over a legally-enforceable reasonable amount of time, as follows: "in 30 days we will move the mailing list. anyone who doesn't want their personal data moved to the new server please say so". unfortunately, in this case, i have to advise that no such announcement had been made. although i gave permission to one of the people who has hijacked the domain my permission to aid and assist in the administration of the server, i did NOT give them permission to do anything else. unfortunately, they then abused the trust placed in them in order to gain unauthorised access to the machine. in this way, the data (ssh keys and user's email addresses) was copied WITHOUT my express permission (constituting unauthorised computer access and misuse of a computer), but worse than that WITHOUT the permission of the users who "own" their data (ssh keys and email addresses). as it's 2am here in the UK and also i will be travelling for the next couple of days, and also to preserve the state of the machine as evidence, i have had to shut down the XEN instance and will not be in a convenient position to access the email addresses in order to directly notify the users of the UK Data Protection Act breach. so for now, this announcement (to the python list, of all places) will have to do. for which i apologise, again, for having to inconvenience others who may not be interested in what has transpired. but to all concerned i apologise again, deeply, for putting everyone to trouble just because i decided to stick to free software principles. strange as that sounds. i honestly didn't see this coming. l. From wuwei23 at gmail.com Tue May 1 22:22:23 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:22:23 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <84384967-6a17-4e21-9438-95619dc4f65d@sm5g2000pbc.googlegroups.com> On May 2, 12:18?am, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Neither does "Kiuhnm prefers it". > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ? ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ? ?pass > > def when_prime(n): > ? ? ?pass > > def before_check(): > ? ? ?pass > > def after_check(): > ? ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? ? 'after_check' : after_check}) I'm sorry, when would you _ever_ do this? Why are you naming the functions twice? If you're passing in a dynamic set of functions, you'd _never know the names_, so my guess is you'd be iterating across it. If you _do_ know the names, why aren't you accessing them directly from the surrounding scope? Why aren't you including them in the function signature? Presenting bad examples as the Pythonic approach is a bit of a straw man. > My way > ------ > > with func(some_args) << ':dict': > ? ? ?with when_odd as 'n': > ? ? ? ? ?pass > ? ? ?with when_prime as 'n': > ? ? ? ? ?pass > ? ? ?with before_check as '': > ? ? ? ? ?pass > ? ? ?with after_check as '': > ? ? ? ? ?pass I'm not sure what value your code blocks really provide. 1. You're effectively making "with when_odd as 'n'" mean "def when_odd(n)" 2. The 'with code_block_name as arguments' syntax is unintuitive, to say the least. Personally, I don't see what value it provides over something more explicit and standard: def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func, arg): def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass I couldn't think of a name for the context manager...but I can't really think of a use for it either, so that seems fair. Actually, here's an even simpler example. In this case, the context manager doesn't have to interrogate the surrounding stack, but the function call itself is then explicit. class FOO(object): def __init__(self, fn): self.fn = fn def __enter__(self): return self.fn def __exit__(self, exc_type, exc_value, traceback): pass def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func) as f: def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass f(1) But again _what do you gain from this_ other than an extra layer of unnecessary complexity. From ben+python at benfinney.id.au Tue May 1 22:31:55 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 02 May 2012 12:31:55 +1000 Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87aa1r8g9w.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 01 May 2012 19:07:58 +0200, Kiuhnm wrote: > > [entitled demands] > Believe it or not, the world does not revolve around you. We cannot > see what is in your head. If we ask for a WORKING EXAMPLE, you need to > give an example that includes EVERYTHING necessary to make it work. To forestall the next obvious but wrong response: no, this is not asking to see a massive complicated module dumped on us to pore over. The term missing from Steven's request is ?minimal?. When presenting code for examination by others, we request that you present a complete, minimal, working example. Complete, so that we can take what you present and use it without guessing (likely incorrect guesses) what extra bits you did. Minimal, so that it contains *only* what is needed to demonstrate what you're trying to communicate. Yes, this probably means writing an example specifically to present to us; tough, the job falls to you if you want us to spend time on your issue. Working example: so that it actually does what you say it does, and we can verify that directly instead of speculating. > [...] > > Talking with you is a real pain. You're always partial in your > > opinions and this urge of yours to criticize other's work makes you > > look dumb or hopefully just lazy. Sometimes one side of a disagreement is just incorrect, and in those cases it's good to be partial in one's opinions and to criticise on the facts. You have entered may people's kill files, including mine, because of this inability to take criticism and this tendency to insult others baselessly. -- \ ?Holy unrefillable prescriptions, Batman!? ?Robin | `\ | _o__) | Ben Finney From wuwei23 at gmail.com Tue May 1 22:43:57 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:43:57 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: [Apologies in advance if this comes through twice] On May 2, 12:18?am, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Nor does it mean "Kiuhnm prefers it". > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ? ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ? ?pass > > def when_prime(n): > ? ? ?pass > > def before_check(): > ? ? ?pass > > def after_check(): > ? ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? ? 'after_check' : after_check}) When would you _ever_ define a function like this? Why are you passing in _named_ callbacks? Are you calling them by name? Then declare them in the function signature and rely on scoping. Does func() branch on existent keys? Then don't write code like that. At the very _least_, you could change the function call to: func(some_args, locals()) But as you're _passing them in by name_ why not just make it func(some_args) and pick them up out of the scope. _No one_ writes Python code like this. Presenting bad code as "pythonic" is a bit of a straw man. > My way > ------ > > with func(some_args) << ':dict': > ? ? ?with when_odd as 'n': > ? ? ? ? ?pass > ? ? ?with when_prime as 'n': > ? ? ? ? ?pass > ? ? ?with before_check as '': > ? ? ? ? ?pass > ? ? ?with after_check as '': > ? ? ? ? ?pass This is unintuitive, to say the least. You're effectively replacing the common form of function definition with "with when_odd as 'n'", then using the surrounding context manager to limit the scope. More importantly, _you're naming your "anonymous" code blocks_, I'm guessing so that func() can choose which ones to use. But if you're naming them, why not just use a function? I'm not entirely sure what your 'solution' offers over something like: class FOO(object): def __init__(self, fn): self.fn = fn def __enter__(self): return self.fn def __exit__(self, exc_type, exc_value, traceback): pass def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func) as f: def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass f(1) I called the context manager FOO because I couldn't think of a more appropriate name (contextscope?)...which is fair, as I can't think of a use for it either. If you want to automate the function call at the context manager exit, use something like this instead: class FOO(object): def __init__(self, fn, *args, **kwargs): self.fn = fn self.args = args self.kwargs = kwargs def __enter__(self): f = inspect.currentframe(1) self.scope_before = dict(f.f_locals) def __exit__(self, exc_type, exc_value, traceback): f = inspect.currentframe(1) scope_after = dict(f.f_locals) scope_context = set(scope_after) - set(self.scope_before) clocals = dict( [(k, scope_after[k]) for k in scope_context] ) self.kwargs.update(clocals) self.fn(*self.args, **self.kwargs) Maybe there is a compelling use case for code blocks but your toy example certainly isn't it. From wuwei23 at gmail.com Tue May 1 22:50:46 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:50:46 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On May 2, 12:43?pm, alex23 wrote: > I'm not entirely sure what your 'solution' offers over something like: > > class FOO(object): > ? ? def __init__(self, fn): > ? ? ? ? self.fn = fn > > ? ? def __enter__(self): > ? ? ? ? return self.fn > > ? ? def __exit__(self, exc_type, exc_value, traceback): > ? ? ? ? pass > > def func(x, before_check=None, after_check=None, when_odd=None, > when_prime=None): > ? ? pass Sorry, the func definition was meant to be: def func(x): # before_check, after_check, when_odd, when_prime used internally pass From samuelmarks at gmail.com Wed May 2 00:11:04 2012 From: samuelmarks at gmail.com (samuelmarks at gmail.com) Date: Tue, 1 May 2012 21:11:04 -0700 (PDT) Subject: Designing and Building an API converter Message-ID: <33200364.1541.1335931864469.JavaMail.geo-discussion-forums@pbgg7> How would I go about building an API converter? I have multiple different APIs with different schemas serialised in XML or JSON which I need to output as a standardised schema. Other features needed: - Authentication (i.e.: can't get/set data unless you're from a certain DNS xor have the correct user+pass) - Role/Scope limitation (i.e.: you can't access everything in our database, only what your role allows for) Is this the sort of problem I would use Slumber (http://slumber.in/) for? Or would there be a different library you'd recommend? Thanks for all suggestions, Alec Taylor From newsboost at gmail.com Wed May 2 02:00:44 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 08:00:44 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <7x62cfv6x9.fsf@ruckus.brouhaha.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: On 05/02/2012 01:05 AM, Paul Rubin wrote: > someone writes: >> Actually I know some... I just didn't think so much about, before >> writing the question this as I should, I know theres also something >> like singular value decomposition that I think can help solve >> otherwise illposed problems, > > You will probably get better advice if you are able to describe what > problem (ill-posed or otherwise) you are actually trying to solve. SVD I don't understand what else I should write. I gave the singular matrix and that's it. Nothing more is to say about this problem, except it would be nice to learn some things for future use (for instance understanding SVD more - perhaps someone geometrically can explain SVD, that'll be really nice, I hope)... > just separates out the orthogonal and scaling parts of the > transformation induced by a matrix. Whether that is of any use to you > is unclear since you don't say what you're trying to do. Still, I dont think I completely understand SVD. SVD (at least in Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I would better understand it with geometric examples, if one would be so kind to maybe write something about that... I can plot 3D vectors in matlab, very easily so maybe I better understand SVD if I hear/read the geometric explanation (references to textbook/similar is also appreciated). From newsboost at gmail.com Wed May 2 02:03:17 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 08:03:17 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On 05/02/2012 01:38 AM, Russ P. wrote: > On May 1, 4:05 pm, Paul Rubin wrote: >> someone writes: >>> Actually I know some... I just didn't think so much about, before >>> writing the question this as I should, I know theres also something >>> like singular value decomposition that I think can help solve >>> otherwise illposed problems, >> >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD >> just separates out the orthogonal and scaling parts of the >> transformation induced by a matrix. Whether that is of any use to you >> is unclear since you don't say what you're trying to do. > > I agree with the first sentence, but I take slight issue with the word > "just" in the second. The "orthogonal" part of the transformation is > non-distorting, but the "scaling" part essentially distorts the space. > At least that's how I think about it. The larger the ratio between the > largest and smallest singular value, the more distortion there is. SVD > may or may not be the best choice for the final algorithm, but it is > useful for visualizing the transformation you are applying. It can > provide clues about the quality of the selection of independent > variables, state variables, or inputs. Me would like to hear more! :-) It would really appreciate if anyone could maybe post a simple SVD example and tell what the vectors from the SVD represents geometrically / visually, because I don't understand it good enough and I'm sure it's very important, when it comes to solving matrix systems... From silideba at gmail.com Wed May 2 02:25:15 2012 From: silideba at gmail.com (Debashish Saha) Date: Wed, 2 May 2012 11:55:15 +0530 Subject: linux Message-ID: can anyone say me how to subscribe linux mailing list like 'python mailing list'. Actually i want to post question there. From russ.paielli at gmail.com Wed May 2 02:36:32 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 23:36:32 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On May 1, 11:03?pm, someone wrote: > On 05/02/2012 01:38 AM, Russ P. wrote: > > > > > > > > > > > On May 1, 4:05 pm, Paul Rubin ?wrote: > >> someone ?writes: > >>> Actually I know some... I just didn't think so much about, before > >>> writing the question this as I should, I know theres also something > >>> like singular value decomposition that I think can help solve > >>> otherwise illposed problems, > > >> You will probably get better advice if you are able to describe what > >> problem (ill-posed or otherwise) you are actually trying to solve. ?SVD > >> just separates out the orthogonal and scaling parts of the > >> transformation induced by a matrix. ?Whether that is of any use to you > >> is unclear since you don't say what you're trying to do. > > > I agree with the first sentence, but I take slight issue with the word > > "just" in the second. The "orthogonal" part of the transformation is > > non-distorting, but the "scaling" part essentially distorts the space. > > At least that's how I think about it. The larger the ratio between the > > largest and smallest singular value, the more distortion there is. SVD > > may or may not be the best choice for the final algorithm, but it is > > useful for visualizing the transformation you are applying. It can > > provide clues about the quality of the selection of independent > > variables, state variables, or inputs. > > Me would like to hear more! :-) > > It would really appreciate if anyone could maybe post a simple SVD > example and tell what the vectors from the SVD represents geometrically > / visually, because I don't understand it good enough and I'm sure it's > very important, when it comes to solving matrix systems... SVD is perhaps the ultimate matrix decomposition and the ultimate tool for linear analysis. Google it and take a look at the excellent Wikipedia page on it. I would be wasting my time if I tried to compete with that. To really appreciate the SVD, you need some background in linear algebra. In particular, you need to understand orthogonal transformations. Think about a standard 3D Cartesian coordinate frame. A rotation of the coordinate frame is an orthogonal transformation of coordinates. The original frame and the new frame are both orthogonal. A vector in one frame is converted to the other frame by multiplying by an orthogonal matrix. The main feature of an orthogonal matrix is that its transpose is its inverse (hence the inverse is trivial to compute). The SVD can be thought of as factoring any linear transformation into a rotation, then a scaling, followed by another rotation. The scaling is represented by the middle matrix of the transformation, which is a diagonal matrix of the same dimensions as the original matrix. The singular values can be read off of the diagonal. If any of them are zero, then the original matrix is singular. If the ratio of the largest to smallest singular value is large, then the original matrix is said to be poorly conditioned. Standard Cartesian coordinate frames are orthogonal. Imagine an x-y coordinate frame in which the axes are not orthogonal. Such a coordinate frame is possible, but they are rarely used. If the axes are parallel, the coordinate frame will be singular and will basically reduce to one-dimensional. If the x and y axes are nearly parallel, the coordinate frame could still be used in theory, but it will be poorly conditioned. You will need large numbers to represent points fairly close to the origin, and small deviations will translate into large changes in coordinate values. That can lead to problems due to numerical roundoff errors and other kinds of errors. --Russ P. From rustompmody at gmail.com Wed May 2 02:37:07 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 1 May 2012 23:37:07 -0700 (PDT) Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: <137f4c31-dbab-4a0d-b96c-476fdc61a0cd@e9g2000yqm.googlegroups.com> On May 1, 9:50?am, deuteros wrote: > I'm using regular expressions to split a string using multiple delimiters. > But if two or more of my delimiters occur next to each other in the > string, it puts an empty string in the resulting list. For example: > > ? ? ? ? re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ? ? ? ? ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? Are you parsing css? If so have you tried things like cssutils http://cthedot.de/cssutils/? [There are other such... And I dont know which is best...] From jpiitula at ling.helsinki.fi Wed May 2 02:42:10 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 02 May 2012 09:42:10 +0300 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: "someone" writes: > except it would be nice to learn some things for future use (for > instance understanding SVD more - perhaps someone geometrically can > explain SVD, that'll be really nice, I hope)... The Wikipedia article looks promising to me: Lots in it, with annotated links to more, including a song. From rosuav at gmail.com Wed May 2 03:25:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 17:25:09 +1000 Subject: linux In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 4:25 PM, Debashish Saha wrote: > can anyone say me how to subscribe linux mailing list like 'python > mailing list'. Actually i want to post question there. Search the web, you'll find something. ChrisA From lamialily at cleverpun.com Wed May 2 03:39:50 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 02 May 2012 00:39:50 -0700 Subject: linux In-Reply-To: References: Message-ID: >can anyone say me how to subscribe linux mailing list like 'python >mailing list'. Actually i want to post question there. It'd probably be best to visit the mailing list (if any) for the distribution that you're using in particular. Odds are any such mailing list would be available on the distro's site. ~Temia -- When on earth, do as the earthlings do. From no.email at nospam.invalid Wed May 2 03:56:31 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 00:56:31 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <7xpqanc8y8.fsf@ruckus.brouhaha.com> someone writes: >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD > I don't understand what else I should write. I gave the singular > matrix and that's it. Nothing more is to say about this problem, You could write what your application is. What do the numbers in that matrix actually represent? > except it would be nice to learn some things for future use (for > instance understanding SVD more The Wikipedia article about SVD is pretty good. > Still, I dont think I completely understand SVD. SVD (at least in > Matlab) returns 3 matrices, one is a diagonal matrix I think. Yes. Two diagonal matrices and a unitary matrix. The diagonal matrices have the singular values which are the magnitudes of the matrix's eigenvalues. A matrix (for simplicity consider it to have nonzero determinant) represents a linear transformation in space. Think of a bunch of vectors as arrows sticking out of the origin in different directions, and consider what happens to them if you use the matrix to act on all of them at once. You could break the transformation into 3 steps: 1) scale the axes by suitable amounts, so all the vectors stretch or shrink depending on their directions. 2) Rotate all the vectors without changing their lengths, through some combination of angles; 3) undo the scaling transformation so that the vectors get their original lengths back. Each of these 3 steps can be described by a matrix and the 3 matrices are what SVD calculates. I still don't have any idea whether this info is going to do you any good. There are some quite knowledgeable numerics folks here (I'm not one) who can probably be of more help, but frankly your questions don't make a whole lot of sense. You might get the book "Numerical Recipes" which is old but instructive. Maybe someone else here has other recommendations. From no.email at nospam.invalid Wed May 2 03:57:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 00:57:59 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: <7xlilbc8vs.fsf@ruckus.brouhaha.com> "Russ P." writes: > The SVD can be thought of as factoring any linear transformation into > a rotation, then a scaling, followed by another rotation. Ah yes, my description was backwards, sorry. From alec.taylor6 at gmail.com Wed May 2 05:19:43 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 2 May 2012 19:19:43 +1000 Subject: How would I go about building an API converter? Message-ID: I have multiple different APIs with different schemas serialised in XML or JSON which I need to output as a standardised schema. Main features needed: - *Serialisation to XML and JSON* - *Authentication* - I.e.: can't get/set data unless you have the correct user+pass - *Role/Scope limitation* - I.e.: you can't access everything in our database, only what your role allows for - *Get/set (conversion) between different schemas* - I.e.: No matter the input API, you can get it formatted in whichever output API you request Is this the sort of problem Slumber with TastyPiewould be best for? Or are there a different libraries you'd recommend? Thanks for all suggestions, Alec Taylor -------------- next part -------------- An HTML attachment was scrubbed... URL: From faulksp at iinet.net.au Wed May 2 05:24:46 2012 From: faulksp at iinet.net.au (Peter Faulks) Date: Wed, 02 May 2012 19:24:46 +1000 Subject: The amazing disappearing stderr Message-ID: <4FA0FD5E.10804@iinet.net.au> G'day All, Following on from my earlier query on overloading print().... I've come up with this: /* < stdcallbk.pyd > */ /*---------------stdcallbk.h---------------------*/ #ifndef STDCALLBK_MODULE_H #include #define STDCALLBK_MODULE_H // Type definition for the callback function. typedef void __stdcall(CALLBK_FUNC_T)(const char* p); #ifdef __cplusplus extern "C" { #endif void register_callback(CALLBK_FUNC_T* callback); void import_stdcallbk(void); #ifdef __cplusplus } #endif #endif /* #define STDCALLBK_MODULE_H */ /*---------------stdcallbk.c---------------------*/ #include "stdcallbk_module.h" static CALLBK_FUNC_T *callback_write_func = NULL; static FILE *fp; /*for debugging*/ static PyObject* g_stdout; typedef struct { PyObject_HEAD CALLBK_FUNC_T *write; } Stdout; static PyObject* write2(PyObject* self, PyObject* args) { const char* p; if (!PyArg_ParseTuple(args, "s", &p)) return NULL; fputs(p, fp); fflush(fp); if(callback_write_func) callback_write_func(p); else printf("----%s----", p); return PyLong_FromLong(strlen(p)); } static PyObject* flush2(PyObject* self, PyObject* args) { // no-op return Py_BuildValue(""); } static PyMethodDef Stdout_methods[] = { {"write", write2, METH_VARARGS, "sys-stdout-write"}, {"flush", flush2, METH_VARARGS, "sys-stdout-write"}, {NULL, NULL, 0, NULL} }; static PyTypeObject StdoutType = { PyVarObject_HEAD_INIT(0, 0) "stdcallbk.StdoutType", /* tp_name */ sizeof(Stdout), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ "stdcallbk.Stdout objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ Stdout_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; static struct PyModuleDef stdcallbkmodule = { PyModuleDef_HEAD_INIT, "stdcallbk", /* name of module */ NULL, /* module documentation, may be NULL */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ NULL, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_stdcallbk(void) { PyObject* m; fp = fopen("debuggered.txt", "wt"); fputs("got to here Vers 12\n", fp); fflush(fp); StdoutType.tp_new = PyType_GenericNew; if (PyType_Ready(&StdoutType) < 0) return 0; m = PyModule_Create(&stdcallbkmodule); if (m) { Py_INCREF(&StdoutType); PyModule_AddObject(m, "Stdout", (PyObject*) &StdoutType); fputs("PyModule_AddObject() Called\n", fp); fflush(fp); } g_stdout = StdoutType.tp_new(&StdoutType, 0, 0); /*PySys_SetObject("stdout", g_stdout)*/ fprintf(fp, "PySys_SetObject(stdout) returned %d\n", PySys_SetObject("stdout", g_stdout)); fflush(fp); /*PySys_SetObject("stderr", g_stdout)*/ fprintf(fp, "PySys_SetObject(stderr) returned %d\n", PySys_SetObject("stderr", g_stdout)); fflush(fp); return m; } /* called by cpp exe _after_ Py_Initialize(); */ void __declspec(dllexport) import_stdcallbk(void) { PyImport_ImportModule("stdcallbk"); } /* called by cpp exe _before_ Py_Initialize(); */ void __declspec(dllexport) register_callback(CALLBK_FUNC_T* callback) { PyImport_AppendInittab("stdcallbk", &PyInit_stdcallbk); callback_write_func = callback; } /* < /stdcallbk.pyd > */ /*------------- Embarcadero C++ Builder exe ---------------------*/ #include "/py_module/stdcallbk_module.h" void __stdcall callback_write_func(const char* p) { ShowMessage(p); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { PyObject *pName, *pModule; register_callback(callback_write_func); Py_Initialize(); import_stdcallbk(); //PyRun_SimpleString("import stdcallbk\n"); pName = PyUnicode_FromString("hello_emb.py"); pModule = PyImport_Import(pName); Py_Finalize(); } //--------------------------------------------------------------------------- -------------- python script - hello_emb.py ---------------- #import stdcallbk print("HELLO FRED !") assert 1==2 ------------------------------------------------------------ When run from the cpp exe, I get a messagebox "HELLO FRED!" followed by an empty message box which I assume is the carriage return. All good so far, but when the exception is raised, I get nothing. Nothing is written to the text file either. But... if I uncomment the "import stdcallbk" from the python script and run it from the command line, I get this: D:\projects\embed_python3\Win32\Debug>hello_emb.py ----HELLO FRED !-------- --------Traceback (most recent call last): -------- File "D:\projects\embed_python3\Win32\Debug\hello_emb.py", line 7, in -------- --------assert 1==2-------- --------AssertionError---------------- ---- and this: D:\projects\embed_python3\Win32\Debug>type debuggered.txt got to here Vers 12 PyModule_AddObject() Called PySys_SetObject(stdout) returned 0 PySys_SetObject(stderr) returned 0 HELLO FRED ! Traceback (most recent call last): File "D:\projects\embed_python3\Win32\Debug\hello_emb.py", line 7, in assert 1==2 AssertionError So it DOES work, just not when it is run from the cpp exe. Anybody have any idea what on earth is going on here? Cheers From etothepowerpi at gmail.com Wed May 2 05:59:55 2012 From: etothepowerpi at gmail.com (ArifulHossain tuhin) Date: Wed, 2 May 2012 02:59:55 -0700 (PDT) Subject: reading data file into a list Message-ID: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> I have this data file which contains raw data in newline terminated for like below: 10.6626 11.2683 11.9244 12.5758 14.1402 15.1636 Now i want to read that file and import this data into a numpy array. how should i go about it? From __peter__ at web.de Wed May 2 06:17:41 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 May 2012 12:17:41 +0200 Subject: reading data file into a list References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for > like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. how > should i go about it? myarray = numpy.loadtxt(filename) From kiuhnm03.4t.yahoo.it Wed May 2 06:52:50 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 12:52:50 +0200 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> On 5/2/2012 4:43, alex23 wrote: > [Apologies in advance if this comes through twice] > > On May 2, 12:18 am, Kiuhnm wrote: >> "Most Pythonic" doesn't mean better, unfortunately. > > Nor does it mean "Kiuhnm prefers it". That goes without saying. >> For instance, assume that you want to write a function that accepts a >> dictionary of callbacks: >> func(some_args, callbacks) >> >> Pythonic way >> ------------ >> >> def when_odd(n): >> pass >> >> def when_prime(n): >> pass >> >> def before_check(): >> pass >> >> def after_check(): >> pass >> >> func(some_args, {'when_odd' : when_odd, >> 'when_prime' : when_prime, >> 'before_check' : before_check, >> 'after_check' : after_check}) > > When would you _ever_ define a function like this? Why are you passing > in _named_ callbacks? Are you calling them by name? Then declare them > in the function signature and rely on scoping. Does func() branch on > existent keys? Then don't write code like that. > > At the very _least_, you could change the function call to: > > func(some_args, locals()) I think that's very bad. It wouldn't be safe either. What about name clashing and how would you pass only some selected functions? A second call would also need some cleaning up leading to some serious bugs. > But as you're _passing them in by name_ why not just make it > func(some_args) and pick them up out of the scope. Because that's not clean and maintainable. It's not different from using global variables. > _No one_ writes Python code like this. Presenting bad code as > "pythonic" is a bit of a straw man. How can I present good code where there's no good way of doing that without my module or something equivalent? That was my point. >> My way >> ------ >> >> with func(some_args)<< ':dict': >> with when_odd as 'n': >> pass >> with when_prime as 'n': >> pass >> with before_check as '': >> pass >> with after_check as '': >> pass > > This is unintuitive, to say the least. You're effectively replacing > the common form of function definition with "with when_odd as 'n'", > then using the surrounding context manager to limit the scope. What's so unintuitive about it? It's just "different". > More importantly, _you're naming your "anonymous" code blocks_, I'm > guessing so that func() can choose which ones to use. But if you're > naming them, why not just use a function? I'm creating a dictionary, not naming my blocks just for the sake of it. If you use a function, you end up with the solution that you called 'bad' and non-pythonic. > I'm not entirely sure what your 'solution' offers over something like: > > class FOO(object): > def __init__(self, fn): > self.fn = fn > > def __enter__(self): > return self.fn > > def __exit__(self, exc_type, exc_value, traceback): > pass > > def func(x, before_check=None, after_check=None, when_odd=None, > when_prime=None): > pass > > with FOO(func) as f: > def before_check(x): > pass > def after_check(x): > pass > def when_odd(x): > pass > def when_prime(x): > pass > > f(1) The problem is always the same. Those functions are defined at the module level so name clashing and many other problems are possible. I remember a post on this ng when one would create a list of commands and then use that list as a switch table. My module let you do that very easily. The syntax is: with func() << ':list': with 'arg': cmd_code with 'arg': cmd_code with '': cmd_code Kiuhnm From miguel.a.guedes at gmail.com Wed May 2 06:55:35 2012 From: miguel.a.guedes at gmail.com (Miguel Guedes) Date: Wed, 02 May 2012 11:55:35 +0100 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: Message-ID: <4fa11386$0$11126$88263eea@blocknews.net> On 27/04/12 03:11, Xah Lee wrote: > John Carmack glorifying functional programing in 3k words > > http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/ > > where was he ten years ago? > > O, and btw, i heard that Common Lispers don't do functional > programing, is that right? > > Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and > Fuck Pythoners. Python fucking idiots.) > > O, don't forget, > > ?Programing: What are OOP's Jargons and Complexities (Object Oriented > Program as Functional Program)? > http://xahlee.org/Periodic_dosage_dir/t2/oop.html > > please you peruse of it. I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or personally affected by your retarded and offensive comment. However, who the fuck do you think you are to post stuff of this nature? (I believe) I'll understand if you've got some sort of psychological issue affecting your behaviour. From kiuhnm03.4t.yahoo.it Wed May 2 07:03:36 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:03:36 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> On 5/2/2012 8:00, someone wrote: > Still, I dont think I completely understand SVD. SVD (at least in > Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I > would better understand it with geometric examples, if one would be so > kind to maybe write something about that... I can plot 3D vectors in > matlab, very easily so maybe I better understand SVD if I hear/read the > geometric explanation (references to textbook/similar is also appreciated). Russ's post is a very good starting point. I hope you read it. Kiuhnm From gdamjan at gmail.com Wed May 2 07:08:04 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Wed, 02 May 2012 13:08:04 +0200 Subject: How can I read streaming output of a subprocess Message-ID: I want to read the stream of an external process that I start with Python. From what I've seen that's not possible with the subprocess module? I want to read the output of "ip monitor neigh" which will show changes in the ARP table on my Linux computer. Each change is a new line printed by "ip" and the process continues to run forever. -- damjan From kiuhnm03.4t.yahoo.it Wed May 2 07:12:08 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:12:08 +0200 Subject: reading data file into a list In-Reply-To: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: <4fa11687$0$1375$4fafbaef@reader2.news.tin.it> On 5/2/2012 11:59, ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. how should i go about it? http://docs.scipy.org/doc/numpy/reference/routines.io.html Kiuhnm From breamoreboy at yahoo.co.uk Wed May 2 07:23:20 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 02 May 2012 12:23:20 +0100 Subject: syntax for code blocks In-Reply-To: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: On 02/05/2012 11:52, Kiuhnm wrote: > I remember a post on this ng when one would create a list of commands > and then use that list as a switch table. My module let you do that very > easily. > > Kiuhnm I'll believe that when I see a reference to your code repository and the working example that others have already asked you to provide. -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Wed May 2 07:33:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 11:33:31 GMT Subject: reading data file into a list References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: <4fa11b8b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 May 2012 02:59:55 -0700, ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for > like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. > how should i go about it? That depends. How big is the file? Could it include extraneous whitespace and possibly even comments? How do you expect to deal with bad data? What version of Python are you using? Who will be maintaining this, a Python expert or somebody who doesn't know Python very well? Here's one way (untested but should work): import numpy f = open("my data file.txt", "r") contents = numpy.array([float(line) for line in f]) f.close() -- Steven From kushal.kumaran+python at gmail.com Wed May 2 07:34:39 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 2 May 2012 17:04:39 +0530 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 4:38 PM, Damjan Georgievski wrote: > I want to read the stream of an external process that I start with Python. > From what I've seen that's not possible with the subprocess module? > > I want to read the output of "ip monitor neigh" which will show changes in > the ARP table on my Linux computer. Each change is a new line printed by > "ip" and the process continues to run forever. > You can use subprocess for this. If you don't call wait() or communicate() on the Popen object, the process will happily continue running. You can call readline on the stdout pipe, which will block until the command you are running outputs (and flushes) a line. Something like this should work: p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE) first_line = p.stdout.readline() Buffering done by "ip" can ruin your day. It seems reasonable to expect, though, that something that is printing state changes on stdout will be careful to flush its output when appropriate. -- regards, kushal From kiuhnm03.4t.yahoo.it Wed May 2 07:46:09 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:46:09 +0200 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: <4fa11e80$0$1388$4fafbaef@reader2.news.tin.it> On 5/2/2012 13:08, Damjan Georgievski wrote: > I want to read the stream of an external process that I start with > Python. From what I've seen that's not possible with the subprocess module? Try with cmd = 'your command here' stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout print(stdout.read()) just to see if it works. You can also use for line in stdout: print(line) or similar. Then you should add some error checking, etc... Kiuhnm From steve+comp.lang.python at pearwood.info Wed May 2 07:52:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 11:52:27 GMT Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 May 2012 08:00:44 +0200, someone wrote: > On 05/02/2012 01:05 AM, Paul Rubin wrote: >> someone writes: >>> Actually I know some... I just didn't think so much about, before >>> writing the question this as I should, I know theres also something >>> like singular value decomposition that I think can help solve >>> otherwise illposed problems, >> >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD > > I don't understand what else I should write. I gave the singular matrix > and that's it. You can't judge what an acceptable condition number is unless you know what your data is. http://mathworld.wolfram.com/ConditionNumber.html http://en.wikipedia.org/wiki/Condition_number If your condition number is ten, then you should expect to lose one digit of accuracy in your solution, over and above whatever loss of accuracy comes from the numeric algorithm. A condition number of 64 will lose six bits, or about 1.8 decimal digits, of accuracy. If your data starts off with only 1 or 2 digits of accuracy, as in your example, then the result is meaningless -- the accuracy will be 2-2 digits, or 0 -- *no* digits in the answer can be trusted to be accurate. -- Steven From shahviral.it at gmail.com Wed May 2 08:30:25 2012 From: shahviral.it at gmail.com (viral shah) Date: Wed, 2 May 2012 18:00:25 +0530 Subject: Code help for understand Message-ID: Hi in every .py file I found this same code line on the below side *def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) run_wsgi_app(application) if __name__ == '__main__': main() * can anyone explain me what's the all this thing suggest? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Wed May 2 08:43:47 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 2 May 2012 14:43:47 +0200 Subject: Code help for understand In-Reply-To: References: Message-ID: if you are referring to the line * * *if __name__ == '__main__':* * * Find a good explanation here * * http://stackoverflow.com/questions/419163/what-does-if-name-main-do On Wed, May 2, 2012 at 2:30 PM, viral shah wrote: > Hi > > in every .py file I found this same code line on the below side > > *def main(): > application = webapp.WSGIApplication([('/', MainHandler)], > debug=True) > run_wsgi_app(application) > > > if __name__ == '__main__': > main() > * > can anyone explain me what's the all this thing suggest? > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From askutt at gmail.com Wed May 2 10:23:27 2012 From: askutt at gmail.com (Adam Skutt) Date: Wed, 2 May 2012 07:23:27 -0700 (PDT) Subject: How can I read streaming output of a subprocess References: <4fa11e80$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: <85021cac-4d0e-474e-ba1f-ddb1371acdb5@w5g2000vbp.googlegroups.com> On May 2, 7:46?am, Kiuhnm wrote: > On 5/2/2012 13:08, Damjan Georgievski wrote: > > > I want to read the stream of an external process that I start with > > Python. From what I've seen that's not possible with the subprocess module? > > Try with > ? ? cmd = 'your command here' > ? ? stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout One should never, ever start a process with shell=True unless it's absolutely necessary. It is a waste of resources and an a security issue waiting to happen. Just say no. Also, stderr shouldn't be combined with stdout unless there is a need to mix the two streams, which usually is not the case. Also, one needs to hold on to the POpen object so the process can be properly reaped later or use a with block. This is where things get tricky for most applications. It gets a little extra tricky for 'ip monitor'. Assuming the intention is to write a command-line application, the right thing to do _most likely_ is: with Popen(['ip', 'monitor', 'neigh'], stdout=PIPE) as proc: try: for line in proc.stdout: # Do your processing here, it need not be line-by-line. finally: process.terminate() Calling process.terminate() explicitly is necessary since "ip monitor" writes output forever. This is not the right thing to do in all situations, and the right thing to do depends on your application and the command being executed as a subprocess. It's not really possible to generalize fully. As such, your error-handling / cleanup code may end up being completely different. Don't use my code if it's not applicable to your situation. In any case, you need to cleanup after yourself, which means waiting until the subprocess terminates. It may also include cleaning up the file objects for the pipes. Using POpen objects in a with block does both, so do that where you can. The official Python documentation for the subprocess module is pretty clear and worth reading. I encourage you to look through it carefully. It does, unfortunately, gloss over which resources need to be cleaned up and when. Adam From jaialai.technology at gmail.com Wed May 2 10:44:36 2012 From: jaialai.technology at gmail.com (jaialai.technology at gmail.com) Date: Wed, 02 May 2012 10:44:36 -0400 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4fa11386$0$11126$88263eea@blocknews.net> References: <4fa11386$0$11126$88263eea@blocknews.net> Message-ID: <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or > personally affected by your retarded and offensive comment. However, who > the fuck do you think you are to post stuff of this nature? (I believe) > I'll understand if you've got some sort of psychological issue affecting > your behaviour. OP lives out of his car and his main source of income seems to be ad revenue from his website. He may be nuts be he is pretty smart and some of the articles he has up there are worth reading. Still, he has to promote it in some way and by constantly posting these sorts of things he brings people to his site. I'm honestly impressed he can survive this way so I am willing to ignore or maybe killfile his postings and leave him be. From slord at mathworks.com Wed May 2 10:47:57 2012 From: slord at mathworks.com (Steven_Lord) Date: Wed, 2 May 2012 10:47:57 -0400 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: "Russ P." wrote in message news:2275231f-405f-4ee3-966a-40c821b7c0a8 at 2g2000yqp.googlegroups.com... > On May 1, 11:52 am, someone wrote: >> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: >> >> > On 04/29/2012 07:59 PM, someone wrote: >> > I do not use python much myself, but a quick google showed that pyhton >> > scipy has API for linalg, so use, which is from the documentation, the >> > following code example >> >> > X = scipy.linalg.solve(A, B) >> >> > But you still need to check the cond(). If it is too large, not good. >> > How large and all that, depends on the problem itself. But the rule of >> > thumb, the lower the better. Less than 100 can be good in general, but >> > I >> > really can't give you a fixed number to use, as I am not an expert in >> > this subjects, others who know more about it might have better >> > recommendations. >> >> Ok, that's a number... >> >> Anyone wants to participate and do I hear something better than "less >> than 100 can be good in general" ? >> >> If I don't hear anything better, the limit is now 100... >> >> What's the limit in matlab (on the condition number of the matrices), by >> the way, before it comes up with a warning ??? I'm not going to answer, and the reason why is that saying "the limit is X" may lead you to believe that "as long as my condition number is less than X, I'm safe." That's not the case. The threshold above which MATLAB warns is the fence that separates the tourists from the edge of the cliff of singularity -- just because you haven't crossed the fence doesn't mean you're not in danger of tripping and falling into the ravine. > The threshold of acceptability really depends on the problem you are > trying to solve. I agree with this statement, although you generally don't want it to be too big. The definition of "too big" is somewhat fluid, though. > I haven't solved linear equations for a long time, > but off hand, I would say that a condition number over 10 is > questionable. That seems pretty low as a general bound IMO. > A high condition number suggests that the selection of independent > variables for the linear function you are trying to fit is not quite > right. For a poorly conditioned matrix, your modeling function will be > very sensitive to measurement noise and other sources of error, if > applicable. If the condition number is 100, then any input on one > particular axis gets magnified 100 times more than other inputs. > Unless your inputs are very precise, that is probably not what you > want. > > Or something like that. Russ, you and the OP (and others) may be interested in one of the books that Cleve Moler has written and made freely available on the MathWorks website: http://www.mathworks.com/moler/ The chapter Linear Equations in "Numerical Computing with MATLAB" includes a section (section 2.9, starting on page 14 if I remember correctly) that discusses norm and condition number and gives a more formal statement of what you described. The code included in the book is written in MATLAB, but even if you don't use MATLAB (since I know this has been cross-posted to comp.lang.python) there's plenty of good, crunchy mathematics in that section. -- Steve Lord slord at mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com From varma.nikhil22 at gmail.com Wed May 2 10:49:13 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 2 May 2012 20:19:13 +0530 Subject: DateTime objectFormatting Message-ID: Hi I am using a DateTimeField in my class and want to do some tweaking with its object. class ClinicVisitDateSettings(models.Model): name = models.CharField(max_length=80,blank=True,null=True) date_created = models.DateTimeField(blank=True,null=True) def __unicode__(self): return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) The user fills Gen GI in name and date along with time. What i am able to achieve with this class object to return is :- Gen GI Monday May 7 I want that the this class should return object like this :- Gen GI Monday AM, May 7 Pancreas Tuesday PM, May 8 How can achieve AM and PM also ? with this datetime object Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Wed May 2 10:51:13 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Wed, 02 May 2012 16:51:13 +0200 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: <4FA149E1.1070508@gmail.com> >> I want to read the stream of an external process that I start with Python. >> From what I've seen that's not possible with the subprocess module? >> >> I want to read the output of "ip monitor neigh" which will show changes in >> the ARP table on my Linux computer. Each change is a new line printed by >> "ip" and the process continues to run forever. >> > > You can use subprocess for this. If you don't call wait() or > communicate() on the Popen object, the process will happily continue > running. You can call readline on the stdout pipe, which will block > until the command you are running outputs (and flushes) a line. > > Something like this should work: > > p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE) > first_line = p.stdout.readline() > > Buffering done by "ip" can ruin your day. It seems reasonable to > expect, though, that something that is printing state changes on > stdout will be careful to flush its output when appropriate. > thanks, With your confirmation, I've rechecked again and now I see that the problem I experienced before was with some strange ssh interaction. From malaclypse2 at gmail.com Wed May 2 10:57:00 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 2 May 2012 10:57:00 -0400 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 10:49 AM, Nikhil Verma wrote: > What i am able to achieve with this class object to return is :- > > Gen GI Monday? May 7 > > I want that the this class should return object like this :- > > Gen GI Monday AM, May 7 > Pancreas Tuesday PM, May 8 Check the documentation for the strftime method: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior That has a list of the various formatting directives that can be used to lay out your date and time as you wish. In this case, instead of "%A %B %d", you probably want "%A %p, %B %d". That is, Full Weekday Name, followed by the AM/PM marker, then a comma, then the Full Month Name and the day of month. -- Jerry From clp2 at rebertia.com Wed May 2 10:57:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 May 2012 07:57:05 -0700 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma wrote: > ??? def __unicode__(self): > ??????? return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) > > > The user fills Gen GI in name and date along with time. > > What i am able to achieve with this class object to return is :- > > Gen GI Monday? May 7 > > I want that the this class should return object like this :- > > Gen GI Monday AM, May 7 > Pancreas Tuesday PM, May 8 > > How can achieve AM and PM also ? with this datetime object Consult the docs. http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior : "%p -- Locale?s equivalent of either AM or PM." So, strftime("%A %p, %B %d"). Regards, Chris From tfb at tfeb.org Wed May 2 11:30:23 2012 From: tfb at tfeb.org (Tim Bradshaw) Date: Wed, 2 May 2012 16:30:23 +0100 Subject: John Carmack glorifying functional programing in 3k words References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On 2012-05-02 14:44:36 +0000, jaialai.technology at gmail.com said: > He may be nuts But he's right: programmers are pretty much fuckwits[*]: if you think that's not true you are not old enough. [*] including me, especially. From rtomek at ceti.pl Wed May 2 11:31:33 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 17:31:33 +0200 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: > > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or > > personally affected by your retarded and offensive comment. However, who > > the fuck do you think you are to post stuff of this nature? (I believe) > > I'll understand if you've got some sort of psychological issue affecting > > your behaviour. > OP lives out of his car and his main source of income seems to be ad > revenue from his website. > He may be nuts be he is pretty smart and some of the articles he has up > there are worth reading. Still, he has to promote it in some way and by > constantly posting these sorts of things he brings people to his site. > I'm honestly impressed he can survive this way so I am willing to > ignore or maybe killfile his postings and leave him be. He may be smart but obviously hasn't figured out this yet: positive aura drives more people and more permamently towards you. Perhaps he should develop an alter ego that could stand side by side with Dalai Lama and see which one gets more attention. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From varma.nikhil22 at gmail.com Wed May 2 11:35:44 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 2 May 2012 21:05:44 +0530 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: Thanks On Wed, May 2, 2012 at 8:27 PM, Chris Rebert wrote: > On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma > wrote: > > > def __unicode__(self): > > return "%s %s" % (self.name, self.date_created.strftime("%A %B > %d")) > > > > > > The user fills Gen GI in name and date along with time. > > > > What i am able to achieve with this class object to return is :- > > > > Gen GI Monday May 7 > > > > I want that the this class should return object like this :- > > > > Gen GI Monday AM, May 7 > > Pancreas Tuesday PM, May 8 > > > > How can achieve AM and PM also ? with this datetime object > > Consult the docs. > http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior: > "%p -- Locale?s equivalent of either AM or PM." > > So, strftime("%A %p, %B %d"). > > Regards, > Chris > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Wed May 2 11:35:50 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 2 May 2012 08:35:50 -0700 (PDT) Subject: Python SOAP library Message-ID: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> What's the best SOAP library for Python? I am creating an API converter which will be serialising to/from a variety of sources, including REST and SOAP. Relevant parsing is XML [incl. SOAP] and JSON. Would you recommend: http://code.google.com/p/soapbox/ Or suggest another? Thanks for all information, Alec Taylor From tjreedy at udel.edu Wed May 2 12:02:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 May 2012 12:02:03 -0400 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On 5/2/2012 10:49 AM, Nikhil Verma wrote: This was posted as html (with text copy). Please send messages to the list and newsgroup as text (only). Html sometimes does strange things, especially if you post code. -- Terry Jan Reedy From tim.wintle at teamrubber.com Wed May 2 12:12:32 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 02 May 2012 17:12:32 +0100 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <1335975152.15772.14.camel@tim-laptop> On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: > positive aura drives more people and more permamently towards you. Perhaps he should > develop an alter ego that could stand side by side with Dalai Lama and see > which one gets more attention. Really? If all you want is attention then "being nice" doesn't seem to be the best option. (of course if you want any respect...) From rosuav at gmail.com Wed May 2 12:23:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:23:29 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola wrote: > He may be smart but obviously hasn't figured out this yet: positive aura > drives more people and more permamently towards you. You catch more flies with honey than with vinegar, but who wants to catch flies? I don't see much value in Xah Lee's posts, myself; if he wants to use LISP and hate Python then he's free to, but why ramble about it on this list? ChrisA From rosuav at gmail.com Wed May 2 12:29:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:29:56 +1000 Subject: [GENERAL] Uppercase to lowercase trigger? In-Reply-To: <1335962003519-5680384.post@n5.nabble.com> References: <1335962003519-5680384.post@n5.nabble.com> Message-ID: On Wed, May 2, 2012 at 10:33 PM, Chrishelring wrote: > Hi, > > I?ve got some tables with column names in lowercase. Before updatering these > tables I want to add a trigger that can convert these lowercase to > uppercase, and when the tables are updates convert them back to lowercase.. Not entirely sure what you're looking for here, but in Postgres, if you don't quote your column names, they are lowercased by default. UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar'; This will work if the table has "columnname" and "columnname2". ChrisA From rosuav at gmail.com Wed May 2 12:31:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:31:02 +1000 Subject: [GENERAL] Uppercase to lowercase trigger? In-Reply-To: References: <1335962003519-5680384.post@n5.nabble.com> Message-ID: On Thu, May 3, 2012 at 2:29 AM, Chris Angelico wrote: > On Wed, May 2, 2012 at 10:33 PM, Chrishelring > wrote: >> Hi, >> >> I?ve got some tables with column names in lowercase. Before updatering these >> tables I want to add a trigger that can convert these lowercase to >> uppercase, and when the tables are updates convert them back to lowercase.. > > Not entirely sure what you're looking for here, but in Postgres, if > you don't quote your column names, they are lowercased by default. > > UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar'; > > This will work if the table has "columnname" and "columnname2". > > ChrisA Take no notice of me... 'py'thon and 'pg'-sql are apparently too close on my keyboard and brain... ChrisA From rtomek at ceti.pl Wed May 2 12:57:13 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 18:57:13 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <1335975152.15772.14.camel@tim-laptop> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <1335975152.15772.14.camel@tim-laptop> Message-ID: On Wed, 2 May 2012, Tim Wintle wrote: > On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: > > positive aura drives more people and more permamently towards you. Perhaps he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > Really? > > +lama&ctab=0&geo=all&date=all&sort=0> > > If all you want is attention then "being nice" doesn't seem to be the > best option. > > (of course if you want any respect...) Okay, I should have given the idea a second thought. OTOH, see for yourself: http://www.google.com/trends/?q=xah+lee,dalai+lama&ctab=0&geo=all&date=all&sort=0 Esp. "xah lee does not have enough search volume for ranking"... For me, the conclusion is simple. If he wants to achieve anything, he should mimic Dalai Lama first and only after becoming comparable to the guy, if he's still dissatisfied, only then he should follow OBL. But by all means he should stop being himself. If becoming DL-like is too hard (I believe it is), he might find something even easier, like Miyamoto Musashi, a sword/Zen master. http://www.google.com/trends/?q=miyamoto+musashi,+dalai+lama&ctab=0&geo=all&date=all&sort=0 Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From ramit.prasad at jpmorgan.com Wed May 2 13:20:01 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 17:20:01 +0000 Subject: syntax for code blocks In-Reply-To: <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303B58@SCACMX008.exchad.jpmchase.net> Steven D'Aprano wrote: > >> Have you actually tried to use these code blocks of yours? I asked you > >> for a *working* example earlier, and you replied with examples that > >> failed with multiple NameErrors and no hint as to how to fix them. And > >> now you give an example that fails with SyntaxError. > > > > The examples I gave you work perfectly. > > Except they don't. > > Look, this isn't difficult. I asked for *working* examples, you gave > examples that give NameError. Some of those errors are easy to fix, e.g. > by importing the random and re modules. Some of them aren't. [snip] > > > It's clear that you don't even > > have the vaguest idea of how my module works or, otherwise, you'd know > > what you're doing wrong. > > Well duh. What module? Where do I find it? [snip part deux] > Whatever man. It's no skin off my nose. I've tried really hard to give > your proposal a fair go, but my care factor is rapidly running out if you > can't even be bothered to ensure your examples use legal Python syntax. I think the crucial link that was provided in another thread (and should have been included in a new thread on the same project) is http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ The only example I see on that page (for running from module) that looks fully complete is: import codeblocks codeblocks.rewrite() def each(iterable, block): for e in iterable: block(e) # step into -> 6: with each(range(0, 10)) << 'x': print('element ' + str(x)) codeblocks.end_of_module() I have not tried this (or any) example. To me it seems like an overly complicated way to avoid creating a function def. Especially since it creates a function anyway (whether anonymous or named). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From lamialily at cleverpun.com Wed May 2 13:21:42 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 02 May 2012 10:21:42 -0700 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4fa11386$0$11126$88263eea@blocknews.net> References: <4fa11386$0$11126$88263eea@blocknews.net> Message-ID: >On 27/04/12 03:11, Xah Lee wrote: >> John Carmack glorifying functional programing in 3k words >> >> http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/ >> >> where was he ten years ago? >> >> O, and btw, i heard that Common Lispers don't do functional >> programing, is that right? >> >> Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and >> Fuck Pythoners. Python fucking idiots.) >> >> O, don't forget, >> >> ?Programing: What are OOP's Jargons and Complexities (Object Oriented >> Program as Functional Program)? >> http://xahlee.org/Periodic_dosage_dir/t2/oop.html >> >> please you peruse of it. > >I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or >personally affected by your retarded and offensive comment. However, who >the fuck do you think you are to post stuff of this nature? (I believe) >I'll understand if you've got some sort of psychological issue affecting >your behaviour. And another one gets trolled. ~Temia -- When on earth, do as the earthlings do. From rtomek at ceti.pl Wed May 2 13:22:27 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 19:22:27 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, 3 May 2012, Chris Angelico wrote: > On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola wrote: > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. > > You catch more flies with honey than with vinegar, but who wants to > catch flies? Nah. Who invents such distorted examples only to prove himself right :-). I think you can catch more girls with honey and I'm not sure if I'd like to catch those who prefer vinegar. I think we can make it into some kind of law, say Angelico-Rola Law (of girlscatching), ok? "One cannot catch a girl on honey without catching some flies in the process." Or is it a hypothesis? > I don't see much value in Xah Lee's posts, myself; if he wants to use > LISP and hate Python then he's free to, but why ramble about it on > this list? Well, it is strange because about half of his every post are filled up with f and sh words. Even I feel a bit dirty after reading them (and I swear without giving it much of second thought). Myself, I think I shouldn't try too hard to understand his motives - because one can easily become what one understands. Especially that he doesn't seem to be interested in getting feedback, so chances are there is some force of chaos behind all this. Or his feelings have been hurt by Lisp/Python/Emacs/Perl community (but I couldn't care less, really). Either way, I greet Xah for taking my mind off a subject of writing some piece of code that should have been written a while ago :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From torriem at gmail.com Wed May 2 13:37:49 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 11:37:49 -0600 Subject: Some posts do not show up in Google Groups In-Reply-To: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> Message-ID: <4FA170ED.6070304@gmail.com> On 05/01/2012 12:12 AM, Frank Millman wrote: > I have had a look at this before, but there is one thing that Google > Groups does that no other reader seems to do, and that is that > messages are sorted according to thread-activity, not original posting > date. This makes it easy to see what has changed since the last time I > checked. Any good threaded e-mail reader will do this. I use Thunderbird, for example, and all incoming python messages to the list come in, sorting the threads by most recent activity. Also coming from google groups I think you would enjoy the capabilities that a true threaded e-mail reader brings. Google's "conversations" view of things just does not preserve the structure of the more complicated and long-running threads. If you want to stick with NNTP, thunderbird works with nntp just fine, and in fact works very well, unlike what Dennis Lee Bieber claims on his post. And as far as nntp goes, I don't see any difference between reading the list in Thunderbird via nntp or a dedicated e-mail feed (which I filter into its own IMAP folder). Avoid using gmail for reading and posting to mailing lists (yes I know I post from gmail). Google helpfully tosses out your own posts to the list so you never see them, which is a real problem for mailing lists. Google certainly knows about this bug but claims its a feature. What a crock. In the gmail web interface, google puts messages from your sent folder into the "conversation" stream, so they toss the duplicate message coming from the list. When using IMAP, this leads to dropped messages as no IMAP client will presume to know enough to put sent messages into a thread. The workwaround, which is what I use, is to send your messages to the list through a non-Gmail SMTP server. From petr.jakes.tpc at gmail.com Wed May 2 13:40:16 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Wed, 2 May 2012 10:40:16 -0700 (PDT) Subject: mmap and bit wise twiddling - Raspberry Pi Message-ID: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Hi, I am trying to work with HW peripherals on Raspberry Pi To achieve this, it is necessary read/write some values from/to the memory directly. I am looking for some wise way how to organize the bit twiddling. To set some specific bit, for example, it is necessary: - read 4 bytes string representation (I am using mmap) - transform it to the corresponding integer (I am using numpy) - do some bit masking over this integer - transport integer to the string representation (numpy again) - write it back to the memory In other words I mean: is there wise way to create an instrument/ machinery to define Class and then simply define all necessary objects and set the bit values over object attributes so the whole bit- twiddling remains under the hood. say: LED01 = GPIO(4) # gpio PIN number 4 is assigned to the LED01 name (attribute) LED01.on() LED01.off() or gpio = GPIO() LED01 = gpio.pin04 LED01 = 1 # led diode is shining (or gpio pin 4 is set) LED01 = 0 # led diode is off General suggestions, how to organise this work are more then welcome. Petr Jakes From laurent.pointal at free.fr Wed May 2 13:57:37 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 02 May 2012 19:57:37 +0200 Subject: Converting a string to list for submission to easygui =?UTF-8?B?bXVsdGVudGVyYuKAi294?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> Message-ID: <4fa17591$0$20186$426a34cc@news.free.fr> ksals wrote: > On May 1, 5:29 pm, John Gordon wrote: >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> >> ksals writes: >> >> > The original choice looks like this when I print it: >> > print(choice) >> > ('ksals', '', 'alsdkfj', '3', '') >> > I need to submit these as defaults to a multenterbox. Each entry above >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. >> > I tried your suggestion so you must be right it is a tuple of 5 >> > strings. But I need them to work in an instruction like >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) >> > fieldNames has 5 fields. >> >> If you just need to convert a tuple to a list, that's easy. Call the >> built-in function list() and pass the tuple as an intializer: >> >> >>> choice = ('ksals', '', 'alsdkfj', '3', '') >> >>> print choice >> >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) >> >>> print choice_list >> >> ['ksals', '', 'alsdkfj', '3', ''] >> >> -- >> John Gordon A is for Amy, who fell down the stairs >> gor... at panix.com B is for Basil, assaulted by bears >> -- Edward Gorey, "The Gashlycrumb Tinies" >> >> > This is a small excert to show you what I get > > for choice in easygui.multchoicebox(msg1, title,qstack): > if choice[0] == None: > print ("No entries made") > break > > > print("CHOICE IS: ",choice) ..... CHOICE IS: > ('', 'ksals', '', '', '') > c=list(choice) > print("C IS: ",c) ..... C IS: ['(', > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", > "'", ',', ' ', "'", "'", ',', ' ', "'", "'", > ')'] Looks like you have your tuple expression ('ksals', '', 'alsdkfj', '3', '') not as a tuple, but as a string. Do you convert it somewhere ? If you have it as a string, you can use eval() (not safe!) on the string to retrieve the tuple, then list() on the tuple to get a list. -- Laurent POINTAL - laurent.pointal at laposte.net 3 all?e des Orangers - 91940 Les Ulis - France T?l. 01 69 29 06 59 From jmwebaze at gmail.com Wed May 2 15:51:22 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 2 May 2012 21:51:22 +0200 Subject: try/except in a loop Message-ID: I have multiple objects, where any of them can serve my purpose.. However some objects might not have some dependencies. I can not tell before hand if the all the dependencies exsit. What i want to is begin processing from the 1st object, if no exception is raised, i am done.. if an exception is raised, the next object is tried, etc Something like objs = [... ] try: obj = objs[0] obj.make() except Exception, e: try: obj = objs[1] obj.make() except Exception, e: try: obj = objs[2] obj.make() except Exception, e: continue The problem is the length of the list of objs is variable... How can i do this? -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Wed May 2 15:58:19 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 2 May 2012 12:58:19 -0700 Subject: try/except in a loop In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: > I have?multiple?objects, where any of them can serve my purpose.. However > some objects might not have some dependencies. I can not tell before hand if > the all the dependencies exsit. What i want to is begin processing from the > 1st object, if no exception is raised, i am done.. if an exception is > raised, the next object is tried, etc ?Something like > > objs = [... ] > try: > ? obj = objs[0] > ? obj.make() > except Exception, e: > ? try: > ? ? ? obj = objs[1] > ? ? ? obj.make() > ? except Exception, e: > ? ? ?try: > ? ? ? ? obj = objs[2] > ? ? ? ? obj.make() > ? ? ?except Exception, e: > ? ? ? ?continue > > The problem is the length of the list of objs is variable... How can i do > this? for obj in objs: try: obj.make() except Exception: continue else: break else: raise RuntimeError('No object worked') > > > > -- > Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | > skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */ > > > -- > http://mail.python.org/mailman/listinfo/python-list > From theller at ctypes.org Wed May 2 16:05:17 2012 From: theller at ctypes.org (Thomas Heller) Date: Wed, 02 May 2012 22:05:17 +0200 Subject: mmap and bit wise twiddling - Raspberry Pi In-Reply-To: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> References: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Message-ID: Am 02.05.2012 19:40, schrieb Petr Jakes: > Hi, > I am trying to work with HW peripherals on Raspberry Pi > To achieve this, it is necessary read/write some values from/to the > memory directly. > > I am looking for some wise way how to organize the bit twiddling. > > To set some specific bit, for example, it is necessary: > - read 4 bytes string representation (I am using mmap) > - transform it to the corresponding integer (I am using numpy) > - do some bit masking over this integer > - transport integer to the string representation (numpy again) > - write it back to the memory > > In other words I mean: is there wise way to create an instrument/ > machinery to define Class and then simply define all necessary objects > and set the bit values over object attributes so the whole bit- > twiddling remains under the hood. > > say: > LED01 = GPIO(4) # gpio PIN number 4 is assigned to the LED01 name > (attribute) > LED01.on() > LED01.off() > or > > gpio = GPIO() > LED01 = gpio.pin04 > LED01 = 1 # led diode is shining (or gpio pin 4 is set) > LED01 = 0 # led diode is off I have an abstract BitVector base-class that allows to get/set single bits or several bits in a convenient way. You must define concrete subclasses which define a _value get/set property that actually updates the byte or word in the hardware. I use it to access bits or groups of bits of I2C devices. You would basically code like this, assuming an 8-bit GPIO port: class GPIO(BitVector): def __init__(self, address, value=0xFF, nbits=8): self.address = address super(GPIO, self).__init__(value, nbits) def _get_value(self): "read an 8-bit value from the hardware as 8-bit integer" ... def _set_value(self, v): "write the 8-bit value 'v' to the hardware" ... then you can do: gpio = GPIO(0x12345678) led0 = gpio[4] # bit 4 led0.value = 1 # switch led on print led0.value # get led status For multiple bits use this (note that different from standard Python practices, indexing works inclusive and uses [high_bitnum:low_bitnum]: port = GPIO(0x12345678) high_nibble = port[7:4] print high_nibble.value low_nibble = port[3:0] low_nibble.value = 0xF Thomas -------------- next part -------------- class BitVector(object): """BitVector class, represents mutable integers constricted to a certain range. Single bits can be get/set by indexing with integers. Slices can be used to get/set the bits in this range, as an integer constricted to this range also. Slices must use [MSB:LSB], and are inclusive. >>> [x for x in BitVector(0xAA)] [0, 1, 0, 1, 0, 1, 0, 1] >>> [x for x in BitVector(0xFF)] [1, 1, 1, 1, 1, 1, 1, 1] >>> >>> bv = BitVector(0) >>> bv[6:3] = 0xf >>> [x for x in bv] [0, 0, 0, 1, 1, 1, 1, 0] >>> bv[6:3] = -1 Traceback (most recent call last): ... ValueError: value out of allowed range >>> bv[6:3] = 16 Traceback (most recent call last): ... ValueError: value out of allowed range >>> hex(bv) '0x78' >>> bin(bv) '0b1111000' >>> """ def __init__(self, value=0, nbits=8): self._nbits = nbits self._value = value def __index__(self): return self._value def __hex__(self): return hex(self._value) def __getitem__(self, index): if isinstance(index, slice): return self._getslice(index) if not 0 <= index < self._nbits: raise IndexError("invalid index") return int(bool(self._value & (1 << index))) @property def bits(self): """ Return some bits as an object that has a .value property. The .value property represents the current value of the specied bits. b = BitVector().bits[7:0] b.value = ... print b.value """ class Bits(object): def __init__(self, bv): self.bv = bv def __getitem__(self, index): class GetSet(object): def __init__(self, bv): self.bv = bv def _get(self): return self.bv[index] def _set(self, value): self.bv[index] = value value = property(_get, _set) return GetSet(self.bv) return Bits(self) def _getslice(self, index): if index.step is not None: raise ValueError("extended slicing not supported") stop, start = index.stop, index.start if start <= stop or start < 0 or stop >= self._nbits: print "START, STOP", start, stop raise ValueError("invalid slice range") mask = (1 << (start+1)) - 1 return (self._value & mask) >> stop def _setslice(self, index, value): if index.step is not None: raise ValueError("extended slicing not supported") stop, start = index.stop, index.start if start <= stop or start < 0 or stop >= self._nbits: print "START, STOP", start, stop raise ValueError("invalid slice range") mask = (1 << (start+1)) - 1 mask &= ~((1 << stop) - 1) value = value << stop if value & ~mask: raise ValueError("value out of allowed range") v = self._value v &= ~mask v |= mask & value self._value = v def __setitem__(self, index, value): value = int(value) if isinstance(index, slice): self._setslice(index, value) return if not 0 <= index < self._nbits: raise IndexError("invalid index") mask = 1 << index if not 0 <= value <= 1: raise ValueError("value must be 0 or 1") if value: self._value |= mask else: self._value &= ~mask From bahamutzero8825 at gmail.com Wed May 2 16:07:15 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 02 May 2012 15:07:15 -0500 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA193F3.30704@gmail.com> Why wouldn't a for loop work? If something works, you can break out, otherwise continue. working_obj = None for obj in iterable: try: obj.do_something() working_obj = obj break except: continue -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From theller at ctypes.org Wed May 2 16:07:33 2012 From: theller at ctypes.org (Thomas Heller) Date: Wed, 02 May 2012 22:07:33 +0200 Subject: mmap and bit wise twiddling - Raspberry Pi In-Reply-To: References: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Message-ID: Am 02.05.2012 22:05, schrieb Thomas Heller: > class GPIO(BitVector): > def __init__(self, address, value=0xFF, nbits=8): > self.address = address > super(GPIO, self).__init__(value, nbits) > def _get_value(self): > "read an 8-bit value from the hardware as 8-bit integer" > ... > def _set_value(self, v): > "write the 8-bit value 'v' to the hardware" > ... Sorry, forgot to create the property; so please add this to the class definition: _value = property(_get_value, _set_value) Thomas From bahamutzero8825 at gmail.com Wed May 2 16:10:39 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 02 May 2012 15:10:39 -0500 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA194BF.5010709@gmail.com> Forgot to add that all this is covered in the tutorial in the official docs: http://docs.python.org/tutorial/controlflow.html#for-statements -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From ramit.prasad at jpmorgan.com Wed May 2 16:12:46 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 20:12:46 +0000 Subject: try/except in a loop In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> > > I have multiple objects, where any of them can serve my purpose.. > However > > some objects might not have some dependencies. I can not tell before > hand if > > the all the dependencies exsit. What i want to is begin processing from > the > > 1st object, if no exception is raised, i am done.. if an exception is > > raised, the next object is tried, etc Something like > > > > objs = [... ] > > try: > > obj = objs[0] > > obj.make() > > except Exception, e: > > try: > > obj = objs[1] > > obj.make() > > except Exception, e: > > try: > > obj = objs[2] > > obj.make() > > except Exception, e: > > continue > > > > The problem is the length of the list of objs is variable... How can i > do > > this? > > > for obj in objs: > try: > obj.make() > except Exception: > continue > else: > break > else: > raise RuntimeError('No object worked') I think you misunderstand the else clauses. >>> for obj in [ 1,2,3,4 ]: ... try: ... print obj ... except Exception: ... print 'EXCEPTION' ... else: ... print 'NO EXCEPTION' ... else: ... print 'NO OBJECTS' ... 1 NO EXCEPTION 2 NO EXCEPTION 3 NO EXCEPTION 4 NO EXCEPTION NO OBJECTS Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From newsboost at gmail.com Wed May 2 16:25:11 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:25:11 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On 05/02/2012 08:36 AM, Russ P. wrote: > On May 1, 11:03 pm, someone wrote: >> On 05/02/2012 01:38 AM, Russ P. wrote: .. >>> On May 1, 4:05 pm, Paul Rubin wrote: >> It would really appreciate if anyone could maybe post a simple SVD >> example and tell what the vectors from the SVD represents geometrically >> / visually, because I don't understand it good enough and I'm sure it's >> very important, when it comes to solving matrix systems... > > SVD is perhaps the ultimate matrix decomposition and the ultimate tool > for linear analysis. Google it and take a look at the excellent > Wikipedia page on it. I would be wasting my time if I tried to compete > with that. Ok. > To really appreciate the SVD, you need some background in linear > algebra. In particular, you need to understand orthogonal > transformations. Think about a standard 3D Cartesian coordinate frame. > A rotation of the coordinate frame is an orthogonal transformation of > coordinates. The original frame and the new frame are both orthogonal. Yep. > A vector in one frame is converted to the other frame by multiplying > by an orthogonal matrix. The main feature of an orthogonal matrix is > that its transpose is its inverse (hence the inverse is trivial to > compute). As far as i know, you have to replace orthogonal with: orthonormal. That much I at least think I know without even going to wikipedia first... > The SVD can be thought of as factoring any linear transformation into > a rotation, then a scaling, followed by another rotation. The scaling > is represented by the middle matrix of the transformation, which is a > diagonal matrix of the same dimensions as the original matrix. The > singular values can be read off of the diagonal. If any of them are > zero, then the original matrix is singular. If the ratio of the > largest to smallest singular value is large, then the original matrix > is said to be poorly conditioned. Aah, thank you very much. I can easily recognize some of this... > Standard Cartesian coordinate frames are orthogonal. Imagine an x-y > coordinate frame in which the axes are not orthogonal. Such a > coordinate frame is possible, but they are rarely used. If the axes > are parallel, the coordinate frame will be singular and will basically > reduce to one-dimensional. If the x and y axes are nearly parallel, > the coordinate frame could still be used in theory, but it will be > poorly conditioned. You will need large numbers to represent points > fairly close to the origin, and small deviations will translate into > large changes in coordinate values. That can lead to problems due to > numerical roundoff errors and other kinds of errors. Thank you very much for your time. It always helps to get the same explanation from different people with slightly different ways of explaining it. Thanks! From newsboost at gmail.com Wed May 2 16:26:03 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:26:03 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On 05/02/2012 01:03 PM, Kiuhnm wrote: > On 5/2/2012 8:00, someone wrote: >> Still, I dont think I completely understand SVD. SVD (at least in >> Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I >> would better understand it with geometric examples, if one would be so >> kind to maybe write something about that... I can plot 3D vectors in >> matlab, very easily so maybe I better understand SVD if I hear/read the >> geometric explanation (references to textbook/similar is also >> appreciated). > > Russ's post is a very good starting point. I hope you read it. Ofcourse I do. From ckaynor at zindagigames.com Wed May 2 16:27:26 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 2 May 2012 13:27:26 -0700 Subject: try/except in a loop In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> Message-ID: On Wed, May 2, 2012 at 1:12 PM, Prasad, Ramit wrote: >> > I have multiple objects, where any of them can serve my purpose.. >> However >> > some objects might not have some dependencies. I can not tell before >> hand if >> > the all the dependencies exsit. What i want to is begin processing from >> the >> > 1st object, if no exception is raised, i am done.. if an exception is >> > raised, the next object is tried, etc ?Something like >> > >> > objs = [... ] >> > try: >> > ? obj = objs[0] >> > ? obj.make() >> > except Exception, e: >> > ? try: >> > ? ? ? obj = objs[1] >> > ? ? ? obj.make() >> > ? except Exception, e: >> > ? ? ?try: >> > ? ? ? ? obj = objs[2] >> > ? ? ? ? obj.make() >> > ? ? ?except Exception, e: >> > ? ? ? ?continue >> > >> > The problem is the length of the list of objs is variable... How can i >> do >> > this? >> >> >> for obj in objs: >> ? ? try: >> ? ? ? ? obj.make() >> ? ? except Exception: >> ? ? ? ? continue >> ? ? else: >> ? ? ? ? break >> else: >> ? ? raise RuntimeError('No object worked') > > > I think you misunderstand the else clauses. > >>>> for obj in [ 1,2,3,4 ]: > ... ? ? try: > ... ? ? ? ? print obj > ... ? ? except Exception: > ... ? ? ? ? print 'EXCEPTION' > ... ? ? else: > ... ? ? ? ? print 'NO EXCEPTION' > ... else: > ... ? ? print 'NO OBJECTS' > ... > 1 > NO EXCEPTION > 2 > NO EXCEPTION > 3 > NO EXCEPTION > 4 > NO EXCEPTION > NO OBJECTS You left out the break in the try clause's else that I had. That break statement causes the for loop to exit early if there is no exception, and thus the for loop's else clause does not run: >>> for obj in [ 1,2,3,4 ]: ... try: ... print obj ... except Exception: ... print 'EXCEPTION' ... else: ... print 'NO EXCEPTION' ... break ... else: ... print 'NO OBJECTS' ... 1 NO EXCEPTION > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list From newsboost at gmail.com Wed May 2 16:29:27 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:29:27 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/02/2012 01:52 PM, Steven D'Aprano wrote: > On Wed, 02 May 2012 08:00:44 +0200, someone wrote: > >> On 05/02/2012 01:05 AM, Paul Rubin wrote: >>> someone writes: >>>> Actually I know some... I just didn't think so much about, before >>>> writing the question this as I should, I know theres also something >>>> like singular value decomposition that I think can help solve >>>> otherwise illposed problems, >>> >>> You will probably get better advice if you are able to describe what >>> problem (ill-posed or otherwise) you are actually trying to solve. SVD >> >> I don't understand what else I should write. I gave the singular matrix >> and that's it. > > You can't judge what an acceptable condition number is unless you know > what your data is. > > http://mathworld.wolfram.com/ConditionNumber.html > http://en.wikipedia.org/wiki/Condition_number > > If your condition number is ten, then you should expect to lose one digit > of accuracy in your solution, over and above whatever loss of accuracy > comes from the numeric algorithm. A condition number of 64 will lose six > bits, or about 1.8 decimal digits, of accuracy. > > If your data starts off with only 1 or 2 digits of accuracy, as in your > example, then the result is meaningless -- the accuracy will be 2-2 > digits, or 0 -- *no* digits in the answer can be trusted to be accurate. I just solved a FEM eigenvalue problem where the condition number of the mass and stiffness matrices was something like 1e6... Result looked good to me... So I don't understand what you're saying about 10 = 1 or 2 digits. I think my problem was accurate enough, though I don't know what error with 1e6 in condition number, I should expect. How did you arrive at 1 or 2 digits for cond(A)=10, if I may ask ? From fred.sells at adventistcare.org Wed May 2 16:31:29 2012 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 2 May 2012 16:31:29 -0400 Subject: Overlayong PDF Files In-Reply-To: <1335443124.15347.1.camel@workstation.wmmi.net> References: <1335443124.15347.1.camel@workstation.wmmi.net> Message-ID: Assuming your form has actual PDF data entry fields. I export the form to a .fdf file, run a little script to replace fieldnames with %(fieldname)s and save this as a staic template. At run time I'll merge the template with a python dictionary using the % operator and shell down to pdftk to merge the two files and create a filled in PDF. This way you don't have to worry about exact placement of data. I have been looking for an api that would let me do this without the .fdf step, but to no avail. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Adam Tauno Williams Sent: Thursday, April 26, 2012 8:25 AM To: python-list at python.org Subject: Re: Overlayong PDF Files On Wed, 2012-04-25 at 13:36 -0500, Greg Lindstrom wrote: > I would like to take an existing pdf file which has the image of a > health care claim and overlay the image with claim data (insured name, > address, procedures, etc.). I'm pretty good with reportlab -- in > fact, I've created a form close to the CMS 1500 (with NPI), but it's > not close enough for scanning. I'd like to read in the "official" > form and add my data. Is this possible? I 'overlay' PDF documents using pypdf. Example -- Adam Tauno Williams System Administrator, OpenGroupware Developer, LPI / CNA Fingerprint 8C08 209A FBE3 C41A DD2F A270 2D17 8FA4 D95E D383 From newsboost at gmail.com Wed May 2 16:32:28 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:32:28 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 05/02/2012 04:47 PM, Steven_Lord wrote: > > Russ, you and the OP (and others) may be interested in one of the books > that Cleve Moler has written and made freely available on the MathWorks > website: > > http://www.mathworks.com/moler/ > > The chapter Linear Equations in "Numerical Computing with MATLAB" > includes a section (section 2.9, starting on page 14 if I remember > correctly) that discusses norm and condition number and gives a more > formal statement of what you described. The code included in the book is > written in MATLAB, but even if you don't use MATLAB (since I know this > has been cross-posted to comp.lang.python) there's plenty of good, > crunchy mathematics in that section. I use matlab more than python. I just want to learn python, which seems extremely powerful and easy but yet, I'm a python beginner. Thank you very much for the reference, Mr. Lord. I'll look closely at that Moler-book, in about 1/2 hour or so.... Looking forward to learning more about this... From kbsals5179 at gmail.com Wed May 2 16:55:59 2012 From: kbsals5179 at gmail.com (ksals) Date: Wed, 2 May 2012 13:55:59 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> <4fa17591$0$20186$426a34cc@news.free.fr> Message-ID: <437857ea-e12b-4088-ae90-c401039d53a9@p21g2000vby.googlegroups.com> On May 2, 1:57?pm, Laurent Pointal wrote: > ksals wrote: > > On May 1, 5:29 pm, John Gordon wrote: > >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> > >> ksals writes: > > >> > The original choice looks like this when I print it: > >> > print(choice) > >> > ('ksals', '', 'alsdkfj', '3', '') > >> > I need to submit these as defaults to a multenterbox. Each entry above > >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > >> > I tried your suggestion so you must be right it is a tuple of 5 > >> > strings. ?But I need them to work in an instruction like > >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > >> > fieldNames has 5 fields. > > >> If you just need to convert a tuple to a list, that's easy. ?Call the > >> built-in function list() and pass the tuple as an intializer: > > >> >>> choice = ('ksals', '', 'alsdkfj', '3', '') > >> >>> print choice > > >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) > >> >>> print choice_list > > >> ['ksals', '', 'alsdkfj', '3', ''] > > >> -- > >> John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > >> gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > >> -- Edward Gorey, "The Gashlycrumb Tinies" > > > This is a small excert to show you what I get > > > for choice in easygui.multchoicebox(msg1, title,qstack): > > ? ? ? ? ? ? if choice[0] == None: > > ? ? ? ? ? ? ? ? print ("No entries made") > > ? ? ? ? ? ? ? ? break > > > ? ? ? ? ? ? print("CHOICE IS: ",choice) ? ?..... ? ? ? ? CHOICE IS: > > ('', 'ksals', '', '', '') > > ? ? ? ? ? ? c=list(choice) > > ? ? ? ? ? ? print("C IS: ",c) ? ? ? ? ? ? ?..... ? ? ?C IS: ?['(', > > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", > > "'", ',', ' ', "'", "'", ',', ' ', "'", "'", > > ')'] > > Looks like you have your tuple expression > ? ? ? ? ('ksals', '', 'alsdkfj', '3', '') > not as a tuple, but as a string. Do you convert it somewhere ? > > If you have it as a string, you can use eval() (not safe!) on the string to > retrieve the tuple, then list() on the tuple to get a list. > > -- > Laurent POINTAL - laurent.poin... at laposte.net > 3 all?e des Orangers - 91940 Les Ulis - France > T?l. 01 69 29 06 59 > > Thank you and everyone that helped me. I did finally figure it out this morning. I am now converting for my use. I just didn't understand what I was looking at From ramit.prasad at jpmorgan.com Wed May 2 17:00:58 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 21:00:58 +0000 Subject: try/except in a loop In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303EC8@SCACMX008.exchad.jpmchase.net> > >> for obj in objs: > >> try: > >> obj.make() > >> except Exception: > >> continue > >> else: > >> break > >> else: > >> raise RuntimeError('No object worked') > > > > > > I think you misunderstand the else clauses. > > > >>>> for obj in [ 1,2,3,4 ]: > > ... try: > > ... print obj > > ... except Exception: > > ... print 'EXCEPTION' > > ... else: > > ... print 'NO EXCEPTION' > > ... else: > > ... print 'NO OBJECTS' > > ... > > 1 > > NO EXCEPTION > > 2 > > NO EXCEPTION > > 3 > > NO EXCEPTION > > 4 > > NO EXCEPTION > > NO OBJECTS > > You left out the break in the try clause's else that I had. That break > statement causes the for loop to exit early if there is no exception, > and thus the for loop's else clause does not run: > > >>> for obj in [ 1,2,3,4 ]: > ... try: > ... print obj > ... except Exception: > ... print 'EXCEPTION' > ... else: > ... print 'NO EXCEPTION' > ... break > ... else: > ... print 'NO OBJECTS' > ... > 1 > NO EXCEPTION Whoops, you are right. My apologies Chris! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nagle at animats.com Wed May 2 17:24:53 2012 From: nagle at animats.com (John Nagle) Date: Wed, 02 May 2012 14:24:53 -0700 Subject: Python SOAP library In-Reply-To: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: On 5/2/2012 8:35 AM, Alec Taylor wrote: > What's the best SOAP library for Python? > I am creating an API converter which will be serialising to/from a variety of sources, including REST and SOAP. > Relevant parsing is XML [incl. SOAP] and JSON. > Would you recommend: http://code.google.com/p/soapbox/ > > Or suggest another? > Thanks for all information, Are you implementing the client or the server? Python "Suds" is a good client-side library. It's strict SOAP; you must have a WSDL file, and the XML queries and replies must verify against the WSDL file. https://fedorahosted.org/suds/ John Nagle From russ.paielli at gmail.com Wed May 2 17:45:22 2012 From: russ.paielli at gmail.com (Russ P.) Date: Wed, 2 May 2012 14:45:22 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 2, 1:29?pm, someone wrote: > > If your data starts off with only 1 or 2 digits of accuracy, as in your > > example, then the result is meaningless -- the accuracy will be 2-2 > > digits, or 0 -- *no* digits in the answer can be trusted to be accurate. > > I just solved a FEM eigenvalue problem where the condition number of the > mass and stiffness matrices was something like 1e6... Result looked good > to me... So I don't understand what you're saying about 10 = 1 or 2 > digits. I think my problem was accurate enough, though I don't know what > error with 1e6 in condition number, I should expect. How did you arrive > at 1 or 2 digits for cond(A)=10, if I may ask ? As Steven pointed out earlier, it all depends on the precision you are dealing with. If you are just doing pure mathematical or numerical work with no real-world measurement error, then a condition number of 1e6 may be fine. But you had better be using "double precision" (64- bit) floating point numbers (which are the default in Python, of course). Those have approximately 12 digits of precision, so you are in good shape. Single-precision floats only have 6 or 7 digits of precision, so you'd be in trouble there. For any practical engineering or scientific work, I'd say that a condition number of 1e6 is very likely to be completely unacceptable. From torriem at gmail.com Wed May 2 18:04:35 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 16:04:35 -0600 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <4FA1AF73.5000804@gmail.com> On 05/02/2012 09:31 AM, Tomasz Rola wrote: > On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: >> OP lives out of his car and his main source of income seems to be ad >> revenue from his website. I'm always curious about this sort of thing. Do you know this for a fact, jaialai.technology? >> He may be nuts be he is pretty smart and some of the articles he has up >> there are worth reading. Still, he has to promote it in some way and by >> constantly posting these sorts of things he brings people to his site. >> I'm honestly impressed he can survive this way so I am willing to >> ignore or maybe killfile his postings and leave him be. > > He may be smart but obviously hasn't figured out this yet: positive aura > drives more people and more permamently towards you. Perhaps he should > develop an alter ego that could stand side by side with Dalai Lama and see > which one gets more attention. He appears to have some degree of the Aspergers/autism spectrum disorder. He quite literally cannot understand how people see him and why other people don't recognize his genius (both real and imagined). At least this is one possibility. Others who have crossed this list appear to have aspergers or autism too, such as Ranting Rick. He pops up occasionally, posts quite normally and even helpfully, and then lapses back into periods of ranting about how he can fix python and we all should be doing something. He refuses to write code to put his ideas into practice, and berates the list readers for being lazy and unwilling to code this ideas. Then eventually he disappears for months even years at a time before resurfacing. I've always been curious to know more about Rick. Where does he work? How does he live, and what does he do outside of the python list (he appears to only use his e-mail address on this list). Then other times I just worry about coding something cool in python. From rtomek at ceti.pl Wed May 2 19:01:33 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Thu, 3 May 2012 01:01:33 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4FA1AF73.5000804@gmail.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <4FA1AF73.5000804@gmail.com> Message-ID: On Wed, 2 May 2012, Michael Torrie wrote: > On 05/02/2012 09:31 AM, Tomasz Rola wrote: > > On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: > >> OP lives out of his car and his main source of income seems to be ad > >> revenue from his website. > > I'm always curious about this sort of thing. Do you know this for a > fact, jaialai.technology? I guess everything we can tell about Xah comes from his own website's "about me" pages :-). > >> He may be nuts be he is pretty smart and some of the articles he has up > >> there are worth reading. Still, he has to promote it in some way and by > >> constantly posting these sorts of things he brings people to his site. > >> I'm honestly impressed he can survive this way so I am willing to > >> ignore or maybe killfile his postings and leave him be. > > > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. Perhaps he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > He appears to have some degree of the Aspergers/autism spectrum > disorder. He quite literally cannot understand how people see him and > why other people don't recognize his genius (both real and imagined). > At least this is one possibility. >From what I have learned, Aspergers know there is a "language" that other people speak that makes them comfortable with each other, but are unable to reproduce it (in a manner similar to, say, Englishman living in France for years, with Frenchmen not very content about his broken accent). OTOH people with autism, even so called Highly Functioning Autism, neither understand there is such a language, nor give a damn (abovementioned Englishman lives in France without realizing guys around him speak differently). About geniuses - I have heard they stand up and deliver, do not rant. Xah has his strong points - they come up on his website, but interaction is probably not one of them. Perhaps Xah (and other guys) have particularly hard time with being attacked by depression and react by ranting? This, or some kind of narcistic delirium. Of course, all of those are just my somewhat-semi-educated guesses. > Others who have crossed this list appear to have aspergers or autism > too, such as Ranting Rick. He pops up occasionally, posts quite > normally and even helpfully, and then lapses back into periods of > ranting about how he can fix python and we all should be doing > something. He refuses to write code to put his ideas into practice, and > berates the list readers for being lazy and unwilling to code this > ideas. Then eventually he disappears for months even years at a time Well? I thought there were some languages similar in form to Python, that could satisfy anybody looking for such form "only with few features different". I don't remember their names - but just staying here and doing like you describe does not look rational. > before resurfacing. I've always been curious to know more about Rick. > Where does he work? How does he live, and what does he do outside of > the python list (he appears to only use his e-mail address on this list). Yep. It is always interesting, in a way. I think if they do not have constant income, they probably live a miserable lifes in some shack, working on hardware in a pre-death state, reanimated and resuscitated and breaking again... Or maybe not. Afterall, ability to resuscitate computer can be sold, too. > Then other times I just worry about coding something cool in python. Or some other language :-) Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From wuwei23 at gmail.com Wed May 2 20:20:16 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 May 2012 17:20:16 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> On May 2, 8:52?pm, Kiuhnm wrote: >> func(some_args, locals()) > > I think that's very bad. It wouldn't be safe either. What about name > clashing locals() is a dict. It's not injecting anything into func's scope other than a dict so there's not going to be any name clashes. If you don't want any of its content in your function's scope, just don't use that content. > and how would you pass only some selected functions? You wouldn't. You would just refer to the required functions in the dict _in the same way you would in both your "bad python" and code block versions. > > But as you're _passing them in by name_ why not just make it > > func(some_args) and pick them up out of the scope. > > Because that's not clean and maintainable. It's not different from using > global variables. ...I'm beginning to suspect we're not engaging in the same conversation. This is very common in Python: from module1 import func1 def func2(args): pass def main(): # do something with func1 and func2 And I've never had problems maintaining code like this. I know _exactly_ the scope that the functions exist within because I added them to it. They're not _global_ because they're restricted to that specific scope. > > _No one_ writes Python code like this. Presenting bad code as > > "pythonic" is a bit of a straw man. > > How can I present good code where there's no good way of doing that > without my module or something equivalent? > That was my point. You haven't presented *any* good code or use cases. > > This is unintuitive, to say the least. You're effectively replacing > > the common form of function definition with "with when_odd as 'n'", > > then using the surrounding context manager to limit the scope. > > What's so unintuitive about it? It's just "different". Because under no circumstance does "with function_name as string_signature" _read_ in an understandable way. It's tortuous grammar that makes no sense as a context manager. You're asking people to be constantly aware that there are two completely separate meanings to 'with x as y'. > > More importantly, _you're naming your "anonymous" code blocks_, I'm > > guessing so that func() can choose which ones to use. But if you're > > naming them, why not just use a function? > > I'm creating a dictionary, not naming my blocks just for the sake of it. > If you use a function, you end up with the solution that you called > 'bad' and non-pythonic. What I considered 'bad' was having a _single_ function that takes _multiple differing collections_ of named functions. Now you've moved the onus onto the caller to ensure that the function is provided what it needs in a specific context to do its thing. Rather than overload one single function and push the complexity out to the caller, why not have multiple functions with obvious names about what they do that only take the data they need to act on? Then again, it's _really difficult_ to tell if something named 'func()' could have a real use like this. > The problem is always the same. Those functions are defined at the > module level so name clashing and many other problems are possible. So define & use a different scope! Thankfully module level isn't the only one to play with. > I remember a post on this ng when one would create a list of commands > and then use that list as a switch table. My module let you do that very > easily. The syntax is: > > ? ? ?with func() << ':list': > ? ? ? ? ?with 'arg': > ? ? ? ? ? ? ?cmd_code > ? ? ? ? ?with 'arg': > ? ? ? ? ? ? ?cmd_code > ? ? ? ? ?with '': > ? ? ? ? ? ? ?cmd_code I'm sorry but it is still clear-as-mud what you're trying to show here. Can you show _one_ practical, real-world, non-toy example that solves a real problem in a way that Python cannot? From pengyu.ut at gmail.com Wed May 2 20:52:25 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 2 May 2012 19:52:25 -0500 Subject: Why variable used in list comprehension available outside? Message-ID: Hi, The following example demonstrates the variable 'v' used in the list comprehension is accessible out site the list comprehension. I think that 'v' should be strictly local. Does anybody know where this behavior is documented and why it is designed this way? ~/linux/test/python/man/library/__buildin__/class/{/iteritems$ cat main1.py #!/usr/bin/env python d = {'one': 10, 'two': 20} for k, v in d.iteritems(): print k, v x=[2*v for v in [1, 2, 3]] print x print k, v ~/linux/test/python/man/library/__buildin__/class/{/iteritems$ ./main1.py two 20 [2, 4, 6] two 3 one 10 [2, 4, 6] one 3 -- Regards, Peng From python.list at tim.thechases.com Wed May 2 21:23:30 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 02 May 2012 20:23:30 -0500 Subject: Why variable used in list comprehension available outside? In-Reply-To: References: Message-ID: <4FA1DE12.90305@tim.thechases.com> On 05/02/12 19:52, Peng Yu wrote: > The following example demonstrates the variable 'v' used in the > list comprehension is accessible out site the list > comprehension. It did in Python 2.x but has been fixed in 3.x: tim at bigbox:~$ python3 Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 42 >>> tim at bigbox:~$ python2.6 Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 9 >>> -tkc From showell30 at yahoo.com Wed May 2 22:14:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 19:14:54 -0700 (PDT) Subject: key/value store optimized for disk storage Message-ID: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> This is slightly off topic, but I'm hoping folks can point me in the right direction. I'm looking for a fairly lightweight key/value store that works for this type of problem: ideally plays nice with the Python ecosystem the data set is static, and written infrequently enough that I definitely want *read* performance to trump all there is too much data to keep it all in memory (so no memcache) users will access keys with fairly uniform, random probability the key/value pairs are fairly homogenous in nature: keys are <= 16 chars values are between 1k and 4k bytes generally approx 3 million key/value pairs total amount of data == 6Gb needs to work on relatively recent versions of FreeBSD and Linux My current solution works like this: keys are file paths directories are 2 levels deep (30 dirs w/100k files each) values are file contents The current solution isn't horrible, but I'm try to squeeze a little performance/robustness out of it. A minor nuisance is that I waste a fair amount of disk space, since the values are generally less than 4k in size. A larger concern is that I'm not convinced that file systems are optimized for dealing with lots of little files in a shallow directory structure. To deal with the latter issue, a minor refinement would be to deepen the directory structure, but I want to do due diligence on other options first. I'm looking for something a little lighter than a full-on database (either SQL or no-SQL), although I'm not completely ruling out any alternatives yet. As I mention up top, I'm mostly hoping folks can point me toward sources they trust, whether it be other mailing lists, good tools, etc. To the extent that this is on topic and folks don't mind discussing this here, I'm happy to follow up on any questions. Thanks, Steve P.S. I've already found some good information via Google, but there's a lot of noise out there. From no.email at nospam.invalid Wed May 2 22:46:20 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 19:46:20 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <7xsjfinfr7.fsf@ruckus.brouhaha.com> Steve Howell writes: > keys are file paths > directories are 2 levels deep (30 dirs w/100k files each) > values are file contents > The current solution isn't horrible, Yes it is ;-) > As I mention up top, I'm mostly hoping folks can point me toward > sources they trust, whether it be other mailing lists, good tools, cdb sounds reasonable for your purposes. I'm sure there are python bindings for it. http://cr.yp.to/cdb.html mentions a 4gb limit (2**32) but I half-remember something about a 64 bit version. From wrw at mac.com Wed May 2 22:50:08 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 02 May 2012 22:50:08 -0400 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: On May 2, 2012, at 10:14 PM, Steve Howell wrote: > This is slightly off topic, but I'm hoping folks can point me in the > right direction. > > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are <= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux > I don't understand that statement, I don't think I agree with it. I'm writing this e-mail on a system with 16 GB of memory. It is just under 3 years old, and if it were purchased today, it would have 32 GB of memory at essentially the same price. I think you might want to re-examine your thinking about the limits of a memory-based system. It could probably be completely written in python and still have acceptable performance. -Bill From tjreedy at udel.edu Wed May 2 23:00:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 May 2012 23:00:28 -0400 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: On 5/2/2012 10:14 PM, Steve Howell wrote: > This is slightly off topic, but I'm hoping folks can point me in the > right direction. > > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are<= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux On my 64bit machine with 64 bit Python, I would consider putting all the values in one data file and creating a key:file-offset dict. Each value would start with length(value) so that is not needed in memory. The dict, once created, could be pickled and unpickled for each run. -- Terry Jan Reedy From python.list at tim.thechases.com Wed May 2 23:03:37 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 02 May 2012 22:03:37 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <4FA1F589.5000201@tim.thechases.com> On 05/02/12 21:14, Steve Howell wrote: > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are <= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux [snip] > I'm looking for something a little lighter than a full-on database > (either SQL or no-SQL), although I'm not completely ruling out any > alternatives yet. This sounds suspiciously like the standard library's anydbm module[1] which should handle everything you list (though I can't be positive about the 6Gb bit, though I expect it should be fine; I can't find any documentation on the limits). -tkc [1] http://docs.python.org/library/anydbm.html From rosuav at gmail.com Wed May 2 23:08:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 13:08:23 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, May 3, 2012 at 3:22 AM, Tomasz Rola wrote: > I think you can catch more girls with honey and I'm not sure if I'd like > to catch those who prefer vinegar. I think we can make it into some kind > of law, say Angelico-Rola Law (of girlscatching), ok? > > "One cannot catch a girl on honey without catching some flies in the > process." > > Or is it a hypothesis? This has the makings of a publication in a respected scientific journal, I think. We should totally pursue that... next time we're bored and have no interesting problems to solve by writing code. Also, I lolled. :) ChrisA From rosuav at gmail.com Wed May 2 23:09:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 13:09:35 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4FA1AF73.5000804@gmail.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <4FA1AF73.5000804@gmail.com> Message-ID: On Thu, May 3, 2012 at 8:04 AM, Michael Torrie wrote: > Others who have crossed this list appear to have aspergers or autism > too, such as Ranting Rick. ?He pops up occasionally, posts quite > normally and even helpfully, and then lapses back into periods of > ranting about how he can fix python and we all should be doing > something. ?He refuses to write code to put his ideas into practice, and > berates the list readers for being lazy and unwilling to code this > ideas. ?Then eventually he disappears for months even years at a time > before resurfacing. ?I've always been curious to know more about Rick. > Where does he work? ?How does he live, and what does he do outside of > the python list (he appears to only use his e-mail address on this list). My first thought was that he was the alt of some regular poster - that he's the email account used for trolling, keeping it separate from the regular address. But that theory hasn't really gained credence. ChrisA From showell30 at yahoo.com Wed May 2 23:20:23 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 20:20:23 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> Message-ID: <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> On May 2, 7:46?pm, Paul Rubin wrote: > Steve Howell writes: > > ? keys are file paths > > ? directories are 2 levels deep (30 dirs w/100k files each) > > ? values are file contents > > The current solution isn't horrible, > > Yes it is ;-) > > As I mention up top, I'm mostly hoping folks can point me toward > > sources they trust, whether it be other mailing lists, good tools, > > cdb sounds reasonable for your purposes. ?I'm sure there are python > bindings for it. > > http://cr.yp.to/cdb.htmlmentions a 4gb limit (2**32) but I > half-remember something about a 64 bit version. Thanks. That's definitely in the spirit of what I'm looking for, although the non-64 bit version is obviously geared toward a slightly smaller data set. My reading of cdb is that it has essentially 64k hash buckets, so for 3 million keys, you're still scanning through an average of 45 records per read, which is about 90k of data for my record size. That seems actually inferior to a btree-based file system, unless I'm missing something. I did find this as follow up to your lead: http://thomas.mangin.com/data/source/cdb.py Unfortunately, it looks like you have to first build the whole thing in memory. From no.email at nospam.invalid Wed May 2 23:29:11 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 20:29:11 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> Message-ID: <7x62cehri0.fsf@ruckus.brouhaha.com> Steve Howell writes: > Thanks. That's definitely in the spirit of what I'm looking for, > although the non-64 bit version is obviously geared toward a slightly > smaller data set. My reading of cdb is that it has essentially 64k > hash buckets, so for 3 million keys, you're still scanning through an > average of 45 records per read, which is about 90k of data for my > record size. That seems actually inferior to a btree-based file > system, unless I'm missing something. 1) presumably you can use more buckets in a 64 bit version; 2) scanning 90k probably still takes far less time than a disk seek, even a "seek" (several microseconds in practice) with a solid state disk. > http://thomas.mangin.com/data/source/cdb.py > Unfortunately, it looks like you have to first build the whole thing > in memory. It's probably fixable, but I'd guess you could just use Bernstein's cdbdump program instead. Alternatively maybe you could use one of the *dbm libraries, which burn a little more disk space, but support online update. From showell30 at yahoo.com Thu May 3 00:08:35 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 21:08:35 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> Message-ID: <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> On May 2, 8:29?pm, Paul Rubin wrote: > Steve Howell writes: > > Thanks. ?That's definitely in the spirit of what I'm looking for, > > although the non-64 bit version is obviously geared toward a slightly > > smaller data set. ?My reading of cdb is that it has essentially 64k > > hash buckets, so for 3 million keys, you're still scanning through an > > average of 45 records per read, which is about 90k of data for my > > record size. ?That seems actually inferior to a btree-based file > > system, unless I'm missing something. > > 1) presumably you can use more buckets in a 64 bit version; 2) scanning > 90k probably still takes far less time than a disk seek, even a "seek" > (several microseconds in practice) with a solid state disk. > Doesn't cdb do at least one disk seek as well? In the diagram on this page, it seems you would need to do a seek based on the value of the initial pointer (from the 256 possible values): http://cr.yp.to/cdb/cdb.txt > >http://thomas.mangin.com/data/source/cdb.py > > Unfortunately, it looks like you have to first build the whole thing > > in memory. > > It's probably fixable, but I'd guess you could just use Bernstein's > cdbdump program instead. > > Alternatively maybe you could use one of the *dbm libraries, > which burn a little more disk space, but support online update. Yup, I don't think I want to incur the extra overhead. Do you have any first hand experience pushing dbm to the scale of 6Gb or so? My take on dbm is that its niche is more in the 10,000-record range. From alec.taylor6 at gmail.com Thu May 3 00:18:20 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 3 May 2012 14:18:20 +1000 Subject: Python SOAP library In-Reply-To: References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: Client and server (unfortunately) I need to support serialisation between formats On Thu, May 3, 2012 at 7:24 AM, John Nagle wrote: > On 5/2/2012 8:35 AM, Alec Taylor wrote: >> >> What's the best SOAP library for Python? >> I am creating an API converter which will be serialising to/from a variety >> of sources, including REST and SOAP. >> Relevant parsing is XML [incl. SOAP] and JSON. >> Would you recommend: http://code.google.com/p/soapbox/ >> >> Or suggest another? >> Thanks for all information, > > > ? Are you implementing the client or the server? > > ? Python "Suds" is a good client-side library. It's strict SOAP; > you must have a WSDL file, and the XML queries and replies must > verify against the WSDL file. > > ? ?https://fedorahosted.org/suds/ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Thu May 3 00:26:35 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 22:26:35 -0600 Subject: syntax for code blocks In-Reply-To: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4FA208FB.8010006@gmail.com> On 05/02/2012 04:52 AM, Kiuhnm wrote: > The problem is always the same. Those functions are defined at the > module level so name clashing and many other problems are possible. Only functions defined at the module level are in fact in the module's namespace. For example, this works fine, and the definitions for one and two are only within their respective scopes: def other_part(): def one(): pass def two(): pass # do something with one and two def main(): def one(): pass def two(): pass # do something with one and two other_part() If you are experiencing name clashes you need to start dividing your code up logically instead of keeping everything in the global namespace of your module. From rosuav at gmail.com Thu May 3 00:29:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 14:29:46 +1000 Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= In-Reply-To: <4fa17591$0$20186$426a34cc@news.free.fr> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> <4fa17591$0$20186$426a34cc@news.free.fr> Message-ID: On Thu, May 3, 2012 at 3:57 AM, Laurent Pointal wrote: > If you have it as a string, you can use eval() (not safe!) on the string to > retrieve the tuple, then list() on the tuple to get a list. Are you saying that eval is not safe (which it isn't), or that it has to be eval() and not safe_eval() to do this job? There's also ast.literal_eval which ought to be safe for this situation (I think). ChrisA From torriem at gmail.com Thu May 3 00:31:00 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 22:31:00 -0600 Subject: syntax for code blocks In-Reply-To: <4FA208FB.8010006@gmail.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <4FA208FB.8010006@gmail.com> Message-ID: <4FA20A04.1080203@gmail.com> On 05/02/2012 10:26 PM, Michael Torrie wrote: > If you are experiencing name clashes you need to start dividing your > code up logically instead of keeping everything in the global namespace > of your module. I shouldn't have used the word "global" here as it's not actually global. From no.email at nospam.invalid Thu May 3 02:33:56 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 23:33:56 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> Message-ID: <7xtxzx3h9n.fsf@ruckus.brouhaha.com> Steve Howell writes: > Doesn't cdb do at least one disk seek as well? In the diagram on this > page, it seems you would need to do a seek based on the value of the > initial pointer (from the 256 possible values): Yes, of course it has to seek if there is too much data to fit in memory. All I'm saying is that if you're spending milliseconds on the seek, that may dominate the lookup time even if you scan the 90k. Actually, looking at the spec more closely, there are 256 hash tables in the file, but each table can be of any size. So there can be far more than 2**16 hash slots. Uncharacteristically for Bernstein, the document is pretty unclear, so maybe you have to look at the code to be sure of the layout. Note also that empty hash buckets have just 2 words of overhead. So with 3M keys and 75% load factor, you get 4M buckets and relatively few collisions. The extra 1M buckets in a 64 bit implementation is just 16MB in the file, which isn't much at all even considering that you want it to stay resident in memory to avoid some seeks, assuming you're on a PC and not some smaller device like a phone. (A phone will have a solid state disk eliminating most seek time, so you're ok in that situation too). > Yup, I don't think I want to incur the extra overhead. Do you have > any first hand experience pushing dbm to the scale of 6Gb or so? My > take on dbm is that its niche is more in the 10,000-record range. There are a bunch of different variants. I'm trying to remember what I've personally done with it and I'm sure I've used much more than 10k records, but maybe not millions. Unix dbm was originally designed to handle millions of records back when that was a lot. I'd expect gdbm, bsddb and so forth can handle it easily. The naive Python dbm module might not be able to. The amount of data you're talking about (a few million keys, a few gb of data) is fairly modest by today's standards, so I would think fancy methods aren't really needed. From no.email at nospam.invalid Thu May 3 02:48:30 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 23:48:30 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> Message-ID: <7xpqal3gld.fsf@ruckus.brouhaha.com> Paul Rubin writes: >looking at the spec more closely, there are 256 hash tables.. ... You know, there is a much simpler way to do this, if you can afford to use a few hundred MB of memory and you don't mind some load time when the program first starts. Just dump all the data sequentially into a file. Then scan through the file, building up a Python dictionary mapping data keys to byte offsets in the file (this is a few hundred MB if you have 3M keys). Then dump the dictionary as a Python pickle and read it back in when you start the program. You may want to turn off the cyclic garbage collector when building or loading the dictionary, as it badly can slow down the construction of big lists and maybe dicts (I'm not sure of the latter). From kushal.kumaran+python at gmail.com Thu May 3 02:53:10 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 3 May 2012 12:23:10 +0530 Subject: bus errors when the network interface is reset? In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 7:31 PM, David M Chess wrote: > > We have a system running Python 2.6.6 under RHEL 6.1. ?A bunch of processes > spend most of their time sitting in a BaseHTTPServer.HTTPServer waiting for > requests. > > Last night an update pushed out via xcat whimsically restarted all of the > network interfaces, and at least some of our processes died with bus errors > (i.e. no errors or exceptions reflected up to the Python level, just a > crash). > > This is just my initial looking into this. ?Seeking opinions of the form, > say: > > Yeah, that happens, don't reset the network interfaces. > Yeah, that happens, and you can prevent the crash by doing X in your OS. > Yeah, that happens, and you can prevent the crash by doing X in your Python > code. > That wouldn't happen if you upgraded S to version V. > That sounds like a new bug and/or more information is needed; please provide > copious details including at least X, Y, and Z. > > Any thoughts or advice greatly appreciated. > Never seen this happen. Does it matter if your listening socket is bound to all interfaces v/s bound to a specific interface? From a cursory look at the source, SocketServer.TCPServer (which BaseHTTPServer is derived from) simply does a select, followed by an accept. Do any other server applications crash as well? -- regards, kushal From pjb at informatimago.com Thu May 3 04:06:42 2012 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 03 May 2012 10:06:42 +0200 Subject: John Carmack glorifying functional programing in 3k words References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <874nrxn0x9.fsf@kuiper.lan.informatimago.com> Tim Bradshaw writes: > On 2012-05-02 14:44:36 +0000, jaialai.technology at gmail.com said: > >> He may be nuts > > But he's right: programmers are pretty much fuckwits[*]: if you think > that's not true you are not old enough. > > [*] including me, especially. You need to watch: http://blog.ted.com/2012/02/29/the-only-way-to-learn-to-fly-is-to-fly-regina-dugan-at-ted2012/ -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From showell30 at yahoo.com Thu May 3 04:42:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 01:42:54 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: On May 2, 11:48?pm, Paul Rubin wrote: > Paul Rubin writes: > >looking at the spec more closely, there are 256 hash tables.. ... > > You know, there is a much simpler way to do this, if you can afford to > use a few hundred MB of memory and you don't mind some load time when > the program first starts. ?Just dump all the data sequentially into a > file. ?Then scan through the file, building up a Python dictionary > mapping data keys to byte offsets in the file (this is a few hundred MB > if you have 3M keys). ?Then dump the dictionary as a Python pickle and > read it back in when you start the program. > > You may want to turn off the cyclic garbage collector when building or > loading the dictionary, as it badly can slow down the construction of > big lists and maybe dicts (I'm not sure of the latter). I'm starting to lean toward the file-offset/seek approach. I am writing some benchmarks on it, comparing it to a more file-system based approach like I mentioned in my original post. I'll report back when I get results, but it's already way past my bedtime for tonight. Thanks for all your help and suggestions. From kiuhnm03.4t.yahoo.it Thu May 3 07:46:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 03 May 2012 13:46:31 +0200 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: <4fa27016$0$1378$4fafbaef@reader2.news.tin.it> On 5/3/2012 10:42, Steve Howell wrote: > On May 2, 11:48 pm, Paul Rubin wrote: >> Paul Rubin writes: >>> looking at the spec more closely, there are 256 hash tables.. ... >> >> You know, there is a much simpler way to do this, if you can afford to >> use a few hundred MB of memory and you don't mind some load time when >> the program first starts. Just dump all the data sequentially into a >> file. Then scan through the file, building up a Python dictionary >> mapping data keys to byte offsets in the file (this is a few hundred MB >> if you have 3M keys). Then dump the dictionary as a Python pickle and >> read it back in when you start the program. >> >> You may want to turn off the cyclic garbage collector when building or >> loading the dictionary, as it badly can slow down the construction of >> big lists and maybe dicts (I'm not sure of the latter). > > I'm starting to lean toward the file-offset/seek approach. I am > writing some benchmarks on it, comparing it to a more file-system > based approach like I mentioned in my original post. I'll report back > when I get results, but it's already way past my bedtime for tonight. > > Thanks for all your help and suggestions. You should really cache the accesses to that file hoping that the accesses are not as random as you think. If that's the case you should notice a *huge* improvement. Kiuhnm From wuwei23 at gmail.com Thu May 3 07:52:36 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 04:52:36 -0700 (PDT) Subject: pyjamas / pyjs Message-ID: Anyone else following the apparent hijack of the pyjs project from its lead developer? From ulrich.eckhardt at dominolaser.com Thu May 3 08:51:54 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 03 May 2012 14:51:54 +0200 Subject: docstrings for data fields Message-ID: Hi! My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with functions I would simply add a docstring explaining the meaning of this, but how do I do that for a non-function member? Note also that ideally, this constant wouldn't show up inside instances of the class but only inside the class itself. There are decorators for static functions or class functions, similarly there is one for instance properties but there isn't one for class properties. Would that be a useful addition? Uli From fayaz at dexetra.com Thu May 3 09:13:39 2012 From: fayaz at dexetra.com (Fayaz Yusuf Khan) Date: Thu, 03 May 2012 18:43:39 +0530 Subject: What is the use of python.cache_ubuntu? Message-ID: My Ubuntu 11.04 server ran out of inodes due to too many files in '/tmp/python.cache_ubuntu'. Does anyone know what it does? -- Cloud architect and hacker, Dexetra, India fayaz.yusuf.khan_AT_gmail_DOT_com fayaz_AT_dexetra_DOT_com +91-9746-830-823 From jeanmichel at sequans.com Thu May 3 09:27:40 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 15:27:40 +0200 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA287CC.9040000@sequans.com> Chris Kaynor wrote: > On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: > >> I have multiple objects, where any of them can serve my purpose.. However >> some objects might not have some dependencies. I can not tell before hand if >> the all the dependencies exsit. What i want to is begin processing from the >> 1st object, if no exception is raised, i am done.. if an exception is >> raised, the next object is tried, etc Something like >> >> objs = [... ] >> try: >> obj = objs[0] >> obj.make() >> except Exception, e: >> try: >> obj = objs[1] >> obj.make() >> except Exception, e: >> try: >> obj = objs[2] >> obj.make() >> except Exception, e: >> continue >> >> The problem is the length of the list of objs is variable... How can i do >> this? >> > > > for obj in objs: > try: > obj.make() > except Exception: > continue > else: > break > else: > raise RuntimeError('No object worked') > > For the record, an alternative solution without try block: candidates = [obj for obj in objs if hasattr(obj, 'make') and callable(obj.make)] if candidates: candidates[0].make() JM From __peter__ at web.de Thu May 3 09:57:32 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 May 2012 15:57:32 +0200 Subject: try/except in a loop References: <4FA287CC.9040000@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Chris Kaynor wrote: >> On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: >> >>> I have multiple objects, where any of them can serve my purpose.. >>> However some objects might not have some dependencies. I can not tell >>> before hand if the all the dependencies exsit. What i want to is begin >>> processing from the 1st object, if no exception is raised, i am done.. >>> if an exception is >>> raised, the next object is tried, etc Something like >>> >>> objs = [... ] >>> try: >>> obj = objs[0] >>> obj.make() >>> except Exception, e: >>> try: >>> obj = objs[1] >>> obj.make() >>> except Exception, e: >>> try: >>> obj = objs[2] >>> obj.make() >>> except Exception, e: >>> continue >>> >>> The problem is the length of the list of objs is variable... How can i >>> do this? >>> >> >> >> for obj in objs: >> try: >> obj.make() >> except Exception: >> continue >> else: >> break >> else: >> raise RuntimeError('No object worked') >> >> > For the record, an alternative solution without try block: Hmm, it's not sufficient that the method exists, it should succeed, too. class Obj: def make(self): raise Exception("I'm afraid I can't do that") objs = [Obj()] > candidates = [obj for obj in objs if hasattr(obj, 'make') and > callable(obj.make)] > if candidates: > candidates[0].make() It is often a matter of taste, but I tend to prefer EAFP over LBYL. From deltaquattro at gmail.com Thu May 3 10:52:54 2012 From: deltaquattro at gmail.com (deltaquattro at gmail.com) Date: Thu, 3 May 2012 07:52:54 -0700 (PDT) Subject: Create directories and modify files with Python In-Reply-To: <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> Message-ID: <31975208.1249.1336056774993.JavaMail.geo-discussion-forums@vbq19> I'm leaving the thread because I cannot read any posts, apart from Irmen's. Anyway, I would like to publicly thank all who contributed, in particular rurpy who solved my problem (and kindly sent me a personal email, so that I could see his/her post :) Best Regards Sergio Rossi From ccurvey at gmail.com Thu May 3 10:53:52 2012 From: ccurvey at gmail.com (Chris Curvey) Date: Thu, 3 May 2012 07:53:52 -0700 (PDT) Subject: c-based version of pyPdf? Message-ID: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot. So performance is starting to become a problem. Does anyone know of an analogue to pyPdf that is faster? (Maybe something based on C with Python bindings?) From jeanmichel at sequans.com Thu May 3 10:54:05 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 16:54:05 +0200 Subject: try/except in a loop In-Reply-To: References: <4FA287CC.9040000@sequans.com> Message-ID: <4FA29C0D.2020107@sequans.com> Peter Otten wrote: > Jean-Michel Pichavant wrote: > > >> Chris Kaynor wrote: >> >>> On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: >>> >>> >>>> I have multiple objects, where any of them can serve my purpose.. >>>> However some objects might not have some dependencies. I can not tell >>>> before hand if the all the dependencies exsit. What i want to is begin >>>> processing from the 1st object, if no exception is raised, i am done.. >>>> if an exception is >>>> raised, the next object is tried, etc Something like >>>> >>>> objs = [... ] >>>> try: >>>> obj = objs[0] >>>> obj.make() >>>> except Exception, e: >>>> try: >>>> obj = objs[1] >>>> obj.make() >>>> except Exception, e: >>>> try: >>>> obj = objs[2] >>>> obj.make() >>>> except Exception, e: >>>> continue >>>> >>>> The problem is the length of the list of objs is variable... How can i >>>> do this? >>>> >>>> >>> for obj in objs: >>> try: >>> obj.make() >>> except Exception: >>> continue >>> else: >>> break >>> else: >>> raise RuntimeError('No object worked') >>> >>> >>> >> For the record, an alternative solution without try block: >> > > Hmm, it's not sufficient that the method exists, it should succeed, too. > > class Obj: > def make(self): > raise Exception("I'm afraid I can't do that") > objs = [Obj()] > > >> candidates = [obj for obj in objs if hasattr(obj, 'make') and >> callable(obj.make)] >> if candidates: >> candidates[0].make() >> > > It is often a matter of taste, but I tend to prefer EAFP over LBYL. > > Could be that the OP did its job by calling the make method if it exists. If the method raises an exception, letting it through is a viable option if you cannot handle the exception. Additionaly, having a method not raising any exception is not a criteria for success, for instance def make(self): return 42 will surely fail to do what the OP is expecting. By the way on a unrelated topic, using try blocks to make the code "robust" is never a good idea, I hope the OP is not try to do that. JM From jeanmichel at sequans.com Thu May 3 11:00:25 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 17:00:25 +0200 Subject: docstrings for data fields In-Reply-To: References: Message-ID: <4FA29D89.4010402@sequans.com> Ulrich Eckhardt wrote: > Hi! > > My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with > functions I would simply add a docstring explaining the meaning of this, > but how do I do that for a non-function member? Note also that ideally, > this constant wouldn't show up inside instances of the class but only > inside the class itself. > > There are decorators for static functions or class functions, similarly > there is one for instance properties but there isn't one for class > properties. Would that be a useful addition? > > Uli > class Foo: MAX_VALUE = 42 """The maximum value""" epydoc support such docstring. If you need a native support for the python help function for instance, document it within the class docstring: class Foo: """Foo support Attributes: MAX_VALUE: the maximum value """ MAX_VALUE = 42 From lamialily at cleverpun.com Thu May 3 11:01:15 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 03 May 2012 08:01:15 -0700 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <9a75q7lj1h82efp9r8mkh0s6r8bu175ke8@4ax.com> >Anyone else following the apparent hijack of the pyjs project from its >lead developer? Not beyond what the lead developer has been posting on the newsgroup, no. Still a damn shame, though. What happens when you have an unresolvable ideological seperation like that is you branch, not take over. ~Temia -- When on earth, do as the earthlings do. From kushal.kumaran+python at gmail.com Thu May 3 11:22:13 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 3 May 2012 20:52:13 +0530 Subject: c-based version of pyPdf? In-Reply-To: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> References: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> Message-ID: On Thu, May 3, 2012 at 8:23 PM, Chris Curvey wrote: > I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot. ?So performance is starting to become a problem. > > Does anyone know of an analogue to pyPdf that is faster? ?(Maybe something based on C with Python bindings?) I wonder if it is possible to use cython to speed it up. -- regards, kushal From ian.g.kelly at gmail.com Thu May 3 11:33:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 09:33:24 -0600 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 5:52 AM, alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? I've been following it but quietly since I don't use pyjs. It surprises me that nobody is talking much about it outside of the thread on pyjamas-dev. Seems to me that any credibility in the long-term stability of the project has been pretty much shot. From tobias.koeck at gmail.com Thu May 3 11:57:01 2012 From: tobias.koeck at gmail.com (joblack) Date: Thu, 3 May 2012 08:57:01 -0700 (PDT) Subject: Problems to list *all* mountedwindows partitions Message-ID: I do have a script which shows me the mounted partitions: c = wmi.WMI ('localhost') for disk in c.Win32_DiskPartition (DriveType=3): diskspace = int(disk.FreeSpace)/1000000 if diskspace < mfspace: trigger = True ldisks.append(disk.Name +'\\ '+str('{0:,}'.format(diskspace).replace(",", "."))+' MByte\t *LOW_DISK_SPACE*') else: ldisks.append(disk.Name+'\\ '+str('{0:,}'.format(diskspace).replace(",", "."))+' MByte\t *OK*') Unfortunetly it only shows partitions mounted to a character (e.g. c: d:). There is another physical partition mounted in d:\www1 which isn't shown. Any idea how to add those partitions as well? From antti.ylikoski at aalto.fi Thu May 3 12:02:18 2012 From: antti.ylikoski at aalto.fi (Antti J Ylikoski) Date: Thu, 03 May 2012 19:02:18 +0300 Subject: Algorithms in Python, cont'd Message-ID: <8_xor.34865$I33.34584@uutiset.elisa.fi> I wrote here about some straightforward ways to program D. E. Knuth in Python, and John Nagle answered that the value of Knuth's book series to the programmer has been significantly diminished by the fact that many functionalities such as sorting and hashing have either been built in the Python language, or are available in libraries (? propos, as an aside, very many functionalities are available notably in the CPAN, the Comprehensive Perl Language Network. I wonder what were the corresponding repository with the Python language....) Nagle's comment is to my opinion very true. So I carried out a search procedure -- and found two good sources of algorithms for the Python programmer: 1) Cormen-Leiserson-Rivest-Stein: Introduction to Algorithms, 2nd edition, ISBN 0-262-53196-8. The 3rd edition has been published, I don't know which one is the most recent one. 2) Atallah-Blanton: Algorithms and Theory of Computation Handbook, Second Edition, 2 books, ISBNs 978-1-58488-822-2 and 978-1-58488-820-8. This one in particular is really good as a general computer science source. The point of this entry is that my answer to Nagle's criticism is that numerous such more or less sophisticated algorithm reference books can be found. I intended to write some demonstrations in Python -- I chose the RSA cryptosystem from Cormen et al's book and the linear programming ellipsoid algorithm from Atallah-Blanton's book -- but I have not yet done so, it would have been straightforward but too time-consuming. yours, and V/R, Antti J Ylikoski Helsinki, Finland, the EU From foobar at invalid.invalid Thu May 3 12:12:30 2012 From: foobar at invalid.invalid (mblume) Date: Thu, 3 May 2012 16:12:30 +0000 (UTC) Subject: docstrings for data fields References: Message-ID: Am Thu, 03 May 2012 14:51:54 +0200 schrieb Ulrich Eckhardt: > Hi! > > My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with > functions I would simply add a docstring explaining the meaning of this, > but how do I do that for a non-function member? Note also that ideally, > this constant wouldn't show up inside instances of the class but only > inside the class itself. > > There are decorators for static functions or class functions, similarly > there is one for instance properties but there isn't one for class > properties. Would that be a useful addition? > > Uli Docstring for Foo? >>> >>> class Foo: ... """ exports a FOO_MAX value """ ... FOO_MAX = 42 ... >>> >>> >>> >>> >>> help(Foo) Help on class Foo in module __main__: class Foo | exports a FOO_MAX value | | Data and other attributes defined here: | | FOO_MAX = 42 >>> Foo.FOO_MAX 42 >>> >>> >>> HTH Martin From kiuhnm03.4t.yahoo.it Thu May 3 12:17:05 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 03 May 2012 18:17:05 +0200 Subject: syntax for code blocks In-Reply-To: <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> Message-ID: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> On 5/3/2012 2:20, alex23 wrote: > On May 2, 8:52 pm, Kiuhnm wrote: >>> func(some_args, locals()) >> >> I think that's very bad. It wouldn't be safe either. What about name >> clashing > > locals() is a dict. It's not injecting anything into func's scope > other than a dict so there's not going to be any name clashes. If you > don't want any of its content in your function's scope, just don't use > that content. The clashing is *inside* the dictionary itself. It contains *all* local functions and variables. >> and how would you pass only some selected functions? > > You wouldn't. You would just refer to the required functions in the > dict _in the same way you would in both your "bad python" and code > block versions. See above. >>> But as you're _passing them in by name_ why not just make it >>> func(some_args) and pick them up out of the scope. >> >> Because that's not clean and maintainable. It's not different from using >> global variables. > > ...I'm beginning to suspect we're not engaging in the same > conversation. > > This is very common in Python: > > from module1 import func1 > > def func2(args): pass > > def main(): > # do something with func1 and func2 > > And I've never had problems maintaining code like this. I know > _exactly_ the scope that the functions exist within because I added > them to it. They're not _global_ because they're restricted to that > specific scope. That's not the same thing. If a function accepts some optional callbacks, and you call that function more than once, you will have problems. You'll need to redefine some callbacks and remove others. That's total lack of encapsulation. >>> _No one_ writes Python code like this. Presenting bad code as >>> "pythonic" is a bit of a straw man. >> >> How can I present good code where there's no good way of doing that >> without my module or something equivalent? >> That was my point. > > You haven't presented *any* good code or use cases. Says who? You and some others? Not enough. >>> This is unintuitive, to say the least. You're effectively replacing >>> the common form of function definition with "with when_odd as 'n'", >>> then using the surrounding context manager to limit the scope. >> >> What's so unintuitive about it? It's just "different". > > Because under no circumstance does "with function_name as > string_signature" _read_ in an understandable way. It's tortuous > grammar that makes no sense as a context manager. You're asking people > to be constantly aware that there are two completely separate meanings > to 'with x as y'. The meaning is clear from the context. I would've come up with something even better if only Python wasn't so rigid. > Rather than overload > one single function and push the complexity out to the caller, why not > have multiple functions with obvious names about what they do that > only take the data they need to act on? Because that would reveal part of the implementation. Suppose you have a complex visitor. The OOP way is to subclass, while the FP way is to accept callbacks. Why the FP way? Because it's more concise. In any case, you don't want to reveal how the visitor walks the data structure or, better, the user doesn't need to know about it. > Then again, it's _really difficult_ to tell if something named > 'func()' could have a real use like this. > >> The problem is always the same. Those functions are defined at the >> module level so name clashing and many other problems are possible. > > So define& use a different scope! Thankfully module level isn't the > only one to play with. We can do OOP even in ASM, you know? >> I remember a post on this ng when one would create a list of commands >> and then use that list as a switch table. My module let you do that very >> easily. The syntax is: >> >> with func()<< ':list': >> with 'arg': >> cmd_code >> with 'arg': >> cmd_code >> with '': >> cmd_code > > I'm sorry but it is still clear-as-mud what you're trying to show > here. Can you show _one_ practical, real-world, non-toy example that > solves a real problem in a way that Python cannot? I just did. It's just that you can't see it. Kiuhnm From lamialily at cleverpun.com Thu May 3 12:31:19 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 03 May 2012 09:31:19 -0700 Subject: syntax for code blocks In-Reply-To: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: > if only Python wasn't so rigid. what. You realize you'd have a little more luck with Python if you weren't wielding it like a cudgel in the examples you've posted here, right? Because it looks like you're treating the language as everything it isn't and nothing it is this whole time. No wonder you're having trouble making your code Pythonic. Go with the flow. ~Temia -- When on earth, do as the earthlings do. From k.sahithi2862 at gmail.com Thu May 3 12:34:39 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 3 May 2012 09:34:39 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: TOP DOT NET INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html Rajsekhar Mahankali Movie Stills http://actressgallery-kalyani.blogspot.in/2012/03/mahankali-movie-stills.html Mamata 100% Prema Movie Hot Stills http://actressgallery-kalyani.blogspot.in/2012/03/mamata-100-prema-movie-stills.html Raviteja Daruvu Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/daruvu-movie-stills.html NUVVA NENA MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/03/nuvva-nena-movie-stills.html Yadartha Prema Katha Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/yadartha-prema-katha-movie-stills.html RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From newsboost at gmail.com Thu May 3 13:30:35 2012 From: newsboost at gmail.com (someone) Date: Thu, 03 May 2012 19:30:35 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/02/2012 11:45 PM, Russ P. wrote: > On May 2, 1:29 pm, someone wrote: > >>> If your data starts off with only 1 or 2 digits of accuracy, as in your >>> example, then the result is meaningless -- the accuracy will be 2-2 >>> digits, or 0 -- *no* digits in the answer can be trusted to be accurate. >> >> I just solved a FEM eigenvalue problem where the condition number of the >> mass and stiffness matrices was something like 1e6... Result looked good >> to me... So I don't understand what you're saying about 10 = 1 or 2 >> digits. I think my problem was accurate enough, though I don't know what >> error with 1e6 in condition number, I should expect. How did you arrive >> at 1 or 2 digits for cond(A)=10, if I may ask ? > > As Steven pointed out earlier, it all depends on the precision you are > dealing with. If you are just doing pure mathematical or numerical > work with no real-world measurement error, then a condition number of > 1e6 may be fine. But you had better be using "double precision" (64- > bit) floating point numbers (which are the default in Python, of > course). Those have approximately 12 digits of precision, so you are > in good shape. Single-precision floats only have 6 or 7 digits of > precision, so you'd be in trouble there. > > For any practical engineering or scientific work, I'd say that a > condition number of 1e6 is very likely to be completely unacceptable. So how do you explain that the natural frequencies from FEM (with condition number ~1e6) generally correlates really good with real measurements (within approx. 5%), at least for the first 3-4 natural frequencies? I would say that the problem lies with the highest natural frequencies, they for sure cannot be verified - there's too little energy in them. But the lowest frequencies (the most important ones) are good, I think - even for high cond number. From russ.paielli at gmail.com Thu May 3 13:55:34 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 10:55:34 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> On May 3, 10:30?am, someone wrote: > On 05/02/2012 11:45 PM, Russ P. wrote: > > > > > On May 2, 1:29 pm, someone ?wrote: > > >>> If your data starts off with only 1 or 2 digits of accuracy, as in your > >>> example, then the result is meaningless -- the accuracy will be 2-2 > >>> digits, or 0 -- *no* digits in the answer can be trusted to be accurate. > > >> I just solved a FEM eigenvalue problem where the condition number of the > >> mass and stiffness matrices was something like 1e6... Result looked good > >> to me... So I don't understand what you're saying about 10 = 1 or 2 > >> digits. I think my problem was accurate enough, though I don't know what > >> error with 1e6 in condition number, I should expect. How did you arrive > >> at 1 or 2 digits for cond(A)=10, if I may ask ? > > > As Steven pointed out earlier, it all depends on the precision you are > > dealing with. If you are just doing pure mathematical or numerical > > work with no real-world measurement error, then a condition number of > > 1e6 may be fine. But you had better be using "double precision" (64- > > bit) floating point numbers (which are the default in Python, of > > course). Those have approximately 12 digits of precision, so you are > > in good shape. Single-precision floats only have 6 or 7 digits of > > precision, so you'd be in trouble there. > > > For any practical engineering or scientific work, I'd say that a > > condition number of 1e6 is very likely to be completely unacceptable. > > So how do you explain that the natural frequencies from FEM (with > condition number ~1e6) generally correlates really good with real > measurements (within approx. 5%), at least for the first 3-4 natural > frequencies? > > I would say that the problem lies with the highest natural frequencies, > they for sure cannot be verified - there's too little energy in them. > But the lowest frequencies (the most important ones) are good, I think - > even for high cond number. Did you mention earlier what "FEM" stands for? If so, I missed it. Is it finite-element modeling? Whatever the case, note that I said, "If you are just doing pure mathematical or numerical work with no real- world measurement error, then a condition number of 1e6 may be fine." I forgot much more than I know about finite-element modeling, but isn't it a purely numerical method of analysis? If that is the case, then my comment above is relevant. By the way, I didn't mean to patronize you with my earlier explanation of orthogonal transformations. They are fundamental to understanding the SVD, and I thought it might be interesting to anyone who is not familiar with the concept. From ian.g.kelly at gmail.com Thu May 3 14:03:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 12:03:43 -0600 Subject: syntax for code blocks In-Reply-To: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: On Thu, May 3, 2012 at 10:17 AM, Kiuhnm wrote: > On 5/3/2012 2:20, alex23 wrote: >> >> On May 2, 8:52 pm, Kiuhnm ?wrote: >>>> >>>> ? ? ?func(some_args, locals()) >>> >>> >>> I think that's very bad. It wouldn't be safe either. What about name >>> clashing >> >> >> locals() is a dict. It's not injecting anything into func's scope >> other than a dict so there's not going to be any name clashes. If you >> don't want any of its content in your function's scope, just don't use >> that content. > > > The clashing is *inside* the dictionary itself. It contains *all* local > functions and variables. Since all locals within a frame must have different names (or else they would actually be the same local), they cannot clash with one another. >> Because under no circumstance does "with function_name as >> string_signature" _read_ in an understandable way. It's tortuous >> grammar that makes no sense as a context manager. You're asking people >> to be constantly aware that there are two completely separate meanings >> to 'with x as y'. > > > The meaning is clear from the context. I would've come up with something > even better if only Python wasn't so rigid. It's really not very clear. I think the biggest difficulty is that it effectively reverses the roles of the elements in the with statement. The usual meaning of: with func(): do_stuff is that func is called to set up a context, and then the block is executed within that context. The modified meaning is that the block is gathered up as a code object and then passed as an argument into func (despite that func *appears* to be called with no arguments), which may or may not do something with it. In the former, the emphasis is on the code block; func is effectively an adverb. In the latter, func describes the main action, and the code block is the adverb. For that reason, I think that this would really need a brand new syntax in order to gain any real acceptance, not just a complicated overload of an existing statement. For that you'll need to use a preprocessor or a compiler patch (although I'm not denying that the run-time module rewriting is a neat trick). From yanegomi at gmail.com Thu May 3 14:49:29 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Thu, 3 May 2012 11:49:29 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? Message-ID: Hi Python folks! I came across a piece of code kicking around a sourcebase that does something similar to the following: >>> START >>>> #!/usr/bin/env python import sys def foo(): bar = 'abcdefg' foo = [ 'a' ] # Should throw SyntaxError? for foo[0]in bar: sys.stdout.write('%s' % foo[0]) sys.stdout.write('\n') sys.stdout.write('%s\n' % (str(foo))) # Should throw SyntaxError? if foo[0]in bar: return True return False sys.stdout.write('%r\n' % (repr(sys.version_info))) sys.stdout.write('%s\n' % (str(foo()))) >>> END >>>> I ran it against several versions of python to ensure that it wasn't a regression or fixed in a later release: $ /scratch/bin/bin/python ~/test_bad_in.py "(2, 3, 7, 'final', 0)" abcdefg ['g'] True $ python2.7 ~/test_bad_in.py "sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)" abcdefg ['g'] True $ python3.2 ~/test_bad_in.py "sys.version_info(major=3, minor=2, micro=3, releaselevel='final', serial=0)" abcdefg ['g'] True $ uname -rom FreeBSD 9.0-STABLE amd64 $ And even tried a different OS, just to make sure it wasn't a FreeBSD thing... % python test_bad_in.py "(2, 6, 5, 'final', 0)" abcdefg ['g'] True % uname -rom 2.6.32-71.el6.x86_64 x86_64 GNU/Linux I was wondering whether this was a parser bug or feature (seems like a bug, in particular because it implicitly encourages bad syntax, but I could be wrong). The grammar notes (for 2.7 at least [1]) don't seem to explicitly require a space between 'in' and another parser token (reserved work, expression, operand, etc), but I could be misreading the documentation. Thanks! -Garrett 1. http://docs.python.org/reference/grammar.html From ian.g.kelly at gmail.com Thu May 3 15:03:25 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 13:03:25 -0600 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper wrote: > ? ?I was wondering whether this was a parser bug or feature (seems > like a bug, in particular because it implicitly encourages bad syntax, > but I could be wrong). The grammar notes (for 2.7 at least [1]) don't > seem to explicitly require a space between 'in' and another parser > token (reserved work, expression, operand, etc), but I could be > misreading the documentation. The grammar doesn't require whitespace there. It tends to be flexible about whitespace wherever it's not necessary to resolve ambiguity. >>> x = [3, 2, 1] >>> x [0]if x [1]else x [2] 3 >>> 1 . real 1 >>> 1.5.real 1.5 From yanegomi at gmail.com Thu May 3 15:21:05 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Thu, 3 May 2012 12:21:05 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:03 PM, Ian Kelly wrote: > On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper wrote: >> ? ?I was wondering whether this was a parser bug or feature (seems >> like a bug, in particular because it implicitly encourages bad syntax, >> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't >> seem to explicitly require a space between 'in' and another parser >> token (reserved work, expression, operand, etc), but I could be >> misreading the documentation. > > The grammar doesn't require whitespace there. ?It tends to be flexible > about whitespace wherever it's not necessary to resolve ambiguity. > >>>> x = [3, 2, 1] >>>> x [0]if x [1]else x [2] > 3 >>>> 1 . real > 1 >>>> 1.5.real > 1.5 Sure.. it's just somewhat inconsistent with other expectations in other languages, and seems somewhat unpythonic. Not really a big deal (if it was I would have filed a bug instead), but this was definitely a bit confusing when I ran it through the interpreter a couple of times... Thanks! -Garrett From nagle at animats.com Thu May 3 15:59:00 2012 From: nagle at animats.com (John Nagle) Date: Thu, 03 May 2012 12:59:00 -0700 Subject: " An HTML page for a major site (http://www.chase.com) has some incorrect HTML. It contains Hi there, If you have USA work visa and if you reside in USA; please send the resume to Preeti at groupwaremax.com or pnbhattad at gmail.com Title Python Developer for Test Development Location: Waukesha, WI (53188) Duration: 12 months Job Description ? Proficient in Python scripting and Pyunit. ? Proficient in Python related packages knowledge. ? Experience in Unix internals and working knowledge as user. ? Expertise in Unit, Integration and System test methodologies and techniques. ? Excellent written and oral communication along with problem solving skills ? Good analytical and trouble shooting skills. ? Knowledge of C/C++ and RTOS is desired. ? Experience of designing a solution for Testing framework is desired. Regards, Preeti Bhattad | Technical Recruiter |Groupware Solution Inc Work: (732) 543 7000 x 208 |Fax: (831) 603 4007 | Email: Preeti at groupwaremax.com | Gmail: Pnbhattad at gmail.com From pnbhattad at gmail.com Thu May 3 17:23:55 2012 From: pnbhattad at gmail.com (Preeti Bhattad) Date: Thu, 3 May 2012 14:23:55 -0700 (PDT) Subject: Immediate need: Python Developer position in Waukesha, Wisconsin, USA-12 months contract with direct client with very good pay rate! Message-ID: Please send the resume to preeti at groupwaremax dot com or pnbhattad at gmail dot com Title Python Developer for Test Development Location: Waukesha, WI (53188) Duration: 12 months Job Description ? Proficient in Python scripting and Pyunit. ? Proficient in Python related packages knowledge. ? Experience in Unix internals and working knowledge as user. ? Expertise in Unit, Integration and System test methodologies and techniques. ? Excellent written and oral communication along with problem solving skills ? Good analytical and trouble shooting skills. ? Knowledge of C/C++ and RTOS is desired. ? Experience of designing a solution for Testing framework is desired. Regards, Preeti Bhattad | Technical Recruiter |Groupware Solution Inc Work: (732) 543 7000 x 208 |Fax: (831) 603 4007 | Email: Preeti at groupwaremax.com | Gmail: Pnbhattad at gmail.com From newsboost at gmail.com Thu May 3 18:21:15 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 00:21:15 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/03/2012 07:55 PM, Russ P. wrote: > On May 3, 10:30 am, someone wrote: >> On 05/02/2012 11:45 PM, Russ P. wrote: >>> For any practical engineering or scientific work, I'd say that a >>> condition number of 1e6 is very likely to be completely unacceptable. >> >> So how do you explain that the natural frequencies from FEM (with >> condition number ~1e6) generally correlates really good with real >> measurements (within approx. 5%), at least for the first 3-4 natural >> frequencies? >> >> I would say that the problem lies with the highest natural frequencies, >> they for sure cannot be verified - there's too little energy in them. >> But the lowest frequencies (the most important ones) are good, I think - >> even for high cond number. > > Did you mention earlier what "FEM" stands for? If so, I missed it. Is > it finite-element modeling? Whatever the case, note that I said, "If Sorry, yes: Finite Element Model. > you are just doing pure mathematical or numerical work with no real- > world measurement error, then a condition number of > 1e6 may be fine." I forgot much more than I know about finite-element > modeling, but isn't it a purely numerical method of analysis? If that I'm not sure exactly, what is the definition of a purely numerical method of analysis? I would guess that the answer is yes, it's a purely numerical method? But I also thing it's a practical engineering or scientific work... > is the case, then my comment above is relevant. Uh, I just don't understand the difference: 1) "For any practical engineering or scientific work, I'd say that a condition number of 1e6 is very likely to be completely unacceptable." vs. 2) "If you are just doing pure mathematical or numerical work with no real-world measurement error, then a condition number of, 1e6 may be fine." I would think that FEM is a practical engineering work and also pure numerical work... Or something... > By the way, I didn't mean to patronize you with my earlier explanation > of orthogonal transformations. They are fundamental to understanding > the SVD, and I thought it might be interesting to anyone who is not > familiar with the concept. Don't worry, I think it was really good and I don't think anyone patronized me, on the contrary, people was/is very helpful. SVD isn't my strongest side and maybe I should've thought a bit more about this singular matrix and perhaps realized what some people here already explained, a bit earlier (maybe before I asked). Anyway, it's been good to hear/read what you've (and others) have written. Yesterday and earlier today I was at work during the day so answering/replying took a bit longer than I like, considering the huge flow of posts in the matlab group. But now I'm home most of the time, for the next 3 days and will check for followup posts quite frequent, I think... From ramit.prasad at jpmorgan.com Thu May 3 18:24:05 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 3 May 2012 22:24:05 +0000 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409305758@SCACMX008.exchad.jpmchase.net> > > Sure.. it's just somewhat inconsistent with other expectations in > > other languages, and seems somewhat unpythonic. > > Never done FORTRAN, have you... Classic FORTRAN even allows > white-space INSIDE keywords. Java tends to ignore a lot of spaces as well...though not as much as classic FORTRAN it would seem. class test{ public static void main( String []args ){ System.out. println( "test" ); for (String each : args){ System.out. println( each ); } System.out. println( args [0] ); } } Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From russ.paielli at gmail.com Thu May 3 18:58:31 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 15:58:31 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: Yeah, I realized that I should rephrase my previous statement to something like this: For any *empirical* engineering or scientific work, I'd say that a condition number of 1e6 is likely to be unacceptable. I'd put finite elements into the category of theoretical and numerical rather than empirical. Still, a condition number of 1e6 would bother me, but maybe that's just me. --Russ P. On May 3, 3:21?pm, someone wrote: > On 05/03/2012 07:55 PM, Russ P. wrote: > > > > > On May 3, 10:30 am, someone ?wrote: > >> On 05/02/2012 11:45 PM, Russ P. wrote: > >>> For any practical engineering or scientific work, I'd say that a > >>> condition number of 1e6 is very likely to be completely unacceptable. > > >> So how do you explain that the natural frequencies from FEM (with > >> condition number ~1e6) generally correlates really good with real > >> measurements (within approx. 5%), at least for the first 3-4 natural > >> frequencies? > > >> I would say that the problem lies with the highest natural frequencies, > >> they for sure cannot be verified - there's too little energy in them. > >> But the lowest frequencies (the most important ones) are good, I think - > >> even for high cond number. > > > Did you mention earlier what "FEM" stands for? If so, I missed it. Is > > it finite-element modeling? Whatever the case, note that I said, "If > > Sorry, yes: Finite Element Model. > > > you are just doing pure mathematical or numerical work with no real- > > world measurement error, then a condition number of > > 1e6 may be fine." I forgot much more than I know about finite-element > > modeling, but isn't it a purely numerical method of analysis? If that > > I'm not sure exactly, what is the definition of a purely numerical > method of analysis? I would guess that the answer is yes, it's a purely > numerical method? But I also thing it's a practical engineering or > scientific work... > > > is the case, then my comment above is relevant. > > Uh, I just don't understand the difference: > > 1) "For any practical engineering or scientific work, I'd say that a > condition number of 1e6 is very likely to be completely unacceptable." > > vs. > > 2) "If you are just doing pure mathematical or numerical work with no > real-world measurement error, then a condition number of, 1e6 may be fine." > > I would think that FEM is a practical engineering work and also pure > numerical work... Or something... > > > By the way, I didn't mean to patronize you with my earlier explanation > > of orthogonal transformations. They are fundamental to understanding > > the SVD, and I thought it might be interesting to anyone who is not > > familiar with the concept. > > Don't worry, I think it was really good and I don't think anyone > patronized me, on the contrary, people was/is very helpful. SVD isn't my > strongest side and maybe I should've thought a bit more about this > singular matrix and perhaps realized what some people here already > explained, a bit earlier (maybe before I asked). Anyway, it's been good > to hear/read what you've (and others) have written. > > Yesterday and earlier today I was at work during the day so > answering/replying took a bit longer than I like, considering the huge > flow of posts in the matlab group. But now I'm home most of the time, > for the next 3 days and will check for followup posts quite frequent, I > think... From drsalists at gmail.com Thu May 3 19:00:29 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 16:00:29 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:21 PM, Garrett Cooper wrote: > On Thu, May 3, 2012 at 12:03 PM, Ian Kelly wrote: > > On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper > wrote: > >> I was wondering whether this was a parser bug or feature (seems > >> like a bug, in particular because it implicitly encourages bad syntax, > >> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't > >> seem to explicitly require a space between 'in' and another parser > >> token (reserved work, expression, operand, etc), but I could be > >> misreading the documentation. > > > > The grammar doesn't require whitespace there. It tends to be flexible > > about whitespace wherever it's not necessary to resolve ambiguity. > > > >>>> x = [3, 2, 1] > >>>> x [0]if x [1]else x [2] > > 3 > >>>> 1 . real > > 1 > >>>> 1.5.real > > 1.5 > > Sure.. it's just somewhat inconsistent with other expectations in > other languages, and seems somewhat unpythonic. > Not really a big deal (if it was I would have filed a bug > instead), but this was definitely a bit confusing when I ran it > through the interpreter a couple of times... > Thanks! > -Garrett > -- > http://mail.python.org/mailman/listinfo/python-list > For the code prettiness police, check out pep8 and/or pylint. I highly value pylint for projects more than a couple hundred lines. For the whitespace matter that's been beaten to death: http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html I'll include one issue about whitespace here. In FORTRAN 77, the following two statements look very similar, but have completely different meanings, because FORTRAN had too little significant whitespace: DO10I=1,10 DO10I=1.10 The first is the start of a loop, the second is an assignment statement. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 3 19:02:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 17:02:02 -0600 Subject: " References: Message-ID: On Thu, May 3, 2012 at 1:59 PM, John Nagle wrote: > ?An HTML page for a major site (http://www.chase.com) has > some incorrect HTML. ?It contains > > ? ? ? ? > which is not valid HTML, XML, or SMGL. ?However, most browsers > ignore it. ?BeautifulSoup treats it as the start of a CDATA section, > and consumes the rest of the document in CDATA format. > > ?Bug? Seems like a bug to me. BeautifulSoup is supposed to parse like a browser would, so if most browsers just ignore an unterminated CDATA section, then BeautifulSoup probably should too. From newsboost at gmail.com Thu May 3 19:59:50 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 01:59:50 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/04/2012 12:58 AM, Russ P. wrote: > Yeah, I realized that I should rephrase my previous statement to > something like this: > > For any *empirical* engineering or scientific work, I'd say that a > condition number of 1e6 is likely to be unacceptable. Still, I don't understand it. Do you have an example of this kind of work, if it's not FEM? > I'd put finite elements into the category of theoretical and numerical > rather than empirical. Still, a condition number of 1e6 would bother > me, but maybe that's just me. Ok, but I just don't understand what's in the "empirical" category, sorry... Maybe the conclusion is just that if cond(A) > 1e15 or 1e16, then that problem shouldn't be solved and maybe this is also approx. where matlab has it's warning-threshold (maybe, I'm just guessing here)... So, maybe I could perhaps use that limit in my future python program (when I find out how to get the condition number etc, but I assume this can be googled for with no problems)... From pengyu.ut at gmail.com Thu May 3 20:36:38 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 3 May 2012 19:36:38 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? Message-ID: Hi, list(a_set) When convert two sets with the same elements to two lists, are the lists always going to be the same (i.e., the elements in each list are ordered the same)? Is it documented anywhere? -- Regards, Peng From drsalists at gmail.com Thu May 3 20:56:40 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 17:56:40 -0700 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: If you need the same ordering in two lists, you really should sort the lists - though your comparison function need not be that traditional. You might be able to get away with not sorting sometimes, but on CPython upgrades or using different Python interpreters (Pypy, Jython), it's almost certain the ordering will be allowed to change. But sorting in a loop is not generally a good thing - there's almost always a better alternative. On Thu, May 3, 2012 at 5:36 PM, Peng Yu wrote: > Hi, > > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? > > -- > Regards, > Peng > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu May 3 21:00:50 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 May 2012 20:00:50 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <4FA32A42.7090009@tim.thechases.com> On 05/03/12 19:36, Peng Yu wrote: > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? Sets are defined as unordered which the documentation[1] confirms. A simple test seems to show that on cPython2.6 on this box, sets with 1000000 elements converted to lists without sorting seem to compare as equal (i.e., cPython is sorting), but I don't see any guarantee that this should hold for other implementations, so I'd sort first to ensure the intended behavior. -tkc [1] http://docs.python.org/library/stdtypes.html#set-types-set-frozenset """ Being an unordered collection, sets do not record element position or order of insertion. """ From miki.tebeka at gmail.com Thu May 3 21:10:46 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 3 May 2012 18:10:46 -0700 (PDT) Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> > I'm looking for a fairly lightweight key/value store that works for > this type of problem: I'd start with a benchmark and try some of the things that are already in the standard library: - bsddb - sqlite3 (table of key, value, index key) - shelve (though I doubt this one) You might find that for a little effort you get enough out of one of these. Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. HTH, -- Miki From bahamutzero8825 at gmail.com Thu May 3 22:06:48 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 03 May 2012 21:06:48 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <4FA339B8.3070306@gmail.com> On 5/3/2012 7:36 PM, Peng Yu wrote: > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? Sets are by definition unordered, so depending on their order would not be a good idea. If the order stays the same, it's at most an implementation detail which may or may not be consistent across versions, and will likely not be consistent across implementations. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From astan.chee at rhubarbfizz.com Thu May 3 22:07:51 2012 From: astan.chee at rhubarbfizz.com (astan.chee Astan) Date: Thu, 3 May 2012 19:07:51 -0700 (PDT) Subject: most efficient way of populating a combobox (in maya) Message-ID: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> Hi, I'm making a GUI in maya using python only and I'm trying to see which is more efficient. I'm trying to populate an optionMenuGrp / combo box whose contents come from os.listdir(folder). Now this is fine if the folder isn't that full but the folder has a few hundred items (almost in the thousands), it is also on the (work) network and people are constantly reading from it as well. Now I'm trying to write the GUI so that it makes the interface, and using threading - Thread, populate the box. Is this a good idea? Has anyone done this before and have experience with any limitations on it? Is the performance not significant? Thanks for any advice From wuwei23 at gmail.com Thu May 3 22:44:57 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 19:44:57 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> On May 4, 2:17?am, Kiuhnm wrote: > On 5/3/2012 2:20, alex23 wrote: > > locals() is a dict. It's not injecting anything into func's scope > > other than a dict so there's not going to be any name clashes. If you > > don't want any of its content in your function's scope, just don't use > > that content. > > The clashing is *inside* the dictionary itself. It contains *all* local > functions and variables. This is nonsense. locals() produces a dict of the local scope. I'm passing it into a function. Nothing in the local scope clashes, so the locals() dict has no "internal clashing". Nothing is injecting it into the function's local scope, so _there is no "internal clashing"_. To revise, your original "pythonic" example was, effectively: def a(): pass def b(): pass func_packet = {'a': a, 'b': b} func(arg, func_packet) My version was: def a(): pass def b(): pass func_packet = locals() func(arg, func_packet) Now, please explain how that produces name-clashes that your version does not. > >> and how would you pass only some selected functions? > > > You wouldn't. You would just refer to the required functions in the > > dict _in the same way you would in both your "bad python" and code > > block versions. > > See above. This is more nonsense. So calling 'a' in your dict is fine, but calling a in the locals() returned dict isn't? > That's not the same thing. If a function accepts some optional > callbacks, and you call that function more than once, you will have > problems. You'll need to redefine some callbacks and remove others. > That's total lack of encapsulation. Hand-wavy, no real example, doesn't make sense. > > You haven't presented *any* good code or use cases. > > Says who? You and some others? Not enough. So far, pretty much everyone who has tried to engage you on this subject on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the commenters on your project page. > The meaning is clear from the context. Which is why pretty much every post in this thread mentioned finding it confusing? > I would've come up with something even better if only Python wasn't so rigid. The inability for people to add 6 billion mini-DSLs to solve any stupid problem _is a good thing_. It makes Python consistent and predictable, and means I don't need to parse _the same syntax_ utterly different ways depending on the context. > Because that would reveal part of the implementation. > Suppose you have a complex visitor. The OOP way is to subclass, while > the FP way is to accept callbacks. Why the FP way? Because it's more > concise. > In any case, you don't want to reveal how the visitor walks the data > structure or, better, the user doesn't need to know about it. Again, nothing concrete, just vague intimations of your way being better. > > So define& ?use a different scope! Thankfully module level isn't the > > only one to play with. > > We can do OOP even in ASM, you know? ??? > > I'm sorry but it is still clear-as-mud what you're trying to show > > here. Can you show _one_ practical, real-world, non-toy example that > > solves a real problem in a way that Python cannot? > > I just did. It's just that you can't see it. "I don't understand this example, can you provide one." "I just did, you didn't understand it." Okay, done with this now. Your tautologies and arrogance are not clarifying your position at all, and I really don't give a damn, so *plonk* From showell30 at yahoo.com Thu May 3 23:12:02 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 20:12:02 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> On May 3, 1:42?am, Steve Howell wrote: > On May 2, 11:48?pm, Paul Rubin wrote: > > > Paul Rubin writes: > > >looking at the spec more closely, there are 256 hash tables.. ... > > > You know, there is a much simpler way to do this, if you can afford to > > use a few hundred MB of memory and you don't mind some load time when > > the program first starts. ?Just dump all the data sequentially into a > > file. ?Then scan through the file, building up a Python dictionary > > mapping data keys to byte offsets in the file (this is a few hundred MB > > if you have 3M keys). ?Then dump the dictionary as a Python pickle and > > read it back in when you start the program. > > > You may want to turn off the cyclic garbage collector when building or > > loading the dictionary, as it badly can slow down the construction of > > big lists and maybe dicts (I'm not sure of the latter). > > I'm starting to lean toward the file-offset/seek approach. ?I am > writing some benchmarks on it, comparing it to a more file-system > based approach like I mentioned in my original post. ?I'll report back > when I get results, but it's already way past my bedtime for tonight. > > Thanks for all your help and suggestions. I ended up going with the approach that Paul suggested (except I used JSON instead of pickle for persisting the hash). I like it for its simplicity and ease of troubleshooting. My test was to write roughly 4GB of data, with 2 million keys of 2k bytes each. The nicest thing was how quickly I was able to write the file. Writing tons of small files bogs down the file system, whereas the one- big-file approach finishes in under three minutes. Here's the code I used for testing: https://github.com/showell/KeyValue/blob/master/test_key_value.py Here are the results: ~/WORKSPACE/KeyValue > ls -l values.txt hash.txt -rw-r--r-- 1 steve staff 44334161 May 3 18:53 hash.txt -rw-r--r-- 1 steve staff 4006000000 May 3 18:53 values.txt 2000000 out of 2000000 records yielded (2k each) Begin READING test num trials 100000 time spent 39.8048191071 avg delay 0.000398048191071 real 2m46.887s user 1m35.232s sys 0m19.723s From steve+comp.lang.python at pearwood.info Thu May 3 23:19:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:19:32 GMT Subject: most efficient way of populating a combobox (in maya) References: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> Message-ID: <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:07:51 -0700, astan.chee Astan wrote: > Hi, > I'm making a GUI in maya using python only and I'm trying to see which > is more efficient. I'm trying to populate an optionMenuGrp / combo box > whose contents come from os.listdir(folder). Now this is fine if the > folder isn't that full but the folder has a few hundred items (almost in > the thousands), it is also on the (work) network and people are > constantly reading from it as well. Now I'm trying to write the GUI so > that it makes the interface, and using threading - Thread, populate the > box. Is this a good idea? Has anyone done this before and have > experience with any limitations on it? Is the performance not > significant? > Thanks for any advice Why don't you try it and see? It's not like populating a combobox in Tkinter with the contents of os.listdir requires a large amount of effort. Just try it and see whether it performs well enough. -- Steven From Joshua.R.English at gmail.com Thu May 3 23:39:47 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Thu, 3 May 2012 20:39:47 -0700 (PDT) Subject: PyTextile Question Message-ID: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> I am working with an XML database and have large chunks of text in certain child and grandchildren nodes. Because I consider well-formed XML to wrap at 70 characters and indent children, I end up with a lot of extra white space in the node.text string. (I parse with ElementTree.) I thought about using pytextile to convert this text to HTML for a nicer display option, using a wx.HTMLWindow (I don't need much in the way of fancy HTML for this application.) However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved. Example (may be munged, formatting-wise):

   This is a long multi-line description
        with several paragraphs and hopefully, eventually,
        proper HTML P-tags.

        This is a new paragraph. It should be surrounded
        by its own P-tag.

        Hopefully (again), I won't have a bunch of unwanted
        BR tags thrown in.
    

I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks. Any suggestions? Is there a good tutorial for PyTextile that I haven't found? Thanks. Josh From steve+comp.lang.python at pearwood.info Thu May 3 23:47:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:47:36 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:44:57 -0700, alex23 wrote: [snip] > My version was: > > def a(): pass > def b(): pass > > func_packet = locals() > func(arg, func_packet) > > Now, please explain how that produces name-clashes that your version > does not. I too am uncomfortable about passing locals() to a function, but not because of imaginary "name clashes". The problem as I see it is that this will give the function access to things the function has no need for. While CPython doesn't allow the called function to rebind names in the local scope (except in the case where the local scope is also the global scope), that may not apply to all Python implementations. So code which works safely in CPython may break badly in some other implementation. Another problem is that even in implementations where you can't rebind locals, the called function might mutate them instead. If any of the content of locals() are mutable, you're giving the function the potential to mutate them, whether it needs that power or not. Let me put it this way... suppose you had a function with a signature like this: def spam(a, b, c, **kwargs): ... and you knew that spam() ignores keyword arguments that it doesn't need. Or at least is supposed to. Suppose you needed to make this call: spam(23, 42, ham=None, cheese="something") Would you do this instead? foo = ['some', 'list', 'of', 'things'] spam(23, 42, ham=None, cheese="something", aardvark=foo) on the basis that since aardvark will be ignored, it is perfectly safe to do so? No, of course not, that would be stupid. Perhaps spam() has a bug that will mutate the list even though it shouldn't touch it. More importantly, you cause difficulty to the reader, who wonders why you are passing this unused and unnecessary aardvark argument to the function. My argument is that this is equivalent to passing locals() as argument. Your local scope contains some arbitrary number of name bindings. Only some of them are actually used. Why pass all (say) 25 of them if the function only needs access to (say) three? To me, passing locals() as an argument in this fashion is a code-smell: not necessary wrong or bad, but a hint that something unusual and slightly worrying is going on, and you should take a close look at it because there *may* be a problem. > So far, pretty much everyone who has tried to engage you on this subject > on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the > commenters on your project page. Goddamit, did I miss a post somewhere? What the hell is this project people keep talking about? -- Steven From steve+comp.lang.python at pearwood.info Thu May 3 23:52:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:52:55 GMT Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:30:35 +0200, someone wrote: > On 05/02/2012 11:45 PM, Russ P. wrote: >> On May 2, 1:29 pm, someone wrote: >> >>>> If your data starts off with only 1 or 2 digits of accuracy, as in >>>> your example, then the result is meaningless -- the accuracy will be >>>> 2-2 digits, or 0 -- *no* digits in the answer can be trusted to be >>>> accurate. >>> >>> I just solved a FEM eigenvalue problem where the condition number of >>> the mass and stiffness matrices was something like 1e6... Result >>> looked good to me... So I don't understand what you're saying about 10 >>> = 1 or 2 digits. I think my problem was accurate enough, though I >>> don't know what error with 1e6 in condition number, I should expect. >>> How did you arrive at 1 or 2 digits for cond(A)=10, if I may ask ? >> >> As Steven pointed out earlier, it all depends on the precision you are >> dealing with. If you are just doing pure mathematical or numerical work >> with no real-world measurement error, then a condition number of 1e6 >> may be fine. But you had better be using "double precision" (64- bit) >> floating point numbers (which are the default in Python, of course). >> Those have approximately 12 digits of precision, so you are in good >> shape. Single-precision floats only have 6 or 7 digits of precision, so >> you'd be in trouble there. >> >> For any practical engineering or scientific work, I'd say that a >> condition number of 1e6 is very likely to be completely unacceptable. > > So how do you explain that the natural frequencies from FEM (with > condition number ~1e6) generally correlates really good with real > measurements (within approx. 5%), at least for the first 3-4 natural > frequencies? I would counter your hand-waving ("correlates really good", "within approx 5%" of *what*?) with hand-waving of my own: "Sure, that's exactly what I would expect!" *wink* By the way, if I didn't say so earlier, I'll say so now: the interpretation of "how bad the condition number is" will depend on the underlying physics and/or mathematics of the situation. The interpretation of loss of digits of precision is a general rule of thumb that holds in many diverse situations, not a rule of physics that cannot be broken in this universe. If you have found a scenario where another interpretation of condition number applies, good for you. That doesn't change the fact that, under normal circumstances when trying to solve systems of linear equations, a condition number of 1e6 is likely to blow away *all* the accuracy in your measured data. (Very few physical measurements are accurate to more than six digits.) -- Steven From rosuav at gmail.com Fri May 4 00:05:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 14:05:53 +1000 Subject: syntax for code blocks In-Reply-To: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: On Fri, May 4, 2012 at 12:44 PM, alex23 wrote: > On May 4, 2:17?am, Kiuhnm wrote: >> I would've come up with something even better if only Python wasn't so rigid. > > The inability for people to add 6 billion mini-DSLs to solve any > stupid problem _is a good thing_. It makes Python consistent and > predictable, and means I don't need to parse _the same syntax_ utterly > different ways depending on the context. Agreed. If a language can be everything, it is nothing. Python has value BECAUSE it is rigid. A while ago I played around with the idea of a language that let you define your own operators... did up a spec for how it could work. It is NOT an improvement over modern languages. http://rosuav.com/1/?id=683 ChrisA From russ.paielli at gmail.com Fri May 4 00:15:20 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 21:15:20 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On May 3, 4:59?pm, someone wrote: > On 05/04/2012 12:58 AM, Russ P. wrote: > > > Yeah, I realized that I should rephrase my previous statement to > > something like this: > > > For any *empirical* engineering or scientific work, I'd say that a > > condition number of 1e6 is likely to be unacceptable. > > Still, I don't understand it. Do you have an example of this kind of > work, if it's not FEM? > > > I'd put finite elements into the category of theoretical and numerical > > rather than empirical. Still, a condition number of 1e6 would bother > > me, but maybe that's just me. > > Ok, but I just don't understand what's in the "empirical" category, sorry... I didn't look it up, but as far as I know, empirical just means based on experiment, which means based on measured data. Unless I am mistaken , a finite element analysis is not based on measured data. Yes, the results can be *compared* with measured data and perhaps calibrated with measured data, but those are not the same thing. I agree with Steven D's comment above, and I will reiterate that a condition number of 1e6 would not inspire confidence in me. If I had a condition number like that, I would look for a better model. But that's just a gut reaction, not a hard scientific rule. From tjreedy at udel.edu Fri May 4 00:16:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 00:16:07 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On 5/3/2012 8:36 PM, Peng Yu wrote: > Hi, > > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? "A set object is an unordered collection of distinct hashable objects". If you create a set from unequal objects with equal hashes, the iteration order may (should, will) depend on the insertion order as the first object added with a colliding hash will be at its 'natural position in the hash table while succeeding objects will be elsewhere. Python 3.3.0a3 (default, May 1 2012, 16:46:00) >>> hash('a') -292766495615408879 >>> hash(-292766495615408879) -292766495615408879 >>> a = {'a', -292766495615408879} >>> b = {-292766495615408879, 'a'} >>> list(a) [-292766495615408879, 'a'] >>> list(b) ['a', -292766495615408879] -- Terry Jan Reedy From wuwei23 at gmail.com Fri May 4 00:26:29 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 21:26:29 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 4, 1:47?pm, Steven D'Aprano wrote: > I too am uncomfortable about passing locals() to a function, but not > because of imaginary "name clashes". The problem as I see it is that this > will give the function access to things the function has no need for. And I would never use it in the real world. If anything, I'd rebind via the function parameters: def f(arg,fn1=None,fn2=None): pass f('arg', **locals()) This way, only the aspects of the local scope that the function explicitly asks for are provided. But: I would _only_ do this in a context I controlled. However, that would be the _same_ context in which the code blocks example would also be used. I think. I'm still waiting to see an example that is clear. I've never _ever_ found myself thinking "this code would be a LOT clearer if I didn't have to give it a name..." > Another problem is that even in implementations where you can't rebind > locals, the called function might mutate them instead. If any of the > content of locals() are mutable, you're giving the function the potential > to mutate them, whether it needs that power or not. This is true. But that would be the case with a provided dict too. I wasn't suggesting someone blindly throw locals into every function and hope for the best. I was merely stating that if you know that your function is only going to use certain values, it doesn't matter how many values you pass it, if it chooses to ignore them. > My argument is that this is equivalent to passing locals() as argument. > Your local scope contains some arbitrary number of name bindings. Only > some of them are actually used. Why pass all (say) 25 of them if the > function only needs access to (say) three? Flip it: I've set up a local scope that _only_ contains the functions I need. Why manually create a dict, repeating the name of each function as a key, when I can just use locals()? > To me, passing locals() as an > argument in this fashion is a code-smell: not necessary wrong or bad, but > a hint that something unusual and slightly worrying is going on, and you > should take a close look at it because there *may* be a problem. Or, conversely, I _know_ what I'm doing in the context of my own code and it's the most elegant way to write it. Frankly, I don't really care; I'm sick of this whole thread. We're all taking bullshit abstractions & toy examples and none of it is indicative of how anyone would really write code. > > So far, pretty much everyone who has tried to engage you on this subject > > on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the > > commenters on your project page. > > Goddamit, did I miss a post somewhere? What the hell is this project > people keep talking about? https://bitbucket.org/mtomassoli/codeblocks/ The examples here are a wonder to behold as well: http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ From no.email at nospam.invalid Fri May 4 00:38:03 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 21:38:03 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> Message-ID: <7xhavw4l3o.fsf@ruckus.brouhaha.com> Steve Howell writes: > My test was to write roughly 4GB of data, with 2 million keys of 2k > bytes each. If the records are something like english text, you can compress them with zlib and get some compression gain by pre-initializing a zlib dictionary from a fixed english corpus, then cloning it. That is, if your messages are a couple paragraphs, you might say something like: iv = (some fixed 20k or so of records concatenated together) compressor = zlib(iv).clone() # I forget what this # operation is actually called # I forget what this is called too, but the idea is you throw # away the output of compressing the fixed text, and sync # to a byte boundary compressor.sync() zout = compressor.compress(your_record).sync() ... i.e. the part you save in the file is just the difference between compress(corpus) and compress(corpus_record). To decompress, you initialize a compressor the same way, etc. It's been a while since I used that trick but for json records of a few hundred bytes, I remember getting around 2:1 compression, while starting with an unprepared compressor gave almost no compression. From research at johnohagan.com Fri May 4 00:52:14 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 4 May 2012 14:52:14 +1000 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> On Thu, 3 May 2012 04:52:36 -0700 (PDT) alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? > -- Just read the thread on pyjamas-dev. Even without knowing anything about the lead-up to the coup, its leader's linguistic contortions trying to justify it ("i have retired Luke of the management duties"), and his eagerness to change the subject ("let's move into more productive areas of discussion", and "this is the path forward; make good of the newfound power") are indicative of a guilty conscience or an underdeveloped sense of ethics. He's convinced himself that his actions were technically legal; get this: "i would recommend you terminate thought paths regarding criminal activity", and "please don't make me further intervene or forcibly terminate additional threats or remarks. there is no case to be had"! But I am having trouble imagining a scenario where sneakily acquiring the domain name and copying all the source and mailinglist data to your own server would be preferable to just forking, which is what everyone knows you're supposed to do in cases where the boss is too FOSS for your taste, or whatever the problem was. Seems like a great deal of hurt has occurred, both to people and to the project, just to save the administrative hassle of forking. In the words of the hijacker, he was going to fork but "an opportunity presented itself, and i ran with it". Nice. -- John From showell30 at yahoo.com Fri May 4 01:09:04 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 22:09:04 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> Message-ID: <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> On May 3, 9:38?pm, Paul Rubin wrote: > Steve Howell writes: > > My test was to write roughly 4GB of data, with 2 million keys of 2k > > bytes each. > > If the records are something like english text, you can compress > them with zlib and get some compression gain by pre-initializing > a zlib dictionary from a fixed english corpus, then cloning it. > That is, if your messages are a couple paragraphs, you might > say something like: > > ? iv = (some fixed 20k or so of records concatenated together) > ? compressor = zlib(iv).clone() ?# I forget what this > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# operation is actually called > > ? # I forget what this is called too, but the idea is you throw > ? # away the output of compressing the fixed text, and sync > ? # to a byte boundary > ? compressor.sync() > > ? zout = compressor.compress(your_record).sync() > ? ... > > i.e. the part you save in the file is just the difference > between compress(corpus) and compress(corpus_record). ?To > decompress, you initialize a compressor the same way, etc. > > It's been a while since I used that trick but for json records of a few > hundred bytes, I remember getting around 2:1 compression, while starting > with an unprepared compressor gave almost no compression. Sounds like a useful technique. The text snippets that I'm compressing are indeed mostly English words, and 7-bit ascii, so it would be practical to use a compression library that just uses the same good-enough encodings every time, so that you don't have to write the encoding dictionary as part of every small payload. Sort of as you suggest, you could build a Huffman encoding for a representative run of data, save that tree off somewhere, and then use it for all your future encoding/decoding. Is there a name to describe this technique? From no.email at nospam.invalid Fri May 4 02:03:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 23:03:02 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> Message-ID: <7xhavwiiuh.fsf@ruckus.brouhaha.com> Steve Howell writes: > Sounds like a useful technique. The text snippets that I'm > compressing are indeed mostly English words, and 7-bit ascii, so it > would be practical to use a compression library that just uses the > same good-enough encodings every time, so that you don't have to write > the encoding dictionary as part of every small payload. Zlib stays adaptive, the idea is just to start with some ready-made compression state that reflects the statistics of your data. > Sort of as you suggest, you could build a Huffman encoding for a > representative run of data, save that tree off somewhere, and then use > it for all your future encoding/decoding. Zlib is better than Huffman in my experience, and Python's zlib module already has the right entry points. Looking at the docs, Compress.flush(Z_SYNC_FLUSH) is the important one. I did something like this before and it was around 20 lines of code. I don't have it around any more but maybe I can write something else like it sometime. > Is there a name to describe this technique? Incremental compression maybe? From ben+python at benfinney.id.au Fri May 4 02:04:57 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 04 May 2012 16:04:57 +1000 Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wr4s7a7q.fsf@benfinney.id.au> alex23 writes: > The examples here are a wonder to behold as well: > http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ Wow. ?What really happens is that rewrite rewrites the code, executes it and quits.? Please keep this far away from anything resembling Python. -- \ ?If you go flying back through time and you see somebody else | `\ flying forward into the future, it's probably best to avoid eye | _o__) contact.? ?Jack Handey | Ben Finney From showell30 at yahoo.com Fri May 4 02:29:28 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 23:29:28 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> Message-ID: <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> On May 3, 11:03?pm, Paul Rubin wrote: > Steve Howell writes: > > Sounds like a useful technique. ?The text snippets that I'm > > compressing are indeed mostly English words, and 7-bit ascii, so it > > would be practical to use a compression library that just uses the > > same good-enough encodings every time, so that you don't have to write > > the encoding dictionary as part of every small payload. > > Zlib stays adaptive, the idea is just to start with some ready-made > compression state that reflects the statistics of your data. > > > Sort of as you suggest, you could build a Huffman encoding for a > > representative run of data, save that tree off somewhere, and then use > > it for all your future encoding/decoding. > > Zlib is better than Huffman in my experience, and Python's zlib module > already has the right entry points. ?Looking at the docs, > Compress.flush(Z_SYNC_FLUSH) is the important one. ?I did something like > this before and it was around 20 lines of code. ?I don't have it around > any more but maybe I can write something else like it sometime. > > > Is there a name to describe this technique? > > Incremental compression maybe? Many thanks, this is getting me on the right path: compressor = zlib.compressobj() s = compressor.compress("foobar") s += compressor.flush(zlib.Z_SYNC_FLUSH) s_start = s compressor2 = compressor.copy() s += compressor.compress("baz") s += compressor.flush(zlib.Z_FINISH) print zlib.decompress(s) s = s_start s += compressor2.compress("spam") s += compressor2.flush(zlib.Z_FINISH) print zlib.decompress(s) From wuwei23 at gmail.com Fri May 4 02:30:51 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 23:30:51 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> <87wr4s7a7q.fsf@benfinney.id.au> Message-ID: On May 4, 4:04?pm, Ben Finney wrote: > Wow. ?What really happens is that rewrite rewrites the code, executes it > and quits.? But that's the best bit! It's the one aspect of the module for which a context manager would actually be applicable and there's not even a suggestion of it :) From neruyume at hotmail.com Fri May 4 02:39:36 2012 From: neruyume at hotmail.com (Neru Yumekui) Date: Fri, 4 May 2012 06:39:36 +0000 Subject: [image-SIG] img.show() does not seem to work. Message-ID: I am trying to get Image.show() to work, but seem to struggle with it. Thus far I have been using PIL on Windows, and it has worked fine and all - But I recently installed it on a Linux-machine, where img.show does not seem to work (All other features apart from screengrab seems to work well). When I run the following as a normal user (id est, not root) Image.new("RGBA", (100, 100), (255, 255, 255, 0)).show() it results in these error messages in popupboxes: Failed to open "/tmp/tmpsVfqf4". Error stating file '/tmp/tmpsVfqf4': No such file or directory. Failed to execute default File Manager. Input/output error. The interpreter has the following printout Thunar: Failed to open "/tmp/tmpFs5EZr": Error stating file '/tmp/tmpFs5EZr': No such file or directory Running the same as root, nothing (visible) seems to happen, either via popups or in the interpreter, but no image shows up either. At first I did not have xv installed (it tried to open the image in gimp, but that did not work as it resulted in the errors above when gimp opened) - So I installed xv, and it still tried to open gimp - So I removed gimp, and that is more or less how I ended up where I am now. I guess show() is not that important to me as I could just save the image and open it manually, but it would be helpful to have show() at times. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shahviral.it at gmail.com Fri May 4 02:47:57 2012 From: shahviral.it at gmail.com (viral shah) Date: Fri, 4 May 2012 12:17:57 +0530 Subject: python sandbox question Message-ID: Hi Can anyone answer these two questions : I have two questions regarding Pysandbox: 1.) How do I achieve the functionality of eval? I understand sandbox.execute() is equivalent to exec, but I can't find anything such that if the code entered were 2 + 2, then it would return 4, or something to that effect. 2.) By default, sandbox.execute() makes a passed-in environment read-only -- i.e. if I do sandbox.execute('data.append(4)', locals={'data': [1, 2, 3]}), an error will occur. How do I make passed-in environments read-write? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri May 4 02:57:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 04 May 2012 08:57:06 +0200 Subject: " References: Message-ID: Ian Kelly, 04.05.2012 01:02: > BeautifulSoup is supposed to parse like a browser would Not at all, that would be html5lib. Stefan From drsalists at gmail.com Fri May 4 02:58:09 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 23:58:09 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <7xhavwiiuh.fsf@ruckus.brouhaha.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> Message-ID: On Thu, May 3, 2012 at 11:03 PM, Paul Rubin wrote: > > Sort of as you suggest, you could build a Huffman encoding for a > > representative run of data, save that tree off somewhere, and then use > > it for all your future encoding/decoding. > > Zlib is better than Huffman in my experience, and Python's zlib module > already has the right entry points. > > Isn't zlib kind of dated? Granted, it's newer than Huffman, but there's been bzip2 and xz since then, among numerous others. Here's something for xz: http://stromberg.dnsalias.org/svn/xz_mod/trunk/ An xz module is in the CPython 3.3 alphas - the above module wraps it if available, otherwise it uses ctypes or a pipe to an xz binary.. And I believe bzip2 is in the standard library for most versions of CPython. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Fri May 4 02:59:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 23:59:59 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> Message-ID: <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Steve Howell writes: > compressor = zlib.compressobj() > s = compressor.compress("foobar") > s += compressor.flush(zlib.Z_SYNC_FLUSH) > > s_start = s > compressor2 = compressor.copy() I think you also want to make a decompressor here, and initialize it with s and then clone it. Then you don't have to reinitialize every time you want to decompress something. I also seem to remember that the first few bytes of compressed output are always some fixed string or checksum, that you can strip out after compression and put back before decompression, giving further savings in output size when you have millions of records. From showell30 at yahoo.com Fri May 4 03:14:06 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 00:14:06 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: On May 3, 11:59?pm, Paul Rubin wrote: > Steve Howell writes: > > ? ? compressor = zlib.compressobj() > > ? ? s = compressor.compress("foobar") > > ? ? s += compressor.flush(zlib.Z_SYNC_FLUSH) > > > ? ? s_start = s > > ? ? compressor2 = compressor.copy() > > I think you also want to make a decompressor here, and initialize it > with s and then clone it. ?Then you don't have to reinitialize every > time you want to decompress something. Makes sense. I believe I got that part correct: https://github.com/showell/KeyValue/blob/master/salted_compressor.py > I also seem to remember that the first few bytes of compressed output > are always some fixed string or checksum, that you can strip out after > compression and put back before decompression, giving further savings in > output size when you have millions of records. I'm pretty sure this happens for free as long as the salt is large enough, but maybe I'm misunderstanding. From no.email at nospam.invalid Fri May 4 04:01:29 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 May 2012 01:01:29 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <7xzk9oidd2.fsf@ruckus.brouhaha.com> Steve Howell writes: > Makes sense. I believe I got that part correct: > > https://github.com/showell/KeyValue/blob/master/salted_compressor.py The API looks nice, but your compress method makes no sense. Why do you include s.prefix in s and then strip it off? Why do you save the prefix and salt in the instance, and have self.salt2 and s[len(self.salt):] in the decompress? You should be able to just get the incremental bit. > I'm pretty sure this happens for free as long as the salt is large > enough, but maybe I'm misunderstanding. No I mean there is some fixed overhead (a few bytes) in the compressor output, to identify it as such. That's fine when the input and output are both large, but when there's a huge number of small compressed strings, it adds up. From showell30 at yahoo.com Fri May 4 04:09:50 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 01:09:50 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> <7xzk9oidd2.fsf@ruckus.brouhaha.com> Message-ID: <0b07d733-1920-4b58-bc3a-1a0881cb02b9@kw17g2000pbb.googlegroups.com> On May 4, 1:01?am, Paul Rubin wrote: > Steve Howell writes: > > Makes sense. ?I believe I got that part correct: > > > ?https://github.com/showell/KeyValue/blob/master/salted_compressor.py > > The API looks nice, but your compress method makes no sense. ?Why do you > include s.prefix in s and then strip it off? ?Why do you save the prefix > and salt in the instance, and have self.salt2 and s[len(self.salt):] > in the decompress? ?You should be able to just get the incremental bit. This is fixed now. https://github.com/showell/KeyValue/commit/1eb316d6e9e44a37ab4f3ca73fcaf4ec0e7f22b4#salted_compressor.py > > I'm pretty sure this happens for free as long as the salt is large > > enough, but maybe I'm misunderstanding. > > No I mean there is some fixed overhead (a few bytes) in the compressor > output, to identify it as such. ?That's fine when the input and output > are both large, but when there's a huge number of small compressed > strings, it adds up. It it's in the header, wouldn't it be part of the output that comes before Z_SYNC_FLUSH? From hansmu at xs4all.nl Fri May 4 04:11:53 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 04 May 2012 10:11:53 +0200 Subject: Create directories and modify files with Python In-Reply-To: References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: <4fa38f4a$0$6924$e4fe514c@news2.news.xs4all.nl> On 1/05/12 17:34:57, rurpy at yahoo.com wrote: > from __future__ import print_function #1 > > ------------------------------------------------------------ > > #1: Not sure whether you're using Python 2 or 3. I ran > this on Python 2.7 and think it will run on Python 3 if > you remove this line. You don't have to remove that line: Python3 will accept it. It doesn't do anything in python3, since 'print' is a function whether or not you include that line, but for backward compatibility, you're still allowed to say it. Incidentally, the same is true for all __future__ features. For example, Python3 still accepts: from __future__ import nested_scopes , even though it's only really needed if you're using python 2.1, since from 2.2 onwards scopes have nested with or without that command. HTH, -- HansM From tjreedy at udel.edu Fri May 4 04:16:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 04:16:35 -0400 Subject: pyjamas / pyjs In-Reply-To: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> References: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> Message-ID: On 5/4/2012 12:52 AM, John O'Hagan wrote: > Just read the thread on pyjamas-dev. Even without knowing anything about the > lead-up to the coup, its leader's linguistic contortions trying to justify it And what is the name of the miscreant, so we know who to have nothing to with? -- Terry Jan Reedy From no.email at nospam.invalid Fri May 4 04:58:25 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 May 2012 01:58:25 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> <7xzk9oidd2.fsf@ruckus.brouhaha.com> <0b07d733-1920-4b58-bc3a-1a0881cb02b9@kw17g2000pbb.googlegroups.com> Message-ID: <7xpqak5nm6.fsf@ruckus.brouhaha.com> Steve Howell writes: >> You should be able to just get the incremental bit. > This is fixed now. Nice. > It it's in the header, wouldn't it be part of the output that comes > before Z_SYNC_FLUSH? Hmm, maybe you are right. My version was several years ago and I don't remember it well, but I half-remember spending some time diddling around with this issue. From jameskhedley at gmail.com Fri May 4 05:56:24 2012 From: jameskhedley at gmail.com (james hedley) Date: Fri, 4 May 2012 02:56:24 -0700 (PDT) Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> On Thursday, 3 May 2012 12:52:36 UTC+1, alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? Yes, me. The guy now in control got the owner of the domain name to turn it over to him, which is probably ok legally, but he had no public mandate or support. As far as I can see from the mailing list, only 3 or 4 out of the 650 subscribers actively support his actions. He's a long time contributor and genuinely seems quite talented. However there's no getting away from the fact that he's done this undemocratically, when he could have forked the project. To my mind he hasn't made a good enough reasoned justification of his arguments and he's coming across as being very defensive at the moment. The former leader, Luke Leighton, seemed to have vanished from the face of the earth but I mailed him yesterday and he's on holiday so trying not to pay too much attention to it at the moment. There's also an allegation, which I am not making myself at this point - only describing its nature, that a person may have lifted data from the original mail server without authorisation and used it to recreate the mailing list on a different machine. *If* that were to be true, then the law has been broken in at least one country. I'm arguing that there should be a public consultation over who gets to run this project and I'm also thinking of making a suggestion to the python software foundation or maybe other bodies such as the FSF (I'm not a FOSS expert but they were suggested by others) that they host a fork of this project so that we can have a legitimate and stable route forward. The problem for me with all this is that I use pyjamas in a commercial capacity and (sorry if this sounds vague but I have to be a bit careful) there are probably going to be issues with our clients - corporate people distrust FOSS at the best of times and this kind of thing will make them run for the bloody hills. In fact, there appear to be a lot of "sleeper" users who make a living out of this stuff and the actions of the new de-facto leader has jeopardised this, pretty needlessly in our opinion. James From jameskhedley at gmail.com Fri May 4 06:02:11 2012 From: jameskhedley at gmail.com (james hedley) Date: Fri, 4 May 2012 03:02:11 -0700 (PDT) Subject: pyjamas / pyjs In-Reply-To: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: <32250799.682.1336125731492.JavaMail.geo-discussion-forums@vbbfr18> By the way, there's a lot more to say on this, which I'll cover another time. There are arguments for and against what's happened; at this stage I'm just trying to flag up that there is *not* unanimity and we are not just carrying on as normal. From pengyu.ut at gmail.com Fri May 4 06:14:06 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 05:14:06 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 11:16 PM, Terry Reedy wrote: > On 5/3/2012 8:36 PM, Peng Yu wrote: >> >> Hi, >> >> list(a_set) >> >> When convert two sets with the same elements to two lists, are the >> lists always going to be the same (i.e., the elements in each list are >> ordered the same)? Is it documented anywhere? > > > "A set object is an unordered collection of distinct hashable objects". > If you create a set from unequal objects with equal hashes, the iteration > order may (should, will) depend on the insertion order as the first object > added with a colliding hash will be at its 'natural position in the hash > table while succeeding objects will be elsewhere. > > Python 3.3.0a3 (default, May ?1 2012, 16:46:00) >>>> hash('a') > -292766495615408879 >>>> hash(-292766495615408879) > -292766495615408879 >>>> a = {'a', -292766495615408879} >>>> b = {-292766495615408879, 'a'} >>>> list(a) > [-292766495615408879, 'a'] >>>> list(b) > ['a', -292766495615408879] Thanks. This is what I'm looking for. I think that this should be added to the python document as a manifestation (but nonnormalized) of what "A set object is an unordered collection of distinct hashable objects" means. -- Regards, Peng From kiuhnm03.4t.yahoo.it Fri May 4 07:12:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 04 May 2012 13:12:59 +0200 Subject: syntax for code blocks In-Reply-To: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> On 5/4/2012 4:44, alex23 wrote: > On May 4, 2:17 am, Kiuhnm wrote: >> On 5/3/2012 2:20, alex23 wrote: >>> locals() is a dict. It's not injecting anything into func's scope >>> other than a dict so there's not going to be any name clashes. If you >>> don't want any of its content in your function's scope, just don't use >>> that content. >> >> The clashing is *inside* the dictionary itself. It contains *all* local >> functions and variables. > > This is nonsense. > > locals() produces a dict of the local scope. I'm passing it into a > function. Nothing in the local scope clashes, so the locals() dict has > no "internal clashing". Nothing is injecting it into the function's > local scope, so _there is no "internal clashing"_. > > To revise, your original "pythonic" example was, effectively: > > def a(): pass > def b(): pass > > func_packet = {'a': a, 'b': b} > func(arg, func_packet) > > My version was: > > def a(): pass > def b(): pass > > func_packet = locals() > func(arg, func_packet) > > Now, please explain how that produces name-clashes that your version > does not. It doesn't always produce name-clashes but it may do so. Suppose that func takes some functions named fn1, fn2 and fn3. If you only define fn2 but you forget that you already defined somewhere before fn1, you inadvertently pass to func both fn1 and fn2. Even worse, if you write def a(): pass def b(): pass func(arg, locals()) and then you want to call func again with c() alone, you must write this: def c(): pass a = b = None func(arg, locals()) Moreover, think what happens if you add a function whose name is equal to that of a function accepted by func. That's what I call name-clashing. My solution avoids all these problems, promote encapsulation and let you program in a more functional way which is more concise that the OOP way, sometimes. >> That's not the same thing. If a function accepts some optional >> callbacks, and you call that function more than once, you will have >> problems. You'll need to redefine some callbacks and remove others. >> That's total lack of encapsulation. > > Hand-wavy, no real example, doesn't make sense. Really? Then I don't know what would make sense to you. >>> You haven't presented *any* good code or use cases. >> >> Says who? You and some others? Not enough. > > So far, pretty much everyone who has tried to engage you on this > subject on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 > like the commenters on your project page. It's impossible to have a constructive discussion while you and others feel that way. You're so biased that you don't even see how biased you are. >> The meaning is clear from the context. > > Which is why pretty much every post in this thread mentioned finding > it confusing? > >> I would've come up with something even better if only Python wasn't so rigid. > > The inability for people to add 6 billion mini-DSLs to solve any > stupid problem _is a good thing_. It makes Python consistent and > predictable, and means I don't need to parse _the same syntax_ utterly > different ways depending on the context. If I and my group of programmers devised a good and concise syntax and semantics to describe some applicative domain, then we would want to translate that into the language we use. Unfortunately, Python doesn't let you do that. I also think that uniformity is the death of creativity. What's worse, uniformity in language is also uniformity in thinking. As I said in some other posts, I think that Python is a good language, but as soon as you need to do something a little different or just differently, it's a pain to work with. >> Because that would reveal part of the implementation. >> Suppose you have a complex visitor. The OOP way is to subclass, while >> the FP way is to accept callbacks. Why the FP way? Because it's more >> concise. >> In any case, you don't want to reveal how the visitor walks the data >> structure or, better, the user doesn't need to know about it. > > Again, nothing concrete, just vague intimations of your way being > better. Sigh. >>> So define& use a different scope! Thankfully module level isn't the >>> only one to play with. >> >> We can do OOP even in ASM, you know? > > ??? You can do whatever you want by hand: you can certainly define your functions inside another function or a class, but that's just more noise added to the mix. >>> I'm sorry but it is still clear-as-mud what you're trying to show >>> here. Can you show _one_ practical, real-world, non-toy example that >>> solves a real problem in a way that Python cannot? >> >> I just did. It's just that you can't see it. > > "I don't understand this example, can you provide one." "I just did, > you didn't understand it." Your rephrasing is quite wrong. You asked for a practical example and I said that I already showed you one. It's just that you can't see it (as practical). > Okay, done with this now. Your tautologies and arrogance are not > clarifying your position at all, and I really don't give a damn, so > *plonk* I don't care if you don't read this post. Now that I've written it I'll post it anyway. Unfortunately, communication is a two-people thing. It's been clear from the first post that your intention wasn't to understand what I'm proposing. There are some things, like what I say about name-clashing, that you should understand no matter how biased you are. If you don't, you're just pretending or maybe you weren't listening at all. Kiuhnm From rosuav at gmail.com Fri May 4 07:21:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 21:21:30 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: > Thanks. This is what I'm looking for. I think that this should be > added to the python document as a manifestation (but nonnormalized) of > what "A set object is an unordered collection of distinct hashable > objects" means. There are other things that can prove it to be unordered, too; the exact pattern and order of additions and deletions can affect the iteration order. The only thing you can be sure of is that you can't be sure of it. ChrisA From rosuav at gmail.com Fri May 4 07:29:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 21:29:29 +1000 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, May 4, 2012 at 9:12 PM, Kiuhnm wrote: > If I and my group of programmers devised a good and concise syntax and > semantics to describe some applicative domain, then we would want to > translate that into the language we use. > Unfortunately, Python doesn't let you do that. No, this is not unfortunate. Python does certain things and does them competently. If Python doesn't let you write what you want the way you want, then you do not want Python. This is not an insult to Python, nor is it a cop-out whereby the Python Cabal tells you to shut up and go away, you aren't doing things the Proper Way, you need to change your thinking to be more in line with Correct Syntax. It is simply a reflection of the nature of languages. If I want to write a massively-parallel program that can be divided across any number of computers around the world, Python isn't the best thing to use. If I want to write a MUD with efficient reloading of code on command, Python isn't the best thing to use. If I want to write a device driver, Python isn't the best thing to use. If I want to write a simple script that does exactly what it should and didn't take me long to write, then Python quite likely IS the best thing to use. But whatever you do, play to the strengths of the language you use, don't play to its weaknesses. Don't complain when C leaks the memory that you forgot to free(), don't bemoan LISP's extreme parenthesizing, don't fight the Python object model. You'll only hurt yourself. In any case, you know where to find Ruby any time you want it. ChrisA From pengyu.ut at gmail.com Fri May 4 08:00:32 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 07:00:32 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 6:21 AM, Chris Angelico wrote: > On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: >> Thanks. This is what I'm looking for. I think that this should be >> added to the python document as a manifestation (but nonnormalized) of >> what "A set object is an unordered collection of distinct hashable >> objects" means. > > There are other things that can prove it to be unordered, too; the > exact pattern and order of additions and deletions can affect the > iteration order. The only thing you can be sure of is that you can't > be sure of it. I agree. My point was just to suggest adding more explanations on the details in the manual. -- Regards, Peng From krishnandhevika at gmail.com Fri May 4 08:14:54 2012 From: krishnandhevika at gmail.com (dhevika k) Date: Fri, 4 May 2012 05:14:54 -0700 (PDT) Subject: Download hot and tempting love application this link click here Message-ID: <005409ef-55aa-4c92-82dd-6efd2bb82751@t2g2000pbl.googlegroups.com> http://123maza.com/48/share007/ From ndbecker2 at gmail.com Fri May 4 08:21:57 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 04 May 2012 08:21:57 -0400 Subject: set PYTHONPATH for a directory? Message-ID: I'm testing some software I'm building against an alternative version of a library. So I have an alternative library in directory L. Then I have in an unrelated directory, the test software, which I need to use the library version from directory L. One approach is to set PYTHONPATH whenever I run this test software. Any suggestion on a more foolproof approach? From newsboost at gmail.com Fri May 4 09:30:12 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 15:30:12 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/04/2012 05:52 AM, Steven D'Aprano wrote: > On Thu, 03 May 2012 19:30:35 +0200, someone wrote: >> So how do you explain that the natural frequencies from FEM (with >> condition number ~1e6) generally correlates really good with real >> measurements (within approx. 5%), at least for the first 3-4 natural >> frequencies? > > I would counter your hand-waving ("correlates really good", "within > approx 5%" of *what*?) with hand-waving of my own: Within 5% of experiments of course. There is not much else to compare with. > "Sure, that's exactly what I would expect!" > > *wink* > > By the way, if I didn't say so earlier, I'll say so now: the > interpretation of "how bad the condition number is" will depend on the > underlying physics and/or mathematics of the situation. The > interpretation of loss of digits of precision is a general rule of thumb > that holds in many diverse situations, not a rule of physics that cannot > be broken in this universe. > > If you have found a scenario where another interpretation of condition > number applies, good for you. That doesn't change the fact that, under > normal circumstances when trying to solve systems of linear equations, a > condition number of 1e6 is likely to blow away *all* the accuracy in your > measured data. (Very few physical measurements are accurate to more than > six digits.) Not true, IMHO. Eigenfrequencies (I think that is a very typical physical measurement and I cannot think of something that is more typical) don't need to be accurate with 6 digits. I'm happy with below 5% error. So if an eigenfrequency is measured to 100 Hz, I'm happy if the numerical model gives a result in the 5%-range of 95-105 Hz. This I got with a condition number of approx. 1e6 and it's good enough for me. I don't think anyone expects 6-digit accuracy with eigenfrequncies. From newsboost at gmail.com Fri May 4 09:36:09 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 15:36:09 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/04/2012 06:15 AM, Russ P. wrote: > On May 3, 4:59 pm, someone wrote: >> On 05/04/2012 12:58 AM, Russ P. wrote: >> Ok, but I just don't understand what's in the "empirical" category, sorry... > > I didn't look it up, but as far as I know, empirical just means based > on experiment, which means based on measured data. Unless I am FEM based on measurement data? Still, I don't understand it, sorry. > mistaken , a finite element analysis is not based on measured data. I'm probably a bit narrow-thinking because I just worked with this small FEM-program (in Matlab), but can you please give an example of a matrix-problem that is based on measurement data? > Yes, the results can be *compared* with measured data and perhaps > calibrated with measured data, but those are not the same thing. Exactly. That's why I don't understand what solving a matrix system using measurement/empirical data, could typically be an example of...? > I agree with Steven D's comment above, and I will reiterate that a > condition number of 1e6 would not inspire confidence in me. If I had a > condition number like that, I would look for a better model. But > that's just a gut reaction, not a hard scientific rule. I don't have any better model and don't know anything better. I still think that 5% accuracy is good enough and that nobody needs 6-digits precision for practical/engineering/empirical work... Maybe quantum physicists needs more than 6 digits of accuracy, but most practical/engineering problems are ok with an accuracy of 5%, I think, IMHO... Please tell me if I'm wrong. From duncan.booth at invalid.invalid Fri May 4 09:43:03 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 May 2012 13:43:03 GMT Subject: pyjamas / pyjs References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: james hedley wrote: > There's also an allegation, which I am not making myself at this point > - only describing its nature, that a person may have lifted data from > the original mail server without authorisation and used it to recreate > the mailing list on a different machine. *If* that were to be true, > then the law has been broken in at least one country. > I don't know whether they moved it to another machine or not, but what they definitely did do was start sending emails to all the people on the list who had sending of emails disabled (including myself) which resulted in a flood of emails and from the sound of it a lot of annoyed people. If he wanted to community support for the takeover that probably wasn't a good start. In case it isn't obvious why I might be subscribed but emails turned off, I read mailing lists like that through gmane in which case I still need to sign up to the list to post but definitely don't want to receive emails. -- Duncan Booth http://kupuguy.blogspot.com From d at davea.name Fri May 4 09:46:36 2012 From: d at davea.name (Dave Angel) Date: Fri, 04 May 2012 09:46:36 -0400 Subject: set PYTHONPATH for a directory? In-Reply-To: References: Message-ID: <4FA3DDBC.9050405@davea.name> On 05/04/2012 08:21 AM, Neal Becker wrote: > I'm testing some software I'm building against an alternative version of a > library. So I have an alternative library in directory L. Then I have in an > unrelated directory, the test software, which I need to use the library version > from directory L. > > One approach is to set PYTHONPATH whenever I run this test software. Any > suggestion on a more foolproof approach? > Simply modify sys.path at the beginning of your test software. That's where import searches. -- DaveA From pedro.larroy.lists at gmail.com Fri May 4 10:04:58 2012 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Fri, 4 May 2012 16:04:58 +0200 Subject: set PYTHONPATH for a directory? In-Reply-To: <4FA3DDBC.9050405@davea.name> References: <4FA3DDBC.9050405@davea.name> Message-ID: Isn't virtualenv for this kind of scenario? Pedro. On Fri, May 4, 2012 at 3:46 PM, Dave Angel wrote: > On 05/04/2012 08:21 AM, Neal Becker wrote: >> I'm testing some software I'm building against an alternative version of a >> library. ?So I have an alternative library in directory L. ?Then I have in an >> unrelated directory, the test software, which I need to use the library version >> from directory L. >> >> One approach is to set PYTHONPATH whenever I run this test software. ?Any >> suggestion on a more foolproof approach? >> > Simply modify ?sys.path ?at the beginning of your test software. ?That's > where import searches. > > > > -- > > DaveA > > -- > http://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Fri May 4 10:41:04 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 May 2012 08:41:04 -0600 Subject: " References: Message-ID: On Fri, May 4, 2012 at 12:57 AM, Stefan Behnel wrote: > Ian Kelly, 04.05.2012 01:02: >> BeautifulSoup is supposed to parse like a browser would > > Not at all, that would be html5lib. Well, I guess that depends on whether we're talking about BeautifulSoup 3 (a regex-based screen scraper with methods for navigating and searching the resulting tree) or 4 (purely a parse tree navigation library that relies on external libraries to do the actual parsing). According to the BS3 documentation, "The BeautifulSoup class is full of web-browser-like heuristics for divining the intent of HTML authors." If we're talking about BS4, though, then the problem in this instance would have nothing to do with BS4 and instead would be an issue of whatever underlying parser the OP is using. From torriem at gmail.com Fri May 4 11:18:27 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 04 May 2012 09:18:27 -0600 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4FA3F343.9050207@gmail.com> On 05/04/2012 05:12 AM, Kiuhnm wrote: >> Hand-wavy, no real example, doesn't make sense. > > Really? Then I don't know what would make sense to you. Speaking as as an observer here, I've read your blog post, and looked at your examples. They don't make sense to me either. They aren't real examples. They are abstract examples. They do not answer the questions, "what actual, real world python problems does this solve?" and "how is this better than a plain python solution?" For example, I've seen ruby code where blocks are used in a real-world way. Could you not put in something similar in your examples? Since you've written this code you must use it in everyday python coding. Show us what you've been doing with it. Also while some of your blog snippets are snippets, other code examples you provide purport to be complete examples, when in fact they are not. For example, about 45% of the way down your blog page you have a block of code that looks to be self-contained. It has "import logging" and "import random" at the top of it. Yet it cannot run as it's missing an import of your module. >>>> You haven't presented *any* good code or use cases. >>> >>> Says who? You and some others? Not enough. How many people do you need to tell you this before it's good enough? Doesn't matter how genius your code is if no one knows when or how to use it. > It's impossible to have a constructive discussion while you and others > feel that way. You're so biased that you don't even see how biased you are. Having followed the conversation somewhat, I can say that you have been given a fair hearing. People aren't just dissing on it because it's ruby. You are failing to listen to them just as much as you claim they are failing to listen to them. >>> The meaning is clear from the context. Not really. For one we're not Ruby programmers here, and like has been said, where is a real example of real code that's not just some abstract "hello this is block1, this is block 2" sort of thing? Providing non-block code to compare is important too. > Unfortunately, communication is a two-people thing. It's been clear from > the first post that your intention wasn't to understand what I'm proposing. > There are some things, like what I say about name-clashing, that you > should understand no matter how biased you are. > If you don't, you're just pretending or maybe you weren't listening at all. well there's my attempt. From showell30 at yahoo.com Fri May 4 11:27:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 08:27:54 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> Message-ID: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> On May 3, 6:10?pm, Miki Tebeka wrote: > > I'm looking for a fairly lightweight key/value store that works for > > this type of problem: > > I'd start with a benchmark and try some of the things that are already in the standard library: > - bsddb > - sqlite3 (table of key, value, index key) > - shelve (though I doubt this one) > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: http://www.gossamer-threads.com/lists/python/python/106494 I'll give sqlite3 a spin. Has anybody out there wrapped sqlite3 behind a hash interface already? I know it's simple to do conceptually, but there are some minor details to work out for large amounts of data (like creating the index after all the inserts), so if somebody's already tackled this, it would be useful to see their code. > You might find that for a little effort you get enough out of one of these. > > Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. Thanks. From lamialily at cleverpun.com Fri May 4 12:53:08 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 04 May 2012 09:53:08 -0700 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <5528q7pvga8sl9dao3psl4n7mlnk77dql6@4ax.com> You know what I find rich about all of this? >>>[ ... ]> I'd like to change the syntax of my module 'codeblocks' to make it more >>>[ ... ]> pythonic. Kiuhnm posted a thread to the group asking us to help him make it more Pythonic, but he has steadfastly refused every single piece of help he was offered because he feels his code is good enough after all. So why are we perpetuating it? ~Temia -- When on earth, do as the earthlings do. From python.list at tim.thechases.com Fri May 4 13:14:36 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 12:14:36 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> Message-ID: <4FA40E7C.3040504@tim.thechases.com> On 05/04/12 10:27, Steve Howell wrote: > On May 3, 6:10 pm, Miki Tebeka wrote: >>> I'm looking for a fairly lightweight key/value store that works for >>> this type of problem: >> >> I'd start with a benchmark and try some of the things that are already in the standard library: >> - bsddb >> - sqlite3 (table of key, value, index key) > > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: Have you tested the standard library's anydbm module (certainly not deprecated)? In a test I threw together, after populating one gig worth of data, lookups were pretty snappy (compared to the lengthy time it took to populate the 1gb of junk data). -tkc From chris at python.org Fri May 4 13:20:29 2012 From: chris at python.org (Chris Withers) Date: Fri, 04 May 2012 18:20:29 +0100 Subject: recruiter spam In-Reply-To: References: Message-ID: <4FA40FDD.1080306@python.org> Please don't spam the list with job adverts, post to the job board instead: http://www.python.org/community/jobs/howto/ cheers, Chris On 03/05/2012 22:13, Preeti Bhattad wrote: > Hi there, > If you have USA work visa and if you reside in USA; > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Fri May 4 13:43:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 13:43:12 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On 5/4/2012 8:00 AM, Peng Yu wrote: > On Fri, May 4, 2012 at 6:21 AM, Chris Angelico wrote: >> On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: >>> Thanks. This is what I'm looking for. I think that this should be >>> added to the python document as a manifestation (but nonnormalized) of >>> what "A set object is an unordered collection of distinct hashable >>> objects" means. >> >> There are other things that can prove it to be unordered, too; the >> exact pattern and order of additions and deletions can affect the >> iteration order. The only thing you can be sure of is that you can't >> be sure of it. > > I agree. My point was just to suggest adding more explanations on the > details in the manual. I am not sure how much clearer we can be in the language manual. The word 'unordered' means just that. If one imposes an arbitrary linear order on an unordered collection, it is arbitrary. It is frustrating that people do not want to believe that, and even write tests depending on today's arbitrary serialization order being deterministic indefinitely. There is a section about this in the doctest doc, but people do it anyway. I will think about a sentence to add. -- Terry Jan Reedy From python.list at tim.thechases.com Fri May 4 13:46:43 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 12:46:43 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> Message-ID: <4FA41603.5000804@tim.thechases.com> On 05/04/12 12:22, Steve Howell wrote: > Which variant do you recommend? > > """ anydbm is a generic interface to variants of the DBM database > ? dbhash (requires bsddb), gdbm, or dbm. If none of these modules > is installed, the slow-but-simple implementation in module > dumbdbm will be used. > > """ If you use the stock anydbm module, it automatically chooses the best it knows from the ones available: import os import hashlib import random from string import letters import anydbm KB = 1024 MB = KB * KB GB = MB * KB DESIRED_SIZE = 1 * GB KEYS_TO_SAMPLE = 20 FNAME = "mydata.db" i = 0 md5 = hashlib.md5() db = anydbm.open(FNAME, 'c') try: print("Generating junk data...") while os.path.getsize(FNAME) < 6*GB: key = md5.update(str(i))[:16] size = random.randrange(1*KB, 4*KB) value = ''.join(random.choice(letters) for _ in range(size)) db[key] = value i += 1 print("Gathering %i sample keys" % KEYS_TO_SAMPLE) keys_of_interest = random.sample(db.keys(), KEYS_TO_SAMPLE) finally: db.close() print("Reopening for a cold sample set in case it matters") db = anydbm.open(FNAME) try: print("Performing %i lookups") for key in keys_of_interest: v = db[key] print("Done") finally: db.close() (your specs said ~6gb of data, keys up to 16 characters, values of 1k-4k, so this should generate such data) -tkc From ramit.prasad at jpmorgan.com Fri May 4 14:19:39 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 4 May 2012 18:19:39 +0000 Subject: most efficient way of populating a combobox (in maya) In-Reply-To: <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409306248@SCACMX008.exchad.jpmchase.net> > > I'm making a GUI in maya using python only and I'm trying to see which > > is more efficient. I'm trying to populate an optionMenuGrp / combo box > > whose contents come from os.listdir(folder). Now this is fine if the > > folder isn't that full but the folder has a few hundred items (almost in > > the thousands), it is also on the (work) network and people are > > constantly reading from it as well. Now I'm trying to write the GUI so > > that it makes the interface, and using threading - Thread, populate the > > box. Is this a good idea? Has anyone done this before and have > > experience with any limitations on it? Is the performance not > > significant? > > Thanks for any advice > > > Why don't you try it and see? > > > It's not like populating a combobox in Tkinter with the contents of > os.listdir requires a large amount of effort. Just try it and see whether > it performs well enough. In my experience, a generic combobox with hundreds or thousands of elements is difficult and annoying to use. Not sure if the Tkinter version has scroll bars or auto-completion, but if not you may want to subclass and add those features. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From emile at fenx.com Fri May 4 15:14:18 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 May 2012 12:14:18 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <4FA41603.5000804@tim.thechases.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> Message-ID: On 5/4/2012 10:46 AM Tim Chase said... I hit a few snags testing this on my winxp w/python2.6.1 in that getsize wasn't finding the file as it was created in two parts with .dat and .dir extension. Also, setting key failed as update returns None. The changes I needed to make are marked below. Emile > import os > import hashlib > import random > from string import letters > > import anydbm > > KB = 1024 > MB = KB * KB > GB = MB * KB > DESIRED_SIZE = 1 * GB > KEYS_TO_SAMPLE = 20 > FNAME = "mydata.db" FDATNAME = r"mydata.db.dat" > > i = 0 > md5 = hashlib.md5() > db = anydbm.open(FNAME, 'c') > try: > print("Generating junk data...") > while os.path.getsize(FNAME)< 6*GB: while os.path.getsize(FDATNAME) < 6*GB: > key = md5.update(str(i))[:16] md5.update(str(i)) key = md5.hexdigest()[:16] > size = random.randrange(1*KB, 4*KB) > value = ''.join(random.choice(letters) > for _ in range(size)) > db[key] = value > i += 1 > print("Gathering %i sample keys" % KEYS_TO_SAMPLE) > keys_of_interest = random.sample(db.keys(), KEYS_TO_SAMPLE) > finally: > db.close() > > print("Reopening for a cold sample set in case it matters") > db = anydbm.open(FNAME) > try: > print("Performing %i lookups") > for key in keys_of_interest: > v = db[key] > print("Done") > finally: > db.close() > From python.list at tim.thechases.com Fri May 4 15:49:25 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 14:49:25 -0500 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> Message-ID: <4FA432C5.3040809@tim.thechases.com> On 05/04/12 14:14, Emile van Sebille wrote: > On 5/4/2012 10:46 AM Tim Chase said... > > I hit a few snags testing this on my winxp w/python2.6.1 in that getsize > wasn't finding the file as it was created in two parts with .dat and > .dir extension. Hrm...must be a Win32 vs Linux thing. > Also, setting key failed as update returns None. Doh, that's what I get for not testing my hand-recreation of the test program I cobbled together and then deleted. Thanks for tweaking that. -tkc From rowen at uw.edu Fri May 4 15:54:27 2012 From: rowen at uw.edu (Russell E. Owen) Date: Fri, 04 May 2012 12:54:27 -0700 Subject: pickle question: sequencing of operations Message-ID: What is the sequence of calls when unpickling a class with __setstate__? >From experimentation I see that __setstate__ is called and __init__ is not, but I think I need more info. I'm trying to pickle an instance of a class that is a subclass of another class that contains unpickleable objects. What I'd like to do is basically just pickle the constructor parameters and then use those to reconstruct the object on unpickle, but I'm not sure how to go about this. Or an example if anyone has one. -- Russell From pengyu.ut at gmail.com Fri May 4 16:08:23 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 15:08:23 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > On 5/4/2012 8:00 AM, Peng Yu wrote: >> >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: >>> >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: >>>> >>>> Thanks. This is what I'm looking for. I think that this should be >>>> added to the python document as a manifestation (but nonnormalized) of >>>> what "A set object is an unordered collection of distinct hashable >>>> objects" means. >>> >>> >>> There are other things that can prove it to be unordered, too; the >>> exact pattern and order of additions and deletions can affect the >>> iteration order. The only thing you can be sure of is that you can't >>> be sure of it. >> >> >> I agree. My point was just to suggest adding more explanations on the >> details in the manual. > > > I am not sure how much clearer we can be in the language manual. The word > 'unordered' means just that. If one imposes an arbitrary linear order on an > unordered collection, it is arbitrary. It is frustrating that people do not > want to believe that, and even write tests depending on today's arbitrary > serialization order being deterministic indefinitely. There is a section > about this in the doctest doc, but people do it anyway. I will think about a > sentence to add. You can just add the example that you posted to demonstrate what the unordered means. A curious user might want to know under what condition the "unorderness" can affect the results, because for trivial examples (like the following), it does seem that there is some orderness in a set. set(['a', 'b', 'c']) set(['c', 'b', 'a']) -- Regards, Peng From emile at fenx.com Fri May 4 16:15:05 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 May 2012 13:15:05 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <4FA432C5.3040809@tim.thechases.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> <4FA432C5.3040809@tim.thechases.com> Message-ID: On 5/4/2012 12:49 PM Tim Chase said... > On 05/04/12 14:14, Emile van Sebille wrote: >> On 5/4/2012 10:46 AM Tim Chase said... >> >> I hit a few snags testing this on my winxp w/python2.6.1 in that getsize >> wasn't finding the file as it was created in two parts with .dat and >> .dir extension. > > Hrm...must be a Win32 vs Linux thing. Or an anydbm thing -- you may get different results depending... Emile From ferreirafm at lim12.fm.usp.br Fri May 4 16:33:39 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Fri, 4 May 2012 13:33:39 -0700 (PDT) Subject: for loop: weird behavior Message-ID: <1336163619790-4953214.post@n6.nabble.com> Hi there, I simply can't print anything in the second for-loop bellow: ######################################### #!/usr/bin/env python import sys filename = sys.argv[1] outname = filename.split('.')[0] + '_pdr.dat' begin = 'Distance distribution' end = 'Reciprocal' first = 0 last = 0 with open(filename) as inf: for num, line in enumerate(inf, 1): #print num, line if begin in line: first = num if end in line: last = num for num, line in enumerate(inf, 1): print 'Ok!' print num, line if num in range(first + 5, last - 1): print line print first, last print range(first + 5, last - 1) #################################### The output goes here: http://pastebin.com/egnahct2 Expected: at least the string 'Ok!' from the second for-loop. What I'm doing wrong? thanks in advance. Fred -- View this message in context: http://python.6.n6.nabble.com/for-loop-weird-behavior-tp4953214.html Sent from the Python - python-list mailing list archive at Nabble.com. From tjreedy at udel.edu Fri May 4 16:47:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 16:47:07 -0400 Subject: for loop: weird behavior In-Reply-To: <1336163619790-4953214.post@n6.nabble.com> References: <1336163619790-4953214.post@n6.nabble.com> Message-ID: On 5/4/2012 4:33 PM, ferreirafm wrote: > Hi there, > I simply can't print anything in the second for-loop bellow: > > ######################################### > #!/usr/bin/env python > > import sys > > filename = sys.argv[1] > outname = filename.split('.')[0] + '_pdr.dat' > begin = 'Distance distribution' > end = 'Reciprocal' > first = 0 > last = 0 > with open(filename) as inf: > for num, line in enumerate(inf, 1): > #print num, line > if begin in line: > first = num > if end in line: > last = num The file pointer is now at the end of the file. As an iterator, the file is exhausted. To reiterate, return the file pointer to the beginning with inf.seek(0). > for num, line in enumerate(inf, 1): > print 'Ok!' > print num, line > if num in range(first + 5, last - 1): > print line > print first, last > print range(first + 5, last - 1) -- Terry Jan Reedy From cs at zip.com.au Fri May 4 19:12:25 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 5 May 2012 09:12:25 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <20120504231225.GA29167@cskk.homeip.net> On 04May2012 15:08, Peng Yu wrote: | On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: | > On 5/4/2012 8:00 AM, Peng Yu wrote: | >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: | >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: | >>>> Thanks. This is what I'm looking for. I think that this should be | >>>> added to the python document as a manifestation (but nonnormalized) of | >>>> what "A set object is an unordered collection of distinct hashable | >>>> objects" means. | >>> | >>> There are other things that can prove it to be unordered, too; the | >>> exact pattern and order of additions and deletions can affect the | >>> iteration order. The only thing you can be sure of is that you can't | >>> be sure of it. | >> | >> I agree. My point was just to suggest adding more explanations on the | >> details in the manual. | > | > I am not sure how much clearer we can be in the language manual. The word | > 'unordered' means just that. [...] | | You can just add the example that you posted to demonstrate what the | unordered means. A curious user might want to know under what | condition the "unorderness" can affect the results, because for | trivial examples (like the following), it does seem that there is some | orderness in a set. I'm with Terry here: anything else in the line you suggest would complicate things for the reader, and potentially mislead. Future implementation changes (and, indeed, _other_ implementations like Jython) can change any of this. So there _are_ no ``condition the "unorderness" can affect the results'': a set is unordered, and you could even _legitimately_ get different orders from the same set if you iterate over it twice. It is unlikely, but permissable. Any attempt to describe such conditions beyond "it might happen at any time" would be misleading. | set(['a', 'b', 'c']) | set(['c', 'b', 'a']) The language does not say these will get the same iteration order. It happens that the Python you're using, today, does that. You can't learn the language specification from watching behaviour; you learn the guarrenteed behaviour -- what you may rely on happening -- from the specification, and you can test that an implementation obeys (or at any rate, does not disobey) the specification by watching behaviour. You seem to be trying to learn the spec from behaviour. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Loud pipes make noise. Skill and experience save lives. - EdBob Morandi From pengyu.ut at gmail.com Fri May 4 19:37:02 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 18:37:02 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: <20120504231225.GA29167@cskk.homeip.net> References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On Fri, May 4, 2012 at 6:12 PM, Cameron Simpson wrote: > On 04May2012 15:08, Peng Yu wrote: > | On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > | > On 5/4/2012 8:00 AM, Peng Yu wrote: > | >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: > | >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: > | >>>> Thanks. This is what I'm looking for. I think that this should be > | >>>> added to the python document as a manifestation (but nonnormalized) of > | >>>> what "A set object is an unordered collection of distinct hashable > | >>>> objects" means. > | >>> > | >>> There are other things that can prove it to be unordered, too; the > | >>> exact pattern and order of additions and deletions can affect the > | >>> iteration order. The only thing you can be sure of is that you can't > | >>> be sure of it. > | >> > | >> I agree. My point was just to suggest adding more explanations on the > | >> details in the manual. > | > > | > I am not sure how much clearer we can be in the language manual. The word > | > 'unordered' means just that. [...] > | > | You can just add the example that you posted to demonstrate what the > | unordered means. A curious user might want to know under what > | condition the "unorderness" can affect the results, because for > | trivial examples (like the following), it does seem that there is some > | orderness in a set. > > I'm with Terry here: anything else in the line you suggest would > complicate things for the reader, and potentially mislead. > > Future implementation changes (and, indeed, _other_ implementations like > Jython) can change any of this. So there _are_ no ``condition the > "unorderness" can affect the results'': a set is unordered, and you > could even _legitimately_ get different orders from the same set > if you iterate over it twice. It is unlikely, but permissable. > > Any attempt to describe such conditions beyond "it might happen at any > time" would be misleading. > > | set(['a', 'b', 'c']) > | set(['c', 'b', 'a']) > > The language does not say these will get the same iteration order. It > happens that the Python you're using, today, does that. > > You can't learn the language specification from watching behaviour; > you learn the guarrenteed behaviour -- what you may rely on happening -- > from the specification, and you can test that an implementation obeys (or > at any rate, does not disobey) the specification by watching behaviour. > > You seem to be trying to learn the spec from behaviour. My point is if something is said in the document, it is better to be substantiated by an example. I don't think that this has anything with "learn the spec from behaviour." -- Regards, Peng From breamoreboy at yahoo.co.uk Fri May 4 20:31:28 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 05 May 2012 01:31:28 +0100 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On 05/05/2012 00:37, Peng Yu wrote: > > My point is if something is said in the document, it is better to be > substantiated by an example. I don't think that this has anything with > "learn the spec from behaviour." > I side with the comments made by Terry Reedy and Cameron Simpson so please give it a rest, you're flogging a dead horse. -- Cheers. Mark Lawrence. From tjreedy at udel.edu Sat May 5 00:28:40 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 May 2012 00:28:40 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: Peng, I actually am thinking about it. Underlying problem: while unordered means conceptually unordered as far as the collection goes, the items in the collection, if homogenous enough, may have a natural order, which users find hard to ignore. Even if not comparable, an implementation such as CPython that uses linear sequential memory will impose some order. Even if the implementation uses unordered (holographic?) memory, order will be imposed to iterate, as when creating a serialized representation of the collection. Abstract objects, concrete objects, and serialized representations are three different things, but people tend to conflate them. Order consistency issues: if the unordered collection is iterated, when can one expect the order to be the same? Theoretically, essentially never, except that iterating dicts by keys, values, or key-value pairs is guaranteed to be consistent, which means that re-iterating has to be consistent. I actually think the same might as well be true for sets, although there is no doc that says so. If two collections are equal, should the iteration order be the same? It has always been true that if hash values collide, insertion order matters. However, a good hash function avoids hash collisions as much as possible in practical use cases. Without doing something artificial, as I did with the example, collisions should be especially rare on 64-bit builds. If one collection has a series of additions and deletions so that the underlying hash table has a different size than an equal collection build just from insertions, then order will also be different. If the same collection is built by insertion in the same order, but in different runs, bugfix versions, or language versions, will iteration order by the same? Historically, it has been for CPython for about a decade, and people has come to depend on that constancy, in spite of warning not to. Even core developers have not been immune, as the CPython test suite has a few set or dict iteration order dependencies until it was recently randomized. Late last year, it became obvious that this constancy is a practical denial-of-service security hole. The option to randomize hashing for each run was added to 2.6, 2.7, 3.1, and 3.2. Randomized hashing by run is part of 3.3. So some of the discussion above is obsolete. The example I gave only works for that one run, as hash('a') changes each run. So iteration order now changes with each run in fact as well as in theory. For the doc, the problem is what to say and where without being repetitous (and to get multiple people to agree ;-). -- Terry Jan Reedy From joncle at googlemail.com Sat May 5 06:03:58 2012 From: joncle at googlemail.com (Jon Clements) Date: Sat, 5 May 2012 03:03:58 -0700 (PDT) Subject: key/value store optimized for disk storage In-Reply-To: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> Message-ID: <15930137.526.1336212238754.JavaMail.geo-discussion-forums@ynep10> On Friday, 4 May 2012 16:27:54 UTC+1, Steve Howell wrote: > On May 3, 6:10?pm, Miki Tebeka wrote: > > > I'm looking for a fairly lightweight key/value store that works for > > > this type of problem: > > > > I'd start with a benchmark and try some of the things that are already in the standard library: > > - bsddb > > - sqlite3 (table of key, value, index key) > > - shelve (though I doubt this one) > > > > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: > > http://www.gossamer-threads.com/lists/python/python/106494 > > I'll give sqlite3 a spin. Has anybody out there wrapped sqlite3 > behind a hash interface already? I know it's simple to do > conceptually, but there are some minor details to work out for large > amounts of data (like creating the index after all the inserts), so if > somebody's already tackled this, it would be useful to see their > code. > > > You might find that for a little effort you get enough out of one of these. > > > > Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. > > Thanks. Could also look at Tokyo cabinet or Kyoto cabinet (but I believe that has slightly different licensing conditions for commercial use). From pengyu.ut at gmail.com Sat May 5 07:04:35 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 5 May 2012 06:04:35 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: Hi Terry, Thank you for you detailed email. > If two collections are equal, should the iteration order be the same? It has > always been true that if hash values collide, insertion order matters. > However, a good hash function avoids hash collisions as much as possible in > practical use cases. Without doing something artificial, as I did with the > example, collisions should be especially rare on 64-bit builds. If one > collection has a series of additions and deletions so that the underlying > hash table has a different size than an equal collection build just from > insertions, then order will also be different. The reason that I asked to add the artificial example in the doc is because I never completely understand the unorderness until I see your artificial example. You will surely use more words for explaining what "unorderness" means than just showing your example. And the example (since formatted as code) is more eye catching than just plain text. For my case, since I didn't understand the unorderness, I made some subtle bug in my program, which works fine in my testing code. However, it produce a small amount of corrupted results for the real production use, which is harder to debug. It did wasted quite some of my time. > For the doc, the problem is what to say and where without being repetitous > (and to get multiple people to agree ;-). I agree that people have different opinions on issues like this. But I think that "The Customer Is God". Readers of the doc is the customers, the writers of the doc is the producers. The opinion of customers should carry more weight than producers. -- Regards, Peng From rosuav at gmail.com Sat May 5 07:53:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 May 2012 21:53:31 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On Sat, May 5, 2012 at 9:04 PM, Peng Yu wrote: > I agree that people have different opinions on issues like this. But I > think that "The Customer Is God". Readers of the doc is the customers, > the writers of the doc is the producers. The opinion of customers > should carry more weight than producers. Nah, the customer's not God, and I have proof. http://notalwaysright.com/ Oops, now everyone's off reading funny stories about stupid/abusive customers. Well, when you're all back... The reason you're reading documentation is to learn. You're not handing over wads of cash and saying "Do stuff for me"; you're reading the Player's Handbook and learning which dice to roll when. Perhaps there's some jargon that you don't understand; in that case, either a FAQ/glossary or a forum post will set you straight. But if the doc says that something can't be relied upon, then there's nothing more to write there. Documentation that takes ten pages to say something is just as bad as documentation that leaves stuff out, because it's almost guaranteed that it won't be read. ChrisA From jmwebaze at gmail.com Sat May 5 08:12:56 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sat, 5 May 2012 14:12:56 +0200 Subject: How to compute a delta: the difference between lists of strings Message-ID: This is out of curiosity, i know this can be done with python diffllib module, but been figuring out how to compute the delta, Consider two lists below. s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] This is the result should be [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ z'] ideas on how to approach this.. ? -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 5 08:39:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 May 2012 22:39:59 +1000 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: On Sat, May 5, 2012 at 10:12 PM, J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' ?e', '+ A', '+ B', ' ?f', ' ?g', '- A', '- B', ' ?C', ' ?D', '- C', '+ > z'] > > ideas on how to approach this.. ? Here's a simple algorithm that produces sorta-mostly-reasonable results most of the time: Set your current-position-index to the beginning of each lists. (Call them 'pos1' and 'pos2'.) If s1[pos1] and s2[pos2] are identical, match - increment and iterate. Otherwise, increment pos2 until either it matches pos1 or you reach the end of s2. If you find a match, report the insertion into s2, increment both pointers past the match, and carry on. If you hit the end of s2, increment pos1 once and report an insertion into s1, then go back to looking for a match. It helps to append a sentinel to each list; that way, you don't need to separately check for additional content at the end of either list (as the sentinel won't match any of the strings). This is the algorithm I used for writing a simple file diff tool ages ago. It's not as good as diff(1), but it was fun to do the exercise. It's quite inefficient at handling large insertions into s1, and needs to be modified for most file handling (for instance, requiring a 2-line or 3-line rematch after a difference, to avoid matching on blank lines), but it's a basis. Producing beautiful or minimal diffs is a more complex task. :) ChrisA From jmwebaze at gmail.com Sat May 5 09:13:23 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sat, 5 May 2012 15:13:23 +0200 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: thank Chris.. On Sat, May 5, 2012 at 2:39 PM, Chris Angelico wrote:k > On Sat, May 5, 2012 at 10:12 PM, J. Mwebaze wrote: > > This is out of curiosity, i know this can be done with python diffllib > > module, but been figuring out how to compute the delta, Consider two > lists > > below. > > > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > > > This is the result should be > > > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ > > z'] > > > > ideas on how to approach this.. ? > > Here's a simple algorithm that produces sorta-mostly-reasonable > results most of the time: > > Set your current-position-index to the beginning of each lists. (Call > them 'pos1' and 'pos2'.) > If s1[pos1] and s2[pos2] are identical, match - increment and iterate. > Otherwise, increment pos2 until either it matches pos1 or you reach > the end of s2. > If you find a match, report the insertion into s2, increment both > pointers past the match, and carry on. > If you hit the end of s2, increment pos1 once and report an insertion > into s1, then go back to looking for a match. > > It helps to append a sentinel to each list; that way, you don't need > to separately check for additional content at the end of either list > (as the sentinel won't match any of the strings). > > This is the algorithm I used for writing a simple file diff tool ages > ago. It's not as good as diff(1), but it was fun to do the exercise. > It's quite inefficient at handling large insertions into s1, and needs > to be modified for most file handling (for instance, requiring a > 2-line or 3-line rematch after a difference, to avoid matching on > blank lines), but it's a basis. > > Producing beautiful or minimal diffs is a more complex task. :) > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Sat May 5 11:50:23 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 05 May 2012 08:50:23 -0700 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: On 5/5/2012 5:12 AM J. Mwebaze said... > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two > lists below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', > '+ z'] > > ideas on how to approach this.. ? > use difflib: from difflib import unified_diff as ud s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] s2 = ['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] [ r for r in ud(s1,s2,lineterm="|") if not r.endswith("|") ] HTH, Emile From emile at fenx.com Sat May 5 12:04:32 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 05 May 2012 09:04:32 -0700 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On 5/5/2012 4:04 AM Peng Yu said... > I agree that people have different opinions on issues like this. But I > think that "The Customer Is God". Readers of the doc is the customers, > the writers of the doc is the producers. The opinion of customers > should carry more weight than producers. Only to a point. The experience of the producers should carry more weight than the opinion of the customers. Emile From vito.detullio at gmail.com Sat May 5 12:16:40 2012 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 05 May 2012 18:16:40 +0200 Subject: How to compute a delta: the difference between lists of strings References: Message-ID: J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ > z'] > > ideas on how to approach this.. ? http://en.wikipedia.org/wiki/Longest_common_subsequence_problem -- ZeD From pengyu.ut at gmail.com Sat May 5 12:17:31 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 5 May 2012 11:17:31 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: > Documentation that takes ten pages to say something is just as bad as > documentation that leaves stuff out, because it's almost guaranteed > that it won't be read. That's the point. If a simple example (6 lines) can demonstrate the concept, why spending "ten pages" to explain it. My experience is that for certain things, it is better describe by a spec once you know it, but it is certainly not true for people to learn it. A reasonable strategy is to interleave spec with demonstrating examples. There is no excuse to not to make the manual easier to read. -- Regards, Peng From bob at bobcowdery.plus.com Sat May 5 15:33:44 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sat, 05 May 2012 20:33:44 +0100 Subject: Problem with time.time() standing still Message-ID: <4FA58098.60009@bobcowdery.plus.com> Hi all, I've been a long time user of Python and written many extensions but this problem has me stumped. I've written a straight forward extension that wraps a vendors SDK for a video capture card. All works well except that in the Python thread on which I call the extension, after certain calls that I believe are using DirectShow, time stands still. The thread returns fine as the extension does its stuff in its own threads. In all other respects the Python thread seems unaffected but calls to time.time() always return the same time which is usually several seconds in the past or future and always has no fractional part. If I leave it long enough time will suddently jump forward after a few minutes, then again after a few minutes more. I've never encountered this behaviour before and can't understand what on earth is going on. If I call the 'C' time() function just the other side of my call to the extension the time is ticking along fine. It's just the one Python thread that is affected. If I call from the main thread then the main thread is affected. The calling program I've used to test this is just a few lines long. I believe the time function is a thin wrapper over the 'C' runtime so its very odd that time only stands still on the Python side but not on the 'C' side. As time is built in I've not looked at the code as its not in the distribution. Don't know if it would help to do that. This also can affect the time.sleep() function making it return immediately but that only seems to happen in my full application. Any ideas would be very greatly received. Bob From danyellawson at gmail.com Sat May 5 16:17:52 2012 From: danyellawson at gmail.com (Danyel Lawson) Date: Sat, 5 May 2012 16:17:52 -0400 Subject: Problem with time.time() standing still In-Reply-To: <4FA58098.60009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: Add a time.sleep(0) call to all your loops. Multithreading in Python is a cooperative cross platform threading simulation if you have tight loops Python won't task switch until you make a system call. Potentially preventing internal library variables from being updated. Your five minute interval may be almost exactly how long it takes to process a flooded queue in a tight loop in your program and it may be why it continues to happen as the queue waits to fill again while processing happens. You can simulate the progression of time by overriding the time.time function by simply setting it to a function that just increments a module level or function property variable. You can also override the time.time function to return the posix time function's value to maybe get around whatever optimization is happening in the time.time function to pass back the same value. If you post your sample code that exhibits the same behavior it may be obvious to someone on the list as to what is the problem. On Sat, May 5, 2012 at 3:33 PM, Bob Cowdery wrote: > Hi all, > > I've been a long time user of Python and written many extensions but > this problem has me stumped. > > I've written a straight forward extension that wraps a vendors SDK for a > video capture card. All works well except that in the Python thread on > which I call the extension, after certain calls that I believe are using > DirectShow, ?time stands still. The thread returns fine as the extension > does its stuff in its own threads. In all other respects the Python > thread seems unaffected but calls to time.time() always return the same > time which is usually several seconds in the past or future and always > has no fractional part. If I leave it long enough time will suddently > jump forward after a few minutes, then again after a few minutes more. > > I've never encountered this behaviour before and can't understand what > on earth is going on. If I call the 'C' time() function just the other > side of my call to the extension the time is ticking along fine. It's > just the one Python thread that is affected. If I call from the main > thread then the main thread is affected. The calling program I've used > to test this is just a few lines long. > > I believe the time function is a thin wrapper over the 'C' runtime so > its very odd that time only stands still on the Python side but not on > the 'C' side. As time is built in I've not looked at the code as its not > in the distribution. Don't know if it would help to do that. > > This also can affect the time.sleep() function making it return > immediately but that only seems to happen in my full application. > > Any ideas would be very greatly received. > > Bob > -- > http://mail.python.org/mailman/listinfo/python-list From bob at bobcowdery.plus.com Sat May 5 16:51:59 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sat, 05 May 2012 21:51:59 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: <4FA592EF.7030807@bobcowdery.plus.com> Thanks Daniel, that's interesting. Unfortunately there is no sensible code I can post because this only happens when I make a specific call into the vendors SDK. I can exercise my own code in the extension without a problem. The python test calling code is doing practically nothing. I make 3 calls to the extension to set things going and then loop every 5 seconds and print the time. I know Pythons own threading model is cooperative because of the GIL and therefore one thread can hog the show but I've never had issues with threads running in a C extension messing up a Python thread. I really need to understand what mechanism is at play here rather than work around it. Bob The time.clock() function does increment correctly. CPU is around 30% On 05/05/2012 21:17, Danyel Lawson wrote: > Add a time.sleep(0) call to all your loops. Multithreading in Python > is a cooperative cross platform threading simulation if you have tight > loops Python won't task switch until you make a system call. > Potentially preventing internal library variables from being updated. > > Your five minute interval may be almost exactly how long it takes to > process a flooded queue in a tight loop in your program and it may be > why it continues to happen as the queue waits to fill again while > processing happens. > > You can simulate the progression of time by overriding the time.time > function by simply setting it to a function that just increments a > module level or function property variable. You can also override the > time.time function to return the posix time function's value to maybe > get around whatever optimization is happening in the time.time > function to pass back the same value. > > If you post your sample code that exhibits the same behavior it may be > obvious to someone on the list as to what is the problem. > > > > On Sat, May 5, 2012 at 3:33 PM, Bob Cowdery wrote: >> Hi all, >> >> I've been a long time user of Python and written many extensions but >> this problem has me stumped. >> >> I've written a straight forward extension that wraps a vendors SDK for a >> video capture card. All works well except that in the Python thread on >> which I call the extension, after certain calls that I believe are using >> DirectShow, time stands still. The thread returns fine as the extension >> does its stuff in its own threads. In all other respects the Python >> thread seems unaffected but calls to time.time() always return the same >> time which is usually several seconds in the past or future and always >> has no fractional part. If I leave it long enough time will suddently >> jump forward after a few minutes, then again after a few minutes more. >> >> I've never encountered this behaviour before and can't understand what >> on earth is going on. If I call the 'C' time() function just the other >> side of my call to the extension the time is ticking along fine. It's >> just the one Python thread that is affected. If I call from the main >> thread then the main thread is affected. The calling program I've used >> to test this is just a few lines long. >> >> I believe the time function is a thin wrapper over the 'C' runtime so >> its very odd that time only stands still on the Python side but not on >> the 'C' side. As time is built in I've not looked at the code as its not >> in the distribution. Don't know if it would help to do that. >> >> This also can affect the time.sleep() function making it return >> immediately but that only seems to happen in my full application. >> >> Any ideas would be very greatly received. >> >> Bob >> -- >> http://mail.python.org/mailman/listinfo/python-list From cs at zip.com.au Sat May 5 18:05:42 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 6 May 2012 08:05:42 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA58098.60009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: <20120505220542.GA15014@cskk.homeip.net> On 05May2012 20:33, Bob Cowdery wrote: | I've written a straight forward extension that wraps a vendors SDK for a | video capture card. All works well except that in the Python thread on | which I call the extension, after certain calls that I believe are using | DirectShow, time stands still. The thread returns fine as the extension | does its stuff in its own threads. In all other respects the Python | thread seems unaffected but calls to time.time() always return the same | time which is usually several seconds in the past or future and always | has no fractional part. Thought #1: you are calling time.time() and haven't unfortunately renamed it? (I doubt this scenario, though the lack of fractional part is interesting.) | If I leave it long enough time will suddently | jump forward after a few minutes, then again after a few minutes more. | | I've never encountered this behaviour before and can't understand what | on earth is going on. If I call the 'C' time() function just the other | side of my call to the extension the time is ticking along fine. It's | just the one Python thread that is affected. [...] Thought #2: On a UNIX system I'd be running the process under strace (or dtrace or ktrace depending on flavour) to see what actual OS system calls are being made during this behaviour. Is this feasible for you? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A slipping sear could let your M203 grenade launcher fire when you least expect it. That would make you quite unpopular in what's left of your unit. - page 9 of the August 1993 issue of PS magazine, the US Army's preventive maintenance magazine From rosuav at gmail.com Sat May 5 19:11:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 May 2012 09:11:26 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA592EF.7030807@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> <4FA592EF.7030807@bobcowdery.plus.com> Message-ID: On Sun, May 6, 2012 at 6:51 AM, Bob Cowdery wrote: > The time.clock() function does increment correctly. CPU is around 30% 30% of how many cores? If that's a quad-core processor, that could indicate one core completely pegged plus a little usage elsewhere. ChrisA From wuwei23 at gmail.com Sat May 5 23:19:51 2012 From: wuwei23 at gmail.com (alex23) Date: Sat, 5 May 2012 20:19:51 -0700 (PDT) Subject: pyjamas / pyjs References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: On May 4, 11:43?pm, Duncan Booth wrote: > In case it isn't obvious why I might be subscribed but emails turned off, I > read mailing lists like that through gmane in which case I still need to > sign up to the list to post but definitely don't want to receive emails. This. I was surprised to suddenly start receiving emails, as I thought I'd left the pyjamas list _years_ ago. I've asked them to stop spamming me and even now and getting snide, shitty emails claiming that what they were doing wasn't spam as I "could have chosen to ignore it or delete it". I've had to email the abuse address at Rackspace. I'm pretty sure it's illegal to add people to a mailing list without their consent, to not include instructions on how to unsubscribe from the mailing list, and to continue to email them when they've asked to be removed. As for the project itself, having a bunch of arrogant assholes decide that the lead developer has "hijacked" the project with his explicit- from-the-start libre software "philosophies", because such belief runs counter to the desires - sorry, the "philosophies" - held by that core group of assholes, is just the must astounding hypocrisy I've ever seen. The correct approach in such an instance is to *fork* the project; but that way you don't get to steal the community, I guess. The unwanted email was bad enough. The overwhelming sense of entitlement those emails expressed was even worse. From emekamicro at gmail.com Sun May 6 00:19:01 2012 From: emekamicro at gmail.com (Emeka) Date: Sun, 6 May 2012 06:19:01 +0200 Subject: Is Python Lazy? Message-ID: Hello All, Could one say that generator expressions and functions are Python way of introducing Lazy concept? Regards, \Emeka -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sun May 6 01:40:59 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 5 May 2012 22:40:59 -0700 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: Generators and iterators are laziness where you tend to need laziness the most. Generator expressions are tiny generators - more full fledged generators are supported. Python probably won't have laziness at its core ever, but it's nice having a dose of it. IOW, you probably won't be able to write a sort routine, and use it as a "first 100 lowest values" routine for free. But you could construct something that does almost the same thing lazily using a generator - not for free. On Sat, May 5, 2012 at 9:19 PM, Emeka wrote: > > Hello All, > > Could one say that generator expressions and functions are Python way of > introducing Lazy concept? > > Regards, \Emeka > -- > *Satajanus Nig. Ltd > > > * > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun May 6 02:10:27 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 06 May 2012 08:10:27 +0200 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: Dan Stromberg, 06.05.2012 07:40: > you probably won't be able to write a sort routine, and > use it as a "first 100 lowest values" routine for free. But you could > construct something that does almost the same thing lazily using a > generator - not for free. OTOH, if you really wanted to do this particular thing, I'd just use heapq. Stefan From bob at bobcowdery.plus.com Sun May 6 04:18:23 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 09:18:23 +0100 Subject: Problem with time.time() standing still In-Reply-To: <20120505220542.GA15014@cskk.homeip.net> References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> Message-ID: <4FA633CF.7060009@bobcowdery.plus.com> On 05/05/2012 23:05, Cameron Simpson wrote: > On 05May2012 20:33, Bob Cowdery wrote: > | I've written a straight forward extension that wraps a vendors SDK for a > | video capture card. All works well except that in the Python thread on > | which I call the extension, after certain calls that I believe are using > | DirectShow, time stands still. The thread returns fine as the extension > | does its stuff in its own threads. In all other respects the Python > | thread seems unaffected but calls to time.time() always return the same > | time which is usually several seconds in the past or future and always > | has no fractional part. > > Thought #1: you are calling time.time() and haven't unfortunately > renamed it? (I doubt this scenario, though the lack of fractional part > is interesting.) Not sure what you mean by renamed it. I also tried datetime and that had the same behaviour. > > | If I leave it long enough time will suddently > | jump forward after a few minutes, then again after a few minutes more. > | > | I've never encountered this behaviour before and can't understand what > | on earth is going on. If I call the 'C' time() function just the other > | side of my call to the extension the time is ticking along fine. It's > | just the one Python thread that is affected. > [...] > > Thought #2: On a UNIX system I'd be running the process under strace (or > dtrace or ktrace depending on flavour) to see what actual OS system calls are > being made during this behaviour. Is this feasible for you? I'm on Windows for this particular part of the application. The video SDK is Windows only. But debugging into this is probably the only way. I looked at the built-in time module. As far as I can tell it just calls the underlying C time() function as an extension. This is more mystifying as that is pretty much what I'm doing by checking the time in my own extension module where it ticks along fine. I have another scenario using a different part of their SDK where the time does still tick but the fractional part is frozen, not 0 but frozen. I'd dearly love to know what's going on here. I thought about extracting the time module, building it, calling it something else and seeing if it behaves the same. All time consuming unfortunately when I have a deadline. > > Cheers, From bob at bobcowdery.plus.com Sun May 6 04:20:23 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 09:20:23 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> <4FA592EF.7030807@bobcowdery.plus.com> Message-ID: <4FA63447.3040800@bobcowdery.plus.com> On 06/05/2012 00:11, Chris Angelico wrote: > On Sun, May 6, 2012 at 6:51 AM, Bob Cowdery wrote: >> The time.clock() function does increment correctly. CPU is around 30% > 30% of how many cores? If that's a quad-core processor, that could > indicate one core completely pegged plus a little usage elsewhere. It is a quad core but no CPU is pegged as there are a number of threads running in C. It's reasonably well spread. > > ChrisA From rosuav at gmail.com Sun May 6 04:24:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 May 2012 18:24:41 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA633CF.7060009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: On Sun, May 6, 2012 at 6:18 PM, Bob Cowdery wrote: > On 05/05/2012 23:05, Cameron Simpson wrote: >> Thought #1: you are calling time.time() and haven't unfortunately >> renamed it? (I doubt this scenario, though the lack of fractional part >> is interesting.) > Not sure what you mean by renamed it. I also tried datetime and that had > the same behaviour. In Python, names are nothing special, so you could do something like: time.time = lambda: 142857 which means that time.time() will forever return that constant. Take a snapshot of time.time early in your code somewhere, and try using that instead, just in case. It's a long shot but might save you some insanity! ChrisA From cs at zip.com.au Sun May 6 04:49:15 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 6 May 2012 18:49:15 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA633CF.7060009@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: <20120506084915.GA19916@cskk.homeip.net> On 06May2012 09:18, Bob Cowdery wrote: | On 05/05/2012 23:05, Cameron Simpson wrote: | > On 05May2012 20:33, Bob Cowdery wrote: | > | [...] calls to time.time() always return the same | > | time which is usually several seconds in the past or future and always | > | has no fractional part. | > | > Thought #1: you are calling time.time() and haven't unfortunately | > renamed it? (I doubt this scenario, though the lack of fractional part | > is interesting.) | | Not sure what you mean by renamed it. Like this: from time import time [...] time = some_unfortunate_other_function [...] now = time() # calls wrong function It seems unlikely, but possible. | I also tried datetime and that had | the same behaviour. Makes my suggestion even less likely unless the time module itself gets monkeypatched (i.e. "time.time = bad_function" somewhere). | > | If I leave it long enough time will suddently | > | jump forward after a few minutes, then again after a few minutes more. | > | | > | I've never encountered this behaviour before and can't understand what | > | on earth is going on. If I call the 'C' time() function just the other | > | side of my call to the extension the time is ticking along fine. It's | > | just the one Python thread that is affected. | > [...] | > | > Thought #2: On a UNIX system I'd be running the process under strace (or | > dtrace or ktrace depending on flavour) to see what actual OS system calls are | > being made during this behaviour. Is this feasible for you? | | I'm on Windows for this particular part of the application. I'd guessed so. I've no Windows programming background; I was wondering if there was something like this you had to hand on windows. | [...] But debugging into this is probably the only way. I | looked at the built-in time module. As far as I can tell it just calls | the underlying C time() function as an extension. This is more | mystifying as that is pretty much what I'm doing by checking the time in | my own extension module where it ticks along fine. Hmm. A C extension I presume? How about writing a little pure Python thread to call time.time(), and spin it off parallel to the rest of the app; does it also get bad time.time() behaviour? | I have another | scenario using a different part of their SDK where the time does still | tick but the fractional part is frozen, not 0 but frozen. Curiouser and curiouser. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ As you can see, unraveling even a small part of 'sendmail' can introduce more complexity than answers. - Brian Costales, _sendmail_ From bob at bobcowdery.plus.com Sun May 6 05:09:01 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 10:09:01 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: <4FA63FAD.8030504@bobcowdery.plus.com> On 06/05/2012 09:24, Chris Angelico wrote: > On Sun, May 6, 2012 at 6:18 PM, Bob Cowdery wrote: >> On 05/05/2012 23:05, Cameron Simpson wrote: >>> Thought #1: you are calling time.time() and haven't unfortunately >>> renamed it? (I doubt this scenario, though the lack of fractional part >>> is interesting.) >> Not sure what you mean by renamed it. I also tried datetime and that had >> the same behaviour. > In Python, names are nothing special, so you could do something like: > > time.time = lambda: 142857 > > which means that time.time() will forever return that constant. > > Take a snapshot of time.time early in your code somewhere, and try > using that instead, just in case. It's a long shot but might save you > some insanity! Thanks. I will try that. Away now until Monday when the battle will resume. Bob > ChrisA From bob at bobcowdery.plus.com Sun May 6 05:19:27 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 10:19:27 +0100 Subject: Problem with time.time() standing still In-Reply-To: <20120506084915.GA19916@cskk.homeip.net> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> Message-ID: <4FA6421F.40002@bobcowdery.plus.com> On 06/05/2012 09:49, Cameron Simpson wrote: > On 06May2012 09:18, Bob Cowdery wrote: > | On 05/05/2012 23:05, Cameron Simpson wrote: > | > On 05May2012 20:33, Bob Cowdery wrote: > | > | [...] calls to time.time() always return the same > | > | time which is usually several seconds in the past or future and always > | > | has no fractional part. > | > > | > Thought #1: you are calling time.time() and haven't unfortunately > | > renamed it? (I doubt this scenario, though the lack of fractional part > | > is interesting.) > | > | Not sure what you mean by renamed it. > > Like this: > > from time import time > [...] > time = some_unfortunate_other_function > [...] > now = time() # calls wrong function > > It seems unlikely, but possible. > > | I also tried datetime and that had > | the same behaviour. > > Makes my suggestion even less likely unless the time module itself gets > monkeypatched (i.e. "time.time = bad_function" somewhere). I don't think the function is subverted unless there is some way inside the vendor SDK or even DirectShow (the SDK uses this as a COM object) which can somehow hijack it. It does catch up every few minutes so there has to be a clue there. > | > | If I leave it long enough time will suddently > | > | jump forward after a few minutes, then again after a few minutes more. > | > | > | > | I've never encountered this behaviour before and can't understand what > | > | on earth is going on. If I call the 'C' time() function just the other > | > | side of my call to the extension the time is ticking along fine. It's > | > | just the one Python thread that is affected. > | > [...] > | > > | > Thought #2: On a UNIX system I'd be running the process under strace (or > | > dtrace or ktrace depending on flavour) to see what actual OS system calls are > | > being made during this behaviour. Is this feasible for you? > | > | I'm on Windows for this particular part of the application. > > I'd guessed so. I've no Windows programming background; I was wondering > if there was something like this you had to hand on windows. Maybe, but not that I know of. > | [...] But debugging into this is probably the only way. I > | looked at the built-in time module. As far as I can tell it just calls > | the underlying C time() function as an extension. This is more > | mystifying as that is pretty much what I'm doing by checking the time in > | my own extension module where it ticks along fine. > > Hmm. A C extension I presume? How about writing a little pure Python > thread to call time.time(), and spin it off parallel to the rest of the > app; does it also get bad time.time() behaviour? I've tried that. It's only the Python thread (or Python main thread) that calls the extension that behaves like this. Other Python threads tick along fine with the correct time including a fractional part. > | I have another > | scenario using a different part of their SDK where the time does still > | tick but the fractional part is frozen, not 0 but frozen. > > Curiouser and curiouser. Indeed. Away now but battle will resume on Tuesday. Bob From jmwebaze at gmail.com Sun May 6 11:57:39 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 17:57:39 +0200 Subject: sorting 1172026 entries Message-ID: I have several lists with approx 1172026 entries. I have been trying to sort the records, but have failed.. I tried lists.sort() i also trired sorted python's inbuilt method. This has been running for weeks. Any one knows of method that can handle such lists. cheers -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin at schollnick.net Sun May 6 12:07:24 2012 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Sun, 6 May 2012 12:07:24 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On May 6, 2012, at 11:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to sort the records, but have failed.. I tried lists.sort() i also trired sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. The issue there is the sheer size of the list. I can't think of an algorithium that wouldn't have a problem with a list of that size. Two suggestions.... 1) Is there no other way to organize this data, other than having it in a single list? You can't organize it by, for example, zip code, area code, year, or something, and make multiple lists? Reducing the size would speed the sort up. 2) Maybe consider a different storage method, for example, adding the data into a database? And then connecting to the database via python? - Benjamin -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Sun May 6 12:09:22 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 May 2012 12:09:22 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 11:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to sort > the records, but have failed.. I tried lists.sort() i also trired sorted > python's?inbuilt?method. This has been running for?weeks. Sorting 1172026 random floats takes about 1.5 seconds to do on my machine. More complicated objects take more time, but usually not that much more time. What exactly are you sorting? -- Devin From jmwebaze at gmail.com Sun May 6 12:10:08 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:10:08 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 6:07 PM, Benjamin Schollnick wrote: > > On May 6, 2012, at 11:57 AM, J. Mwebaze wrote: > > I have several lists with approx 1172026 entries. I have been trying to > sort the records, but have failed.. I tried lists.sort() i also trired > sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. > > > The issue there is the sheer size of the list. I can't think of an > algorithium that wouldn't have a problem with a list of that size. > > Two suggestions.... > > 1) Is there no other way to organize this data, other than having it in a > single list? You can't organize it by, for example, zip code, area code, > year, or something, and make multiple lists? Reducing the size would speed > the sort up. > > 2) Maybe consider a different storage method, for example, adding the data > into a database? And then connecting to the database via python? > > - Benjamin > > I could try the database option.. -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:11:44 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:11:44 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 6:09 PM, Devin Jeanpierre wrote: > On Sun, May 6, 2012 at 11:57 AM, J. Mwebaze wrote: > > I have several lists with approx 1172026 entries. I have been trying to > sort > > the records, but have failed.. I tried lists.sort() i also trired sorted > > python's inbuilt method. This has been running for weeks. > > Sorting 1172026 random floats takes about 1.5 seconds to do on my > machine. More complicated objects take more time, but usually not that > much more time. What exactly are you sorting? > > -- Devin > [ (datatime, int) ] * 1172026 -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Sun May 6 12:21:45 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 May 2012 12:21:45 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: > [ (datatime, int) ] *?1172026 I can't duplicate slowness. It finishes fairly quickly here. Maybe you could try posting specific code? It might be something else that is making your program take forever. >>> x = [(datetime.datetime.now() + datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ in xrange(1172026)] >>> random.shuffle(x) >>> x.sort() >>> -- Devin From jmwebaze at gmail.com Sun May 6 12:26:31 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:26:31 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: I have attached one of the files, try to sort and let me know the results. Kindly sort by date. ooops - am told the file exceed 25M. below is the code import glob txtfiles =glob.glob('*.txt') import dateutil.parser as parser for filename in txtfiles: temp=[] f=open(filename) for line in f.readlines(): line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) temp=sorted(temp) with open(filename.strip('.txt')+ '.sorted', 'wb') as p: for i, j in temp: p.write('%s %s\n' %(str(i),j)) On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: > On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: > > [ (datatime, int) ] * 1172026 > > I can't duplicate slowness. It finishes fairly quickly here. Maybe you > could try posting specific code? It might be something else that is > making your program take forever. > > >>> x = [(datetime.datetime.now() + > datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ > in xrange(1172026)] > >>> random.shuffle(x) > >>> x.sort() > >>> > > -- Devin > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:29:10 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:29:10 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: sorry see, corrected code for filename in txtfiles: temp=[] f=open(filename) for line in f.readlines(): line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) temp=sorted(temp) with open(filename.strip('.txt')+ '.sorted', 'wb') as p: for i, j in temp: p.write('%s %s\n' %(str(i),j)) On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze wrote: > I have attached one of the files, try to sort and let me know the results. > Kindly sort by date. ooops - am told the file exceed 25M. > > below is the code > > import glob > txtfiles =glob.glob('*.txt') > import dateutil.parser as parser > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: > >> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: >> > [ (datatime, int) ] * 1172026 >> >> I can't duplicate slowness. It finishes fairly quickly here. Maybe you >> could try posting specific code? It might be something else that is >> making your program take forever. >> >> >>> x = [(datetime.datetime.now() + >> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ >> in xrange(1172026)] >> >>> random.shuffle(x) >> >>> x.sort() >> >>> >> >> -- Devin >> > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:36:37 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:36:37 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: I noticed the error in code please ignore this post.. On Sun, May 6, 2012 at 6:29 PM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze wrote: > >> I have attached one of the files, try to sort and let me know the >> results. Kindly sort by date. ooops - am told the file exceed 25M. >> >> below is the code >> >> import glob >> txtfiles =glob.glob('*.txt') >> import dateutil.parser as parser >> >> >> for filename in txtfiles: >> temp=[] >> f=open(filename) >> for line in f.readlines(): >> line = line.strip() >> line=line.split() >> temp.append((parser.parse(line[0]), float(line[1]))) >> temp=sorted(temp) >> with open(filename.strip('.txt')+ '.sorted', 'wb') as p: >> for i, j in temp: >> p.write('%s %s\n' %(str(i),j)) >> >> >> On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: >> >>> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: >>> > [ (datatime, int) ] * 1172026 >>> >>> I can't duplicate slowness. It finishes fairly quickly here. Maybe you >>> could try posting specific code? It might be something else that is >>> making your program take forever. >>> >>> >>> x = [(datetime.datetime.now() + >>> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ >>> in xrange(1172026)] >>> >>> random.shuffle(x) >>> >>> x.sort() >>> >>> >>> >>> -- Devin >>> >> >> >> >> -- >> *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze >> | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze >> >> /* Life runs on code */* >> >> > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary.herron at islandtraining.com Sun May 6 12:37:53 2012 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 06 May 2012 09:37:53 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <4FA6A8E1.3040001@islandtraining.com> On 05/06/2012 09:29 AM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) Don't do temp = sorted(temp) That will create a *new* copy of the list to sort, and the assignment will free up the original list for deletion and garbage collection. Instead do the in-place sort: temp.sort() Same result, less thrashing. This will make your program slightly more efficient, HOWEVER, it is not the solution of your week-long sort problem. Gary Herron > > > On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze > wrote: > > I have attached one of the files, try to sort and let me know the > results. Kindly sort by date. ooops - am told the file exceed 25M. > > below is the code > > import glob > txtfiles =glob.glob('*.txt') > import dateutil.parser as parser > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre > > wrote: > > On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze > > wrote: > > [ (datatime, int) ] * 1172026 > > I can't duplicate slowness. It finishes fairly quickly here. > Maybe you > could try posting specific code? It might be something else > that is > making your program take forever. > > >>> x = [(datetime.datetime.now() + > datetime.timedelta(random.getrandbits(10)), > random.getrandbits(32)) for _ in xrange(1172026)] > >>> random.shuffle(x) > >>> x.sort() > >>> > > -- Devin > > > > > -- > *Mob UG: +256 (0) 70 1735800 > | NL +31 (0) 6 852 841 38 > | Gtalk: jmwebaze | > skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > > /* Life runs on code */* > > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: > jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > > /* Life runs on code */* > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at gmail.com Sun May 6 12:49:41 2012 From: thudfoo at gmail.com (xDog Walker) Date: Sun, 6 May 2012 09:49:41 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <201205060949.42169.thudfoo@gmail.com> On Sunday 2012 May 06 09:29, J. Mwebaze wrote: > ?temp=sorted(temp) Change to: temp.sort() RTFM on sorted() and .sort(). -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From clp2 at rebertia.com Sun May 6 13:03:36 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 6 May 2012 10:03:36 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 9:29 AM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > ? ?temp=[] > ? ?f=open(filename) Why not use `with` here too? > ? ?for line in f.readlines(): readlines() reads *the entire file contents* into memory all at once! Use `for line in f:` instead, which will read from the file one line at a time. > ? ? ?line = line.strip() > ? ? ?line=line.split() > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) > ? ?temp=sorted(temp) As already pointed out, use temp.sort() instead. > ? ?with open(filename.strip('.txt')+ '.sorted', 'wb') as p: strip() doesn't do quite what you think it does: $ python Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) >>> '.xtx.foo'.strip('.txt') 'foo' >>> Consult the docs. Also, please avoid top-posting in the future. Cheers, Chris From stefan_ml at behnel.de Sun May 6 13:15:07 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 06 May 2012 19:15:07 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: J. Mwebaze, 06.05.2012 18:29: > sorry see, corrected code > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > >> I have attached one of the files, try to sort and let me know the results. >> Kindly sort by date. ooops - am told the file exceed 25M. >> >> below is the code >> >> import glob >> txtfiles =glob.glob('*.txt') >> import dateutil.parser as parser >> >> >> for filename in txtfiles: >> temp=[] >> f=open(filename) >> for line in f.readlines(): >> line = line.strip() >> line=line.split() >> temp.append((parser.parse(line[0]), float(line[1]))) >> temp=sorted(temp) >> with open(filename.strip('.txt')+ '.sorted', 'wb') as p: >> for i, j in temp: >> p.write('%s %s\n' %(str(i),j)) How much memory do you have on your system? Does the list fit into memory easily or is it swapping to disk while you are running the sort? Stefan From alec.taylor6 at gmail.com Sun May 6 15:11:58 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 7 May 2012 05:11:58 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: Also, is there a reason you are sorting the data-set after insert rather than using a self-sorting data-structure? A well chosen self-sorting data-structure is always more efficient when full data flow is controlled. I.e.: first insert can be modified to use the self-sorting data-structure I cannot think of a situation requiring permanently sorted data-sets which would be better served with a non-self-sorting data-structure except those where you do not have full data-flow control. From breamoreboy at yahoo.co.uk Sun May 6 15:52:56 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 May 2012 20:52:56 +0100 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On 06/05/2012 20:11, Alec Taylor wrote: > Also, is there a reason you are sorting the data-set after insert > rather than using a self-sorting data-structure? > > A well chosen self-sorting data-structure is always more efficient > when full data flow is controlled. > > I.e.: first insert can be modified to use the self-sorting data-structure > > I cannot think of a situation requiring permanently sorted data-sets > which would be better served with a non-self-sorting data-structure > except those where you do not have full data-flow control. Possibly blist from http://pypi.python.org/pypi/blist/1.3.4 ? -- Cheers. Mark Lawrence. From drsalists at gmail.com Sun May 6 18:30:25 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 6 May 2012 15:30:25 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: How much physical RAM (not the virtual memory, but the physical memory) does your machine have available? We know the number of elements in your dataset, but how big are the individual elements? If a sort is never completing, you're probably swapping. list.sort() is preferrable to sorted(list), if you need to conserve memory. A self-sorting datastructure like a B Tree or whatever is rarely faster than using a good sorting algorithm, assuming that you only need to sort the data once per program invocation. If you're sorting the data in a loop, then yes, a self-sorting datastructure is most likely a much better idea. I've started a page about python trees and heaps at http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ - but again, unless you're sorting in a loop, you're probably better off with a good sorting algorithm, and Python's built-in Timsort is excellent for all-in-RAM sorting. If you have too much data to sort in RAM all at once, it's best to sort sublists that -do- fit in memory, using something like list_.sort() (that's Timsort by another name in CPython), and then write the sorted sublists to disk for subsequent merging using the merge step of a mergesort. If you just need something quick-to-code, GNU sort(1) is very highly optimized (for a text-based sort), and will sort datasets that are larger than your physical memory efficiently using an algorithm similar to (not identical) what I described in the previous paragraph. It's /usr/bin/sort on most Linux systems, and is available for a large number of other operating systems including windows via http://cygwin.com/ or https://github.com/bmatzelle/gow/wiki/ On Sun, May 6, 2012 at 8:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to > sort the records, but have failed.. I tried lists.sort() i also trired > sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. > > cheers > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sun May 6 19:54:16 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 09:54:16 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120506235416.GA13895@cskk.homeip.net> On 06May2012 18:36, J. Mwebaze wrote: | > for filename in txtfiles: | > temp=[] | > f=open(filename) | > for line in f.readlines(): | > line = line.strip() | > line=line.split() | > temp.append((parser.parse(line[0]), float(line[1]))) Have you timed the different parts of your code instead of the whole thing? Specificly, do you know the sort time is the large cost? I would point out that the loop above builds the list by append(), one item at a time. That should have runtime cost of the square of the list length, 1172026 * 1172026. Though I've just done this: [Documents/python]oscar1*> python Python 2.7.3 (default, May 4 2012, 16:19:02) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> L1 = [] >>> for i in range(1000000): L1.append(0) ... and it only took a few seconds. As pointed out by others, the readlines() is also a little expensive, conceivably similarly so (it also needs to build a huge list). Anyway, put some: print time.time() at various points. Not in the inner bits of the loops, but around larger chunks, example: from time import time temp=[] f=open(filename) print "after open", time() lines = f.readlines() print "after readlines", time() for line in lines: line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) print "after read loop", time() and so on. AT least then you will have more feel for what part of your code is taking so long. Ceers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The shortest path between any two truths in the real domain passes through the complex domain. - J. Hadamand From clp2 at rebertia.com Sun May 6 20:10:22 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 6 May 2012 17:10:22 -0700 Subject: sorting 1172026 entries In-Reply-To: <20120506235416.GA13895@cskk.homeip.net> References: <20120506235416.GA13895@cskk.homeip.net> Message-ID: On Sun, May 6, 2012 at 4:54 PM, Cameron Simpson wrote: > On 06May2012 18:36, J. Mwebaze wrote: > | > for filename in txtfiles: > | > ? ?temp=[] > | > ? ?f=open(filename) > | > ? ?for line in f.readlines(): > | > ? ? ?line = line.strip() > | > ? ? ?line=line.split() > | > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) > > Have you timed the different parts of your code instead of the whole > thing? > > Specificly, do you know the sort time is the large cost? > > I would point out that the loop above builds the list by append(), one > item at a time. That should have runtime cost of the square of the list > length, 1172026 * 1172026. Though I've just done this: Er, what? list.append() is O(1) amortized. Perhaps you're confusing list.append() with list.insert(), which is indeed O(n)? Cheers, Chris From cs at zip.com.au Sun May 6 20:31:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 10:31:14 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120507003113.GA16860@cskk.homeip.net> On 06May2012 17:10, Chris Rebert wrote: | On Sun, May 6, 2012 at 4:54 PM, Cameron Simpson wrote: | > On 06May2012 18:36, J. Mwebaze wrote: | > | > for filename in txtfiles: | > | > ? ?temp=[] | > | > ? ?f=open(filename) | > | > ? ?for line in f.readlines(): | > | > ? ? ?line = line.strip() | > | > ? ? ?line=line.split() | > | > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) | > | > Have you timed the different parts of your code instead of the whole | > thing? | > | > Specificly, do you know the sort time is the large cost? | > | > I would point out that the loop above builds the list by append(), one | > item at a time. That should have runtime cost of the square of the list | > length, 1172026 * 1172026. Though I've just done this: | | Er, what? list.append() is O(1) amortized. I didn't mean per .append() call (which I'd expect to be O(n) for large n), I meant overall for the completed list. Don't the realloc()s make it O(n^2) overall for large n? The list must get copied when the underlying space fills. I confess to being surprised at how quick it went for me though. I suppose reallocing in chunks (eg to double the available size) might conceal this for a while. It should still be well over O(n) overall (not amortised per .append() call). | Perhaps you're confusing list.append() with list.insert(), which is indeed O(n)? I wasn't, though .insert() is surely way more expensive. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The Borg assimilated my race and all I got was this lousy tagline. - Cath Lawrence From rosuav at gmail.com Sun May 6 21:02:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 May 2012 11:02:57 +1000 Subject: sorting 1172026 entries In-Reply-To: <20120507003113.GA16860@cskk.homeip.net> References: <20120507003113.GA16860@cskk.homeip.net> Message-ID: On Mon, May 7, 2012 at 10:31 AM, Cameron Simpson wrote: > I didn't mean per .append() call (which I'd expect to be O(n) for large > n), I meant overall for the completed list. > > Don't the realloc()s make it O(n^2) overall for large n? The list > must get copied when the underlying space fills. I confess to being > surprised at how quick it went for me though. I suppose reallocing in > chunks (eg to double the available size) might conceal this for a while. > It should still be well over O(n) overall (not amortised per .append() > call). I haven't checked the CPython code, but the usual way to do reallocations is to double the size (or add 50% or something) each time, meaning that as n increases, the frequency of reallocations decreases - hence the O(1) amortized time. In any case, it's the recommended way to build large strings: s = "" while condition: s += "some_value" versus: s = [] while condition: s.append("some_value") s = "".join(s) so I would be very much surprised if this common wisdom is merely replacing one O(n*n) operation with another O(n*n) operation. ChrisA From scubacuda at gmail.com Sun May 6 22:12:42 2012 From: scubacuda at gmail.com (Rogelio) Date: Sun, 6 May 2012 19:12:42 -0700 Subject: new to Python - modules to leverage Perl scripts? Message-ID: I've got quite a few Perl scripts that I would like to leverage, and I'd like to make some Python wrapper scripts for them. The Perl scripts shell into various network appliances, run certain commands, and then output those commands into a file. I recently found out about the subprocess modules (including "call") and am wondering what other Python libraries and modules I should check out. Specifically, I need functions that will do the following... 1) Take a big IP file and break it up into smaller chunks (e.g. 20 IP addresses per file) 2) Run the Perl script on those smaller IP files 3) Run the Perl commands in parallel (to take less time) 4) Take the little logs and concatenate the files 5) Look for existence of certain strings in the logs I'm still playing with the subprocess.call command to make sure that it calls everything okay. But I'm hoping someone can point me where to look for functions that will make this an effective wrapper script. From nospam at nospam.com Sun May 6 23:08:06 2012 From: nospam at nospam.com (Javier) Date: Mon, 7 May 2012 03:08:06 +0000 (UTC) Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: > Learn how to use a database. Creating and managing a > big collection of directories to handle small data items is the > wrong approach to data storage. > > John Nagle Or not... Using directories may be a way to do rapid prototyping, and check quickly how things are going internally, without needing to resort to complex database interfaces. Just a quote from the history of usenet: I wrote the very first version of netnews as a 150-line shellscript. It had multiple newsgroups and cross-posting; newsgroups were directories and cross-posting was implemented as multiple links to the article. It was far too slow to use for production, but the flexibility permitted endless experimentation with the protocol design. -- Steven M. Bellovin http://www.linuxtopia.org/online_books/programming_books/art_of_unix_programming/ch14s04_2.html for the question of the OP: import string import os namefile="..." for line in open("foobar").readlines() dirname,number=string.split(line) os.system("mkdir "+dirname) f=open(dirname+"/"+namefile,"w") f.write("TEXT..."+number) f.close() Portability can be improved by using os.path or something like that. John Nagle wrote: > On 4/30/2012 8:19 AM, deltaquattro at gmail.com wrote: >> Hi, >> >> I would like to automate the following task under Linux. I need to create a set of directories such as >> >> 075 >> 095 >> 100 >> 125 >> >> The directory names may be read from a text file foobar, which also contains a number corresponding to each dir, like this: >> >> 075 1.818 >> 095 2.181 >> 100 2.579 >> 125 3.019 >> >> >> In each directory I must copy a text file input.in. This file contains two lines which need to be edited: > From no.email at nospam.invalid Mon May 7 00:59:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 06 May 2012 21:59:59 -0700 Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: <7x62c8bn74.fsf@ruckus.brouhaha.com> Javier writes: > Or not... Using directories may be a way to do rapid prototyping, and > check quickly how things are going internally, without needing to resort > to complex database interfaces. dbm and shelve are extremely simple to use. Using the file system for a million item db is ridiculous even for prototyping. From nagle at animats.com Mon May 7 01:21:46 2012 From: nagle at animats.com (John Nagle) Date: Sun, 06 May 2012 22:21:46 -0700 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: On 5/4/2012 12:14 AM, Steve Howell wrote: > On May 3, 11:59 pm, Paul Rubin wrote: >> Steve Howell writes: >>> compressor = zlib.compressobj() >>> s = compressor.compress("foobar") >>> s += compressor.flush(zlib.Z_SYNC_FLUSH) >> >>> s_start = s >>> compressor2 = compressor.copy() That's awful. There's no point in compressing six characters with zlib. Zlib has a minimum overhead of 11 bytes. You just made the data bigger. John Nagle From no.email at nospam.invalid Mon May 7 01:34:52 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 06 May 2012 22:34:52 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <7xlil44kqr.fsf@ruckus.brouhaha.com> John Nagle writes: > That's awful. There's no point in compressing six characters > with zlib. Zlib has a minimum overhead of 11 bytes. You just > made the data bigger. This hack is about avoiding the initialization overhead--do you really get 11 bytes after every SYNC_FLUSH? I do remember with that SYNC_FLUSH trick, that I got good compression with a few hundred bytes of input (the records I was dealing with at the time). From yegorslists at googlemail.com Mon May 7 02:54:50 2012 From: yegorslists at googlemail.com (Yegor Yefremov) Date: Sun, 6 May 2012 23:54:50 -0700 (PDT) Subject: Override path to python during installation (setuptools) Message-ID: <14367991.255.1336373690973.JavaMail.geo-discussion-forums@ynmk20> I'm trying to add lava-test package to Buildroot. After "cross-compilation" I get following path in the /usr/bin/lava: #!/home/user/MyProjects/versioned/buildroot/output/host/usr/bin/python instead of #!/usr/bin/python I use following command to install lava_test package: +define LAVA_TEST_INSTALL_TARGET_CMDS + (cd $(@D); PYTHONPATH="$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages"\ + $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr) +endef How can I override this auto-generated path? The whole patch can be seen here: http://patchwork.ozlabs.org/patch/155498/ Regards, Yegor From __peter__ at web.de Mon May 7 03:16:20 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 May 2012 09:16:20 +0200 Subject: new to Python - modules to leverage Perl scripts? References: Message-ID: Rogelio wrote: > I've got quite a few Perl scripts that I would like to leverage, and > I'd like to make some Python wrapper scripts for them. > > The Perl scripts shell into various network appliances, run certain > commands, and then output those commands into a file. > > I recently found out about the subprocess modules (including "call") > and am wondering what other Python libraries and modules I should > check out. Specifically, I need functions that will do the > following... > > 1) Take a big IP file and break it up into smaller chunks (e.g. 20 IP > addresses per file) itertools.islice() > 2) Run the Perl script on those smaller IP files subprocess. If the script can read from stdin you may not need the intermediate file; use subprocess.Popen(..., stdin=PIPE).communicate(inputdata_as_a_string) instead. > 3) Run the Perl commands in parallel (to take less time) multiprocessing? Though your problem may be I/O-bound. > 4) Take the little logs and concatenate the files itertools.chain.from_iterable() > 5) Look for existence of certain strings in the logs with open(logfile) as f: for line in f: if some_string in line: # whatever If you know Perl you will not be completely puzzled when you have to switch to a regex. You'll rather make that switch to early ;) > I'm still playing with the subprocess.call command to make sure that > it calls everything okay. But I'm hoping someone can point me where > to look for functions that will make this an effective wrapper script. You sound like you are not completely satisfied with subprocess. What are you missing? From cs at zip.com.au Mon May 7 03:37:21 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 17:37:21 +1000 Subject: new to Python - modules to leverage Perl scripts? In-Reply-To: References: Message-ID: <20120507073721.GA10158@cskk.homeip.net> On 07May2012 09:16, Peter Otten <__peter__ at web.de> wrote: | Rogelio wrote: | > I've got quite a few Perl scripts that I would like to leverage, and | > I'd like to make some Python wrapper scripts for them. | > | > The Perl scripts shell into various network appliances, run certain | > commands, and then output those commands into a file. | > | > I recently found out about the subprocess modules (including "call") | > and am wondering what other Python libraries and modules I should | > check out. Specifically, I need functions that will do the | > following... [...] | > 2) Run the Perl script on those smaller IP files | | subprocess. If the script can read from stdin you may not need the | intermediate file; use | | subprocess.Popen(..., stdin=PIPE).communicate(inputdata_as_a_string) | | instead. | | > 3) Run the Perl commands in parallel (to take less time) | | multiprocessing? Though your problem may be I/O-bound. If he stuffs the inputs into TemporaryFiles he can attach them to subprocess.Popen() stdin and just not wait. Dispatch them all and collect afterwards. Only tempfile and subprocess needed; no need for communicate. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ One of the most important things you learn from the internet is that there is no 'them' out there. It's just an awful lot of 'us'. - Douglas Adams From bwalker at itree.com.au Mon May 7 03:57:22 2012 From: bwalker at itree.com.au (nbw) Date: Mon, 7 May 2012 00:57:22 -0700 (PDT) Subject: Scrapy - importing files from local, rather than www Message-ID: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> Hi everyone, I'm new to Python (loving it!) and Scrapy. I have a question I just can't seem to get my head around. I can get a simple Scrapy spider to pick up URLs and download them fine, but the HTML files I have are stored locally. The reason for this, is for some reason when I "Save As" the pages I get everything, whereas if Scrapy runs over them it seems to miss certain areas where there's Javascript. So, I have them sitting in a directory (C:/scrapy_test) but can't for the life of me get Scrapy to find them. Is there anyone who's had this problem and solved it, or can help? Any help is much appreciated. Kind regards, nbw From Nadhiya.A at lnties.com Mon May 7 04:42:39 2012 From: Nadhiya.A at lnties.com (Nadhiya A) Date: Mon, 7 May 2012 08:42:39 +0000 Subject: problem in event handling on change of variable value. Message-ID: Hi, I want know how can I control Canoe tool from Python. I want to use Python as the mediator for linking CANoe and Matlab. Please give me some inputs regarding this. Thanks & Regards Nadhiya.A Larsen & Toubro Limited www.larsentoubro.com This Email may contain confidential or privileged information for the intended recipient (s). If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system. Earth Day. Every Day. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramapraba2653 at gmail.com Mon May 7 06:10:01 2012 From: ramapraba2653 at gmail.com (SUPREME) Date: Mon, 7 May 2012 03:10:01 -0700 (PDT) Subject: LATEST HOT PHOTOS & VIDEOS Message-ID: <9a6a80ce-1fa3-4dab-938c-931e1e87a992@to5g2000pbc.googlegroups.com> TOP DOT NET INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html Rajsekhar Mahankali Movie Stills http://actressgallery-kalyani.blogspot.in/2012/03/mahankali-movie-stills.html Mamata 100% Prema Movie Hot Stills http://actressgallery-kalyani.blogspot.in/2012/03/mamata-100-prema-movie-stills.html Raviteja Daruvu Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/daruvu-movie-stills.html NUVVA NENA MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/03/nuvva-nena-movie-stills.html Yadartha Prema Katha Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/yadartha-prema-katha-movie-stills.html RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From aya.exam at gmail.com Mon May 7 06:23:09 2012 From: aya.exam at gmail.com (Exam Aya) Date: Mon, 7 May 2012 03:23:09 -0700 (PDT) Subject: Workshop on Design Patterns and Advanced OOPS, Bangalore Message-ID: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> Workshop on Design Patterns and Advanced OOPS Date: Sunday , 13th May, 2012 At Bangalore Hurry Register Online Now https://docs.google.com/spreadsheet/viewform?formkey=dGlMMnEtYmJVY2M3bEhNZG5WY3BHTkE6MA#gid=0 About the workshop: For anyone working on object oriented programing languages like C++, Java, C#, Python, PHP, etc. this workshop is a must. It goes through the set of design patterns that started it all - Go4 - (Gang of 4) patterns. The workshop will very interactive and each design pattern will be explored rather than taught or lectured on. A problem statement will be provided and the group will move towards why the design pattern is required. This will not only drill into you why use a pattern in the first place but also which pattern to use in what scenario. Course Contents (Day 1) 1. The Pit Falls of OOPS - Refresher on OOPS - When does OOPS get confusing 2. Design Pattern Intro - What are Design Patterns - What are its uses and applications 3. Design Patterns - Strategy Pattern - Observer Pattern Course Contents (Day 1) - Decorator Pattern - Factory Pattern - Singleton Pattern - Command Pattern - Adapter Pattern - Facade Pattern - Template Pattern - Iterator Pattern - Composite Pattern - State Pattern Time : 09:30 am to 05:30 pm Venue: 1910, 8th A Cross (road connects 4th Main and 6th Main), HAL 3rd Stage (New Thippasandira), Bangalore - 75 Email events at examaya.com Website: www.examaya.com Course Fees: Rs. 750 Cost of Course Materials, Refreshments and Lunch Hurry Register Online Now! https://docs.google.com/spreadsheet/viewform?formkey=dGlMMnEtYmJVY2M3bEhNZG5WY3BHTkE6MA#gid=0 About the Speaker: Sethuraman is a passionate Java programmer who is currently working in Thoughtworks. He has a total of 8 years of experience in the industry and is a very "hands on guy". He is known in the professional circle for his excellent communication From varma.nikhil22 at gmail.com Mon May 7 07:31:20 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 7 May 2012 17:01:20 +0530 Subject: return respective values when mutiple keys are passed in dictionary Message-ID: HI All I was clearing my concepts on dictionary and stuck in this problem. I have a dictionary which i have formed by using zip function on two list so that one list (which i have hardcoded) becomes the keys and the other list becomes its values. Now i want to know how can i get the values of keys at once if i pass the keys in a dictionary. Let say I have a dictionary mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} Now if i do :- mydict.get('a') 'apple' What i want is some i pass keys in get and in return i should have all the values of those keys which i pass. ################## mydict.get('a','b','c') ###demo for what i want 'apple','boy','cat' ### Output i want ################# -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hash.3g at gmail.com Mon May 7 07:36:57 2012 From: hash.3g at gmail.com (=?KOI8-R?B?98nUwczJyiD3z8zLz9c=?=) Date: Mon, 7 May 2012 14:36:57 +0300 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: You can try to use map(mydict.get, ('a', 'b', 'c')) and then make join On May 7, 2012 2:33 PM, "Nikhil Verma" wrote: > HI All > > I was clearing my concepts on dictionary and stuck in this problem. > I have a dictionary which i have formed by using zip function on two list > so that one list (which i have hardcoded) becomes the keys and the other > list > becomes its values. > > Now i want to know how can i get the values of keys at once if i pass the > keys in a dictionary. > > Let say I have a dictionary > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' > > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c') ###demo for what i want > 'apple','boy','cat' ### Output i want > ################# > > -- > Regards > Nikhil Verma > +91-958-273-3156 > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ferreirafm at lim12.fm.usp.br Mon May 7 07:48:16 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Mon, 7 May 2012 04:48:16 -0700 (PDT) Subject: [SOLVED] for-loop: weird behavior In-Reply-To: <1336163619790-4953214.post@n6.nabble.com> References: <1336163619790-4953214.post@n6.nabble.com> Message-ID: <1336391296054-4957597.post@n6.nabble.com> The problem has been solved opening the file for iteration in the second loop. I didn't realized such Python behavior. Any comments are appreciated. Fred -- View this message in context: http://python.6.n6.nabble.com/SOLVED-for-loop-weird-behavior-tp4953214p4957597.html Sent from the Python - python-list mailing list archive at Nabble.com. From dinkypumpkin at gmail.com Mon May 7 09:13:28 2012 From: dinkypumpkin at gmail.com (dinkypumpkin at gmail.com) Date: Mon, 7 May 2012 06:13:28 -0700 (PDT) Subject: PyTextile Question In-Reply-To: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> References: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> Message-ID: <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> On Friday, 4 May 2012 04:39:47 UTC+1, Josh English wrote: > However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved. I think any Textile implementation will preserve line breaks within a paragraph by converting them to BR tags. Both RedCloth and PyTextile do, anyway. > I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks. Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV. import re, textile print "INPUT1:" s1 = """This is a long multi-line description with several paragraphs and hopefully, eventually, proper HTML P-tags. This is a new paragraph. It should be surrounded by its own P-tag. Hopefully (again), I won't have a bunch of unwanted BR tags thrown in.""" print(s1) print "OUTPUT1:" html1 = textile.textile(s1) print(html1) print "INPUT2:" s2 = re.sub(r'[ \t]*\n[ \t]*(\n?)[ \t]*', r' \1\1', s1, flags=re.MULTILINE) print(s2) print "OUTPUT2:" html2 = textile.textile(s2) print(html2) From arnodel at gmail.com Mon May 7 09:40:02 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 7 May 2012 14:40:02 +0100 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: On 7 May 2012 12:31, Nikhil Verma wrote: > HI All > > I was clearing my concepts on dictionary and stuck in this problem. > I have a dictionary which i have formed by using zip function on two list so > that one list (which i have hardcoded) becomes the keys and the other list > becomes its values. > > Now i want to know how can i get the values of keys at once if i pass the > keys in a dictionary. > > Let say I have a dictionary > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' mydict['a'] is the usual way to get the value associated with a key. The difference is that it will throw an exception if the key doesn't exist, which is most of the time the sanest thing to do. > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c')??? ###demo for what i want > 'apple','boy','cat'??????? ### Output i want > ################# 1. You can use a list comprehension >>> [mydict[k] for k in 'a', 'b', 'c'] ['apple', 'boy', 'cat'] 2. You can use map (for python 3.X, you need to wrap this in list(...)) >>> map(mydict.__getitem__, ['a', 'b', 'c']) ['apple', 'boy', 'cat'] 3. You can use operator.itemgetter >>> from operator import itemgetter >>> itemgetter('a', 'b', 'c')(mydict) ('apple', 'boy', 'cat') -- Arnaud From rosuav at gmail.com Mon May 7 09:45:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 May 2012 23:45:46 +1000 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: On Mon, May 7, 2012 at 9:31 PM, Nikhil Verma wrote: > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' > > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c')??? ###demo for what i want > 'apple','boy','cat'??????? ### Output i want > ################# Presumably you want to get back a list or tuple, so a list comprehension is your best bet. [mydict.get(i) for i in ('a','b','c')] Incidentally, are you aware that dictionaries can be subscripted? The get() method is good when you want a default value for anything that doesn't exist, otherwise you can simply use: mydict['a'] ChrisA From showell30 at yahoo.com Mon May 7 12:39:05 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 7 May 2012 09:39:05 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <2322bfb1-217e-40af-ac43-bc3f2ec3db91@qg3g2000pbc.googlegroups.com> On May 6, 10:21?pm, John Nagle wrote: > On 5/4/2012 12:14 AM, Steve Howell wrote: > > > On May 3, 11:59 pm, Paul Rubin ?wrote: > >> Steve Howell ?writes: > >>> ? ? ?compressor = zlib.compressobj() > >>> ? ? ?s = compressor.compress("foobar") > >>> ? ? ?s += compressor.flush(zlib.Z_SYNC_FLUSH) > > >>> ? ? ?s_start = s > >>> ? ? ?compressor2 = compressor.copy() > > ? ? That's awful. There's no point in compressing six characters > with zlib. ?Zlib has a minimum overhead of 11 bytes. ?You just > made the data bigger. > The actual strings that I'm compressing are much longer than six characters. Obviously, "foobar" was just for example purposes. From tjreedy at udel.edu Mon May 7 12:49:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 07 May 2012 12:49:28 -0400 Subject: Workshop on Design Patterns and Advanced OOPS, Bangalore In-Reply-To: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> References: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> Message-ID: On 5/7/2012 6:23 AM, Exam Aya wrote: > For anyone working on object oriented programing languages like C++, > Java, C#, Python, PHP, etc. this workshop is a must. It goes through > the set of design patterns that started it all - Go4 - (Gang of 4) > patterns. The workshop will very interactive and each design pattern > will be explored rather than taught or lectured on. A problem > statement will be provided and the group will move towards why the > design pattern is required. I hope someone who really knows Python attends, so people can discover how easy some of the patterns are in Python, which does not have the straightjacket of statically typed names. For instance, heterogeneous sets and lists, used for instance for composites consisting of items and sub-composites, are part of Python rather than a tricky add-on. > Course Contents (Day 1) > > 1. The Pit Falls of OOPS > - Refresher on OOPS > - When does OOPS get confusing > > 2. Design Pattern Intro > - What are Design Patterns > - What are its uses and applications > > 3. Design Patterns > - Strategy Pattern > - Observer Pattern > > > Course Contents (Day 1) > - Decorator Pattern > - Factory Pattern > - Singleton Pattern > - Command Pattern > - Adapter Pattern > - Facade Pattern > - Template Pattern > - Iterator Pattern > - Composite Pattern > - State Pattern > > > Time : 09:30 am to 05:30 pm > > Venue: > > 1910, 8th A Cross (road connects 4th Main and 6th Main), HAL 3rd Stage > (New Thippasandira), Bangalore - 75 If I lived in Bangalore, I might attend. This announcement is, however, a bit OT for this list. On the other hand, it is encouraging that Python is now routinely listed as a major language in such things. Not so when I learned it 16 years ago ;-). -- Terry Jan Reedy From cs at zip.com.au Mon May 7 17:52:24 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 8 May 2012 07:52:24 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120507215224.GA10765@cskk.homeip.net> On 07May2012 11:02, Chris Angelico wrote: | On Mon, May 7, 2012 at 10:31 AM, Cameron Simpson wrote: | > I didn't mean per .append() call (which I'd expect to be O(n) for large | > n), I meant overall for the completed list. | > | > Don't the realloc()s make it O(n^2) overall for large n? The list | > must get copied when the underlying space fills. I confess to being | > surprised at how quick it went for me though. I suppose reallocing in | > chunks (eg to double the available size) might conceal this for a while. | > It should still be well over O(n) overall (not amortised per .append() | > call). | | I haven't checked the CPython code, but the usual way to do | reallocations is to double the size My example above:-) | (or add 50% or something) each | time, meaning that as n increases, the frequency of reallocations | decreases - hence the O(1) amortized time. Hmm, yes. But it is only O(1) for doubling. If one went with a smaller increment (to waste less space in the end case where one stops growing the array) then there are more copies and less .append efficiency, trading potential memory bloat for compute time in .append(). If you went all the way to adding only one item the cost goes to O(n) for .append() and O(n^2) overall, with varying costs in between. | In any case, it's the | recommended way to build large strings: | | s = "" | while condition: | s += "some_value" | | versus: | | s = [] | while condition: | s.append("some_value") | s = "".join(s) | | so I would be very much surprised if this common wisdom is merely | replacing one O(n*n) operation with another O(n*n) operation. It sort of is (except that list.append may be specially tuned to realloc in big chunks). The join-lots-of-strings standard example is based on the length of the strings in characters/bytes being far more than the number of strings. So you do a lot of tiny listappends instead, copying nothing, then a big allocate-the-correct-size-and-copy-once with s.join. Also, this: s += "some_value" is not a list extension. Because strings are immutable (and anyway in general for "+" in python) you're making a new string and copying two other string contents into it. Inherently a copy of the whole of "s" on every "+" operation. Compared with list.append() or list.extend(), which are in-place modifications to the original list. So these are really apples and oranges here. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ We are in great haste to construct a magnetic telegraph from Maine to Texas; but Maine and Texas, it may be, have nothing important to communicate. - H. D. Thoreau From rafadurancastaneda at gmail.com Mon May 7 17:59:30 2012 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Mon, 07 May 2012 23:59:30 +0200 Subject: try/except KeyboardInterrupt vs signal handler for SIGINT Message-ID: <4FA845C2.4010206@gmail.com> Hi, I was wondering which approach is better to stop several servers from just on python application when 'ctrl-c' is pressed, a try/except KeyboardInterrupt or just registering a SIGINT handler and exit when the signal is triggered. Any advantage/disadvantage from one approach over the other? P.S.: Since several servers are started just one 'ctrl-c' doesn't work without any extra change and I have some concerns about the signal handler. Thank you for your answers. From pinard at iro.umontreal.ca Mon May 7 19:00:32 2012 From: pinard at iro.umontreal.ca (=?utf-8?Q?Fran=C3=A7ois_Pinard?=) Date: Mon, 07 May 2012 19:00:32 -0400 Subject: RELEASED: Pymacs 0.25 Message-ID: <86obpzsijz.fsf@mercure.progiciels-bpi.ca> Hello to everybody, and Emacs users in the Python community. Pymacs 0.25 is now available. There has been a while, so I advise current Pymacs users to switch with caution. - Python 3 is now supported. This required new installation mechanics, and a Python pre-processor written for the circumstance (named *pppp*). - Pymacs now installs a single Python file instead of a Python module. Nice thanks to Pymacs contributors. It surely has been fun working with you all! -------------------------------------- Pymacs is a powerful tool which, once started from Emacs, allows both-way communication between Emacs Lisp and Python. Pymacs aims Python as an extension language for Emacs rather than the other way around, and this asymmetry is reflected in some design choices. Within Emacs Lisp code, one may load and use Python modules. Python functions may themselves use Emacs services, and handle Emacs Lisp objects kept in Emacs Lisp space. For more information, see http://pymacs.progiciels-bpi.ca/ . You may fetch the distribution as one of: - https://github.com/pinard/Pymacs/tarball/v0.25 - https://github.com/pinard/Pymacs/zipball/v0.25 -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From albertsun05 at gmail.com Mon May 7 19:20:35 2012 From: albertsun05 at gmail.com (Albert) Date: Mon, 7 May 2012 16:20:35 -0700 (PDT) Subject: How do I run a python program from an internet address? Message-ID: I have a small text based python program that I want to make available to people who might be behind a firewall or can't install python on their office computers, but can access the internet. It is just an algorithm that makes a handful of straightforward calculations on some input that the user provides and spits out some text as output that they might want to print out on a printer. I can program python on my local machine, but don't know how to make the code accessible from a browser. What would be the best way to figure out how to do this? I looked at Google app engine tutorial, but can't figure out how that will help we get the code into the cloud so I can access it from any browser. From rosuav at gmail.com Mon May 7 19:51:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 09:51:54 +1000 Subject: How do I run a python program from an internet address? In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 9:20 AM, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. ?It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that > they might want to print out on a printer. ?I can program python on my > local machine, but don't know how to make the code accessible from a > browser. Probably the easiest way is to make your program into a web server itself: http://docs.python.org/py3k/library/http.server.html Put it on a high port (eg 8000) and then direct people to http://your.machine.ip.address:8000/ to access it. There are other ways, too, such as CGI scripting, but the http.server module is pretty convenient. ChrisA From steve+comp.lang.python at pearwood.info Mon May 7 20:11:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2012 00:11:33 GMT Subject: How do I run a python program from an internet address? References: Message-ID: <4fa864b5$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 May 2012 16:20:35 -0700, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that they > might want to print out on a printer. I can program python on my local > machine, but don't know how to make the code accessible from a browser. > > What would be the best way to figure out how to do this? Try googling "python web app how to". For example, the very first link found here: https://duckduckgo.com/html/?q=python%20web%20app%20how%20to is an introduction to making Python applications available to run over the Internet. -- Steven From charleshixsn at earthlink.net Mon May 7 23:15:36 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 20:15:36 -0700 Subject: indexed property? Can it be done? Message-ID: <4FA88FD8.4000905@earthlink.net> class Node: def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, [key], [value], [downRight], parent, dirty, dlu] Note that node[3] is a list of keys (initially 1) and node[3] is a list of values, etc. What I'd like to do is to be able to address them thusly: k = node.key[2] v = node.value[2] but if there's a way to do this, I haven't been able to figure it out. Any suggestions? -- Charles Hixson From clp2 at rebertia.com Mon May 7 23:33:49 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 7 May 2012 20:33:49 -0700 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: On Mon, May 7, 2012 at 8:15 PM, Charles Hixson wrote: > class Node: > > ? ?def ? ?__init__(self, nodeId, key, value, downRight, downLeft, parent): > ? ? ? ?dirty ? ?= ? ?True > ? ? ? ?dlu ? ?= ? ?utcnow() > ? ? ? ?self.node ? ?= ? ?[nodeId, downLeft, [key], [value], [downRight], > parent, dirty, dlu] Why are you using a single opaque list instead of separate, meaningful attributes for each datum? Cheers, Chris From dan at tombstonezero.net Mon May 7 23:44:05 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 7 May 2012 20:44:05 -0700 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: <20120507204405.2840e422@particle> On Mon, 07 May 2012 20:15:36 -0700 Charles Hixson wrote: > class Node: > > def __init__(self, nodeId, key, value, downRight, downLeft, > parent): dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a > list of values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it > out. Any suggestions? Untested: def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, dict(key=value), [downRight], parent, dirty, dlu] Now you can use self.node[2][key] to get/set value. But why not make the elements of node their own attributes? Untested: def __init__(self, nodeId, key, value, downRight, downLeft, parent): self.dirty = True self.dlu = utcnow() self.nodeId = nodeId self.downLeft = downLeft self.downRight = downRight self.values = dict(key=value) self.parent = parent And then you don't have to remember that node[2] is the key/value pairs (note the typo (the two "3"s) in your original post). With each attribute in its own, well, attribute, you can always use node.values[key] to access the value associated with a particular key. HTH, Dan From nagle at animats.com Mon May 7 23:46:57 2012 From: nagle at animats.com (John Nagle) Date: Mon, 07 May 2012 20:46:57 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: <7x62c8bn74.fsf@ruckus.brouhaha.com> References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On 5/6/2012 9:59 PM, Paul Rubin wrote: > Javier writes: >> Or not... Using directories may be a way to do rapid prototyping, and >> check quickly how things are going internally, without needing to resort >> to complex database interfaces. > > dbm and shelve are extremely simple to use. Using the file system for a > million item db is ridiculous even for prototyping. Right. Steve Bellovin wrote that back when UNIX didn't have any database programs, let alone free ones. John Nagle From steve+comp.lang.python at pearwood.info Mon May 7 23:54:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2012 03:54:11 GMT Subject: Open Source: you're doing it wrong - the Pyjamas hijack Message-ID: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> A.k.a. "we had to destroy the project in order to save it". http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html Seriously, this was a remarkably ham-fisted and foolish way to "resolve" a dispute over the direction of an open source project. That's the sort of thing that gives open source a bad reputation. (The sad thing is, when closed source software developers do this sort of thing, it gets blamed on "bad apples"; when open source developers do it, it gets used as an indictment on the entire FOSS community.) -- Steven From charleshixsn at earthlink.net Tue May 8 00:07:27 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 21:07:27 -0700 Subject: indexed property? Can it be done? In-Reply-To: References: <4FA88FD8.4000905@earthlink.net> Message-ID: <4FA89BFF.1080203@earthlink.net> On 05/07/2012 08:33 PM, Chris Rebert wrote: > On Mon, May 7, 2012 at 8:15 PM, Charles Hixson > wrote: > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], [downRight], >> parent, dirty, dlu] >> > Why are you using a single opaque list instead of separate, meaningful > attributes for each datum? > > Cheers, > Chris > > Because that's the most reasonable implementation. The various list items would not be the same from instance to instance. I could pull the top-level list items off as separate variables, but this would leave the problem exactly where it is, and ordinary properties allow me to address the entries like id, and dlu without problem. But the list variables are a separate problem, and not so readily soluble. FWIW, if I must I can operate with only a list, and define functions to do the access and manipulation. I'd rather not, which is why I'm exploring whether an indexed property is feasible. Note that I *could* return, e.g., the entire keys list, but I'd rather use a bit more data protection than that. Which is what an indexed setter property would allow. And node.key[3] is as fully informative a name as I can construct for that entry. But the number of items in the keys list varies from node to node, so defining a key3 property is not reasonable. (Besides, that's so ugly that I'd rather use a function, even though indexing in Python really should be done with brackets rather than parens.) -- Charles Hixson From showell30 at yahoo.com Tue May 8 00:09:33 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 7 May 2012 21:09:33 -0700 (PDT) Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On May 7, 8:46?pm, John Nagle wrote: > On 5/6/2012 9:59 PM, Paul Rubin wrote: > > > Javier ?writes: > >> Or not... Using directories may be a way to do rapid prototyping, and > >> check quickly how things are going internally, without needing to resort > >> to complex database interfaces. > > > dbm and shelve are extremely simple to use. ?Using the file system for a > > million item db is ridiculous even for prototyping. > > ? ? Right. ?Steve Bellovin wrote that back when UNIX didn't have any > database programs, let alone free ones. > It's kind of sad that the Unix file system doesn't serve as an effective key-value store at any kind of nontrivial scale. It would simplify a lot of programming if filenames were keys and file contents were values. From charleshixsn at earthlink.net Tue May 8 00:18:37 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 21:18:37 -0700 Subject: indexed property? Can it be done? In-Reply-To: <20120507204405.2840e422@particle> References: <4FA88FD8.4000905@earthlink.net> <20120507204405.2840e422@particle> Message-ID: <4FA89E9D.4070406@earthlink.net> On 05/07/2012 08:44 PM, Dan Sommers wrote: > On Mon, 07 May 2012 20:15:36 -0700 > Charles Hixson wrote: > > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, >> parent): dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> >> Note that node[3] is a list of keys (initially 1) and node[3] is a >> list of values, etc. >> >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it >> out. Any suggestions? >> > Untested: > > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, dict(key=value), > [downRight], parent, dirty, dlu] > > Now you can use self.node[2][key] to get/set value. > > But why not make the elements of node their own attributes? > > Untested: > > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > self.dirty = True > self.dlu = utcnow() > self.nodeId = nodeId > self.downLeft = downLeft > self.downRight = downRight > self.values = dict(key=value) > self.parent = parent > > And then you don't have to remember that node[2] is the key/value pairs > (note the typo (the two "3"s) in your original post). With each > attribute in its own, well, attribute, you can always use > node.values[key] to access the value associated with a particular key. > > HTH, > Dan > Did you notice that the node list contained sublists? I can access the top level node items through ordinary properties, and that is my intent. So I don't need to remember what top level index represents what item. But the second level items are variable in length, so I really want to do an indexed access to them. Yes, I admit that in the snipped defined by the __init__ method those secondary lists only received one entry. Other method would extend their length, to a variable amount for different class instances. A part of the reason that the class retains that top level list is so that if I can't create an indexed property to get and set them, I can revert to an alternative that is a bit uglier than this, but might be more efficient. (It would have methods that operated directly on the list rather than using properties for ANY of the approach...and avoid creating a class that they handle. Not as clean as what I'm hoping for, but so far I haven't come up with any way except functions that doesn't directly expose the data...and if I must use that approach, then the class doesn't buy me anything for the overhead.) -- Charles Hixson From nagle at animats.com Tue May 8 00:50:33 2012 From: nagle at animats.com (John Nagle) Date: Mon, 07 May 2012 21:50:33 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On 5/7/2012 9:09 PM, Steve Howell wrote: > On May 7, 8:46 pm, John Nagle wrote: >> On 5/6/2012 9:59 PM, Paul Rubin wrote: >> >>> Javier writes: >>>> Or not... Using directories may be a way to do rapid prototyping, and >>>> check quickly how things are going internally, without needing to resort >>>> to complex database interfaces. >> >>> dbm and shelve are extremely simple to use. Using the file system for a >>> million item db is ridiculous even for prototyping. >> >> Right. Steve Bellovin wrote that back when UNIX didn't have any >> database programs, let alone free ones. >> > > It's kind of sad that the Unix file system doesn't serve as an > effective key-value store at any kind of nontrivial scale. It would > simplify a lot of programming if filenames were keys and file contents > were values. You don't want to go there in a file system. Some people I know tried that around 1970. "A bit is a file. An ordered collection of files is a file". Didn't work out. There are file models other than the UNIX one. Many older systems had file versioning. Tandem built their file system on top of their distributed, redundant database system. There are backup systems where the name of the file is its hash, allowing elimination of duplicates. Most of the "free online storage" sites do that. John Nagle From rosuav at gmail.com Tue May 8 01:20:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 15:20:39 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 1:54 PM, Steven D'Aprano wrote: > A.k.a. "we had to destroy the project in order to save it". > > http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html Great summary, very handily peppered with links to appropriate posts. > Seriously, this was a remarkably ham-fisted and foolish way to "resolve" > a dispute over the direction of an open source project. That's the sort > of thing that gives open source a bad reputation. I'd probably be on the side of the dissidents in terms of philosophy - freedom is there to be used, but if it costs you too much (effort, quality, etc) to use all-free-software, the cart's involved in equine artistry. You want a wiki? Throw down MySQL and MediaWiki. Want hosting? GitHub is fine. I don't restrict my hardware purchases to "free BIOS or no sale". But a backstabbing takeover is not doing anyone any good. Especially not the reputation of the project. Here at work we have some familiarity with Python, and my boss is just starting to learn Javascript (after our main JS developer left); but there's no way that I'm going to consider introducing pyjamas / pyjs until this is resolved. > (The sad thing is, when closed source software developers do this sort of > thing, it gets blamed on "bad apples"; when open source developers do it, > it gets used as an indictment on the entire FOSS community.) It's not quite as mixed-standards as that. If you see Microsoft or Apple charging a fortune for trivial upgrades and/or bug fixes, you blame it on corporate development. And some low-quality software in the FOSS market is acknowledged as "you get what you pay for", although that one can backfire too. But yes, it's a harsh reality that one open-source community's actions reflect badly on another. (Which is why I want to be really REALLY careful of using the term "open source" here at work. Just because we let people have the source code to certain scripts etc does not mean we should use that term. Just sayin'.) I hope that pyjamas can be restored at some point to a single live project. Whether that's headed by Luke Leighton or C Anthony Risinger (neither of whom I know at all and thus I can't speak to either's merits) or someone else, I don't particularly care, but frankly, I don't think there's need in the world for a fork of such a project. Aside from philosophical disagreements, what would be the differences between the Luke fork and the Anthony fork? Could anyone explain, to a prospective user, why s/he should pick one or the other? If not, the projects need to merge, or else one will die a sad death of stagnation. ChrisA From wuwei23 at gmail.com Tue May 8 01:37:38 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 7 May 2012 22:37:38 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> On May 8, 1:54?pm, Steven D'Aprano wrote: > Seriously, this was a remarkably ham-fisted and foolish way to "resolve" > a dispute over the direction of an open source project. That's the sort > of thing that gives open source a bad reputation. The arrogance and sense of entitlement was so thick you could choke on it. Here's a sampling from the circle jerk of self-justification that flooded my inbox over the weekend: "i did not need to consult Luke, nor would that have be productive" No, it's generally _not_ productive to ask someone if you can steal their project from them. "i have retired Luke of the management duties, particularly, *above* the source" Who is this C Anthony Risinger asshole and in what way did he _hire_ the lead developer? "What I have wondered is, what are effects of having the project hostage to the whims of an individuals often illogically radical software libre beliefs which are absolutely not up for discussion at all with anyone." What I'm wondering is: how is the new set up any different? Why were Luke Leighton's philosophies/"whims" any more right or wrong than those held by the new Gang of Dicks? "Further more, the reason I think it's a bad idea to have this drawn out discussion is that pretty much the main reason for this fork is because of Luke leadership and project management decisions and actions. To have discussions of why the fork was done would invariably lead to quite a bit of personal attacks and petty arguments." Apparently it's nicer to steal someone's work than be mean to them. "I agree, Lex - this is all about moving on. This is a software project, not a cult of personality." Because recognising the effort of the lead developer is cult-like. "My only quibble is with the term "fork." A fork is created when you disagree with the technical direction of a project. That's not the issue here. This is a reassignment of the project administration only - a shuffling of responsibility among *current leaders* of the community. There is no "divine right of kings" here." My quibble is over the term "fork" too, as this is outright theft. I don't remember the community acknowledging _any other leadership_ over Luke Leighton's. "I suspect Luke will be busy with other projects and not do much more for Pyjamas/pyjs, Luke correct me if you see this and I am wrong." How about letting the man make his own fucking decisions? "All of you spamming the list with your unsubscribe attempts: Anthony mentioned in a previous email that he's using mailman now" Apparently it's the responsibility of the person who was subscribed without their permission to find out the correct mechanism for unsubscribing from that list. "apparantly a bunch of people were marked as "POSTING" in the DB, but not receiving mail (?)" Oh I see, the sudden rush of email I received was due to an error in the data they stole... "Nobody wins if we spend any amount of time debating the details of this transition, what's done is done." Truly the justification of assholes. From ian.g.kelly at gmail.com Tue May 8 01:42:49 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 7 May 2012 23:42:49 -0600 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: On Mon, May 7, 2012 at 9:15 PM, Charles Hixson wrote: > class Node: > > ? ?def ? ?__init__(self, nodeId, key, value, downRight, downLeft, parent): > ? ? ? ?dirty ? ?= ? ?True > ? ? ? ?dlu ? ?= ? ?utcnow() > ? ? ? ?self.node ? ?= ? ?[nodeId, downLeft, [key], [value], [downRight], > parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a list of > values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. ?Any > suggestions? http://code.activestate.com/recipes/577703-item-properties/ From wuwei23 at gmail.com Tue May 8 01:46:34 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 7 May 2012 22:46:34 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> Message-ID: <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> Even worse, here's what Risinger had to say when Leighton asked them to stop sending him email: "probably best not to feed the troll, Pascal -- especially one overwrought and lost in high dudgeon -- they tend to brickwall common reason and simple social advices." "Luke has made his decision -- and burned all ties -- by pitching a snit of hollow threats" "i full-heartily recommend that everyone do exactly as Luke requests, i.e. "cease and desist from all communications" with him, regarding this project's past or future ..." There's being an asshole, and then there's being an absolute fucking asshole. It seems pretty clear which category this behaviour falls in. From rosuav at gmail.com Tue May 8 02:01:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 16:01:00 +1000 Subject: indexed property? Can it be done? In-Reply-To: <4FA89E9D.4070406@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> <20120507204405.2840e422@particle> <4FA89E9D.4070406@earthlink.net> Message-ID: On Tue, May 8, 2012 at 2:18 PM, Charles Hixson wrote: > Not as clean as what I'm hoping for, but so far I haven't come up with any > way except functions that doesn't directly expose the data...and if I must > use that approach, then the class doesn't buy me anything for the overhead.) C++ and Java teach us to hide everything and use trivial getters and setters to make things available: class Foo { private: int value; public: int getValue() {return value;} int setValue(int newval) {return value=newval;} }; Python lets us happily access members directly, but change to getter/setter if we need to: (example lifted from http://docs.python.org/library/functions.html#property ) class C(object): def __init__(self): self._x = None def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") Not fundamentally different, except that with Python, you can skip all this in the simple case: class C(object): def __init__(self,val): self.value = val In short, data hiding isn't such a great thing after all. Just use the members directly until such time as you find you need to change that (and be honest, how often have you had thin getter/setter methods and then changed their functionality?). ChrisA From ian.g.kelly at gmail.com Tue May 8 02:15:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 00:15:19 -0600 Subject: sorting 1172026 entries In-Reply-To: <20120507215224.GA10765@cskk.homeip.net> References: <20120507215224.GA10765@cskk.homeip.net> Message-ID: On Mon, May 7, 2012 at 3:52 PM, Cameron Simpson wrote: > | (or add 50% or something) each > | time, meaning that as n increases, the frequency of reallocations > | decreases - hence the O(1) amortized time. > > Hmm, yes. But it is only O(1) for doubling. If one went with a smaller > increment (to waste less space in the end case where one stops growing the > array) then there are more copies and less .append efficiency, trading > potential memory bloat for compute time in .append(). If you went all > the way to adding only one item the cost goes to O(n) for .append() > and O(n^2) overall, with varying costs in between. It's O(1) amortized as long as the increment is exponential. IIRC Python actually grows the list by a factor of 1/8 in the limit, which is still exponential and still O(1) amortized. Cheers, Ian From __peter__ at web.de Tue May 8 03:50:13 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 May 2012 09:50:13 +0200 Subject: indexed property? Can it be done? References: <4FA88FD8.4000905@earthlink.net> Message-ID: Charles Hixson wrote: > class Node: > > def __init__(self, nodeId, key, value, downRight, downLeft, > parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a list > of values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. > Any suggestions? I don't see the problem: >>> class Node(object): ... def __init__(self, key): ... self.node = ["foo", "bar", [key], "baz"] ... @property ... def key(self): ... return self.node[2] ... >>> node = Node(42) >>> node.key [42] >>> node.key[0] 42 >>> node.key.append(7) >>> node.key [42, 7] >>> del node.key[0] >>> node.key[:] = [3, 2, 1] >>> node.key [3, 2, 1] >>> node.key = "foo" Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute But the design proposed by Dan Sommers really is the way to go... From jameskhedley at gmail.com Tue May 8 05:10:13 2012 From: jameskhedley at gmail.com (james hedley) Date: Tue, 8 May 2012 02:10:13 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> Message-ID: <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> Agreed with pretty much all of that. It's third-world politics, lurching from one dictator to another. Risinger seems to have banned all discussion of the subject from the list too, I'm not posting anymore because I don't want to give him an excuse to wield his newly found banhammer. But yeah, a lot of the commentary from the pro-rebel side ( not that any of them admit they had anything to do with it ) really does come across as being ill-informed and childish. This story is on reddit, if anyone is that way inclined: http://www.reddit.com/r/opensource/comments/t5acr/project_hijacked_advice_from_experience_foss/ From davidgshi at yahoo.co.uk Tue May 8 05:38:29 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 8 May 2012 10:38:29 +0100 (BST) Subject: Looking for proven Python code for Line Simplication such as Douglas-Peucker Message-ID: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> Dear All, I am looking for? proven Python code for Line Simplication such as Douglas-Peucker. Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Tue May 8 07:04:13 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 08 May 2012 12:04:13 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1336475053.24832.18.camel@tim-laptop> On Tue, 2012-05-08 at 15:20 +1000, Chris Angelico wrote: > I hope that pyjamas can be restored at some point to a single live > project. Whether that's headed by Luke Leighton or C Anthony Risinger > (neither of whom I know at all and thus I can't speak to either's > merits) or someone else, I don't particularly care I have met Luke (At Europython), and honestly it was his enthusiasm that got me to look at pyjamas in the first place. To be fair I still haven't used it in anger, but I've poked around a lot, it's been under consideration for several bits of work. Although I don't think I've met C Anthony Risinger, his behaviour has seriously put me off the project - and if I consider using it in the future I'm going to be "pricing in" the cost of maintaining a complete local fork as part of the decision. Tim From bob at bobcowdery.plus.com Tue May 8 07:17:33 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Tue, 08 May 2012 12:17:33 +0100 Subject: Problem with time.time() standing still In-Reply-To: <4FA6421F.40002@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> Message-ID: <4FA900CD.7070604@bobcowdery.plus.com> Can anyone make sense of this. I've looked over the Python timemodule.c again and it uses one of gettimeofday(), ftime() or time(). The gettimeofday() is not available on Windows so its going to use ftime() or time(). As time() only has a resolution of 1 second and returns a long and I know Python time.time() has a ms resolution it must be using ftime(). After going round the houses - a lot. I've made a trivially simple extension that goes wrong. I can only think I must be doing something incredibly stupid. Perhaps someone can put me out of my misery. In the full app what happens is that it reports the correct time as given by time() by gets the ms from somewhere also. When it goes wrong it reports the same time as ftime(). Bob >>> import mytime >>> mytime.doTime() TIME : 1336474857 FTIME secs 1336474880.000000 FTIME ms 0.601000 FTIME secs+ms 1336474880.601000 0 >>> mytime.doTime() TIME : 1336474871 FTIME secs 1336474880.000000 FTIME ms 0.548000 FTIME secs+ms 1336474880.548000 0 >>> mytime.doTime() TIME : 1336474897 FTIME secs 1336474880.000000 FTIME ms 0.007000 FTIME secs+ms 1336474880.007000 0 The extension just prints out the time as got from time() and ftime(). For a start the two do not agree on what the time is. Secondly ftime() stops incrementing while the python session is running. If I start a new session it will have incremented. >>> import mytime >>> mytime.doTime() TIME : 1336475029 FTIME secs 1336475008.000000 FTIME ms 0.265000 FTIME secs+ms 1336475008.265000 0 Code and build file ================ #include "Python.h" #include #include #include #include static struct timeb t; static float secs = 0.0; static float ms = 0.0; static float both = 0.0; static PyObject *doTime( PyObject *self, PyObject *args) { time_t seconds; seconds = time (NULL); printf ("TIME : %ld\n", seconds); ftime(&t); secs = (float)t.time; ms = (float)((float)t.millitm * 0.001); printf("FTIME secs+ms %f\n", secs + ms); return PyInt_FromLong((long)0); } static PyMethodDef pyInst_Methods[] = { {"doTime", doTime, METH_VARARGS}, {NULL, NULL, 0, NULL} }; #ifndef PyMODINIT_FUNC #define PyMODINIT_FUNC void #endif /* PyMODINIT_FUNC */ PyMODINIT_FUNC initmytime(void) { PyObject *module; module = Py_InitModule3("mytime", pyInst_Methods,"Time module"); if (!module) return; } Build file ======== import os from distutils.core import setup from distutils.extension import Extension if os.path.exists('C:\\Program Files (x86)'): # 64 bit ProgramFiles = 'Program Files (x86)' else: # 32 bit ProgramFiles = 'Program Files' setup( name='Time Test', author='Bob Cowdery', ext_modules = [ Extension('mytime', ['pytime.cpp'], include_dirs = ['C:\\' + ProgramFiles + '\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'], #define_macros = [("_AFXDLL", None)], library_dirs = ['C:\\' + ProgramFiles + '\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'], libraries = ['User32', 'Gdi32', 'python26', 'odbc32', 'odbccp32'] ) ] ) On 06/05/2012 10:19, Bob Cowdery wrote: > On 06/05/2012 09:49, Cameron Simpson wrote: >> On 06May2012 09:18, Bob Cowdery wrote: >> | On 05/05/2012 23:05, Cameron Simpson wrote: >> |> On 05May2012 20:33, Bob Cowdery wrote: >> |> | [...] calls to time.time() always return the same >> |> | time which is usually several seconds in the past or future and always >> |> | has no fractional part. >> |> >> |> Thought #1: you are calling time.time() and haven't unfortunately >> |> renamed it? (I doubt this scenario, though the lack of fractional part >> |> is interesting.) >> | >> | Not sure what you mean by renamed it. >> >> Like this: >> >> from time import time >> [...] >> time = some_unfortunate_other_function >> [...] >> now = time() # calls wrong function >> >> It seems unlikely, but possible. >> >> | I also tried datetime and that had >> | the same behaviour. >> >> Makes my suggestion even less likely unless the time module itself gets >> monkeypatched (i.e. "time.time = bad_function" somewhere). > I don't think the function is subverted unless there is some way inside > the vendor SDK or even DirectShow (the SDK uses this as a COM object) > which can somehow hijack it. It does catch up every few minutes so there > has to be a clue there. >> |> | If I leave it long enough time will suddently >> |> | jump forward after a few minutes, then again after a few minutes more. >> |> | >> |> | I've never encountered this behaviour before and can't understand what >> |> | on earth is going on. If I call the 'C' time() function just the other >> |> | side of my call to the extension the time is ticking along fine. It's >> |> | just the one Python thread that is affected. >> |> [...] >> |> >> |> Thought #2: On a UNIX system I'd be running the process under strace (or >> |> dtrace or ktrace depending on flavour) to see what actual OS system calls are >> |> being made during this behaviour. Is this feasible for you? >> | >> | I'm on Windows for this particular part of the application. >> >> I'd guessed so. I've no Windows programming background; I was wondering >> if there was something like this you had to hand on windows. > Maybe, but not that I know of. >> | [...] But debugging into this is probably the only way. I >> | looked at the built-in time module. As far as I can tell it just calls >> | the underlying C time() function as an extension. This is more >> | mystifying as that is pretty much what I'm doing by checking the time in >> | my own extension module where it ticks along fine. >> >> Hmm. A C extension I presume? How about writing a little pure Python >> thread to call time.time(), and spin it off parallel to the rest of the >> app; does it also get bad time.time() behaviour? > I've tried that. It's only the Python thread (or Python main thread) > that calls the extension that behaves like this. Other Python threads > tick along fine with the correct time including a fractional part. >> | I have another >> | scenario using a different part of their SDK where the time does still >> | tick but the fractional part is frozen, not 0 but frozen. >> >> Curiouser and curiouser. > Indeed. Away now but battle will resume on Tuesday. > > Bob > > > From roy at panix.com Tue May 8 09:02:12 2012 From: roy at panix.com (Roy Smith) Date: Tue, 08 May 2012 09:02:12 -0400 Subject: Expand RFC-2445 (iCalendar) recurrence rule? Message-ID: Does there exist a stand-alone module to expand RFC-2445 recurrence rule? The idea is to start with a string like: "RRULE:FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR" and derive a list of dates on which that event occurs. I'm aware of http://codespeak.net/icalendar/, but that solves a much larger problem (parsing ics files) and I can't see how to tease out just this one function from that module. From robert.kern at gmail.com Tue May 8 09:08:35 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 08 May 2012 14:08:35 +0100 Subject: Looking for proven Python code for Line Simplication such as Douglas-Peucker In-Reply-To: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> References: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> Message-ID: On 5/8/12 10:38 AM, David Shi wrote: > Dear All, > > I am looking for proven Python code for Line Simplication such as Douglas-Peucker. https://svn.enthought.com/svn/enthought/EnthoughtBase/trunk/enthought/util/dp.py -- 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 jameskhedley at gmail.com Tue May 8 09:12:18 2012 From: jameskhedley at gmail.com (james hedley) Date: Tue, 8 May 2012 06:12:18 -0700 (PDT) Subject: How do I run a python program from an internet address? In-Reply-To: References: Message-ID: <9136960.456.1336482739269.JavaMail.geo-discussion-forums@vbvx4> > What would be the best way to figure out how to do this? I looked at > Google app engine tutorial, but can't figure out how that will help we > get the code into the cloud so I can access it from any browser. GAE is quite a good option, since it includes free hosting. You should be able to get started just by downloading the SDK and making your app work locally. It includes a little development server so you can see what your users will see in your own browser. In this way, you don't have to do anything with the web until everything is ready, then you just press a button (windows) or run a script (nix) and yor app appears on the web. The datastore is quite complicated though! If you rig up your own host though, you have a lot more freedom with what software you get to use. A very simple way is to plug mod_wsgi into apache (a common web server) and then write your app as a wsgi script; this usually just entails adding a couple of necessary methods to your script. In my case, I have a buddy with a web host set up so I can get things up on there very easily and for free. From jeanpierreda at gmail.com Tue May 8 09:43:19 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 8 May 2012 09:43:19 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 1:20 AM, Chris Angelico wrote: > I hope that pyjamas can be restored at some point to a single live > project. Whether that's headed by Luke Leighton or C Anthony Risinger > (neither of whom I know at all and thus I can't speak to either's > merits) or someone else, I don't particularly care, but frankly, I > don't think there's need in the world for a fork of such a project. > Aside from philosophical disagreements, what would be the differences > between the Luke fork and the Anthony fork? Could anyone explain, to a > prospective user, why s/he should pick one or the other? If not, the > projects need to merge, or else one will die a sad death of > stagnation. There is no "both projects". there was Luke's project, and then Risinger stole it and it's Risinger's project. There is only that one thing -- Luke has no """fork""" of his own codebase. I guess it won't die of stagnation, eh? It'll be a perfectly usable, stable project, led by a thief. -- Devin From rosuav at gmail.com Tue May 8 09:47:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 23:47:56 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre wrote: > There is no "both projects". there was Luke's project, and then > Risinger stole it and it's Risinger's project. There is only that one > thing -- Luke has no """fork""" of his own codebase. Presumably Luke could fork his own project, though. I haven't checked, but presumably the source is properly managed, so it can be forked as of any point in time. But it's pretty nasty to have to fork your own project. ChrisA From roy at panix.com Tue May 8 10:12:04 2012 From: roy at panix.com (Roy Smith) Date: Tue, 8 May 2012 07:12:04 -0700 (PDT) Subject: Expand RFC-2445 (iCalendar) recurrence rule? In-Reply-To: References: Message-ID: <23988809.256.1336486324508.JavaMail.geo-discussion-forums@ynei13> O.B. Murithi suggested I look at http://labix.org/python-dateutil, which turns out to have exactly what I'm looking for. Thanks! from dateutil.rrule import rrulestr from dateutil.parser import parse rule = rrulestr("FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR", dtstart=parse("2012-06-15")) for date in rule: print date ./rrule.py 2012-06-15 00:00:00 2012-06-29 00:00:00 2012-07-13 00:00:00 2012-07-27 00:00:00 2012-08-10 00:00:00 2012-08-24 00:00:00 From bob at bobcowdery.plus.com Tue May 8 11:42:29 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Tue, 08 May 2012 16:42:29 +0100 Subject: Problem with time.time() standing still In-Reply-To: <4FA900CD.7070604@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> <4FA900CD.7070604@bobcowdery.plus.com> Message-ID: <4FA93EE5.4040200@bobcowdery.plus.com> Hopefully somebody can add the last piece of this puzzle. My code didn't work because I did make a silly mistake. The number of seconds since EPOC is a large number but it also needs a high precision. Attempting to put this value into a 32 bit float corrupts the least significant part because 24 bits cannot hold that precision. Now Python floats are C doubles and the calculation in timemodule.c is in doubles right back to Python. Normally this retains the precision. For some inexplicable reason when I make certain calls into this vendors SDK, ftime() is getting precision problems and appears to be frozen as a result. C, only supporting early binding cannot change the function referenced at runtime so how the devil is it managing to do this. On 08/05/2012 12:17, Bob Cowdery wrote: > Can anyone make sense of this. > > I've looked over the Python timemodule.c again and it uses one of > gettimeofday(), ftime() or time(). The gettimeofday() is not available > on Windows so its going to use ftime() or time(). As time() only has a > resolution of 1 second and returns a long and I know Python > time.time() has a ms resolution it must be using ftime(). > > After going round the houses - a lot. I've made a trivially simple > extension that goes wrong. I can only think I must be doing something > incredibly stupid. Perhaps someone can put me out of my misery. > > In the full app what happens is that it reports the correct time as > given by time() by gets the ms from somewhere also. When it goes wrong > it reports the same time as ftime(). > > Bob > > >>> import mytime > >>> mytime.doTime() > TIME : 1336474857 > FTIME secs 1336474880.000000 > FTIME ms 0.601000 > FTIME secs+ms 1336474880.601000 > 0 > >>> mytime.doTime() > TIME : 1336474871 > FTIME secs 1336474880.000000 > FTIME ms 0.548000 > FTIME secs+ms 1336474880.548000 > 0 > >>> mytime.doTime() > TIME : 1336474897 > FTIME secs 1336474880.000000 > FTIME ms 0.007000 > FTIME secs+ms 1336474880.007000 > 0 > > The extension just prints out the time as got from time() and ftime(). > For a start the two do not agree on what the time is. Secondly ftime() > stops incrementing while the python session is running. If I start a > new session it will have incremented. > > >>> import mytime > >>> mytime.doTime() > TIME : 1336475029 > FTIME secs 1336475008.000000 > FTIME ms 0.265000 > FTIME secs+ms 1336475008.265000 > 0 > > Code and build file > ================ > > #include "Python.h" > #include > #include > #include > #include > > static struct timeb t; > static float secs = 0.0; > static float ms = 0.0; > static float both = 0.0; > > static PyObject *doTime( > PyObject *self, > PyObject *args) { > time_t seconds; > seconds = time (NULL); > printf ("TIME : %ld\n", seconds); > ftime(&t); > secs = (float)t.time; > ms = (float)((float)t.millitm * 0.001); > printf("FTIME secs+ms %f\n", secs + ms); > > return PyInt_FromLong((long)0); > } > > static PyMethodDef pyInst_Methods[] = { > > {"doTime", > doTime, > METH_VARARGS}, > {NULL, NULL, 0, NULL} > }; > > #ifndef PyMODINIT_FUNC > #define PyMODINIT_FUNC void > #endif /* PyMODINIT_FUNC */ > > PyMODINIT_FUNC initmytime(void) > { > PyObject *module; > module = Py_InitModule3("mytime", pyInst_Methods,"Time module"); > if (!module) return; > } > > Build file > ======== > import os > from distutils.core import setup > from distutils.extension import Extension > > if os.path.exists('C:\\Program Files (x86)'): > # 64 bit > ProgramFiles = 'Program Files (x86)' > else: > # 32 bit > ProgramFiles = 'Program Files' > > setup( > name='Time Test', > author='Bob Cowdery', > ext_modules = [ > Extension('mytime', > ['pytime.cpp'], > include_dirs = ['C:\\' + ProgramFiles + > '\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'], > #define_macros = [("_AFXDLL", None)], > library_dirs = ['C:\\' + ProgramFiles + > '\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'], > libraries = ['User32', 'Gdi32', 'python26', > 'odbc32', 'odbccp32'] > ) > ] > ) > > On 06/05/2012 10:19, Bob Cowdery wrote: >> On 06/05/2012 09:49, Cameron Simpson wrote: >>> On 06May2012 09:18, Bob Cowdery wrote: >>> | On 05/05/2012 23:05, Cameron Simpson wrote: >>> |> On 05May2012 20:33, Bob Cowdery wrote: >>> |> | [...] calls to time.time() always return the same >>> |> | time which is usually several seconds in the past or future >>> and always >>> |> | has no fractional part. >>> |> >>> |> Thought #1: you are calling time.time() and haven't unfortunately >>> |> renamed it? (I doubt this scenario, though the lack of >>> fractional part >>> |> is interesting.) >>> | >>> | Not sure what you mean by renamed it. >>> >>> Like this: >>> >>> from time import time >>> [...] >>> time = some_unfortunate_other_function >>> [...] >>> now = time() # calls wrong function >>> >>> It seems unlikely, but possible. >>> >>> | I also tried datetime and that had >>> | the same behaviour. >>> >>> Makes my suggestion even less likely unless the time module itself gets >>> monkeypatched (i.e. "time.time = bad_function" somewhere). >> I don't think the function is subverted unless there is some way inside >> the vendor SDK or even DirectShow (the SDK uses this as a COM object) >> which can somehow hijack it. It does catch up every few minutes so there >> has to be a clue there. >>> |> | If I leave it long enough time will suddently >>> |> | jump forward after a few minutes, then again after a few >>> minutes more. >>> |> | >>> |> | I've never encountered this behaviour before and can't >>> understand what >>> |> | on earth is going on. If I call the 'C' time() function just >>> the other >>> |> | side of my call to the extension the time is ticking along >>> fine. It's >>> |> | just the one Python thread that is affected. >>> |> [...] >>> |> >>> |> Thought #2: On a UNIX system I'd be running the process under >>> strace (or >>> |> dtrace or ktrace depending on flavour) to see what actual OS >>> system calls are >>> |> being made during this behaviour. Is this feasible for you? >>> | >>> | I'm on Windows for this particular part of the application. >>> >>> I'd guessed so. I've no Windows programming background; I was wondering >>> if there was something like this you had to hand on windows. >> Maybe, but not that I know of. >>> | [...] But debugging into this is probably the only way. I >>> | looked at the built-in time module. As far as I can tell it just >>> calls >>> | the underlying C time() function as an extension. This is more >>> | mystifying as that is pretty much what I'm doing by checking the >>> time in >>> | my own extension module where it ticks along fine. >>> >>> Hmm. A C extension I presume? How about writing a little pure Python >>> thread to call time.time(), and spin it off parallel to the rest of the >>> app; does it also get bad time.time() behaviour? >> I've tried that. It's only the Python thread (or Python main thread) >> that calls the extension that behaves like this. Other Python threads >> tick along fine with the correct time including a fractional part. >>> | I have another >>> | scenario using a different part of their SDK where the time does >>> still >>> | tick but the fractional part is frozen, not 0 but frozen. >>> >>> Curiouser and curiouser. >> Indeed. Away now but battle will resume on Tuesday. >> >> Bob >> >> >> > From tjreedy at udel.edu Tue May 8 12:12:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 12:12:04 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 9:47 AM, Chris Angelico wrote: > On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre > wrote: >> There is no "both projects". there was Luke's project, and then >> Risinger stole it and it's Risinger's project. There is only that one >> thing -- Luke has no """fork""" of his own codebase. > > Presumably Luke could fork his own project, though. I haven't checked, > but presumably the source is properly managed, so it can be forked as > of any point in time. > > But it's pretty nasty to have to fork your own project. You still have it backwards. Risinger forked the project with a new code host and mailing list, but stole the name and and some data in the process and made the false claim that his fork was the original. It is not clear if he damaged anything in the process. If Luke continues his original project, it would still be the true pyjamas project, not a fork. -- Terry Jan Reedy From charleshixsn at earthlink.net Tue May 8 12:30:11 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 08 May 2012 09:30:11 -0700 Subject: indexed property? Can it be done? In-Reply-To: References: <4FA88FD8.4000905@earthlink.net> Message-ID: <4FA94A13.5080703@earthlink.net> On 05/08/2012 12:50 AM, Peter Otten wrote: > Charles Hixson wrote: > > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, >> parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> >> Note that node[3] is a list of keys (initially 1) and node[3] is a list >> of values, etc. >> >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it out. >> Any suggestions? >> > I don't see the problem: > > >>>> class Node(object): >>>> > ... def __init__(self, key): > ... self.node = ["foo", "bar", [key], "baz"] > ... @property > ... def key(self): > ... return self.node[2] > ... > >>>> node = Node(42) >>>> node.key >>>> > [42] > >>>> node.key[0] >>>> > 42 > >>>> node.key.append(7) >>>> node.key >>>> > [42, 7] > >>>> del node.key[0] >>>> node.key[:] = [3, 2, 1] >>>> node.key >>>> > [3, 2, 1] > >>>> node.key = "foo" >>>> > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute > > But the design proposed by Dan Sommers really is the way to go... > > That depends on what you're doing. For many, perhaps most, purposes I would agree. Not for this one. And I couldn't use an internal dict, as the order in which the items of the sub-lists occur is significant. The sub-lists need to be lists, though they could be separated out as named variables (which would be lists). The approach of returning the entire list would, indeed, work, but it exposes things that I would prefer to keep internal to the class (i.e., all the, e.g., keys that aren't currently being addressed). I suppose it isn't too inefficient, as IIUC, all you're really passing back and forth are pointers, but it doesn't *feel* like the right answer. So I can handle it by using getter and setter functions that recognize indicies, but it's less elegant than using indexing to access them. So I thought I'd ask. The ActiveState recipe *might* do what I want. I honestly can't tell after a brief study. But it's much too complex to be a worthwhile choice. I was hoping that I'd just overlooked one of the standard features of Python. To be truthful, the main benefit I see from using a class rather than a naked list structure is that I can readily test the type of the data. A secondary benefit would be the nicer syntax, as with the list all manipulation would be done via specialized functions, and for some of the terms indexed access would be syntactically nicer. But it looks like that isn't one of the possibilities. Using a native list structure and manipulatory functions is nicer except in two ways: 1) There's no data hiding, so discipline must substitute for language structure. 2) There's excess names apparent at an upper level. I wouldn't exactly call it namespace pollution, but it's certainly an increase in the higher-level namespace background noise level, even though it's all functional. -- Charles Hixson From rosuav at gmail.com Tue May 8 12:42:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 May 2012 02:42:10 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: > On 5/8/2012 9:47 AM, Chris Angelico wrote: >> >> On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre >> ?wrote: >>> >>> There is no "both projects". there was Luke's project, and then >>> Risinger stole it and it's Risinger's project. There is only that one >>> thing -- Luke has no """fork""" of his own codebase. >> >> >> Presumably Luke could fork his own project, though. I haven't checked, >> but presumably the source is properly managed, so it can be forked as >> of any point in time. >> >> But it's pretty nasty to have to fork your own project. > > > You still have it backwards. Risinger forked the project with a new code > host and mailing list, but stole the name and and some data in the process > and made the false claim that his fork was the original. It is not clear if > he damaged anything in the process. Yes, but now that it's happened, the most obvious way forward is to fork the hijacked project back to the original, given that the hijacked one is being posted as the original. > If Luke continues his original project, it would still be the true pyjamas > project, not a fork. Yeah, but if he doesn't have command of the domain any more, then he'll likely be spawning it under a new name somewhere. ChrisA From ian.g.kelly at gmail.com Tue May 8 12:49:33 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 10:49:33 -0600 Subject: indexed property? Can it be done? In-Reply-To: <4FA94A13.5080703@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> <4FA94A13.5080703@earthlink.net> Message-ID: On Tue, May 8, 2012 at 10:30 AM, Charles Hixson wrote: > That depends on what you're doing. ?For many, perhaps most, purposes I would > agree. ?Not for this one. ?And I couldn't use an internal dict, as the order > in which the items of the sub-lists occur is significant. ?The sub-lists > need to be lists, though they could be separated out as named variables > (which would be lists). It sounds like a collections.OrderedDict should do what you need. In the cases where you really need to have a list of keys or values, you can just use the .keys() and .values() methods. > The ActiveState recipe *might* do what I want. ?I honestly can't tell after > a brief study. ?But it's much too complex to be a worthwhile choice. ?I was > hoping that I'd just overlooked one of the standard features of Python. What do you find complex about it? The two class definitions are something you would put in a library module to be imported. The rest is just example / test code. The actual usage is no more complex than a regular property: class Node(object): def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, [key], [value], [downRight], parent, dirty, dlu] @itemproperty def key(self, index): return self.node[2][index] @itemproperty def value(self, index): return self.node[3][index] And of course you could also add setters and/or deleters if desired. From d.poreh at gmail.com Tue May 8 14:16:01 2012 From: d.poreh at gmail.com (d.poreh at gmail.com) Date: Tue, 8 May 2012 11:16:01 -0700 (PDT) Subject: which book? Message-ID: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> folks hi, I am going to learn python for some plot issues. which book or sources, do you recommend please? Cheers, Dave From alec.taylor6 at gmail.com Tue May 8 14:31:34 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 9 May 2012 04:31:34 +1000 Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: plot issues? On Wed, May 9, 2012 at 4:16 AM, wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave > -- > http://mail.python.org/mailman/listinfo/python-list From mephisto_9000 at hotmail.com Tue May 8 15:07:49 2012 From: mephisto_9000 at hotmail.com (F L) Date: Tue, 8 May 2012 15:07:49 -0400 Subject: Retrieving result from embedded execution Message-ID: Hello everyone, We are trying to implement our own interactive interpreter in our applicationusing an embedded Python interpreter. I was wondering what would be the best way to retreive as text the result of executing Python code. The text must be exactly the same as it would be in thestandalone interpreter. We used to do this by changing the embedded interpreter's sys.stdout and sys.stderrwith a FILE created in C++. We could then execute code using the PyRun_InteractiveOnefunction and easily retrieve the result from the FILE. The problem is, our applicationshouldn't create any files if possible. We also tried replacing sys.stdout and sys.stderr with a custom made Python objectwhich could be more easily read from C++. We then used the function PyRun_Stringto execute the code. The problem here is that using the Py_file_input start tokendoesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not write 4).It also doesn't print a traceback to sys.stderr when there is an exception. Using theother two start tokens is impossible since we need to be able to execute more than one instruction at once. We also tried using the function PyRun_SimpleString but weencounter the same problems. We are using python 2.7. Any suggestions? Thank you for your time. Also, I'm new to mailling lists, what is the proper way to reply to someone? Should Ireply directly to someone's email adress or is there a way to answer trough the server. F. Lab -------------- next part -------------- An HTML attachment was scrubbed... URL: From edcjones at comcast.net Tue May 8 15:13:03 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 08 May 2012 15:13:03 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 Message-ID: <4FA9703F.50207@comcast.net> I use up-to-date Debian testing (wheezy), amd64 architecture. I downloaded, compiled and installed Python 3.3.0 alpha 3 (from python.org) using "altinstall". Debian wheezy comes with python3.2 (and 2.6 and 2.7). I installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3). Note: Debian uses eggs. Python3.3a3 cannot find module bs4. Python3.2 can find the module. Here is a session with Python 3.3: > python3.3 Python 3.3.0a3 (default, May 5 2012, 11:30:48) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import bs4 Traceback (most recent call last): File "", line 1, in File "", line 1012, in _find_and_load ImportError: No module named 'bs4' >>> Here is what I have tried: 1. Put bs4.pth in /usr/local/lib/python3.3/site-packages. This file should contain the line: /usr/lib/python3/dist-packages This works. 2. At the start of each Python program using bs4: import sys sys.path.append('/usr/lib/python3/dist-packages') import bs4 This works. 3. In the Python 3.3 source code, do ".configure" then edit Modules/Setup to contain SITEPATH=:/usr/lib/python3/dist-packages Finish compiling and altinstalling python. "import bs4" works. The last is the best because I only have to do it once. Next I tried numpy. It is installed from Debian package "python3-numpy". If I compile Python 3.3 _without_ the change in (3) above, I get: > python3.3 Python 3.3.0a3 (default, May 8 2012, 14:30:18) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1012, in _find_and_load ImportError: No module named 'numpy' >>> which is not a surprise. If I compile and install Python 3.3 _with_ the change in (3) above, I get: > python3.3 Python 3.3.0a3 (default, May 8 2012, 14:43:28) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1015, in _find_and_load File "", line 634, in load_module File "", line 294, in module_for_loader_wrapper File "", line 522, in _load_module File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in from . import add_newdocs ImportError: cannot import name add_newdocs >>> "add_newdocs.py" is present in the numpy directory. The "import numpy" works for the Debian python 3.2. What is the problem? From rowen at uw.edu Tue May 8 15:19:35 2012 From: rowen at uw.edu (Russell E. Owen) Date: Tue, 08 May 2012 12:19:35 -0700 Subject: pickle question: sequencing of operations References: Message-ID: In article , "Russell E. Owen" wrote: > What is the sequence of calls when unpickling a class with __setstate__? > > >From experimentation I see that __setstate__ is called and __init__ is > not, but I think I need more info. > > I'm trying to pickle an instance of a class that is a subclass of > another class that contains unpickleable objects. > > What I'd like to do is basically just pickle the constructor parameters > and then use those to reconstruct the object on unpickle, but I'm not > sure how to go about this. Or an example if anyone has one. The following seems to work, but I don't know why: def __getstate__(self): ...return the argument dict needed for __init__ def __setstate__(self, argdict): self.__init__(**argdict) -- Russell From wrw at mac.com Tue May 8 15:44:01 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Tue, 08 May 2012 15:44:01 -0400 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: <1051143A-3EDC-4612-8FA2-E91636122EC6@mac.com> On May 8, 2012, at 3:07 PM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in the > standalone interpreter. > > We used to do this by changing the embedded interpreter's sys.stdout and sys.stderr > with a FILE created in C++. We could then execute code using the PyRun_InteractiveOne > function and easily retrieve the result from the FILE. The problem is, our application > shouldn't create any files if possible. > > We also tried replacing sys.stdout and sys.stderr with a custom made Python object > which could be more easily read from C++. We then used the function PyRun_String > to execute the code. The problem here is that using the Py_file_input start token > doesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not write 4). > It also doesn't print a traceback to sys.stderr when there is an exception. Using the > other two start tokens is impossible since we need to be able to execute more than > one instruction at once. We also tried using the function PyRun_SimpleString but we > encounter the same problems. > > We are using python 2.7. > > Any suggestions? > > Thank you for your time. [byte] I'm pretty new to Python myself, and I may not understand what you are trying to do, but have you looked at the subprocess module? Documented here: http://docs.python.org/library/subprocess.html Using subprocess.Popen would let you hook stdin and staout directly to pipes that will pass data back to the calling program with no intermediate steps. -Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 8 15:55:05 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 13:55:05 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > In article , > ?"Russell E. Owen" wrote: > >> What is the sequence of calls when unpickling a class with __setstate__? I believe it just calls object.__new__ followed by yourclass.__setstate__. So at the point __setstate__ is called, you have a pristine instance of whatever class you're unpickling. > The following seems to work, but I don't know why: > def __getstate__(self): > ? ...return the argument dict needed for __init__ > > def __setstate__(self, argdict): > ? self.__init__(**argdict) That seems like it should be fine as long as all your initialization code is in __init__ and not in __new__. Cheers, Ian From gordon at panix.com Tue May 8 16:05:20 2012 From: gordon at panix.com (John Gordon) Date: Tue, 8 May 2012 20:05:20 +0000 (UTC) Subject: How to get outer class name from an inner class? Message-ID: I'm trying to come up with a scheme for organizing exceptions in my application. Currently, I'm using a base class which knows how to look up the text of a specific error in a database table, keyed on the error class name. The base class looks like this: class ApplicationException(Exception): """Base class for application-specific errors.""" def get_message(self): """Return the error message associated with this class name.""" class_name = self.__class__.__name__ return UserMessage.objects.get(key=class_name).text And then I define a bunch of subclasses which all have different names: class QuestionTooShortError(NetIDAppsError): """User entered a security question which is too short.""" pass class QuestionTooLongError(NetIDAppsError): """User entered a security question which is too long.""" pass This scheme works, but I'd like to make it more streamlined. Specifically, I'd like to group the classes underneath a parent class, like so: class Question(ApplicationException): class TooShort(ApplicationException): pass class TooLong(ApplicationException): pass This will make it easier in the future for organizing lots of sub-errors. My problem is this: the get_message() method in the base class only knows the current class name, i.e. "TooShort" or "TooLong". But that's not enough; I also need to know the outer class name, i.e. "Question.TooShort" or "Question.TooLong". How do I get the outer class name? Thanks, -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gordon at panix.com Tue May 8 16:08:24 2012 From: gordon at panix.com (John Gordon) Date: Tue, 8 May 2012 20:08:24 +0000 (UTC) Subject: How to get outer class name from an inner class? References: Message-ID: In John Gordon writes: > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass Oops! These classes inherit from ApplicationException, not NetIDAppsError. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From awilliam at whitemice.org Tue May 8 16:19:41 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 08 May 2012 16:19:41 -0400 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: <1336508381.9435.15.camel@linux-nysu.site> On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote: > class Node: > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > Note that node[3] is a list of keys (initially 1) and node[3] is a list > of values, etc. > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. > Any suggestions? Do not do this; this is bad code in any language. -------------- 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 clp2 at rebertia.com Tue May 8 16:21:13 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 8 May 2012 13:21:13 -0700 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 1:05 PM, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ?"""Base class for application-specific errors.""" > > ? ?def get_message(self): > ? ? ? ?"""Return the error message associated with this class name.""" > > ? ? ? ?class_name = self.__class__.__name__ > ? ? ? ?return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ?"""User entered a security question which is too short.""" > ? ?pass > > class QuestionTooLongError(NetIDAppsError): > ? ?"""User entered a security question which is too long.""" > ? ?pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ?class TooShort(ApplicationException): > ? ? ? ?pass > > ? ?class TooLong(ApplicationException): > ? ? ? ?pass > > This will make it easier in the future for organizing lots of sub-errors. You could use modules instead? Nested classes are stylistically questionable. > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? Use __qualname__ and chop off the last dotted part (i.e. the innermost class' name, thus yielding its parent's name). PEP 3155 -- Qualified name for classes and functions: http://www.python.org/dev/peps/pep-3155/ Cheers, Chris From tjreedy at udel.edu Tue May 8 17:47:36 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 17:47:36 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 12:42 PM, Chris Angelico wrote: > On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: >> You still have it backwards. Risinger forked the project with a new code >> host and mailing list, but stole the name and and some data in the process >> and made the false claim that his fork was the original. It is not clear if >> he damaged anything in the process. > > Yes, but now that it's happened, the most obvious way forward is to > fork the hijacked project back to the original, given that the > hijacked one is being posted as the original. Risinger's fork is NOT the original, no matter what his claim. People should not give credit to his false claim or regard it as an accomplished fact. From what others have posted, it has a new code repository (that being the ostensible reason for the fork), project site, and mailing list -- the latter two incompetently. Apparently, the only thing he has kept are the domain and project names (the latter for sure not legitimately). Luke has not abandoned pyjamas and has not, as of now, ceded ownership of the name to anyone. I am pretty sure Luke he has no plans to adandon his current codebase and and re-fork off of the Risinger et al revised codebase. >> If Luke continues his original project, it would still be the true pyjamas >> project, not a fork. > > Yeah, but if he doesn't have command of the domain any more, then > he'll likely be spawning it under a new name somewhere. Yes, but so what? The domain name is not the project. Open source projects change domain names all the time (though hopefully rarely for any particular project). -- Terry Jan Reedy From tjreedy at udel.edu Tue May 8 18:11:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 18:11:51 -0400 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: On 5/8/2012 4:05 PM, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > """Base class for application-specific errors.""" > > def get_message(self): > """Return the error message associated with this class name.""" > > class_name = self.__class__.__name__ > return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. I think maybe you are being much too fine-grained in your exception hierarchy. Python has, for instance, just one ValueError, with details in the error. The details can include specific values only known at the point of the error. You are putting some specifics in the exception name and then (apparently) given them somewhat redundant canned messages lacking situation-specific details. For instance errfmt = "Security question length {:d} not in legal range {:d} - {:d}" if not (secquemin <= len(secque) <= secquemax): raise ValueError(errfmt.format(len(secque), secquemin, secquemax)) # or ApplicationError or AppValueError if you want. The messages in Python are not this good, but they slowly improve as people raises an issue on the tracker and others implement and apply fixex. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 8 18:46:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 18:46:43 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 In-Reply-To: <4FA9703F.50207@comcast.net> References: <4FA9703F.50207@comcast.net> Message-ID: On 5/8/2012 3:13 PM, Edward C. Jones wrote: > I use up-to-date Debian testing (wheezy), amd64 architecture. I downloaded, > compiled and installed Python 3.3.0 alpha 3 (from python.org) using > "altinstall". Debian wheezy comes with python3.2 (and 2.6 and 2.7). I > installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3). Your problem with bs4 seems to be that it got installed in a way that 3.2 could find it and 3.3 could not. > 1. Put bs4.pth in /usr/local/lib/python3.3/site-packages. This file should > contain the line: > /usr/lib/python3/dist-packages > This works. As it should, being the standard alternative to putting the module in site-packages. > 2. At the start of each Python program using bs4: > import sys > sys.path.append('/usr/lib/python3/dist-packages') > import bs4 > This works. Another standard methods. > 3. In the Python 3.3 source code, do ".configure" then edit > Modules/Setup to > contain > SITEPATH=:/usr/lib/python3/dist-packages > Finish compiling and altinstalling python. "import bs4" works. An option only for those who compile. The two above work on windows for those who do not. > The last is the best because I only have to do it once. The .pth entry is also once only. > Next I tried numpy. It is installed from Debian package "python3-numpy". I bet the Debian packager has not tested the python packages with 3.3ax yet. On Windows, compiled packages don't work with new Python versions. On *nix, things are better but not necessarily perfect. > If I compile and install Python 3.3 _with_ the > change in (3) above, I get: > > > python3.3 > Python 3.3.0a3 (default, May 8 2012, 14:43:28) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > Traceback (most recent call last): > File "", line 1, in > File "", line 1015, in _find_and_load > File "", line 634, in load_module > File "", line 294, in > module_for_loader_wrapper > File "", line 522, in _load_module > File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in > > from . import add_newdocs > ImportError: cannot import name add_newdocs In this case, the problem in Python rather than C code. > "add_newdocs.py" is present in the numpy directory. > The "import numpy" works for the Debian python 3.2. > What is the problem? Question 1: if you use the .pth method, do you get the same result? (I expect you will, but good to check.) Question 2: has anyone successfully run numpy with 3.3 on Debian or anything else? If no one here answers, try Debian or numpy lists. Comment: the import machinery is heavily revised for 3.3. I believe is new. I believe relative imports may have been changed to fix bugs. One could have been introduced (though there are no reports on the tracker). If so, we need to fix it. Or perhaps there is something special about __init__ I am not aware of. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue May 8 18:55:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 08 May 2012 23:55:38 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/05/2012 22:47, Terry Reedy wrote: > On 5/8/2012 12:42 PM, Chris Angelico wrote: >> On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: > >>> You still have it backwards. Risinger forked the project with a new code >>> host and mailing list, but stole the name and and some data in the >>> process >>> and made the false claim that his fork was the original. It is not >>> clear if >>> he damaged anything in the process. >> >> Yes, but now that it's happened, the most obvious way forward is to >> fork the hijacked project back to the original, given that the >> hijacked one is being posted as the original. > > Risinger's fork is NOT the original, no matter what his claim. People > should not give credit to his false claim or regard it as an > accomplished fact. > > From what others have posted, it has a new code repository (that being > the ostensible reason for the fork), project site, and mailing list -- > the latter two incompetently. Apparently, the only thing he has kept are > the domain and project names (the latter for sure not legitimately). > > Luke has not abandoned pyjamas and has not, as of now, ceded ownership > of the name to anyone. I am pretty sure Luke he has no plans to adandon > his current codebase and and re-fork off of the Risinger et al revised > codebase. > >>> If Luke continues his original project, it would still be the true >>> pyjamas >>> project, not a fork. >> >> Yeah, but if he doesn't have command of the domain any more, then >> he'll likely be spawning it under a new name somewhere. > > Yes, but so what? The domain name is not the project. Open source > projects change domain names all the time (though hopefully rarely for > any particular project). > {Not replying To Terry Reedy or anybody else specifically, but didn't know where to jump in] Who cares, in the sense that zero people (apart from five(ish) morons) will follow the hijacked project, while the vast majority will support Luke as a matter of principal. I suggest the thieves be subjected to this http://en.wikipedia.org/wiki/Send_to_Coventry -- Cheers. Mark Lawrence. From charleshixsn at earthlink.net Tue May 8 18:59:23 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 08 May 2012 15:59:23 -0700 Subject: indexed property? Can it be done? In-Reply-To: <1336508381.9435.15.camel@linux-nysu.site> References: <4FA88FD8.4000905@earthlink.net> <1336508381.9435.15.camel@linux-nysu.site> Message-ID: <4FA9A54B.6090707@earthlink.net> On 05/08/2012 01:19 PM, Adam Tauno Williams wrote: > On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote: > >> class Node: >> def __init__(self, nodeId, key, value, downRight, downLeft, parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> Note that node[3] is a list of keys (initially 1) and node[3] is a list >> of values, etc. >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it out. >> Any suggestions? >> > Do not do this; this is bad code in any language. > I'm sorry, but why do you say that? In D or Eiffel it is a standard approach, with compiler support. I will admit that one shouldn't do it in C++, or, it appears, in Python. This is far from justifying saying one should never do it. -- Charles Hixson From breamoreboy at yahoo.co.uk Tue May 8 18:59:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 08 May 2012 23:59:40 +0100 Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: On 08/05/2012 19:16, d.poreh at gmail.com wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave matplotlib - google and yee shall find. -- Cheers. Mark Lawrence. From k.sharagovind at gmail.com Tue May 8 19:04:05 2012 From: k.sharagovind at gmail.com (sharadha devi) Date: Tue, 8 May 2012 16:04:05 -0700 (PDT) Subject: $1000.00 Daily - See PROOF ! Message-ID: <69009982-6127-45f6-ab32-657dddbd311a@k7g2000pbo.googlegroups.com> REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX +++ Jesus Loves You +++ http://jesuslovesyou-youlovejesus.blogspot.in/ CHECK ALL THESE AMAZING HUGE DISCOUNTED PRODUCTS & BUY THEM WHAT YOU LIKE !!! http://alloffersblog.blogspot.in/ http://myblog-mycash.blogspot.in/ http://stephenanand.blogspot.in/ http://clickforgreatoffers.blogspot.in/ http://buyallamazonproducts.blogspot.in/ CHECK OUT THIS AMAZING ONLINE BUSSINESS STORES : http://linkshareoffers.blogspot.in/ http://buythemwhatyoulike.blogspot.com/ http://paydotoffers.blogspot.com/ SEARCH & BUY FROM OVER 10,000 INFO-PRODUCTS INSTANTLY : http://cbglobe.com/x.cgi?id=stephen1 WORLD BEST DIAMOND RINGS & JEWELRY WEBSITE : CHOOSE FROM A WIDE RANGE ALL @ WHOLESALE PRICES http://www.shireeodiz.com/diamond-engagement-rings/4d6a526826ecd/08898bec.html REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX @@@@@ AMAZING HUGE DISCOUNTED PRODUCTS @@@@@@ >>>> BUY THEM WHAT YOU LIKE !!! <<<<<<<<< Resell Products Monthly (Lifetime Member) - Get Instant Access To 1,132 Private Label Rights And Master Resale Rights Products http://payspree.com/4644/stephen1 Prosperity Party ($608 of Inspiring Vid/Aud/etc) http://payspree.com/2084/stephen1 Hot Marketing Videos - Lifetime Membership http://payspree.com/3242/stephen1 The Art Of Making Money Online Get rid of fear once and for all. Make money on your PC from home with your own stuff. http://payspree.com/4304/stephen1 Nikon D3100 14.2 Megapixel Digital SLR Camera - Overview of Nikon D3100 14.2 Megapixel Digital SLR Camera (Body with Lens Kit) - 18 mm-55 mm - Black http://payspree.com/5242/stephen1 Take Control | Health | Life | MP3 and ebook - "Who Else Is Ready To Be Healthy NOW?" | Take Control ...it's your health ... it's your life | by Donald M. Alanen http://payspree.com/3996/stephen1 Fireball Internet Marketing Course - 2-Month Internet Marketing Course with Ian del Carmen http://payspree.com/858/stephen1 eCover Crusher - High Quality Photoshop Action Scripts with photoshop how to videos, sales page writing template and how to start a ecover design business http://payspree.com/2733/stephen1 Squeeze Synergy One-Time Offer For Fast Track Cash http://payspree.com/3885/stephen1 10 Strategy Sessions With Experts (+transcripts) - Converts like crazy! http://payspree.com/4311/stephen1 Answer Marketing Traffic No Hard Selling, No Product Of Your Own An NO Risk! http://payspree.com/1169/stephen1 Niche Hunting For Newbies, which converts like crazy. http://payspree.com/1391/stephen1 Ezine Articles Quick Niche Secrets - Uncover Complete Gold Mine Niches From Ezine Articles In 10 Minutes Or Less... http://payspree.com/1517/stephen1 Social Marketing Tips http://payspree.com/1398/stephen1 OTO Firesale http://payspree.com/5667/stephen1 Sniper List Building - List building Crushing it online http://payspree.com/3559/stephen1 One Time Offer Blueprint http://payspree.com/1173/stephen1 Easy Offline SEO - How to make money as an offline SEO consultant without doing ANY of the work yourself and with zero expert knowledge! http://payspree.com/4922/stephen1 List Building Conquest - Build Quick In Demand Products And Create A 10,000+ Subscriber Traffic Machine. http://payspree.com/3262/stephen1 Online Paycheck Blueprint - Learn everything you need to start your Internet business. http://payspree.com/5209/stephen1 EASY MONEY - 100% COMMISSIONS INSTANT PAYMENTS NICE PRODUCTS http://payspree.com/5308/stephen1 $20 Dollar Bill Blaster - Get $20 Instantly Blasted into your PayPal Account Every Time Someone Joins through your $20 Bill Blaster Referral Link! http://payspree.com/4406/stephen1 WordPress Product Automator - WP product delivery plugin, includes great bonuses 5 WP themes, making money with PLR/MRR http://payspree.com/1504/stephen1 Quick and Easy CB Riches http://payspree.com/3883/stephen1 20 Newbie Videos - Firesale OTO ($10 Off) - 20 Newbie Videos http://payspree.com/5823/stephen1 From edcjones at comcast.net Tue May 8 20:19:45 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 08 May 2012 20:19:45 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 Message-ID: <4FA9B821.8000202@comcast.net> Terry Reedy said: > Question 1: if you use the .pth method, do you get the same result? (I expect you will, but good to > check.) Recompiled Pyhton 3.3 without the SITEPATH change. Same result: > python3.3 Python 3.3.0a3 (default, May 8 2012, 19:57:45) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1015, in _find_and_load File "", line 634, in load_module File "", line 294, in module_for_loader_wrapper File "", line 522, in _load_module File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in from . import add_newdocs ImportError: cannot import name add_newdocs >>> > Question2: has anyone successfully run numpy with 3.3 on Debian or anything else? If no one here > answers, try Debian or numpy lists. I don't know. But Python 3.3.0a3 has been in Debian experimental for only a few days. I have a bunch of code that I want to port to Python 3. I delayed for years because numpy and PIL had not been ported to Python 3. Numpy has now been converted and there are alternatives to PIL. Since I want to deal with unicode only once, I would prefer to use 3.3 but 3.2 would be OK. From wuwei23 at gmail.com Tue May 8 20:42:40 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 8 May 2012 17:42:40 -0700 (PDT) Subject: How do I run a python program from an internet address? References: Message-ID: <1fb7ca0d-854c-4976-8a2a-d362f187b897@s9g2000pbq.googlegroups.com> On May 8, 9:20?am, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. ?It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that > they might want to print out on a printer. ?I can program python on my > local machine, but don't know how to make the code accessible from a > browser. You could do this quite easily with CherryPy: import cherrypy class WebApp(object): def calc(self, a, b): c = int(a) + int(b) return str(c) calc.exposed = True cherrypy.quickstart(WebApp()) This can be called via '/calc/1/2' or 'calc?a=1&b=2'. You can add a method to provide a form and another to produce a pretty output and it's good to go. http://www.cherrypy.org/ From showell30 at yahoo.com Tue May 8 20:52:10 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 8 May 2012 17:52:10 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: On May 8, 1:05?pm, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ? """Base class for application-specific errors.""" > > ? ? def get_message(self): > ? ? ? ? """Return the error message associated with this class name.""" > > ? ? ? ? class_name = self.__class__.__name__ > ? ? ? ? return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ? """User entered a security question which is too short.""" > ? ? pass > > class QuestionTooLongError(NetIDAppsError): > ? ? """User entered a security question which is too long.""" > ? ? pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? This may be somewhat relevant to you, although it doesn't specifically answer your question for pre-3.3: http://www.python.org/dev/peps/pep-3155/ (Qualified name for classes and functions) From tjreedy at udel.edu Tue May 8 21:35:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 21:35:22 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 5:47 PM, Terry Reedy wrote: > From what others have posted, it has a new code repository (that being > the ostensible reason for the fork), project site, and mailing list -- > the latter two incompetently. Apparently, the only thing he has kept are > the domain and project names (the latter for sure not legitimately). Update: the pyjs.org group (or member thereof) has registered pyjs as a new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they seem not to be claiming the name 'pyjames', at least not on pypi. -- Terry Jan Reedy From sdiwcconferences at gmail.com Tue May 8 23:20:26 2012 From: sdiwcconferences at gmail.com (sdiwc conferences) Date: Tue, 8 May 2012 20:20:26 -0700 (PDT) Subject: Last CFP- CyberSecurity - Malaysia - IEEE Message-ID: <23d473f8-e3a4-401d-9192-e11578af85cf@l5g2000pbo.googlegroups.com> The International Conference on Cyber Security, Cyber Warfare and Digital Forensic (CyberSec2012) University Putra Malaysia, Kuala Lumpur, Malaysia June 26-28, 2012 http://www.sdiwc.net/CyberSec2012/ The CyberSec2012 is technically co-sponsored by IEEE Malaysia Chapter and All papers will be submitted to IEEE for potential inclusion to IEEE Xplore and Ei Compendex. ======================================================================== The proposed conference on the above theme will be held at University Putra Malaysia, Kuala Lumpur, Malaysia, From June 26-28, 2012 which aims to enable researchers to build connections between different digital applications. The conference welcomes papers on the following (but not limited to) research topics: *Cyber Security -Privacy issues -Formal Methods Application in Security -Incident Handling and Penetration Testing -Operating Systems and Database Security -Security in Cloud Computing -Security in Social Networks -Multimedia and Document Security -Hardware-Based security -VOIP, Wireless and Telecommunications Network Security -Security of Web-based Applications and Services -Enterprise Systems Security -SCADA and Embedded systems security -Distributed and Pervasive Systems Security -Secure Software Development, Architecture and Outsourcing -Security for Future Networks -Security protocols -Legal Issues *Digital Forensic -Data leakage, Data protection and Database forensics -Forensics of Virtual and Cloud Environments -Network Forensics and Traffic Analysis Hardware Vulnerabilities and Device Forensics -Information Hiding -File System and Memory Analysis Multimedia Forensic -Executable Content and Content Filtering -Anti-Forensics and Anti-Anti-Forensics Techniques -Malware forensics and Anti-Malware techniques -Evidentiary Aspects of Digital Forensics -Investigation of Insider Attacks -Cyber-Crimes -Large-Scale Investigations -New threats and Non-Traditional approaches *Information Assurance and Security Management -Corporate Governance -Laws and Regulations -Threats, Vulnerabilities, and Risk Management -Business Continuity & Disaster Recovery Planning -Critical Infrastructure Protection -Digital Rights Management and Intellectual Property Protection -Security Policies and Trust Management -Identity Management -Decidability and Complexity -Economics of Security -Fraud Management *Cyber warfare and Physical Security -Surveillance Systems -Cyber Warfare Trends and Approaches -Social engineering -Authentication and Access Control Systems -Biometrics Applications -Electronic Passports, National ID and Smart Card Security -Template Protection and Liveliness detection -Biometrics standards and standardization -New theories and algorithms in biometrics Researchers are encouraged to submit their work electronically. All papers will be fully refereed by a minimum of two specialized referees. Before final acceptance, all referees comments must be considered. Important Dates ============== Submission Date : May 12, 2012 Notification of acceptance: May 22, 2012 Camera Ready submission : May 25, 2012 Registration : May 30, 2012 Conference dates : June 26-28, 2012 From wuwei23 at gmail.com Wed May 9 02:31:04 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 8 May 2012 23:31:04 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: <725e554b-914a-48c6-b4f3-10e6adcfc8f2@r2g2000pbs.googlegroups.com> On May 9, 6:05?am, John Gordon wrote: > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? This might do the trick: import inspect def exception_members(scope): classes = (m[1] for m in inspect.getmembers(scope, inspect.isclass)) return set( c for c in classes if Exception in c.__mro__ ) class ApplicationException(Exception): @property def outer_scope(self): for _class in exception_members(inspect.getmodule(self.__class__)): if self.__class__ in exception_members(_class): return _class def get_message(self): scope = self.outer_scope class_name = scope.__name__ + '.' if scope else '' class_name += self.__class__.__name__ return class_name When get_message is run, it looks in the module where the exception was defined for any new classes derived from Exception, then looks at the members of each of those to see if it matches the current object's class. Not really well tested, so beware :) From varma.nikhil22 at gmail.com Wed May 9 02:56:37 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 12:26:37 +0530 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: Thanks Arnaud List comprehension method really works nicely.sorry for late reply. On Mon, May 7, 2012 at 7:10 PM, Arnaud Delobelle wrote: > On 7 May 2012 12:31, Nikhil Verma wrote: > > HI All > > > > I was clearing my concepts on dictionary and stuck in this problem. > > I have a dictionary which i have formed by using zip function on two > list so > > that one list (which i have hardcoded) becomes the keys and the other > list > > becomes its values. > > > > Now i want to know how can i get the values of keys at once if i pass the > > keys in a dictionary. > > > > Let say I have a dictionary > > > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > > > Now if i do :- > > > > mydict.get('a') > > 'apple' > > mydict['a'] is the usual way to get the value associated with a key. > The difference is that it will throw an exception if the key doesn't > exist, which is most of the time the sanest thing to do. > > > What i want is some i pass keys in get and in return i should have all > the > > values of those keys which i pass. > > > > ################## > > mydict.get('a','b','c') ###demo for what i want > > 'apple','boy','cat' ### Output i want > > ################# > > 1. You can use a list comprehension > > >>> [mydict[k] for k in 'a', 'b', 'c'] > ['apple', 'boy', 'cat'] > > 2. You can use map (for python 3.X, you need to wrap this in list(...)) > > >>> map(mydict.__getitem__, ['a', 'b', 'c']) > ['apple', 'boy', 'cat'] > > 3. You can use operator.itemgetter > > >>> from operator import itemgetter > >>> itemgetter('a', 'b', 'c')(mydict) > ('apple', 'boy', 'cat') > > -- > Arnaud > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From varma.nikhil22 at gmail.com Wed May 9 03:01:49 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 12:31:49 +0530 Subject: tweaking random number Message-ID: Hi All I want to generate a random number of 8 digits which involve 3 number and 5 digits. Like this :- def random_number(): # do something random_number() "123abcde" # first 3 numbers and 5 letters after the numbers. I am able to generate the random number 8 digit like this:- def random_number(): characters = list(string.ascii_lowercase + string.ascii_uppercase\ + string.digits) coll_rand = [] for i in range(8): random.shuffle(characters) coll_rand.append(characters[0]) return ''.join(coll_rand) This generates like this "Kkrgt56r" Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed May 9 03:38:34 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 08:38:34 +0100 Subject: tweaking random number In-Reply-To: References: Message-ID: <4FAA1EFA.5020708@mrabarnett.plus.com> On 09/05/2012 08:01, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number > and 5 digits. > Like this :- > > def random_number(): > # do something > > random_number() > "123abcde" # first 3 numbers and 5 letters after the numbers. > > I am able to generate the random number 8 digit like this:- > > def random_number(): > characters = list(string.ascii_lowercase + string.ascii_uppercase\ > + string.digits) > coll_rand = [] > for i in range(8): > random.shuffle(characters) > coll_rand.append(characters[0]) > return ''.join(coll_rand) > > This generates like this "Kkrgt56r" > Use random.choice to pick a random digit or a random letter. From rosuav at gmail.com Wed May 9 03:44:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 May 2012 17:44:00 +1000 Subject: tweaking random number In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your current random_number function (btw, I wouldn't call it "number" as it isn't one) is most of one possible solution. Divide it into two parts, one part that generates the digits and another part that generates the letters. Your 'characters' template would thus be different for the two parts. There are other solutions, which involve the generation of less random numbers, but your way will work. ChrisA From ulrich.eckhardt at dominolaser.com Wed May 9 03:56:25 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 09 May 2012 09:56:25 +0200 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: Am 08.05.2012 22:05, schrieb John Gordon: [...] > class QuestionTooShortError(ApplicationException): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(ApplicationException): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. What is it that this "parent class" represents? What is the relation between class Question and class TooShort? In general terms, it isn't even a parent class but just an outer class, a parent class implies that child classes inherit from it. I think that you're going about this the wrong way, and that a module represents much better what you are trying to express here. Your code actually looks a bit like it was written with a strong Java or C++ background, could that be the case? > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". How do I get the outer class name? # in module "Question" class _Exception(ApplicationException): def get_message(self): return self._lookup_message("Question." + self.__class__.__name__) class TooLong(_Exception): pass You might even be able to look up the module name instead of hard-coding it in one place. Uli From __peter__ at web.de Wed May 9 04:30:10 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 May 2012 10:30:10 +0200 Subject: tweaking random number References: Message-ID: Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and > 5 digits. > Like this :- > > def random_number(): > # do something > > random_number() > "123abcde" # first 3 numbers and 5 letters after the numbers. > > I am able to generate the random number 8 digit like this:- > > def random_number(): > characters = list(string.ascii_lowercase + string.ascii_uppercase\ > + string.digits) > coll_rand = [] > for i in range(8): > random.shuffle(characters) > coll_rand.append(characters[0]) > return ''.join(coll_rand) > > This generates like this "Kkrgt56r" > > Thanks in advance If you generalize your random_number() function >>> import random, string >>> def random_code(n=8, chars=string.ascii_lowercase+string.ascii_uppercase+string.digits): ... return "".join(random.choice(chars) for _ in range(n)) ... >>> random_code() 'NgcLhYdR' >>> random_code() 'j9gafcHh' >>> random_code(chars="123ABC") 'C311BA31' >>> random_code(n=4) 'MAsV' you can use it as a building block quite easily: >>> def three_five(): ... return random_code(3, string.digits) + random_code(5, string.ascii_lowercase + string.ascii_uppercase) ... >>> three_five() '656xEWmd' >>> three_five() '589XqZcI' >>> three_five() '168iOOIM' From esabel711 at googlemail.com Wed May 9 04:36:30 2012 From: esabel711 at googlemail.com (lilin Yi) Date: Wed, 9 May 2012 01:36:30 -0700 (PDT) Subject: Question of Python second loop break and indexes Message-ID: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> //final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the next time I want to start from next index in x,which will save time. That is to say , when the if command satisfied ,it can automatically jump out out the second while loop and come to the next identifier of final_1 ,meanwhile the j should start not from the beginning but the position previous. //when I run the code it takes too much time more than one hour and give the wrong result....so could you help me make some improvement of the code? i=0 offset_1=0 while i Message-ID: <7xfwb9682w.fsf@ruckus.brouhaha.com> Albert writes: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. What kind of people? I.e. is it something you're doing for work, where the users are (say) your co-workers? If you're just asking the simplest way to put a python script on a web page, I'd say it's to write a cgi and put it behind a normal web server. I'd avoid stuff like Google app server if possible, especially if there are any privacy concerns about the data going into the program. I much prefer to use cheap virtual servers even though I have to pay for them. They are amazingly affordable: you can get a 128MB server with enough resources for typical personal websites for a couple USD a month. That approach does require you to know a little bit about server administration but it's not that big a deal. From python at mrabarnett.plus.com Wed May 9 05:13:00 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 10:13:00 +0100 Subject: Question of Python second loop break and indexes In-Reply-To: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> References: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> Message-ID: <4FAA351C.1070606@mrabarnett.plus.com> On 09/05/2012 09:36, lilin Yi wrote: > //final_1 is a list of Identifier which I need to find corresponding > files(four lines) in x(x is the file) and write following four lines > in a new file. > > //because the order of the identifier is the same, so after I find the > same identifier in x , the next time I want to start from next index > in x,which will save time. That is to say , when the if command > satisfied ,it can automatically jump out out the second while loop and > come to the next identifier of final_1 ,meanwhile the j should start > not from the beginning but the position previous. > > //when I run the code it takes too much time more than one hour and > give the wrong result....so could you help me make some improvement of > the code? > > i=0 > > offset_1=0 > > > while i j = offset_1 > while j if final_1[i] == x1[j]: > new_file.write(x1[j]) > new_file.write(x1[j+1]) > new_file.write(x1[j+2]) > new_file.write(x1[j+3]) > offset_1 = j+4 > quit_loop="True" > if quit_loop == "True":break > else: j=j +1 > i=i+1 This is roughly equivalent: j = 0 for f in final_1: try: # Look for the identifier starting at index 'j'. j = x1.index(f, j) except ValueError: # Failed to find the identifier. pass else: # Found the identifier at index 'j'. new_file.write(x1[j]) new_file.write(x1[j + 1]) new_file.write(x1[j + 2]) new_file.write(x1[j + 3]) # Skip over the 4 lines. j += 4 From jameskhedley at gmail.com Wed May 9 05:32:28 2012 From: jameskhedley at gmail.com (james hedley) Date: Wed, 9 May 2012 02:32:28 -0700 (PDT) Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: <5524911.6.1336555948102.JavaMail.geo-discussion-forums@vbez18> On Tuesday, 8 May 2012 19:16:01 UTC+1, d.p... at gmail.com wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave I started with Dive Into Python. It's getting old now but for me it really catches the spirit of Python programming; clean, readable, and idiomatic. Plus it's fairly concise itself and emphasises the standard libraries. If you get stuck, obviously just search, but there is a lot of good info on Stack Overflow particularly. James From jeanmichel at sequans.com Wed May 9 05:37:33 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 11:37:33 +0200 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: <4FAA3ADD.7030409@sequans.com> Emeka wrote: > > Hello All, > > Could one say that generator expressions and functions are Python way > of introducing Lazy concept? > > Regards, \Emeka > -- > /Satajanus Nig. Ltd > > > / No. From ulrich.eckhardt at dominolaser.com Wed May 9 05:52:33 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 09 May 2012 11:52:33 +0200 Subject: Question of Python second loop break and indexes In-Reply-To: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> References: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> Message-ID: <2crp79-rdi.ln1@satorlaser.homedns.org> Am 09.05.2012 10:36, schrieb lilin Yi: > //final_1 is a list of Identifier which I need to find corresponding > files(four lines) in x(x is the file) and write following four lines > in a new file. > > //because the order of the identifier is the same, so after I find the > same identifier in x , the next time I want to start from next index > in x,which will save time. That is to say , when the if command > satisfied ,it can automatically jump out out the second while loop and > come to the next identifier of final_1 ,meanwhile the j should start > not from the beginning but the position previous. > > //when I run the code it takes too much time more than one hour and > give the wrong result....so could you help me make some improvement of > the code? If the code takes too much time and gives the wrong results, you must fix and improve it. In order to do that, the first thing you should do is get familiar with "test-driven development" and Python's unittest library. You can start by fixing the code, but chances are that you will break it again trying to make it fast then. Having tests that tell you after each step that the code still works correctly is invaluable. Some more comments below... > i=0 > > offset_1=0 > > > while i j = offset_1 > while j if final_1[i] == x1[j]: > new_file.write(x1[j]) > new_file.write(x1[j+1]) > new_file.write(x1[j+2]) > new_file.write(x1[j+3]) > offset_1 = j+4 > quit_loop="True" > if quit_loop == "True":break > else: j=j +1 > i=i+1 Just looking at the code, there are a few things to note: 1. You are iterating "i" from zero to len(final_1)-1. The pythonic way to code this is using "for i in range(len(final_1)):...". However, since you only use the index "i" to look up an element inside the "final_1" sequence, the proper way is "for f in final_1:..." 2. Instead of writing four lines separately, you could write them in a loop: "for x in x1[j:j+4]: new_file.write(x)". 3. "x1" is a list, right? In that case, there is a member function "index()" that searches for an element and accepts an optional start position. 4. The "quit_loop" is useless, and you probably are getting wrong results because you don't reset this value. If you use "break" at the place where you assign "True" to it, you will probably get what you want. Also, Python has real boolean variables with the two values "True" and "False", you don't have to use strings. Concerning the speed, you can probably improve it by not storing the lines of the input file in "x1", but rather creating a dictionary mapping between the input value and the according four lines: content = open(...).readlines() d = {} for i in range(0, len(content), 4): d[content[i]] = tuple(content[i, i+4]) Then, drop the "offset_1" (at least do that until you have the code working correctly), as it doesn't work with a dictionary and the dictionary will probably be faster anyway. The whole loop above then becomes: for idf in final_1: for l in d.get(idf): new_file.write(l) ;) I hope I gave you a few ideas, good luck! Uli From varma.nikhil22 at gmail.com Wed May 9 06:17:34 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 15:47:34 +0530 Subject: rndom number tweaks Message-ID: Hi Chris (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? No i really don't care for that. I just want first three should be numbers and rest 5 are characters. "123aAbBc" Can you give examples ? ---------- Forwarded message ---------- From: Chris Angelico To: python-list at python.org Cc: Date: Wed, 9 May 2012 17:44:00 +1000 Subject: Re: tweaking random number On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your current random_number function (btw, I wouldn't call it "number" as it isn't one) is most of one possible solution. Divide it into two parts, one part that generates the digits and another part that generates the letters. Your 'characters' template would thus be different for the two parts. There are other solutions, which involve the generation of less random numbers, but your way will work. ChrisA -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed May 9 06:23:37 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 12:23:37 +0200 Subject: Help with how to combine two csv files In-Reply-To: <1335710457.64665.YahooMailClassic@web161203.mail.bf1.yahoo.com> References: <1335710457.64665.YahooMailClassic@web161203.mail.bf1.yahoo.com> Message-ID: <4FAA45A9.1030400@sequans.com> Sammy Danso wrote: > Hello Experts, > I am new to python and I have been trying to merge two csv files, and > upon several hours of unsuccessful attempts, I have decided to seek > for help. > > the format of the file is as follows. file A has columns a, b, c and > values 1,2,3 for several rows. File B also has columns d,e and values > 4,5 for same number of rows as A. the files however do not have any > unique column between the two. > I want an output file C to have columns a,b,c,d,e with values 1,2,3,4,5 > > I would be very grateful for your help with some code. > > Thanks very much, > Sammy > Post some code so we may point at your problem. The solution is easy, the code very small. Something like (pseudo code): import csv writer = csv.writer(file3) for index, row in enumerate(csv.reader(file1)): writer.writerow(row + csv.reader(file2)[index]) JM From askutt at gmail.com Wed May 9 06:30:51 2012 From: askutt at gmail.com (Adam Skutt) Date: Wed, 9 May 2012 03:30:51 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: <2acada35-eb30-4ac8-bb27-8bd6f35b0c50@m13g2000yqc.googlegroups.com> On May 8, 4:05?pm, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ? """Base class for application-specific errors.""" > > ? ? def get_message(self): > ? ? ? ? """Return the error message associated with this class name.""" > > ? ? ? ? class_name = self.__class__.__name__ > ? ? ? ? return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ? """User entered a security question which is too short.""" > ? ? pass > > class QuestionTooLongError(NetIDAppsError): > ? ? """User entered a security question which is too long.""" > ? ? pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. It's no more or less organized than using a module, so use a module. This is why they exist, after all. That being said, this seems like a bad idea to me: this is a lot of code and types just for a message lookup! Exception types should usually be created based on what you expect users to catch, not based on what you could throw. If all of these exceptions will be handled in the same way, then they shouldn't be distinct types. Adam From cyborgv2 at hotmail.com Wed May 9 07:01:47 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Wed, 9 May 2012 12:01:47 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , , , , , , Message-ID: Hi, I'm not big Python user but like to keep a eye on this mailing list as there are a few subjects that can be applied to other languages and just for general interest (Yes, I'm a geek!!! lol) This message thread has really shocked me: I've been a programmer for some thirty years and yes in the past I've had code/intellectual property stolen mainly by corporate bodies (well more like little upstart twats that cannot come up with ideas for themselves, acting in the name of a company.) I've never been able to do anything about it, proving that code and/or an idea has been stolen is not a simple thing to do... But surely in this case, as the project is so visibly the intellectual property of Luke that Risinger and his sheep are standing on the edge of a very large and loose cliff! > To: python-list at python.org > From: tjreedy at udel.edu > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Tue, 8 May 2012 21:35:22 -0400 > > On 5/8/2012 5:47 PM, Terry Reedy wrote: > > > From what others have posted, it has a new code repository (that being > > the ostensible reason for the fork), project site, and mailing list -- > > the latter two incompetently. Apparently, the only thing he has kept are > > the domain and project names (the latter for sure not legitimately). > > Update: the pyjs.org group (or member thereof) has registered pyjs as a > new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they > seem not to be claiming the name 'pyjames', at least not on pypi. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Wed May 9 07:02:02 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 9 May 2012 13:02:02 +0200 Subject: dynamically selecting a class to instantiate based on the object attributes. Message-ID: I have a bunch of objects of the same type. Each object has a version attribute and this refers to source code that was used to make the object. SouceCode is maintained in separate files. eg. myclass_01.py, myclass_02.py, myclass_03.py, myclass_04.py .. During object instantiaton, i would like to use the specific class, that corresponds to the version of the class that was used to create the object. However i cant know the specific "myclass_??.py" before i read the version attribute of the object. Seems like a situation where i have to partially instantiate the object to read the version attribute, and after that continue with instantiaton with the specific version of the version.. Is this doeable? - -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony at xtfx.me Wed May 9 07:02:03 2012 From: anthony at xtfx.me (anthony at xtfx.me) Date: Wed, 9 May 2012 04:02:03 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> Message-ID: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote: > Agreed with pretty much all of that. It's third-world politics, lurching from one dictator to another. Risinger seems to have banned all discussion of the subject from the list too, I'm not posting anymore because I don't want to give him an excuse to wield his newly found banhammer. hello James, i'm not really sure what you're referring too ... you appear to be making these things up. i have not banned anything, or even alluded to it, whatsoever. i asked that one specific mail not be commented upon, as a request; perhaps this is the dreaded bannhammer you speak of? reading your accounts strewn about is interesting, what exactly are *your* motives? a simple curiosity, nothing more. your comparison to gov'ts is pretty skewed i would say, you know this as well as i. regardless of what you think or know of me, i have a permanent track record of being pretty fair and receptive to virtually anything, and am involved in a wide range of projects. Luke is a talented developer, there is no doubt of this, but he is one of the most socially inept persons i have ever encountered. leading your users to statements such as this: https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ ... dozens of times on several occasions, is truly incredible. other such behavior, eg. being the only person in the history of the webkit project to ever be *ejected* from contributing or communicating *at all*, is further testament to the deficiencies provoking this maneuver. however, i have no interest in comparing or being compared. go read my notes again; i have a high level of respect for Luke in many capacities, and this has not changed. lets make one thing perfectly clear; you are not the only one who cares of this project or wishes it to succeed. mistakes were made. problems were had. the decisions however, stands. > But yeah, a lot of the commentary from the pro-rebel side ( not that any of them admit they had anything to do with it ) really does come across as being ill-informed and childish. indeed, you have witnessed little chatter. however, barring your belief of such, i had received dozens of notes thanking me and attesting to a renewed impetus for action. the original goal was to purchase a domain and fork -- i made this very clear in my notes -- `uxpy.net`. however, the most respectable member of the commit IMO convinced me otherwise. names names, yes you want names? sorry :-(. alas, he, myself, and numerous others are still active and moving forward. the list is actually approaching 100 ... not the "4-5" you so graciously quoted. i am simply the point man willing to stand the flurry. likewise, i did not "convince" the domain holder to give me the domain. not only was he already aware prior to me approaching him -- list member, passive -- he was more that willing to assist in reinstating the projects foundations and direction. he *was* the person who "left Luke in charge" ... why do you think he was the owner? as far as im concerned, the domain was already "hijacked"; this was, in good faith, intended as remedy. this was not a easy or light decision, the dissonance exists to this day. the idea was to retain Luke, but he decided to play legal threats as the first card (which i'm afraid can only backfire), before he even knew of the domain changes. hge is not a victim here, nor is anyone else. so please, show some cognitive capacity by realizing this is not as black-and-white as you's like it to be. when you decide to include yourself -- sooner, or later -- you are more than welcome. @alex23 ... try reading a bit further. as a human i am subject to annoyance and frustration. i probably shouldn't have started the message in that manner, but the absurdity and absolute inaccurate statements being made were rather upsetting. you will note that i make it perfectly clear that Luke is a fantastic developer, and a great part of the team. this of course has neither waned nor faltered. i encourage anyone willing to take the time to consult the archives, pyjamas' and elsewhere, as they are the only path to proper answers. this will impact the project in both known and untold ways, but we have a great number of minds willing to push beyond. -- C Anthony From john at hamilton.org.uk Wed May 9 07:16:21 2012 From: john at hamilton.org.uk (hamiljf) Date: Wed, 9 May 2012 04:16:21 -0700 (PDT) Subject: Pydev configuration In-Reply-To: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> Message-ID: <1336562181117-4962800.post@n6.nabble.com> I suppose this is the nearest thread... editor configuration and all. I'm using PyDev in a MyEclipse environment and it works fine, except for one tiny but horrible niggle. The editor function I can't find is block indent/exdent... like you can block comment/uncomment it would be really handy to be able to do the same with indentation. I cannot believe the function isn't there, but I cannot find it. PyDev works fine now I'm running in the latest JRE, btw: used to bomb the 1.6 JRE on a regular basis. -- View this message in context: http://python.6.n6.nabble.com/Pydev-configuration-tp1102326p4962800.html Sent from the Python - python-list mailing list archive at Nabble.com. From fetchinson at googlemail.com Wed May 9 07:34:05 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 9 May 2012 13:34:05 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: > the original goal was to purchase a domain and fork -- > i made this very clear in my notes -- `uxpy.net`. however, the most > respectable member of the commit IMO convinced me otherwise. (I'm a total outsider, never used pyjs.) Anthony, you never explained what the reasoning behind the advice of the "most respectable member of the commit" was. Why didn't you finally buy the new domain name, pick a new name, and fork the project? As it stands now the obvious answer for most people is "because it looked easier to just take over than to build a new community, new infrastructure, new fame, etc, and I sure as hell like to take the easy road as opposed to the hard road". Until you clearly explain your reasoning for taking over as opposed to forking, the default answer is the above one. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed May 9 07:44:38 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 9 May 2012 13:44:38 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: It's also quite ironic that the initial complaining started from how the domain name www.pyjs.org is not available only pyjs.org is. At the same time the Rebel Chief's listed domain name on github, see https://github.com/xtfxme, gives you a server not found: http://the.xtfx.me/ :) On 5/9/12, anthony at xtfx.me wrote: > On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote: >> Agreed with pretty much all of that. It's third-world politics, lurching >> from one dictator to another. Risinger seems to have banned all discussion >> of the subject from the list too, I'm not posting anymore because I don't >> want to give him an excuse to wield his newly found banhammer. > > hello James, > > i'm not really sure what you're referring too ... you appear to be making > these things up. i have not banned anything, or even alluded to it, > whatsoever. i asked that one specific mail not be commented upon, as a > request; perhaps this is the dreaded bannhammer you speak of? > > reading your accounts strewn about is interesting, what exactly are *your* > motives? a simple curiosity, nothing more. > > your comparison to gov'ts is pretty skewed i would say, you know this as > well as i. regardless of what you think or know of me, i have a permanent > track record of being pretty fair and receptive to virtually anything, and > am involved in a wide range of projects. Luke is a talented developer, > there is no doubt of this, but he is one of the most socially inept persons > i have ever encountered. leading your users to statements such as this: > > https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ > > ... dozens of times on several occasions, is truly incredible. other such > behavior, eg. being the only person in the history of the webkit project to > ever be *ejected* from contributing or communicating *at all*, is further > testament to the deficiencies provoking this maneuver. > > however, i have no interest in comparing or being compared. go read my > notes again; i have a high level of respect for Luke in many capacities, and > this has not changed. > > lets make one thing perfectly clear; you are not the only one who cares of > this project or wishes it to succeed. mistakes were made. problems were > had. the decisions however, stands. > >> But yeah, a lot of the commentary from the pro-rebel side ( not that any >> of them admit they had anything to do with it ) really does come across as >> being ill-informed and childish. > > indeed, you have witnessed little chatter. however, barring your belief of > such, i had received dozens of notes thanking me and attesting to a renewed > impetus for action. the original goal was to purchase a domain and fork -- > i made this very clear in my notes -- `uxpy.net`. however, the most > respectable member of the commit IMO convinced me otherwise. names names, > yes you want names? sorry :-(. alas, he, myself, and numerous others are > still active and moving forward. the list is actually approaching 100 ... > not the "4-5" you so graciously quoted. i am simply the point man willing > to stand the flurry. > > likewise, i did not "convince" the domain holder to give me the domain. not > only was he already aware prior to me approaching him -- list member, > passive -- he was more that willing to assist in reinstating the projects > foundations and direction. he *was* the person who "left Luke in charge" > ... why do you think he was the owner? as far as im concerned, the domain > was already "hijacked"; this was, in good faith, intended as remedy. > > this was not a easy or light decision, the dissonance exists to this day. > the idea was to retain Luke, but he decided to play legal threats as the > first card (which i'm afraid can only backfire), before he even knew of the > domain changes. hge is not a victim here, nor is anyone else. so please, > show some cognitive capacity by realizing this is not as black-and-white as > you's like it to be. > > when you decide to include yourself -- sooner, or later -- you are more than > welcome. > > @alex23 ... try reading a bit further. as a human i am subject to annoyance > and frustration. i probably shouldn't have started the message in that > manner, but the absurdity and absolute inaccurate statements being made were > rather upsetting. you will note that i make it perfectly clear that Luke is > a fantastic developer, and a great part of the team. this of course has > neither waned nor faltered. > > i encourage anyone willing to take the time to consult the archives, > pyjamas' and elsewhere, as they are the only path to proper answers. this > will impact the project in both known and untold ways, but we have a great > number of minds willing to push beyond. > > -- > > C Anthony > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jeanmichel at sequans.com Wed May 9 08:21:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 14:21:26 +0200 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: <4FAA6146.1030601@sequans.com> John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > """Base class for application-specific errors.""" > > def get_message(self): > """Return the error message associated with this class name.""" > > class_name = self.__class__.__name__ > return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". How do I get the outer class name? > > Thanks, > > You're going way too much into details regarding your exceptions. Basically, you need to create an exception class is at some point you need different handlers. For instance, try: whatever() except Question.TooShort: dosomething() except Question.TooLong: dosomethingelse() But I'm not sure you really need this. Try to keep it simple. You fetch you exception message from a database, is that really required ? Why can't you just write it in your code ? Another problem is getting the database key from the class name, this makes difficult changing any class name, I'm not sure this is a good idea. Anyway I'm not sure I'm helping here, providing more questions than answer. What you could do : class AppException(Exception): pass class Question(AppException): pass class TooShort(Question): pass class TooLong(Question): pass def getName(cls): if not hasattr(cls, '__base__'): raise ValueError('Not a new class style') if cls is AppException: return cls.__name__ return getName(cls.__base__)+'.' + cls.__name__ > getName(TooShort) < 'AppException.Question.TooShort' This implies you're using only inheritance, not using class as ccontainer/namespace. JM From jeanmichel at sequans.com Wed May 9 08:47:57 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 14:47:57 +0200 Subject: Communication between C++ server and Python app In-Reply-To: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> References: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> Message-ID: <4FAA677D.8070308@sequans.com> kenk wrote: > Hi, > > I've got a server process written in C++ running on Unix machine. > On the same box I'd like to run multiple Python scripts that will > communicate with this server. > > Can you please suggest what would be best was to achieve this ? > > Kind regards and thanks in advance! > M. > xmlrpc shoudl do it. http://en.wikipedia.org/wiki/XML-RPC There's is a client/server python module fort that, same for C++. Your python client will be able to call C++ server procedures. It could be slighlty overkill but that get rid of the tedious socket programming. JM From miki.tebeka at gmail.com Wed May 9 10:13:54 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 9 May 2012 07:13:54 -0700 (PDT) Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> > I am going to learn python for some plot issues. which book or sources, do you recommend please? The tutorial is pretty good if you already know how to program. I also heard a lot of good things on "Python Essential Reference". From mailinglists at xgm.de Wed May 9 11:35:36 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 9 May 2012 17:35:36 +0200 Subject: tee-like behavior in Python Message-ID: Hello, how can I achieve a behavior like tee in Python? * execute an application * leave the output to stdout and stderr untouched * but capture both and save it to a file (resp. file-like object) I have this code proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, stderr=subprocess.STDOUT) while True: out = proc.stdout.readline() if out == '' and proc.poll() != None: break sys.stdout.write(out) logfile.write(out) This works so far but always buffers a couple of lines and outputs them en bloc. The final output is like it is desired but with a significant delay. Is there a way around that? Thanks, Florian From toby at tobiah.org Wed May 9 11:52:59 2012 From: toby at tobiah.org (Tobiah) Date: Wed, 09 May 2012 08:52:59 -0700 Subject: Real time event accuracy Message-ID: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah From d at davea.name Wed May 9 12:13:19 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 12:13:19 -0400 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <4FAA979F.3040604@davea.name> On 05/09/2012 11:52 AM, Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. > > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to > the other program's MIDI in. > > Thanks, > > Tobiah You really need to specify the OS environment you're targeting, as well as telling what program you're intending to feed MIDI into, if you've already picked one. Also, the midi file format has timing information, and that timing should be much better than trying to do it in python before sending commands to some external program. In other words, instead of sleeping in your code and then issuing one midi event, use the midi file format to send a stream of commands that will be played according to the timing information included. -- DaveA From d at davea.name Wed May 9 12:14:58 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 12:14:58 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: <4FAA9802.6030107@davea.name> On 05/09/2012 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian Chances are that other program is buffering its output. Many programs check if they're running on a tty, and turn off buffering for interactive use. But redirect them into a pipe, and they'll run as efficiently as possible, which includes buffering the output. -- DaveA From dreadpiratejeff at gmail.com Wed May 9 12:22:48 2012 From: dreadpiratejeff at gmail.com (J) Date: Wed, 9 May 2012 12:22:48 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > ? ?out = proc.stdout.readline() > ? ?if out == '' and proc.poll() != None: > ? ? ? break > ? ?sys.stdout.write(out) > ? ?logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? Perhaps this would help: http://docs.python.org/library/subprocess.html#popen-constructor specifically, the bits about setting bufsize to 0 indicating unbuffered behaviour. From toby at tobiah.org Wed May 9 12:33:39 2012 From: toby at tobiah.org (Toby) Date: Wed, 09 May 2012 09:33:39 -0700 Subject: Real time event accuracy In-Reply-To: <4FAA979F.3040604@davea.name> References: <4FAA979F.3040604@davea.name> Message-ID: <4FAA9C63.7000905@tobiah.org> On 05/09/2012 09:13 AM, Dave Angel wrote: > On 05/09/2012 11:52 AM, Tobiah wrote: >> I'd like to send MIDI events from python to another >> program. I'd like advice as to how to accurately >> time the events. I'll have a list of floating point >> start times in seconds for the events, and I'd like to send them >> off as close to the correct time as possible. >> >> I'd also appreciate suggestions and pointers to a >> suitable python MIDI library, and maybe an outline >> of what must be done to get the MIDI events to >> the other program's MIDI in. >> >> Thanks, >> >> Tobiah > > You really need to specify the OS environment you're targeting, as well > as telling what program you're intending to feed MIDI into, if you've > already picked one. I'm using Kontakt on Windows 7. The MIDI file think would be good, but (not having that computer in front of me) I don't think that Kontakt had the ability to open a MIDI file. Now, I know that I could load the file into Reaper, and use Kontakt as a plugin. My problem is that I can't afford to mess with GUI menus during my composition process. I need to edit a python program in Vi, then slap it out to python, hearing the music, then edit again. The cycle has to be very quick in order to get anything done. Loading Kontakt with a bunch of samples is very time consuming, so it needs to keep running. Now, if I could find a program that would interpret the MIDI file and send events off to Kontakt either as a plugin or standalone, then the MIDI file generation idea would be perfect. > Also, the midi file format has timing information, and that timing > should be much better than trying to do it in python before sending > commands to some external program. In other words, instead of sleeping > in your code and then issuing one midi event, use the midi file format > to send a stream of commands that will be played according to the timing > information included. > > > > From oliver at obeattie.com Wed May 9 13:11:34 2012 From: oliver at obeattie.com (Oliver Beattie) Date: Wed, 9 May 2012 10:11:34 -0700 (PDT) Subject: Re-raised exceptions in 2.7.3 -- stack trace missing Message-ID: <6286778.1710.1336583494655.JavaMail.geo-discussion-forums@vbbgl4> Hi there I'm tying to investigate a bit of a weird problem here. Basically, I've just upgraded Python (from 2.7.2 -> 2.7.3) by way of an OS upgrade (Ubuntu), and now all the tracebacks I'm getting sent from my web app are looking like this: http://dpaste.org/EgKJp/ As you can see, Django is correctly re-raising the exception, but the original stack trace is not there by way of sys.exc_info(). I've dug into the code a little and it seems fairly simple, exc_info is passed through logging.error from sys.exc_info() so I see no reason why this shouldn't work. Bit perplexing, any idea what could cause this? ?Oliver From kroger at pedrokroger.net Wed May 9 13:14:22 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Wed, 9 May 2012 14:14:22 -0300 Subject: Real time event accuracy In-Reply-To: <4FAA9C63.7000905@tobiah.org> References: <4FAA979F.3040604@davea.name> <4FAA9C63.7000905@tobiah.org> Message-ID: <008AFB2C-FB5F-49CF-8C3C-7BB31B5A0667@pedrokroger.net> I don't know the details of how Kontakt works, but you can try pygame.midi: pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. Also pygame.music can play midi files. Can get input from midi devices and can output to midi devices. For osx, linux and windows. New with pygame 1.9.0. python -m pygame.examples.midi --output (http://wiki.python.org/moin/PythonInMusic) Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ On May 9, 2012, at 1:33 PM, Toby wrote: > On 05/09/2012 09:13 AM, Dave Angel wrote: >> On 05/09/2012 11:52 AM, Tobiah wrote: >>> I'd like to send MIDI events from python to another >>> program. I'd like advice as to how to accurately >>> time the events. I'll have a list of floating point >>> start times in seconds for the events, and I'd like to send them >>> off as close to the correct time as possible. >>> >>> I'd also appreciate suggestions and pointers to a >>> suitable python MIDI library, and maybe an outline >>> of what must be done to get the MIDI events to >>> the other program's MIDI in. >>> >>> Thanks, >>> >>> Tobiah >> >> You really need to specify the OS environment you're targeting, as well >> as telling what program you're intending to feed MIDI into, if you've >> already picked one. > > I'm using Kontakt on Windows 7. The MIDI file think would be good, but > (not having that computer in front of me) I don't think that Kontakt > had the ability to open a MIDI file. > > Now, I know that I could load the file into Reaper, and use Kontakt > as a plugin. My problem is that I can't afford to mess with GUI menus > during my composition process. I need to edit a python program in > Vi, then slap it out to python, hearing the music, then edit again. > The cycle has to be very quick in order to get anything done. > > Loading Kontakt with a bunch of samples is very time consuming, so > it needs to keep running. Now, if I could find a program that would > interpret the MIDI file and send events off to Kontakt either as a plugin > or standalone, then the MIDI file generation idea would be perfect. > > > >> Also, the midi file format has timing information, and that timing >> should be much better than trying to do it in python before sending >> commands to some external program. In other words, instead of sleeping >> in your code and then issuing one midi event, use the midi file format >> to send a stream of commands that will be played according to the timing >> information included. >> >> >> >> > > -- > http://mail.python.org/mailman/listinfo/python-list From kroger at pedrokroger.net Wed May 9 13:15:04 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Wed, 9 May 2012 14:15:04 -0300 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <107FC3CF-737A-4C76-948A-4E157C981862@pedrokroger.net> > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to the other program's MIDI in. Mark Wirt's MidiUtil is a nice library for MIDI. It doesn't do exactly what you want (it generates MIDI files) but it's a nice library and it may be a good starting point: http://code.google.com/p/midiutil/ Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ From RDRichardson at rad-con.com Wed May 9 13:52:45 2012 From: RDRichardson at rad-con.com (Rob Richardson) Date: Wed, 9 May 2012 17:52:45 +0000 Subject: How do I find out what file an import is using? Message-ID: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> I am trying to work with a Python script someone else wrote. The script includes the line from Level3Utils import * I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! How do I find out where the class definition actually is? (There is no PYTHONPATH environmental variable defined on my machine.) Thanks very much! RobR From darcy at druid.net Wed May 9 14:09:42 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 09 May 2012 14:09:42 -0400 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: <4FAAB2E6.7000200@druid.net> On 12-05-09 01:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! >>> import Level3Utils >>> Level3Utils.__file__ -- 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. IM: darcy at Vex.Net From robert.kern at gmail.com Wed May 9 14:10:54 2012 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 09 May 2012 19:10:54 +0100 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: On 5/9/12 6:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! > > How do I find out where the class definition actually is? > > (There is no PYTHONPATH environmental variable defined on my machine.) import Level3Utils print Level3Utils.__file__ -- 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 d at davea.name Wed May 9 14:15:17 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 14:15:17 -0400 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: <4FAAB435.1030603@davea.name> On 05/09/2012 01:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! > > How do I find out where the class definition actually is? > > (There is no PYTHONPATH environmental variable defined on my machine.) > > Thanks very much! > > RobR First, if you want to see the import path, just display sys.path import sys print sys.path Next, it's bad practice to use the form: from nnnn import * because it's then hard to see what (if anything) you actually imported from there. And you can easily hide your own globals, or conversely hide some imports with a new global you might define. If removing the import doesn't stop the code from running, you probably aren't using anything from it, and should leave the line out. However, it is frequently useful to find where a module is coming from, and what symbols it defines. I'm using wxversion module for an example, because it's not very big. And I'm doing it interactively, while you probably want to print these values from your code. >>> dir(wxversion) ['AlreadyImportedError', 'UPDATE_URL', 'VersionError', '_EM_DEBUG', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_find_default', '_find_installed', '_get_best_match', '_pattern', '_selected', '_wxPackageInfo', 'checkInstalled', 'ensureMinimal', 'fnmatch', 'getInstalled', 'glob', 'os', 're', 'select', 'sys'] >>> wxversion.__file__ '/usr/lib/python2.7/dist-packages/wxversion.pyc' In other words, try print Level3Utils.__file__ -- DaveA From wrw at mac.com Wed May 9 14:19:00 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 09 May 2012 14:19:00 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: <4026A618-D662-4792-8E7D-720EC4B3B245@mac.com> On May 9, 2012, at 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list Have you tried explicitly calling file.flush() on the log file? (The docs note that you may have to follow this with os.fsync() on some systems.) -Bill From no.email at nospam.invalid Wed May 9 14:30:04 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 09 May 2012 11:30:04 -0700 Subject: Real time event accuracy References: Message-ID: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Tobiah writes: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. I don't think you can really do this accurately enough to get good sound, but the basic mechanism is time.sleep(t) which takes a floating point argument. That turns into the appropriate microsleep, I think. I'm not even sure how to do it from C code with the Linux realtime scheduler. Traditionally for this sort of thing you'd use dedicated hardware, or else generate waveforms with a little bit of buffering in the sound card. From lamialily at cleverpun.com Wed May 9 14:45:34 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 09 May 2012 11:45:34 -0700 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: If the support you have from the other contributors is anywhere near what you claim it is, I may as well be kissing Pyjamas goodbye. Doubt it, though - this whole post reeks of vagueities and doublespeak garbage. Too many undefined "whos". I'll wait until Leighton gets the reins back. And you know what? Leighton was right to threaten legal action. What you did was not only in violation of his IP, but also multiple data theft laws. ~Temia -- When on earth, do as the earthlings do. From jeanpierreda at gmail.com Wed May 9 15:00:11 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 9 May 2012 15:00:11 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri wrote: > And you know what? Leighton was right to threaten legal action. What > you did was not only in violation of his IP, but also multiple data > theft laws. As far as copyright goes, it was open source, so he's allowed to continue making modifications. I don't think Luke had any patents. There might be something with stealing the name "PyJS" (which was, AFAIK, used as a synonym for "PyJamas") -- apparently "common law trademark" is a thing. Otherwise... The domain was apparently not directly owned by Luke (but pointed to a server luke administered), and its transfer was apparently consensual. It seems like nearly every evil thing the hijacker did is legally permissible. The one other thing was the way he created the new mailing list might not have been legal, apparently. (See http://mail.python.org/pipermail/python-list/2012-May/1291804.html ). -- Devin From toby at tobiah.org Wed May 9 15:26:05 2012 From: toby at tobiah.org (Tobiah) Date: Wed, 09 May 2012 12:26:05 -0700 Subject: Real time event accuracy In-Reply-To: <7xk40lxl5f.fsf@ruckus.brouhaha.com> References: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Message-ID: > I don't think you can really do this accurately enough to get good > sound, but the basic mechanism is time.sleep(t) which takes a floating > point argument. That turns into the appropriate microsleep, I think. I think the time would have to come from a hardware clock. From jstitch at invernalia.homelinux.net Wed May 9 15:38:31 2012 From: jstitch at invernalia.homelinux.net (Javier Novoa C.) Date: Wed, 9 May 2012 19:38:31 +0000 (UTC) Subject: strptime format string nasty default Message-ID: Hi, I am using time.strptime method as follows: I receive an input string, representing some date in the following format: %d%m%Y However, the day part may be a single digit or two, depending on magnitude. For example: '10052012' will be parsed as day 10, month 5, year 2012 Again: '8052012' will be parsed as day 8, month 5, year 2012 What happens when day is 1 or 2? '1052012' will be parsed as day 10, month 5, year 2012 !!!! That's not the expected behaviour! Not for me at least. I mean, in my case, month will always be a 2 digit string, so there's no ambiguity problem by pretending that... say '1052012' is correctly parsed. Is there a way out of here? I know I can pre-parse the string and append a '0' to it when lenght == 7, but I think that a better way would be if strptime allowed me to define my format in a better way... To say that the month is the optional one-two digit part is just a default, isn't it? Why can't I specify that the day part is the one with one-or-two digits on the input string...? Or is there a way out that I don't know yet? -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From rowen at uw.edu Wed May 9 15:39:05 2012 From: rowen at uw.edu (Russell E. Owen) Date: Wed, 09 May 2012 12:39:05 -0700 Subject: pickle question: sequencing of operations References: Message-ID: In article , Ian Kelly wrote: > On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > > In article , > > ?"Russell E. Owen" wrote: > > > >> What is the sequence of calls when unpickling a class with __setstate__? > > I believe it just calls object.__new__ followed by > yourclass.__setstate__. So at the point __setstate__ is called, you > have a pristine instance of whatever class you're unpickling. I was wondering. I override __new__ (and __init__) to print messages and was quite surprised to only see __new__being called when the object was first created, not when it was being unpickled. But maybe there's something funny about my override that caused unpickle to ignore it and use the default version. I hope so. I can't see how the object could be constructed during unpickle without calling __new__. But that's one reason I was curious about the unpickling sequence of operations. -- Russell From yanegomi at gmail.com Wed May 9 15:54:51 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Wed, 9 May 2012 12:54:51 -0700 Subject: strptime format string nasty default In-Reply-To: References: Message-ID: On May 9, 2012, at 12:38 PM, "Javier Novoa C." wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? Delimiters, e.g. dashes, slashes, etc, can remove ambiguity in the date string. Leading 0s in elements in the date would help as well. HTH! -Garrett From news at idlcoyote.com Wed May 9 16:09:09 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:09:09 -0600 Subject: IDL Books On Sale Message-ID: Folks, My wife says that as long as I'm retired, she wants the bedroom back, so I've put all my books I have in storage there on sale! I only have four copies left of IDL Programming Techniques, 2nd Edition, and I don't plan to print any more of those. If you want one, this may be your last chance! I have a few of Ronn Kling's books left and enough Traditional IDL Graphics books to make the bonfire at the 4th of July picnic more than spectacular. No more need for these once IDL 8.2 comes out, I guess. ;-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From grahn+nntp at snipabacken.se Wed May 9 16:11:02 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 9 May 2012 20:11:02 GMT Subject: strptime format string nasty default References: Message-ID: On Wed, 2012-05-09, Javier Novoa C. wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? You'd have to read the strptime(3) manual page (it's a Unix function, imported straight into Python, I'm sure). Judging from a quick read it's not intended to support things like these. I'm surprised it doesn't parse your last example to (10, 52, 12) and then fail it due to month>12. Can't you use a standard date format, like ISO? Apart from not being possible to parse with standard functions, this one looks quite odd and isn't very human-readable. If you have to use this format, I strongly recommend parsing it "manually" as text first. Then you can create an ISO date and feed that to strptime, or perhaps use your parsed (day, month, year) tuple directly. /Jorgen -- // Jorgen Grahn O o . From news at idlcoyote.com Wed May 9 16:11:02 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:11:02 -0600 Subject: IDL Books On Sale References: Message-ID: David Fanning writes: > > Folks, > > My wife says that as long as I'm retired, she wants the > bedroom back, so I've put all my books I have in storage > there on sale! > > I only have four copies left of IDL Programming Techniques, > 2nd Edition, and I don't plan to print any more of those. > If you want one, this may be your last chance! > > I have a few of Ronn Kling's books left and enough > Traditional IDL Graphics books to make the bonfire > at the 4th of July picnic more than spectacular. > No more need for these once IDL 8.2 comes out, I guess. ;-) > > Cheers, > > David Whoops! A link might be good, I guess. I've been gone so long I've forgotten how to do this: http://www.idlcoyote.com/store David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Wed May 9 16:14:26 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:14:26 -0600 Subject: IDL Books On Sale References: Message-ID: David Fanning writes: > Whoops! A link might be good, I guess. I've been gone so > long I've forgotten how to do this: > > http://www.idlcoyote.com/store Whoops! Sorry again. I just realized I was posting this to my NEW newsgroup. How embarrassing... :-( David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From jstitch at invernalia.homelinux.net Wed May 9 16:25:47 2012 From: jstitch at invernalia.homelinux.net (Javier Novoa C.) Date: Wed, 9 May 2012 20:25:47 +0000 (UTC) Subject: strptime format string nasty default References: Message-ID: On 2012-05-09, Jorgen Grahn wrote: > > You'd have to read the strptime(3) manual page (it's a Unix function, > imported straight into Python, I'm sure). Judging from a quick read > it's not intended to support things like these. I'm surprised it > doesn't parse your last example to (10, 52, 12) and then fail it due > to month>12. Well, it doesn't, at least on my Python. I'm using 2.7.3 version > > Can't you use a standard date format, like ISO? Apart from not being > possible to parse with standard functions, this one looks quite odd > and isn't very human-readable. No, sadly the input doesn't depends on me :-( > > If you have to use this format, I strongly recommend parsing it > "manually" as text first. Then you can create an ISO date and feed > that to strptime, or perhaps use your parsed (day, month, year) tuple > directly. Ok, I'll do that. > > /Jorgen > Thanks! -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From ian.g.kelly at gmail.com Wed May 9 16:34:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 14:34:06 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: > I was wondering. I override __new__ (and __init__) to print messages and > was quite surprised to only see __new__being called when the object was > first created, not when it was being unpickled. But maybe there's > something funny about my override that caused unpickle to ignore it and > use the default version. I hope so. I can't see how the object could be > constructed during unpickle without calling __new__. But that's one > reason I was curious about the unpickling sequence of operations. You're probably pickling with the default protocol. Unpickling calls an overridden __new__ method only if the pickle protocol is at least 2. Using protocol 0 or 1, new-style class instances are constructed with the base object.__new__ instead. From python at mrabarnett.plus.com Wed May 9 16:39:33 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 21:39:33 +0100 Subject: strptime format string nasty default In-Reply-To: References: Message-ID: <4FAAD605.5080809@mrabarnett.plus.com> On 09/05/2012 20:38, Javier Novoa C. wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? > You could just right-justify the string to 8 characters, padding with '0': >>> '1052012'.rjust(8, '0') '01052012' From ian.g.kelly at gmail.com Wed May 9 16:40:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 14:40:00 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 2:34 PM, Ian Kelly wrote: > On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: >> I was wondering. I override __new__ (and __init__) to print messages and >> was quite surprised to only see __new__being called when the object was >> first created, not when it was being unpickled. But maybe there's >> something funny about my override that caused unpickle to ignore it and >> use the default version. I hope so. I can't see how the object could be >> constructed during unpickle without calling __new__. But that's one >> reason I was curious about the unpickling sequence of operations. > > You're probably pickling with the default protocol. ?Unpickling calls > an overridden __new__ method only if the pickle protocol is at least > 2. ?Using protocol 0 or 1, new-style class instances are constructed > with the base object.__new__ instead. BTW, in case you're wondering where all this is documented, pull up PEP 307 and read the sections "Case 2" and Case 3". Cheers, Ian From martin.hellwig at gmail.com Wed May 9 16:50:10 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 09 May 2012 21:50:10 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On 09/05/2012 12:02, anthony at xtfx.me wrote: Hello C Anthony, I am an pyjs user and introduced the project as one of the fundamental parts of a new application that is now core of a company of a reasonable size (30+), customers include several companies in the top 10 of largest IT infrastructures, I can mail you a list in private if you wish so. I agree that the project leadership had certainly room for improvement. I also agree that to move forward there had to be made some choices. However, as the person introducing this project in a commercial venture, I am also the one having the responsibility of it in my setting. I have been put in a position where I have to come up with answers, like why the examples page didn't work, why the project seems fragile and if there is any viability at all. Of course, I still believe in the project, with all it warts and so forth. However my position has been made needlessly difficult, because the action you took did not leave room for choice. Let me explain this, if you had forked the project, created a new domain, mailing list and, took over the majority of the devs, I would be able to make a choice if I go with the new guys or stick with the couple of old ones, just like the xorg fork. If your argument is that this was your intention but was persuaded to do other wise, I would say that is a lapse of judgement and not a very good restart of the project. Unfortunately mistakes made in public, even if arguably they are not mistakes at all, are not easy forgotten and can end up haunting you. I hope you will take these comments with you as a lesson learned, I do wish you all the best and look forward to the improvements you are going to contribute. -- Martin P. Hellwig (mph) From drsalists at gmail.com Wed May 9 16:58:05 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 9 May 2012 13:58:05 -0700 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: You've had some good responses already, but here're two more: 1) Easiest would be to use setvbuf in the child process, if you have access to its source. This allows you to force line-oriented buffering. 2) stdio likes to buffer to tty/pty's in a line-oriented manner, and other things in a block-oriented manner - by default, so users get pleasing output increments, and programs get efficiency. To trick stdio into buffering line-oriented by default when it's sending output to another program, you may have to talk to the child process using a pty, AKA a pseudo terminal. There are a few ways of doing this: A) Use CPython's pty module. B) Use something like pexpect. C) Check out the pty program in comp.sources.unix volume 25. This might be pretty easy too, assuming that pty still builds on a modern *ix. On Wed, May 9, 2012 at 8:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed May 9 17:13:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 09 May 2012 14:13:16 -0700 Subject: __del__ and wisdom Message-ID: <4FAADDEC.6070804@stoneleaf.us> Every time discussion about __del__ had come up I had thought to myself, "yeah, but I'm being careful to not have reference loops -- /my/ classes are okay." and then... BITE! But hey, it wasn't a reference loop that got me, it was data being written back to disk after the disk portion had changed, thus clobbering new data with old. Yeah, I know, that's not really any better. *sigh* Okay, no more __del__ for me! ~Ethan~ Knowledge is knowing that tomatoes are a fruit. Wisdom is not putting them in a fruit salad. From d at davea.name Wed May 9 17:13:57 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 17:13:57 -0400 Subject: Real time event accuracy In-Reply-To: References: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Message-ID: <4FAADE15.3030602@davea.name> On 05/09/2012 03:26 PM, Tobiah wrote: >> I don't think you can really do this accurately enough to get good >> sound, but the basic mechanism is time.sleep(t) which takes a floating >> point argument. That turns into the appropriate microsleep, I think. > I think the time would have to come from a hardware clock. Python has a high-res time function when run on an Intel X86 platform, though I forget which one you should use on Windows. The problem is that Windows makes no assurance that you will be executing at that particular point in time. You can approximate it with time.sleep(), which is what Paul Rubin was suggesting. Windows is not a real time operating system. Still, if the system is lightly loaded, sleep() will probably get you within 50 milliseconds. I don't think you should even worry about it till you see the capabilities of whatever MIDI library you choose. I'd be surprised if it doesn't allow you to attach timing hints to the notes, same as the file format I discussed earlier. -- DaveA From alan.ristow at gmail.com Wed May 9 17:25:18 2012 From: alan.ristow at gmail.com (Alan Ristow) Date: Wed, 09 May 2012 23:25:18 +0200 Subject: Pydev configuration In-Reply-To: <1336562181117-4962800.post@n6.nabble.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> <1336562181117-4962800.post@n6.nabble.com> Message-ID: <4FAAE0BE.5080307@gmail.com> On 05/09/2012 01:16 PM, hamiljf wrote: > I suppose this is the nearest thread... editor configuration and all. > I'm using PyDev in a MyEclipse environment and it works fine, except for one > tiny but horrible niggle. > > The editor function I can't find is block indent/exdent... like you can > block comment/uncomment it would be really handy to be able to do the same > with indentation. I cannot believe the function isn't there, but I cannot > find it. Select the code block you want to indent and hit Tab. To do the reverse, hit Shift-Tab. Alan From clp2 at rebertia.com Wed May 9 17:51:35 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 9 May 2012 14:51:35 -0700 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 8:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, shlex.split() should just be used once, at "development time", to determine the form of the argument list. It shouldn't generally be used at runtime. Otherwise, you need to do the proper escaping/quoting yourself, which defeats the entire purpose of bypassing the shell. Cheers, Chris From Joshua.R.English at gmail.com Wed May 9 18:04:40 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 9 May 2012 15:04:40 -0700 (PDT) Subject: PyTextile Question In-Reply-To: <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> References: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> Message-ID: <27335393.1619.1336601080479.JavaMail.geo-discussion-forums@pbhb1> On Monday, May 7, 2012 6:13:28 AM UTC-7, dinkyp... at gmail.com wrote: > > Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV. > > import re, textile > ... Wow. Thank you. This works. I'm trying to figure what that regular expression does, but I swear it's copying the lines twice. (Clearly, I don't speak re.) Josh From cyborgv2 at hotmail.com Wed May 9 18:30:15 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Wed, 9 May 2012 23:30:15 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , Message-ID: Hi ya, Not to be confrontative but just because a project is open-source, it doesn't mean IP is open too!! The original idea is still property of the originator... It just has the global community adding their own IP and fixes. This is a core of corporate contracts ensuring that a developers IP become freely usable by the company they work for at the time, but their IP is still their IP. In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. The problem is proving it!!! > From: jeanpierreda at gmail.com > Date: Wed, 9 May 2012 15:00:11 -0400 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: lamialily at cleverpun.com > CC: python-list at python.org > > On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri wrote: > > And you know what? Leighton was right to threaten legal action. What > > you did was not only in violation of his IP, but also multiple data > > theft laws. > > As far as copyright goes, it was open source, so he's allowed to > continue making modifications. I don't think Luke had any patents. > > There might be something with stealing the name "PyJS" (which was, > AFAIK, used as a synonym for "PyJamas") -- apparently "common law > trademark" is a thing. Otherwise... > > The domain was apparently not directly owned by Luke (but pointed to a > server luke administered), and its transfer was apparently consensual. > > It seems like nearly every evil thing the hijacker did is legally > permissible. The one other thing was the way he created the new > mailing list might not have been legal, apparently. (See > http://mail.python.org/pipermail/python-list/2012-May/1291804.html ). > > -- Devin > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed May 9 18:44:01 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 May 2012 23:44:01 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , Message-ID: On 09/05/2012 23:30, Adrian Hunt wrote: > > In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. > References please, as this is completely opposite to my understanding. -- Cheers. Mark Lawrence. From ian.g.kelly at gmail.com Wed May 9 19:01:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 17:01:08 -0600 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > Hi ya, > > Not to be confrontative but just because a project is open-source, it > doesn't mean IP is open too!! The original idea is still property of the > originator... It just has the global community adding their own IP and > fixes.? This is a core of corporate contracts ensuring that a developers IP > become freely usable by the company they work for at the time, but their IP > is still their IP. Luke Leighton was not the originator of the project. James Tauber was, and his original code was a port of Google Web Toolkit. Even if Luke could somehow be considered the "owner" of the project, it was released under the Apache License, which includes a "/perpetual/, worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/ copyright license to reproduce, /prepare Derivative Works of/, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works". I don't agree with what Anthony has done, but I don't see how it violates the license in any way or how Luke has any possible recourse through IP claims. From cyborgv2 at hotmail.com Wed May 9 19:04:11 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Thu, 10 May 2012 00:04:11 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , Message-ID: Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!!!!!! > From: ian.g.kelly at gmail.com > Date: Wed, 9 May 2012 16:59:00 -0600 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: cyborgv2 at hotmail.com > > On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > > > Hi ya, > > > > Not to be confrontative but just because a project is open-source, it > > doesn't mean IP is open too!! The original idea is still property of the > > originator... It just has the global community adding their own IP and > > fixes. This is a core of corporate contracts ensuring that a developers IP > > become freely usable by the company they work for at the time, but their IP > > is still their IP. > > Luke Leighton was not the originator of the project. James Tauber > was, and his original code was a port of Google Web Toolkit. Even if > Luke could somehow be considered the "owner" of the project, it was > released under the Apache License, which includes a "/perpetual/, > worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/ > copyright license to reproduce, /prepare Derivative Works of/, > publicly display, publicly perform, sublicense, and distribute the > Work and such Derivative Works". I don't agree with what Anthony has > done, but I don't see how it violates the license in any way or how > Luke has any possible recourse through IP claims. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyborgv2 at hotmail.com Wed May 9 19:19:38 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Thu, 10 May 2012 00:19:38 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, , <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, , <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, , <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , Message-ID: Hi there Mark There has been a few that I know of but going back quite a long time... Soon after I got my qualifications, a small company called Merlio, not only did the court case get passed in UK courts by it went to the European court too... I wasn't directly involved but I know the EU court upheld the decision of the UK courts. Still there are was little to no enforcement of what they decided!!! Any how IP IS the IP of the developer... Proving it and enforcing it is another matter!! > To: python-list at python.org > From: breamoreboy at yahoo.co.uk > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Wed, 9 May 2012 23:44:01 +0100 > > On 09/05/2012 23:30, Adrian Hunt wrote: > > > > In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. > > > > References please, as this is completely opposite to my understanding. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From merwok at netwok.org Wed May 9 19:20:40 2012 From: merwok at netwok.org (=?UTF-8?B?w4lyaWMgQXJhdWpv?=) Date: Wed, 09 May 2012 19:20:40 -0400 Subject: Distutils2 Sprint in Montreal Message-ID: <4FAAFBC8.9040204@netwok.org> Hi all, The Montreal-Python user group is organizing a second sprint to work on distutils2 on May 12th. If you live in Montreal, take a laptop and come join us! No previous knowledge of Distutils2 is required, just general Python skills. All details are found here: http://montrealpython.org/2012/05/distutils2-sprint-2/ Cheers From breamoreboy at yahoo.co.uk Wed May 9 20:12:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 01:12:12 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, , <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, , <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, , <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , Message-ID: On 10/05/2012 00:19, Adrian Hunt wrote: > > Hi there Mark > > There has been a few that I know of but going back quite a long time... Soon after I got my qualifications, a small company called Merlio, not only did the court case get passed in UK courts by it went to the European court too... I wasn't directly involved but I know the EU court upheld the decision of the UK courts. Still there are was little to no enforcement of what they decided!!! > > Any how IP IS the IP of the developer... Proving it and enforcing it is another matter!! > > >> To: python-list at python.org >> From: breamoreboy at yahoo.co.uk >> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack >> Date: Wed, 9 May 2012 23:44:01 +0100 >> >> On 09/05/2012 23:30, Adrian Hunt wrote: >>> >>> In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. >>> >> >> References please, as this is completely opposite to my understanding. >> >> -- >> Cheers. >> >> Mark Lawrence. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > Google was a right PITA but eventually I found this http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ It appears to contradict what you've said above, or have I misread it? E.g "Under the (Patents) Act (1977), there is a presumption that an employer will own the patent of an invention made by its employee if the invention was made in the employee?s normal or specifically assigned duties and either, an invention might reasonably be expected to result from such duties or, the employee has a special obligation to further the employee?s interests, arising from the nature of those duties and responsibilities and the employee?s status." -- Cheers. Mark Lawrence. From rosuav at gmail.com Wed May 9 20:27:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 10:27:27 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: > Google was a right PITA but eventually I found this > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ > ?It appears to contradict what you've said above, or have I misread it? ?E.g > "Under the (Patents) Act (1977), there is a presumption that an employer > will own the patent of an invention made by its employee if the invention > was made in the employee?s normal or specifically assigned duties and > either, an invention might reasonably be expected to result from such duties > or, the employee has a special obligation to further the employee?s > interests, arising from the nature of those duties and responsibilities and > the employee?s status." That's patents... intellectual property goes by other rules I think. I am not a lawyer, and I try to avoid getting placed in any position where this sort of thing will come up, because it's messy... especially with internationalization. ChrisA From breamoreboy at yahoo.co.uk Wed May 9 21:48:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 02:48:55 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On 10/05/2012 01:27, Chris Angelico wrote: > On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: >> Google was a right PITA but eventually I found this >> http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ >> It appears to contradict what you've said above, or have I misread it? E.g >> "Under the (Patents) Act (1977), there is a presumption that an employer >> will own the patent of an invention made by its employee if the invention >> was made in the employee?s normal or specifically assigned duties and >> either, an invention might reasonably be expected to result from such duties >> or, the employee has a special obligation to further the employee?s >> interests, arising from the nature of those duties and responsibilities and >> the employee?s status." > > That's patents... intellectual property goes by other rules I think. I > am not a lawyer, and I try to avoid getting placed in any position > where this sort of thing will come up, because it's messy... > especially with internationalization. > > ChrisA The title of the referenced page is "Intellectual Property and Employees". My quote is from the "Employees and Patents" section, but there are several more sections, so it appears that patents are a part of the intellectual property rule set. I'm with you on avoiding this type of situation, but sadly the whole pyjamas issue is a right pig's ear :( -- Cheers. Mark Lawrence. From cs at zip.com.au Wed May 9 22:12:28 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 10 May 2012 12:12:28 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: Message-ID: <20120510021228.GA11896@cskk.homeip.net> On 10May2012 10:27, Chris Angelico wrote: | On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: | > Google was a right PITA but eventually I found this | > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ | > ?It appears to contradict what you've said above, or have I misread it? ?E.g | > "Under the (Patents) Act (1977), there is a presumption that an employer | > will own the patent of an invention made by its employee if the invention | > was made in the employee?s normal or specifically assigned duties and | > either, an invention might reasonably be expected to result from such duties | > or, the employee has a special obligation to further the employee?s | > interests, arising from the nature of those duties and responsibilities and | > the employee?s status." | | That's patents... intellectual property goes by other rules I think. Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to the author, except that most companies require employees to assign it to the company, including the Berne Convention "moral rights" (such as attribution). Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ People are paid for coming in the morning and leaving at night, and for saying "Good morning" in the morning and "Good afternoon" in the afternoon and never confusing the two. - Albert Shanker, president of the American Federation of Teachers From rosuav at gmail.com Wed May 9 22:13:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 12:13:53 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <20120510021228.GA11896@cskk.homeip.net> References: <20120510021228.GA11896@cskk.homeip.net> Message-ID: On Thu, May 10, 2012 at 12:12 PM, Cameron Simpson wrote: > Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to > the author, except that most companies require employees to assign it to > the company, including the Berne Convention "moral rights" (such as > attribution). Oh. Thanks, I stand corrected. Like I said, not a lawyer. :) ChrisA From pa at see.signature.invalid Wed May 9 22:36:29 2012 From: pa at see.signature.invalid (Pierre Asselin) Date: Thu, 10 May 2012 02:36:29 +0000 (UTC) Subject: __doc__+= """Detailed description""" Message-ID: Hi. Started using python a few months back, still settling on my style. I write docstrings and I use "pydoc mymodule" to refresh my memory. Problem: if I just docstring my classes/methods/functions the output of pydoc more or less works as a reference manual, but if I get sidetracked for even a few weeks I find that documentation inadequate when I return to my code. I need to see some introductory context first, so that the reference material makes sense. Wery well, write a module docstring then. The problem now: the many paragraphs of detailed description at the top of the module get in the way. The pydoc output is good, but the code becomes hard to read. So I come up with this: ###################################################################### #! env python """One-liner docstring.""" # Many classes, methods, functions, attributes, # with docstrings as needed. Docs tend to be # short and the code speaks for itself. # ... # Much further down, ___doc___+= """ Detailed description goes here. Provide some context, explain what the classes are for and what the most important methods are, give simple examples, whatever. Say enough to make the rest understandable.""" if __name__ == "__main__": # test code follows ###################################################################### It seems to work, too. But is that a sound way to write python? Am I relying on undocumented implementation details or am I safe? I guess I am trying to control the order of exposition without resorting to full-fledged Literate Programming. -- pa at panix dot com From rosuav at gmail.com Wed May 9 23:13:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 13:13:48 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? Message-ID: The azet.sk MTA is behaving badly wrt bounced messages from python-list. Instead of sending them to the list software (where they'll result in the subscription being suspended), they're being sent to the original sender of the message. As a result, every message sent to the list triggers a useless bounce message. Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? I've already forwarded a bounce to abuse at azet.sk but have heard nothing back. This isn't the list's fault, but maybe the listowner can deal with the spam coming back. Chris Angelico (Bounce message follows.) ---------- Forwarded message ---------- From: <> Date: Thu, May 10, 2012 at 12:27 PM Subject: Sprava nebola dorucena (Message was not delivered) To: rosuav at gmail.com Vasa sprava Pre: pyjko21 at azet.sk Predmet: Re: Open Source: you're doing it wrong - the Pyjamas hijack Poslana: ?Thu, 10 May 2012 12:13:53 +1000 Sprava nemohla byt dorucena, pretoze e-mailova schranka prijemcu je plna. Pokuste sa tento e-mail zaslat neskor. Tato sprava bola automaticky vygenerova serverom azet.sk. ----- Your message To: pyjko21 at azet.sk Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack Sent: ? Thu, 10 May 2012 12:13:53 +1000 The message could not be delivered because the recipient's mailbox is full. Try to send it later. This message was automatically generated by e-mail server azet.sk. From ben+python at benfinney.id.au Wed May 9 23:18:56 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 May 2012 13:18:56 +1000 Subject: __doc__+= """Detailed description""" References: Message-ID: <8762c467vj.fsf@benfinney.id.au> pa at see.signature.invalid (Pierre Asselin) writes: > Hi. Started using python a few months back, still settling on my > style. Welcome! Please consider your part in the Python community, and found your style on PEP 8 , the Style Guide for Python Code. > I write docstrings and I use "pydoc mymodule" to refresh my memory. Excellent. Please conform to the Docstring Conventions of PEP 257 . > Problem: if I just docstring my classes/methods/functions the output > of pydoc more or less works as a reference manual Hmm. That doesn't sound like a good use for docstrings. They are reference material, but very focussed; a ?reference manual? sounds much more comprehensive and isn't well suited to docstrings, in my opinion. > but if I get sidetracked for even a few weeks I find that > documentation inadequate when I return to my code. Yes, that would be a natural outcome of trying to make docstrings too large. There are other forms of documentation available, such as a separate reference manual, that you could write as well. > Wery well, write a module docstring then. The problem now: the many > paragraphs of detailed description at the top of the module get in the > way. The pydoc output is good, but the code becomes hard to read. So don't put so much into the module docstring. Your module should consist of many smaller pieces, mainly classes and functions. Document the specifics in those more local docstrings. > So I come up with this: > > ###################################################################### > #! env python > > """One-liner docstring.""" > > # Many classes, methods, functions, attributes, > # with docstrings as needed. Docs tend to be > # short and the code speaks for itself. > # ... > # Much further down, > > ___doc___+= """ > > Detailed description goes here. Provide some context, > explain what the classes are for and what the most important > methods are, give simple examples, whatever. Say enough > to make the rest understandable.""" I'm having trouble imagining what would need to be put in that separate chunk of docstring. Can you point to real code online that uses this style? > if __name__ == "__main__": > # test code follows As an aside, if your modules are complex, this style of test code is likely to be too big for shoving into the same module, and too brittle written this way. Instead, make lots of distinct, focussed unit tests using the ?unittest? module, and make other kinds of tests (e.g. feature tests) using other frameworks ? leaving the actual implementation code clear of this cruft. > It seems to work, too. But is that a sound way to write python? > Am I relying on undocumented implementation details or am I safe? I think you're trying to make one file do everything, which is ignoring the better organisation that multiple files can make. > I guess I am trying to control the order of exposition without > resorting to full-fledged Literate Programming. Yes. Maybe you need to let go of this need to control the order in which the reader views your code; we're going to be looking at small, focussed parts anyway, not reading the whole thing in one go. So work with that instead. -- \ ?There are only two ways to live your life. One is as though | `\ nothing is a miracle. The other is as if everything is.? | _o__) ?Albert Einstein | Ben Finney From cs at zip.com.au Thu May 10 01:21:17 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 10 May 2012 15:21:17 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: References: Message-ID: <20120510052117.GA32315@cskk.homeip.net> On 10May2012 13:13, Chris Angelico wrote: | The azet.sk MTA is behaving badly wrt bounced messages from | python-list. Instead of sending them to the list software (where | they'll result in the subscription being suspended), they're being | sent to the original sender of the message. [...] | I've already forwarded a bounce to abuse at azet.sk but have heard | nothing back. This isn't the list's fault, but maybe the listowner can | deal with the spam coming back. Try "postmaster". I'm not sure "abuse" is so widely implemented. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you 'aint falling off, you ar'nt going hard enough. - Fred Gassit From vincent.vandevyvre at swing.be Thu May 10 03:34:11 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Thu, 10 May 2012 09:34:11 +0200 Subject: 2to3 change direct import to relative import Message-ID: <4FAB6F73.4020900@swing.be> Hi, I use 2to3 into a python script wich convert all .py files of an application. 2to3 is executed into the same directory as files. All import are now relative import: ----------------------------------------- --- main_ui.py (original) +++ main_ui.py (refactored) @@ -15,18 +15,18 @@ -from ui_toolBar import ToolBar -from ui_properties import PropertiesPanel -from ui_menu import MenuBar -from ui_statusBar import StatusBar -from trailer import Trailer ... +from .ui_toolBar import ToolBar +from .ui_properties import PropertiesPanel +from .ui_menu import MenuBar +from .ui_statusBar import StatusBar +from .trailer import Trailer ... -------------------------------------------- Of course the application don't run: from .ui_toolBar import ToolBar ValueError: Attempted relative import in non-package 2to3 help don't help me about that. Thank's for any advice. -- Vincent V.V. Oqapy . Qarte+7 . PaQager From rosuav at gmail.com Thu May 10 04:06:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 18:06:42 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: <20120510052117.GA32315@cskk.homeip.net> References: <20120510052117.GA32315@cskk.homeip.net> Message-ID: On Thu, May 10, 2012 at 3:21 PM, Cameron Simpson wrote: > On 10May2012 13:13, Chris Angelico wrote: > | The azet.sk MTA is behaving badly wrt bounced messages from > | python-list. Instead of sending them to the list software (where > | they'll result in the subscription being suspended), they're being > | sent to the original sender of the message. [...] > | I've already forwarded a bounce to abuse at azet.sk but have heard > | nothing back. This isn't the list's fault, but maybe the listowner can > | deal with the spam coming back. > > Try "postmaster". I'm not sure "abuse" is so widely implemented. Both are in the spec, but I usually find that postmaster is more often ignored. I'll re-send to postmaster tomorrow if the issue isn't solved. ChrisA From jameskhedley at gmail.com Thu May 10 04:06:47 2012 From: jameskhedley at gmail.com (james hedley) Date: Thu, 10 May 2012 01:06:47 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> > i have not banned anything, or even alluded to it, whatsoever. i asked that > one specific mail not be commented upon OK, sorry if I misunderstood, but that's still suppression in my book. > reading your accounts strewn about is interesting, what exactly are *your* motives? My motives are as I've stated; I'm a commercial user with products in development which use Pyjamas and that I have a long-term stake in. With a bit of thought, anyone should see why I value stability and continued viability. It's a long game but the potential payback to pyjamas could be huge *if* it can keep commercial users on board. This is where the existential threat to pyjamas comes from and why I and many others consider the takeover to be reckless and unjustified. > Luke is a talented developer, there is no doubt of this, but he is one of the most > socially inept persons i have ever encountered I don't think this is the right place to bash people or even defend them on a personal level. We get it though. You didn't get along with the guy. > the idea was to retain Luke I'm sorry but I don't believe this. Luke can speak for himself of course but this is not how you keep people on-board. > he decided to play legal threats as the first card He's claimed that you lifted data from his server without permission. I'm not commenting on that, but if it's true then this is a massive roadblock in the viability of the project. I for one don't want to be involved in it. Can you picture the scene where a developer or businessperaon goes into a meeting with very senior, very conservative executives trying to pitch a product, and it turns out there are serious legal concerns surrounding the technology platform? If it isn't true then perhaps you should put people's minds at rest by giving a detailed explanation of the whole mail server situation, including where the data originated, where it is now, how it got there and why the accidental mailing of so many people occurred. > indeed, you have witnessed little chatter I'd invite anyone to review the pyjamas list for the last 7 days before they make up their minds. Some of the statements I've seen have been regrettable. > by realizing this is not as black-and-white as you's like it to be. I have an ethical objection here, but moreover; it clearly just runs against my interests to support your actions. I'm not sure you considered the commercial users here, and with respect nor do I really get the impression you've understood it, still. By the way; I'm not associated with Luke at all. I've emailed him off-list a few times this week to discuss some angles to do with my work, but that's it. In fact, I support Kees' proposition that Pyjamas should seek sponsorship from the Python/Apache/Free Software Foundation. This would resolve questions of legitimacy and leadership. In my ideal outcome, we could tailor pyjamas more to business use; e.g. tidying up any license issues, offering a commercial support contract (this will help mitigate the damage done to perceptions of credibility), publishing a commercial use policy (one of the foundations could offer support with this I hope). James From jamespic at gmail.com Thu May 10 04:27:16 2012 From: jamespic at gmail.com (James Pic) Date: Thu, 10 May 2012 10:27:16 +0200 Subject: Uploaded package not pip installable Message-ID: Hello everybody, I uploaded a couple of packages: - http://pypi.python.org/pypi/django-cities-light/1.0 - http://pypi.python.org/pypi/django-autocomplete-light/0.1 But they are not pip installable: <<< 10:12.00 Thu May 10 2012!~ <<< jpic at germaine!10012 E:1 env >>> pip install django-autocomplete-light Downloading/unpacking django-autocomplete-light Could not find any downloads that satisfy the requirement django-autocomplete-light No distributions at all found for django-autocomplete-light Storing complete log in /home/jpic/.pip/pip.log <<< 10:20.47 Thu May 10 2012!~ <<< jpic at germaine!10012 E:1 env >>> pip install django-cities-light Downloading/unpacking django-cities-light Could not find any downloads that satisfy the requirement django-cities-light No distributions at all found for django-cities-light Storing complete log in /home/jpic/.pip/pip.log Any idea please ? Regards From steve+comp.lang.python at pearwood.info Thu May 10 04:50:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2012 08:50:42 GMT Subject: __doc__+= """Detailed description""" References: Message-ID: <4fab8161$0$29975$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 May 2012 02:36:29 +0000, Pierre Asselin wrote: > Hi. Started using python a few months back, still settling on my style. > I write docstrings and I use "pydoc mymodule" to refresh my memory. > > Problem: if I just docstring my classes/methods/functions the output of > pydoc more or less works as a reference manual, but if I get sidetracked > for even a few weeks I find that documentation inadequate when I return > to my code. I need to see some introductory context first, so that the > reference material makes sense. It's very difficult to give advice on how to write docstrings when you are talking in such sweeping generalities. Perhaps what you are doing is perfectly fine, and perhaps it is terrible, but without seeing it, how can I tell? Nevertheless, I make some attempt to answer your questions below, although my answers will also be sweeping generalities. > Wery well, write a module docstring then. The problem now: the many > paragraphs of detailed description at the top of the module get in the > way. The pydoc output is good, but the code becomes hard to read. This does not follow. How does a docstring make the code hard to read? Just scroll past the docstring and read the code. Most good editors will colour-code the docstring differently from the actual code, but even if you're using Notepad (shudders), how hard can it be to scroll past a few paragraphs, or pages, of explanatory text in a docstring? I don't understand the nature of your problem here. If your module needs an explanatory module-level docstring to explain what it does, just give it one. > So I come up with this: > > ###################################################################### > #! env python > > """One-liner docstring.""" Why a one-liner? Why not put the detailed description here? > # Many classes, methods, functions, attributes, # with docstrings as > needed. Docs tend to be # short and the code speaks for itself. # Apparently not, since you find the docs insufficient. Perhaps the solution is not to have a huge module docstring and classes with short docstring, but to document the class in the class docstring instead of the module. > ... > # Much further down, > > ___doc___+= """ > > Detailed description goes here. Provide some context, explain what > the classes are for and what the most important methods are, give > simple examples, whatever. Say enough to make the rest > understandable.""" This sounds to me like *exactly* the sort of thing which belongs in the documentation for the classes themselves. The module docstring should document a high-level introduction and show some examples. Detailed description of what the classes do should be in the class docstring, detailed documentation of methods should be in the method docstring, and so forth. Also, as Ben suggests, you don't *have* to put all your documentation in the source code. You can also have a separate documentation document, such as a website or wiki. > if __name__ == "__main__": > # test code follows > ###################################################################### Have you considered turning your tests (at least some of them) into doctests? That way they act as both test and documentation at the same time: executable examples, in the docstrings themselves. > It seems to work, too. But is that a sound way to write python? Am I > relying on undocumented implementation details or am I safe? Are you referring to the part where you define a __doc__ string at the top of the module, and then add to it with __doc__ += "more text"? If not, it isn't clear to me what you mean. -- Steven From research at johnohagan.com Thu May 10 05:16:36 2012 From: research at johnohagan.com (John O'Hagan) Date: Thu, 10 May 2012 19:16:36 +1000 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <20120510191636.e13251e8e8231bccfec4e3b9@johnohagan.com> On Wed, 09 May 2012 08:52:59 -0700 Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. I've done something similar using Fluidsynth (which I think is cross platform) to play the midi. It has the advantage that you can send it midi commands as simple human-readable strings over a socket, like: fluidsynth_socket.send("noteon 0 0 64 \n") making it easy to do things on the fly withoutwriting/reading midi files. On Linux I've found just using: time.sleep(correct_time - time.time()) before sending is accurate to the millisecond, but I understand you have to specify a (hardware) timer to achieve this for Windows. > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to > the other program's MIDI in. > I haven't used it but python-pypm looks about right: "pyPortMidi is a Python wrapper for PortMidi. PortMidi is a cross-platform C library for realtime MIDI control. Using pyPortMidi, you can send and receive MIDI data in realtime from Python. "Besides using pyPortMidi to communicate to synthesizers and the like, it is possible to use pyPortMidi as a way to send MIDI messages between software packages on the same computer." HTH, John From breamoreboy at yahoo.co.uk Thu May 10 05:31:41 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 10:31:41 +0100 Subject: Real time event accuracy In-Reply-To: References: Message-ID: On 09/05/2012 16:52, Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. > For an idea of how difficult timing can be, search the Python development mailing list for PEP 418 and associated threads. Make sure you have a large supply of sandwiches and coffee cos you'll need it :) > Thanks, > > Tobiah -- Cheers. Mark Lawrence. From d.poreh at gmail.com Thu May 10 05:58:55 2012 From: d.poreh at gmail.com (d.poreh at gmail.com) Date: Thu, 10 May 2012 02:58:55 -0700 (PDT) Subject: which book? In-Reply-To: <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> Message-ID: <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote: > > I am going to learn python for some plot issues. which book or sources, do you recommend please? > The tutorial is pretty good if you already know how to program. > I also heard a lot of good things on "Python Essential Reference". Thanks. Could you please pass the line for tutorial? From jeanmichel at sequans.com Thu May 10 06:47:00 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 10 May 2012 12:47:00 +0200 Subject: __doc__+= """Detailed description""" In-Reply-To: References: Message-ID: <4FAB9CA4.4020109@sequans.com> Pierre Asselin wrote: > Hi. Started using python a few months back, still settling on my style. > I write docstrings and I use "pydoc mymodule" to refresh my memory. > > Problem: if I just docstring my classes/methods/functions the > output of pydoc more or less works as a reference manual, but if > I get sidetracked for even a few weeks I find that documentation > inadequate when I return to my code. I need to see some introductory > context first, so that the reference material makes sense. > > Wery well, write a module docstring then. The problem now: the > many paragraphs of detailed description at the top of the module > get in the way. [snip] How is that a problem ? Having a well detailed description of a module at the top is just fine. If only all modules featured such documentation, the world would be a better place. Cheers, JM From jabba.laci at gmail.com Thu May 10 08:14:47 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 10 May 2012 14:14:47 +0200 Subject: parallel programming in Python Message-ID: Hi, I would like to do some parallel programming with Python but I don't know how to start. There are several ways to go but I don't know what the differences are between them: threads, multiprocessing, gevent, etc. I want to use a single machine with several cores. I want to solve problems like this: iterate over a loop (with millions of steps) and do some work at each step. The steps are independent, so here I would like to process several steps in parallel. I want to store the results in a global list (which should be "synchronised"). Typical use case: crawl webpages, extract images and collect the images in a list. What's the best way? Thanks, Laszlo From d at davea.name Thu May 10 08:34:26 2012 From: d at davea.name (Dave Angel) Date: Thu, 10 May 2012 08:34:26 -0400 Subject: parallel programming in Python In-Reply-To: References: Message-ID: <4FABB5D2.3090808@davea.name> On 05/10/2012 08:14 AM, Jabba Laci wrote: > Hi, > > I would like to do some parallel programming with Python but I don't > know how to start. There are several ways to go but I don't know what > the differences are between them: threads, multiprocessing, gevent, > etc. > > I want to use a single machine with several cores. I want to solve > problems like this: iterate over a loop (with millions of steps) and > do some work at each step. The steps are independent, so here I would > like to process several steps in parallel. I want to store the results > in a global list (which should be "synchronised"). Typical use case: > crawl webpages, extract images and collect the images in a list. > > What's the best way? > > Thanks, > > Laszlo There's no single best-way. First question is your programming environment. That includes the OS you're running, and the version # and implementation of Python. I'll assume you're using CPython 2.7 on Linux, which is what I have the most experience on. But after you answer, others will probably make suggestions appropriate to whatever you're actually using Next question is whether the problem you're solving at any given moment is cpu-bound or i/o bound. I'll try to answer for both cases, here. CPU-bound: In CPython 2.7, there's a GIL, which is a global lock preventing more than one CPU-bound thread from running at the same time. it's more complex than that, but bottom line is that multiple threads won't help (and might hurt) a CPU-bound program, even in a multi-core situation. So use multiple processes, and cooperate between them with queues or shared memory, or even files. In fact, you can use multiple computers, and communicate using sockets, in many cases. IO-bound: This is what CPython is good at solving with threads. Once you make a blocking I/O call, usually the C code involves releases the GIL, and other threads can run. For this situation, the fact that you can share data structures makes threads a performance win. Web crawling is likely to be IO-bound, but i wanted to be as complete as I could. -- DaveA From jeanpierreda at gmail.com Thu May 10 08:46:01 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 10 May 2012 08:46:01 -0400 Subject: parallel programming in Python In-Reply-To: References: Message-ID: On Thu, May 10, 2012 at 8:14 AM, Jabba Laci wrote: > What's the best way? >From what I've heard, http://scrapy.org/ . It is a single-thread single-process web crawler that nonetheless can download things concurrently. Doing what you want in Scrapy would probably involve learning about Twisted, the library Scrapy works on top of. This is somewhat more involved than just throwing threads and urllib and lxml.html together, although most of the Twisted developers are really helpful. It might not be worth it to you, depending on the size of the task. Dave's answer is pretty general and good though. -- Devin From jabba.laci at gmail.com Thu May 10 08:46:31 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 10 May 2012 14:46:31 +0200 Subject: parallel programming in Python In-Reply-To: <4FABB5D2.3090808@davea.name> References: <4FABB5D2.3090808@davea.name> Message-ID: Hi, Thanks for the answer. I use Linux with CPython 2.7. I plan to work with CPU bound and I/O bound problems too. Which packages to use in these cases? Could you redirect me to some guides? When to use multiprocessing / gevent? Thanks, Laszlo On Thu, May 10, 2012 at 2:34 PM, Dave Angel wrote: > On 05/10/2012 08:14 AM, Jabba Laci wrote: >> Hi, >> >> I would like to do some parallel programming with Python but I don't >> know how to start. There are several ways to go but I don't know what >> the differences are between them: threads, multiprocessing, gevent, >> etc. >> >> I want to use a single machine with several cores. I want to solve >> problems like this: iterate over a loop (with millions of steps) and >> do some work at each step. The steps are independent, so here I would >> like to process several steps in parallel. I want to store the results >> in a global list (which should be "synchronised"). Typical use case: >> crawl webpages, extract images and collect the images in a list. >> >> What's the best way? >> >> Thanks, >> >> Laszlo > > There's no single best-way. ?First question is your programming > environment. ?That includes the OS you're running, and the version # and > implementation of Python. > > I'll assume you're using CPython 2.7 on Linux, which is what I have the > most experience on. ?But after you answer, others will probably make > suggestions appropriate to whatever you're actually using > > Next question is whether the problem you're solving at any given moment > is cpu-bound or i/o bound. ?I'll try to answer for both cases, here. > > CPU-bound: > In CPython 2.7, there's a GIL, which is a global lock preventing more > than one CPU-bound thread from running at the same time. ?it's more > complex than that, but bottom line is that multiple threads won't help > (and might hurt) a CPU-bound program, even in a multi-core situation. > So use multiple processes, and cooperate between them with queues or > shared memory, or even files. In fact, you can use multiple computers, > and communicate using sockets, in many cases. > > IO-bound: > This is what CPython is good at solving with threads. ?Once you make a > blocking I/O call, usually the C code involves releases the GIL, and > other threads can run. ?For this situation, the fact that you can share > data structures makes threads a performance win. > > Web crawling is likely to be IO-bound, but i wanted to be as complete as > I could. > > -- > > DaveA > From andreas.tawn at ubisoft.com Thu May 10 09:33:03 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 10 May 2012 15:33:03 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Say I've got a class... class test(object): def __init__(self): self.foo = 1 self.bar = 2 self.baz = 3 I can say... def __str__(self): return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) and everything's simple and clean and I can vary the formatting if I need to. This gets ugly when the class has a lot of attributes because the string construction gets very long. I can do... return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) which is an improvement, but there's still a very long line. And there's also something like... return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) Is there a better way? Cheers, Drea p.s. I may want to substitute __repr__ for __str__ perhaps? From bahamutzero8825 at gmail.com Thu May 10 09:33:09 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 10 May 2012 08:33:09 -0500 Subject: Pydev configuration In-Reply-To: <4FAAE0BE.5080307@gmail.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> <1336562181117-4962800.post@n6.nabble.com> <4FAAE0BE.5080307@gmail.com> Message-ID: <4FABC395.5020705@gmail.com> On 5/9/2012 4:25 PM, Alan Ristow wrote: > Select the code block you want to indent and hit Tab. To do the reverse, > hit Shift-Tab. You can also select a code block and choose "Shift Right" or "Shift Left" from the context menu. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From p.f.moore at gmail.com Thu May 10 09:46:19 2012 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 10 May 2012 06:46:19 -0700 (PDT) Subject: Instrumenting a class to see how it is used Message-ID: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> I'm trying to reverse-engineer some pretty complex code. One thing that would help me a lot is if I could instrument a key class, so that I'd get a report of when and how each method was called and any properties or attributes were accessed during a typical run. I could do this relatively easily by just adding print calls to each method/attribute, but I was wondering - is there a library that does this sort of wrapping already? I tried writing my own but got bogged down in infinite recursion in _getattribute__ and couldn't see an easy way out. If anyone has any suggestions, I'd be interested. Thanks, Paul. From jhnwsk at gmail.com Thu May 10 09:47:11 2012 From: jhnwsk at gmail.com (John) Date: Thu, 10 May 2012 15:47:11 +0200 Subject: Python SOAP library References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: W dniu 2012-05-02 17:35, Alec Taylor pisze: > Would you recommend: http://code.google.com/p/soapbox/ > > Or suggest another? I am having lots of fun and positive experience with https://github.com/arskom/rpclib Awesome doc and example code and, most importantly, it works! :) -- John From g.rodola at gmail.com Thu May 10 10:26:25 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 10 May 2012 16:26:25 +0200 Subject: Creating a Windows installer for Python + a set of dependencies Message-ID: Hi all, I need to create an installer for Windows which should be able to install a specific version of the Python interpreter (2.7) plus a set a dependencies such as ipython, numpy, pandas, etc. Basically this is the same thing Active State did for their Active Python distribution: a single bundle including interpreter + deps. Not being a Windows user I'm not sure where to start with this except maybe looking into NSIS (could that be of any help?). Thanks in advance, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From g2mahendra at gmail.com Thu May 10 10:31:39 2012 From: g2mahendra at gmail.com (Mahendra) Date: Thu, 10 May 2012 07:31:39 -0700 (PDT) Subject: Python ABAQUS debugging problem. Message-ID: Dear all, I am learning to use python script for running ABAQUS (commerical finite element program). I am having a bug in the following chunk of code and am not sure what it is. I have three loops in my code. The first two loops work fine. The third loop is a combination of loop 1 and loop 2. It doesnt work. There is some syntax issue which it is not clear to me. #--------------------------#-------------------# # Creating a list of moduli for parametric study moduli = [ 1000, 500] #--------------------------#-------------------# # This loop works fine for E in moduli: print E lengthE='length'+str(E) print lengthE #--------------------------#-------------------# #--------------------------#-------------------# # This loop works fine. for E in moduli: # lengthE = 'length'+str(E) # print E # print lengthE mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, 0.18), )) job.submit() job.waitForCompletion() print 'Completed job for %s E' % (E) #--------------------------#-------------------# #--------------------------#-------------------# # This loop doesnt work. # It says syntax error in lengthE = 'length' + str(E) #--------------------------#-------------------# for E in moduli: print E lengthE = 'length' + str(E) mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, 0.18), )) job.submit() job.waitForCompletion() # print lengthE print 'Completed job for %s E' % (E) #--------------------------#-------------------# Any help is deeply appreciated in this regard. Sincerely, Mahendra. From rosuav at gmail.com Thu May 10 10:33:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 00:33:13 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn wrote: > Say I've got a class... > > class test(object): > ? ?def __init__(self): > ? ? ? ?self.foo = 1 > ? ? ? ?self.bar = 2 > ? ? ? ?self.baz = 3 > > I can say... > > def __str__(self): > ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) This might be of use: return """foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) You're repeating yourself a bit, but this allows the labels to differ from the format tags. If you're certain that you don't need that flexibility, you could generate the format string dynamically: return "\n".join(x+": {"+x+"}" for x in ("foo","bar","baz")).format(**self.__dict__) That scales more nicely as the number of elements desired increases (while still being 100% explicit - the presence and order of elements is governed by the tuple), but is a bit inflexible and complicated. I'd be inclined toward the triple-quoted-string one. Tim Toady. ChrisA From g2mahendra at gmail.com Thu May 10 10:37:43 2012 From: g2mahendra at gmail.com (Mahendra) Date: Thu, 10 May 2012 07:37:43 -0700 (PDT) Subject: Python ABAQUS debugging problem. References: Message-ID: <4d25a4fe-cf29-434d-a856-0fcfb6caa0c9@g6g2000pbq.googlegroups.com> On May 10, 9:31?am, Mahendra wrote: > Dear all, > ? ? ? ? ? ? I am learning to use python script for running ABAQUS > (commerical finite element program). I am having a bug in the > following chunk of code and am not sure what it is. I have three loops > in my code. The first two loops work fine. The third loop is a > combination of loop 1 and loop 2. It doesnt work. There is some syntax > issue which it is not clear to me. > > #--------------------------#-------------------# > # Creating a list of moduli for parametric study > moduli = [ 1000, 500] > > #--------------------------#-------------------# > # This loop works fine > > for E in moduli: > ? ? print E > ? ? lengthE='length'+str(E) > ? ? print lengthE > #--------------------------#-------------------# > > #--------------------------#-------------------# > # This loop works fine. > > for E in moduli: > # ? lengthE = 'length'+str(E) > # ? ? ? print E > # ? ? ? print lengthE > > mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, > 0.18), )) > ? ? ? ? job.submit() > ? ? ? ? job.waitForCompletion() > ? ? ? ? print 'Completed job for %s E' % (E) > #--------------------------#-------------------# > > #--------------------------#-------------------# > # This loop doesnt work. > # It says syntax error in lengthE = 'length' + str(E) > #--------------------------#-------------------# > for E in moduli: > ? ? print E > ? ? ? ? lengthE = 'length' + str(E) > > mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, > 0.18), )) > ? ? ? ? job.submit() > ? ? ? ? job.waitForCompletion() > # ? ? ? print lengthE > ? ? ? ? print 'Completed job for %s E' % (E) > #--------------------------#-------------------# > > Any help is deeply appreciated in this regard. > Sincerely, > Mahendra. I think when I pasted the message from the code in this email, the indentation is little off. I used notepad++ for writing the code. It didnt show wrong indentation. However, on notepad it is wrongly indented. The program is working now. Thanks for your time and sorry for the inconvenience. Mahendra. From rkraats at dds.nl Thu May 10 11:09:16 2012 From: rkraats at dds.nl (Roel van de Kraats) Date: Thu, 10 May 2012 17:09:16 +0200 Subject: Running embedded python shell on a separate thread Message-ID: <4FABDA1C.5050008@dds.nl> For those who are interested, In an application I am working on, an embedded python shell needs to be run on a separate thread, since the main thread is already 'taken' (by Qt). This causes an issue with handling SIGINT (Control-C) when using the readline package; the 'KeyboardInterrupt' is only shown/handled after pressing . With a work-around, I was able to get this working 'normally' without modifying the python code itself, which I want to share with you. For completeness, I'm using Python 2.6.5 on Ubuntu Lucid. Our application is in C++. The problem is that Control-C causes a SIGINT signal to be sent to the main/initial thread. Python's signal handler (signal_handler in Modules/signalmodule.c) handles this signal by marking that it occurred and adding a 'pending call'. But the readline functionality (readline_until_enter_or_signal in Modules/readline.c) only notices this when select() returns errno==EINTR. That is, when select() itself was interrupted. And that only happens when the SIGINT signal is sent to the thread on which readline is running. The work-around I made was to install my own SIGINT signal handler with this functionality: - When it receives a signal on a thread different from the 'python' thread, it uses pthread_kill() to forward the signal to that 'python' thread. - When it receives a signal on the 'python' thread, it temporarily restores the 'python' signal handler and raises the signal again. Installing the signal handler is done by a wrapper around the readline function, through the PyOS_ReadlineFunctionPointer hook. My application code (simplified C++) can be found below. I guess all these 'hacks' could be prevented when Python's own signal handler would forward the SIGINT signal (or any signal) to the 'python' thread. Kind regards, Roel van de Kraats typedef void (*sighandler_t)(int); // don't use PyOS_setsig() since we need the SA_NODEFER flag int set_sighandler(int sig, sighandler_t handler, sighandler_t * old_handler = NULL, int flags = SA_NODEFER) { struct sigaction action; struct sigaction oldaction; memset(&action, 0, sizeof(action)); memset(&oldaction, 0, sizeof(oldaction)); action.sa_handler = handler; action.sa_flags = flags; int ret = sigaction(sig,&action,&oldaction); if (old_handler) { *old_handler = oldaction.sa_handler; } return ret; } sighandler_t old_int_signal_handler; void int_signal_handler(int) { if ( this_is_the_python_thread() ) { static volatile bool calling = false; // for error checking if (calling) { // unexpected recursive call return; } calling = true; sighandler_t prev_handler; // restore original handler (void)set_sighandler(SIGINT, old_int_signal_handler,&prev_handler); if (prev_handler != int_signal_handler) { // expected int_signal_handler return; } // raise signal which will be handled by the original handler ::pthread_kill(_python_thread_id, SIGINT); // install our handler again (void)set_sighandler(SIGINT, int_signal_handler); calling = false; } else { // not meant for this thread; redirect to python thread ::pthread_kill(_python_thread_id, SIGINT); } } char *(*old_readline)(FILE *, FILE *, char *); char * my_readline(FILE * a1, FILE * a2, char * a3) { // replace signal handler (void)set_sighandler(SIGINT, int_signal_handler,&old_int_signal_handler); char * ret = (*old_readline)(a1, a2, a3); // restore original handler (void)set_sighandler(SIGINT, old_int_signal_handler, NULL, 0); return ret; } void python_thread_function() { Py_Initialize(); // some other initialization stuff here // make sure readline is initialized before we replace the readline function PyRun_SimpleString("import readline\n"); old_readline = PyOS_ReadlineFunctionPointer; if (old_readline) { PyOS_ReadlineFunctionPointer = my_readline; } else { // PyOS_ReadlineFunctionPointer was not set so don't replace } // the python prompt appears now... int ret = PyRun_InteractiveLoop(stdin, ""); Py_Exit(ret); } From andreas.tawn at ubisoft.com Thu May 10 11:15:12 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 10 May 2012 17:15:12 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> > On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn > wrote: > > Say I've got a class... > > > > class test(object): > > ? ?def __init__(self): > > ? ? ? ?self.foo = 1 > > ? ? ? ?self.bar = 2 > > ? ? ? ?self.baz = 3 > > > > I can say... > > > > def __str__(self): > > ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, > > self.baz) > > This might be of use: > > return """foo: {foo} > bar: {bar} > baz: {baz}""".format(**self.__dict__) > > You're repeating yourself a bit, but this allows the labels to differ from the format > tags. If you're certain that you don't need that flexibility, you could generate the > format string dynamically: > > return "\n".join(x+": {"+x+"}" for x in > ("foo","bar","baz")).format(**self.__dict__) > > That scales more nicely as the number of elements desired increases (while still > being 100% explicit - the presence and order of elements is governed by the tuple), > but is a bit inflexible and complicated. > I'd be inclined toward the triple-quoted-string one. I considered the triple quote string one, but it's not very PEP 8 compatible in a real class because it includes the indentation in the formatted string. To make it print properly, it has to look like this... def __str__(self): return """foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) I didn't realise I could do implicit line continuation inside a list comprehension. That might be the best way. Even more so with continuation lines inside the attribute name tuple. def __str__(self): return "\n".join(x+": {"+x+"}" for x in ("foo", "bar", "baz")).format(**self.__dict__) Still feels a bit icky though. From torriem at gmail.com Thu May 10 12:01:04 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 May 2012 10:01:04 -0600 Subject: parallel programming in Python In-Reply-To: References: Message-ID: <4FABE640.4030805@gmail.com> On 05/10/2012 06:46 AM, Devin Jeanpierre wrote: > On Thu, May 10, 2012 at 8:14 AM, Jabba Laci wrote: >> What's the best way? > >>From what I've heard, http://scrapy.org/ . It is a single-thread > single-process web crawler that nonetheless can download things > concurrently. Yes, for i/o bound things, asynchronous (event-driven callbacks, where events are triggered by the data) will usually beat multi-threaded. Sometimes a combination of multi-threaded and asynchronous is necessary (thread pools). Twisted is another asynchronous framework core that is very popular for lots of things, both clients and servers. From gridsngators at gmail.com Thu May 10 12:07:39 2012 From: gridsngators at gmail.com (ks) Date: Thu, 10 May 2012 09:07:39 -0700 (PDT) Subject: Alternative to subprocess in order to not wait for calling commands to complete Message-ID: Hi All, >From within one Python program, I would like to invoke three other Python programs. Usually I would use the subprocess module to invoke these sequentially. I now have a use case in which I must invoke the first one (not wait for it to complete), then invoke the second (similarly not wait for it to complete) and then go on to the third. I am not sure where I should start looking to be able to do this. I am reading about threads and forking and there are many options out there. So I was wondering if anyone might have suggestions on where I can start. Any hints/references would be very helpful! Thank you, ks From michele.simionato at gmail.com Thu May 10 12:08:33 2012 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 10 May 2012 09:08:33 -0700 (PDT) Subject: Instrumenting a class to see how it is used In-Reply-To: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> References: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> Message-ID: <17323732.904.1336666113137.JavaMail.geo-discussion-forums@vbvx4> This may get you started (warning: not really tested). $ echo instr.py from warnings import warn oget = object.__getattribute__ tget = type.__getattribute__ class Instr(object): class __metaclass__(type): def __getattribute__(cls, name): clsname = tget(cls, '__name__') warn('accessing %s.%s' % (clsname, name), stacklevel=2) return tget(cls, name) def __getattribute__(self, name): warn('accessing %s.%s' % (self, name), stacklevel=2) return oget(self, name) Then change the base classes of the class you want to instrument, i.e. class MyClass(MyBase) -> class MyClass(MyBase, Instr) and see what happens. It should work in simple cases. It will log a lot, so will have to adapt this. From roel at roelschroeven.net Thu May 10 13:06:14 2012 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 10 May 2012 19:06:14 +0200 Subject: Problem with time.time() standing still In-Reply-To: <4FA93EE5.4040200@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> <4FA900CD.7070604@bobcowdery.plus.com> <4FA93EE5.4040200@bobcowdery.plus.com> Message-ID: Hi Bob, This reminds of a problem we had at work some years ago. I've followed the thread from the beginning, but I hadn't a clue about what could possibly cause the problem until you said: Bob Cowdery schreef: > Hopefully somebody can add the last piece of this puzzle. My code didn't > work because I did make a silly mistake. The number of seconds since > EPOC is a large number but it also needs a high precision. Attempting to > put this value into a 32 bit float corrupts the least significant part > because 24 bits cannot hold that precision. Now Python floats are C > doubles and the calculation in timemodule.c is in doubles right back to > Python. Normally this retains the precision. For some inexplicable > reason when I make certain calls into this vendors SDK, ftime() is > getting precision problems and appears to be frozen as a result. Our problem turned out to be caused by a loss of precision in an application of ours, caused by Direct3D. The solution for us was to include the flag D3DCREATE_FPU_PRESERVE in CreateDevice(). The documentation seems to imply that the lower precision only has effect in the Direct3D code, but in reality it lowers precision in the rest of the code too (the whole process or the whole thread, I'm not sure). In your case it seems harder to solve: as far as I understand, the trigger is somewhere in the vendors SDK, which you have no control over. I'm afraid I don't know what you can do about that. Best regards, Roel -- "The reasonable man adapts himself to the world. The unreasonable man persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw roel at roelschroeven.net http://roelschroeven.net From nad at acm.org Thu May 10 13:55:05 2012 From: nad at acm.org (Ned Deily) Date: Thu, 10 May 2012 10:55:05 -0700 Subject: Mailing list assistance: manual unsubscribing of failed recipient? References: Message-ID: In article , Chris Angelico wrote: > Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? http://mail.python.org/mailman/listinfo/python-list -- Ned Deily, nad at acm.org From askutt at gmail.com Thu May 10 13:58:48 2012 From: askutt at gmail.com (Adam Skutt) Date: Thu, 10 May 2012 10:58:48 -0700 (PDT) Subject: Alternative to subprocess in order to not wait for calling commands to complete References: Message-ID: On May 10, 12:07?pm, ks wrote: > Hi All, > > From within one Python program, I would like to invoke three other > Python programs. Usually I would use the subprocess module to invoke > these sequentially. I now have a use case in which I must invoke the > first one (not wait for it to complete), then invoke the second > (similarly not wait for it to complete) and then go on to the third. > > I am not sure where I should start looking to be able to do this. I am > reading about threads and forking and there are many options out > there. So I was wondering if anyone might have suggestions on where I > can start. > subprocess.Popen objects only block for process termination when you request it, via wait() or communicate(). As such, if you never call those methods, you will never block for process termination. What you want is essentially the default behavior if you're creating Popen objects directly (instead of using the call() function). However, you must call the wait() or poll() methods at least once, after the subprocess has terminated, to release system resources. There are many ways to accomplish this, and the best approach depends on your application. One simple option is to call poll() once each time your application goes through its main loop. Another option is to use a dedicated thread for the purpose of reaping processes. Please note that calling Popen.poll() in a loop over many processes does not scale (each call incurs an expensive system call) and will cause noticeable CPU consumption with even a handful of processes (3 is just fine, though). Unfortunately, the subprocess module lacks any way to wait on multiple processes simultaneously. This is possible with operating-system specific code, however. I would not worry about it for now, but it may be something you need to consider in the future. Adam From wescpy at gmail.com Thu May 10 14:07:01 2012 From: wescpy at gmail.com (wesley chun) Date: Thu, 10 May 2012 11:07:01 -0700 Subject: ANN: Intro+Intermediate Python, San Francisco, Aug 1-3 Message-ID: Greetings! I'll be doing another hardcore Python course this summer in the San Francisco area. If you're somewhat new to Python or have tinkered but want to fill-in the holes, this course is for you. It's somewhat true you can learn Python online, watching videos, or reading books, but it still takes time and experience to master... I help accelerate this process. The course is based on my bestselling "Core Python" books and is made up of 3 full days complete with lectures and three hands-on coding labs per day. Please pass on this message to your colleagues who also need to learn Python. It's also a great excuse to coming to beautiful Northern California for a summer vacation! More details at http://goo.gl/uW4oF as well as the links in my .signature below. Since I hate spam, I'll only send out one more reminder as the date gets closer... probably around OSCON's timeframe. Hope to meet some of you soon! --Wesley Chun - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "A computer never does what you want... only what you tell it." ? ? wesley chun : wescpy at gmail?: @wescpy/+wescpy ? ? Python training & consulting :?http://CyberwebConsulting.com ? ? "Core Python" books :?http://CorePython.com ? ? Python blog: http://wescpy.blogspot.com From samdansobe at yahoo.com Thu May 10 16:55:40 2012 From: samdansobe at yahoo.com (Sammy Danso) Date: Thu, 10 May 2012 13:55:40 -0700 (PDT) Subject: Help with how to combine two csv files Message-ID: <1336683340.71877.YahooMailClassic@web161202.mail.bf1.yahoo.com> Hi JM and All, Thank you all very much for your response and help. I managed to work out the problem eventually. But my code is ridiculously long compared to what you have just offered here. I think your code is elegant and should be much faster.? Thanks? a lot Sammy ? Below is my code. ? ?outputfile = codecs.open(csvfile3, 'wb') ?inputfile1 =? codecs.open(csvfile1, 'rb') ?inputfile2 = codecs.open(csvfile2, 'rb') ???????????? ??????????????? ???????????????? dictreader2 = csv.DictReader(inputfile2) ???????????????? dictreader1 = csv.DictReader(inputfile1) ???????????????? mergedDict = {} ???????????????? ???????????????? mergedDictb = {} ???????????????? matchedlistA = [] ???????????????? matchedlistB = [] ???????????????? matchedlist = [] ???????????????? cnt = 0 ???????????????? cntb = 0 ???????????????? for dictline1 in dictreader1: ?????????????????????????cnt? += 1 ???????????????????????? print cnt ???????????????????????? mergedDict = dictline1.copy() ???????????????????????? mergedDict['UniqID']=? cnt ????????????????????????? matchedlistA.append(mergedDict) ???????????????????????? ??????????????? ???????????????? for dictline2 in dictreader2: ????????????????????????? cntb? += 1 ????????????????????????? mergedDictb = dictline2.copy() ????????????????????????? mergedDictb['UniqID']=? cntb ????????????????????????? matchedlistB.append(mergedDictb) ???????????????????????? ?????????????? ???????????????? for dictline1 in matchedlistA: ??????????????????? for dictline2 in matchedlistB: ??????????????????????? if dictline1['UniqID'] == dictline2['UniqID']: ??????????????????????????? entry = dictline1.copy() ??????????????????????????? entry.update(dictline2) ??????????????????????????? matchedlist.append(entry) ? ? --- On Wed, 5/9/12, Jean-Michel Pichavant wrote: From: Jean-Michel Pichavant Subject: Re: Help with how to combine two csv files To: "Sammy Danso" Cc: python-list at python.org Date: Wednesday, May 9, 2012, 11:23 AM Sammy Danso wrote: > Hello Experts, > I am new to python and I have been trying to merge two csv files, and upon several hours of unsuccessful attempts, I have decided to seek for help. >? the format of the file is as follows. file A has? columns a, b, c and values 1,2,3 for several rows. File B also has columns d,e and values 4,5? for same number of rows as A. the files however do not have any unique column between the two. > I want an output file C to have columns? a,b,c,d,e with values 1,2,3,4,5 >? I would be very grateful for your help with some code. >? Thanks very much, > Sammy > Post some code so we may point at your problem. The solution is easy, the code very small. Something like (pseudo code): import csv writer = csv.writer(file3) for index, row in enumerate(csv.reader(file1)): ???writer.writerow(row + csv.reader(file2)[index]) JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 17:39:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 07:39:15 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 3:55 AM, Ned Deily wrote: > In article > , > ?Chris Angelico wrote: >> Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? > > http://mail.python.org/mailman/listinfo/python-list Doh! I checked the top of that page ("We" this and "We" that) but didn't see the bit at the bottom with email addresses. Whoops! Thanks Ned. ChrisA From rosuav at gmail.com Thu May 10 17:47:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 07:47:03 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Fri, May 11, 2012 at 1:15 AM, Andreas Tawn wrote: > I considered the triple quote string one, but it's not very PEP 8 compatible in a real class because it includes the indentation in the formatted string. Yeah, that is an annoying side effect. My personal view is that code should be written concisely, even if that means violating indentation. One possible way around that is to break out the format string to a module variable (thus completely unindented); another way is to accept the indentation, for instance: def __str__(self): return """test(): foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) resulting in a string that has a somewhat Pythonic syntax to it. Would work nicely if you have a few "primary" attributes that go onto the first line, and a bunch of "secondary" attributes that get listed below. ChrisA From bob at bobcowdery.plus.com Thu May 10 18:10:42 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Thu, 10 May 2012 23:10:42 +0100 Subject: Problem with time.time() standing still Message-ID: <4FAC3CE2.4080409@bobcowdery.plus.com> Hi Roel "Our problem turned out to be caused by a loss of precision in an application of ours, caused by Direct3D. The solution for us was to include the flag D3DCREATE_FPU_PRESERVE in CreateDevice(). The documentation seems to imply that the lower precision only has effect in the Direct3D code, but in reality it lowers precision in the rest of the code too (the whole process or the whole thread, I'm not sure). " That is spot on and very likely the cause. Thanks very much for responding. I do have some control over the vendor and have passed that information on to them. Hopefully they will investigate and fix the problem. Bob From ethan at stoneleaf.us Thu May 10 18:38:04 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 10 May 2012 15:38:04 -0700 Subject: ANN: dbf version 0.92.002 released Message-ID: <4FAC434C.40304@stoneleaf.us> Available at http://pypi.python.org/pypi/dbf Fixed issue with Memo fields not returning correct unicode data. Updated many docstrings. Nulls now fully supported. Getting closer to a 1.0 (non-beta!) release; working on PEP 8 compliance, index files, and actual documentation. Biggest change ============== records no longer auto-update back to disk; make sure and use record.write_record() if you want the on-disk version of the table updated, or use the new Write generator which calls .write_record() before returning the next record in the table/list/index/whatever. As always, comments and bug-reports appreciated! From ethan at stoneleaf.us Thu May 10 18:52:10 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 10 May 2012 15:52:10 -0700 Subject: PyPI is being spammed Message-ID: <4FAC469A.1090601@stoneleaf.us> with Dr Sultan Spells of various natures. Can anybody put a stop to that? ~Ethan~ From cyborgv2 at hotmail.com Thu May 10 19:36:00 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 00:36:00 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4FAB205B.8000804@gmail.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , <4FAB205B.8000804@gmail.com> Message-ID: Hi ya, Please don't attack me or pull me into the centre of this conflict... I don't have any idea of what is really happening here; other than that I've read on the python-list mailing list. Your right, I have never released any code, under any license of any description. I have only offered snippets of code to people/projects to be used as they see fit (besides my professional developments and private projects.) All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor have ever had any prior contact with) about releasing code under a license... And, what I said stands: once anyone releases code, they are bound by the license they released it under as much as anyone else that may use it and cannot then withdraw that code from the domain they released it to (except by maybe creating a new and different version.) Being dyslexic, my message (and this one) may not be worded in the best way but that is no reason to start on me! Date: Wed, 9 May 2012 22:56:43 -0300 From: ricaraoz at gmail.com To: cyborgv2 at hotmail.com Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack On 09/05/12 20:04, Adrian Hunt wrote: Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!!!!!! Sorry, but you are not being accurate. "You" don't release code under a license, James Tauber did, or the Google Web Toolkit did. So you are in no positon to "think better of it" even if it was allowed to the original releaser. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 19:57:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 09:57:49 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> <4FAB205B.8000804@gmail.com> Message-ID: On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > have ever had any prior contact with) about releasing code under a > license... And, what I said stands: once anyone releases code, they are > bound by the license they released it under as much as anyone else that may > use it and cannot then withdraw that code from the domain they released it > to (except by maybe creating a new and different version.) And that's absolutely correct. Open source licenses are deliberately worded to guarantee rights in perpetuity, so there's no way to withdraw it or change the license (though of course a copyright owner can release the same code under an additional license). > Being dyslexic, my message (and this one) may not be worded in the best way > but that is no reason to start on me! Your message is fine. Believe you me, I'd much rather read a message posted by a non-native English speaker, or a dyslexic person, or someone who has a clinical aversion to the letter 'q', than someone who's simply sloppy and doesn't care about their language at all. Chris Angelico From cyborgv2 at hotmail.com Thu May 10 20:04:51 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 01:04:51 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , , Message-ID: Hi there, Yes, it's very messy by what I understand and is why Merlio never had it's judgements enforced. Although, employment contracts that were in place at the time (including mine), were declared null and void... I think it was something like: if a programmer has an idea and uses it within an employers project then the employer has a legal claim to that implementation but not to the original idea. And, a contract that claims IP rights would stop a developer from ever working again as a programmer: this again, being illegal and making the contract null and void. With internationalization, the problem is compounded as different countries have different laws. Since my days at Merlio, I have managed to avoid singing any contract that claims IP and I have worked for some large international companies (from within the UK.) > Date: Thu, 10 May 2012 10:27:27 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: > > Google was a right PITA but eventually I found this > > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ > > It appears to contradict what you've said above, or have I misread it? E.g > > "Under the (Patents) Act (1977), there is a presumption that an employer > > will own the patent of an invention made by its employee if the invention > > was made in the employee?s normal or specifically assigned duties and > > either, an invention might reasonably be expected to result from such duties > > or, the employee has a special obligation to further the employee?s > > interests, arising from the nature of those duties and responsibilities and > > the employee?s status." > > That's patents... intellectual property goes by other rules I think. I > am not a lawyer, and I try to avoid getting placed in any position > where this sort of thing will come up, because it's messy... > especially with internationalization. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From memilanuk at gmail.com Thu May 10 20:12:11 2012 From: memilanuk at gmail.com (Monte Milanuk) Date: Thu, 10 May 2012 17:12:11 -0700 Subject: Looking for video/slides from PyCon 2011... Message-ID: ...specifically the two lectures on creating GUI applications with Python + QT http://us.pycon.org/2011/schedule/presentations/207/ Various searches on the 'Net don't seem to be turning up much... kinda curious as to why? Anyone here know? TIA, Monte From cs at zip.com.au Thu May 10 20:15:35 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 11 May 2012 10:15:35 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <20120511001535.GA8056@cskk.homeip.net> On 10May2012 15:33, Andreas Tawn wrote: | Say I've got a class... | | class test(object): | def __init__(self): | self.foo = 1 | self.bar = 2 | self.baz = 3 | | I can say... | | def __str__(self): | return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) | | and everything's simple and clean and I can vary the formatting if I need to. | | This gets ugly when the class has a lot of attributes because the string construction gets very long. This issue bit me once too often a few months ago, and now I have a class called "O" from which I often subclass instead of from "object". Its main purpose is a friendly __str__ method, though it also has a friendly __init__. Code: class O(object): ''' A bare object subclass to allow storing arbitrary attributes. It also has a nicer default str() action, and an aggressive repr(). ''' def __init__(self, **kw): ''' Initialise this O. Fill in attributes from any keyword arguments if supplied. This call can be omitted in subclasses if desired. ''' for k in kw: setattr(self, k, kw[k]) def __str__(self): return ( "<%s %s>" % ( self.__class__.__name__, ",".join([ "%s=%s" % (attr, getattr(self, attr)) for attr in sorted(dir(self)) if attr[0].isalpha() ]) ) ) So I have some code thus: from cs.misc import O ...... class FilterModes(O): def __init__(self, **kw): # special case one parameter self._maildb_path = kw.pop('maildb_path') self._maildb_lock = allocate_lock() O.__init__(self, **kw) ...... filter_modes = FilterModes(justone=justone, delay=delay, no_remove=no_remove, no_save=no_save, maildb_path=os.environ['MAILDB'], maildir_cache={}) This removes a lot of guff from some common procedures. Hope this helps, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's a fine line between pathos and pathetic. - David Stivers stiv at stat.rice.edu DoD #857 From cyborgv2 at hotmail.com Thu May 10 20:21:37 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 01:21:37 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , <4FAB205B.8000804@gmail.com>, , Message-ID: lol, Cheers Chris. Just so you know, I care about what and how I write... I almost always run my emails though a word-processor before sending. And, that has paid off for me: thanks to MS Word, MS Works and Open Office, I have better understanding of "correct" punctuation use (if not spelling and grammar) than most school leavers!!! PS. It hasn't gone a miss that you are one of the core python-list responders (and I bet this goes for most of the python-list users): your responses, time and knowledge is appreciated... Thank you. > Date: Fri, 11 May 2012 09:57:49 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > > have ever had any prior contact with) about releasing code under a > > license... And, what I said stands: once anyone releases code, they are > > bound by the license they released it under as much as anyone else that may > > use it and cannot then withdraw that code from the domain they released it > > to (except by maybe creating a new and different version.) > > And that's absolutely correct. Open source licenses are deliberately > worded to guarantee rights in perpetuity, so there's no way to > withdraw it or change the license (though of course a copyright owner > can release the same code under an additional license). > > > Being dyslexic, my message (and this one) may not be worded in the best way > > but that is no reason to start on me! > > Your message is fine. Believe you me, I'd much rather read a message > posted by a non-native English speaker, or a dyslexic person, or > someone who has a clinical aversion to the letter 'q', than someone > who's simply sloppy and doesn't care about their language at all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 20:46:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 10:46:33 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> <4FAB205B.8000804@gmail.com> Message-ID: On Fri, May 11, 2012 at 10:21 AM, Adrian Hunt wrote: > lol, Cheers Chris. > > Just so you know, I care about what and how I write... I almost always run > my emails though a word-processor before sending. And, that has paid off for > me: thanks to MS Word, MS Works and Open Office, I have better understanding > of "correct" punctuation use (if not spelling and grammar) than most school > leavers!!! Absolutely. Taking care puts you miles ahead of the average (unfortunately for the average). I was home educated, and taught to value correctness, so I tend to speak and write more carefully than most do (people say I sound British for some reason - my accent doesn't sound Australian). That's why I tend to do a lot (note, not "alot", though the cute drawings are fun) of copyediting. > PS. It hasn't gone a miss that you are one of the core python-list > responders (and I bet this goes for most of the python-list users): your > responses, time and knowledge is appreciated... Thank you. Thanks! I'm just a guy who types fast, mainly; but I've been coding for about twenty years, and I'm always happy to help people. But this list is more for me to learn than for me to share. I've learned no end of things from these threads - it's awesome! ChrisA From cyborgv2 at hotmail.com Thu May 10 21:05:05 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 02:05:05 +0100 Subject: Creating a Windows installer for Python + a set of dependencies In-Reply-To: References: Message-ID: Hi there, I've use NSIS for quite a few projects... NSIS will do it with ease. You write a script that gets "compiled" into a install exe and the scripting language is not too hard to learn. You can do it in several different ways: 1. You can include the Python installer as a file compressed into your installer (that is decompressed to a temp directory before being run.) 2. The Python installer could be a included along side you installer and run as needed 3. You can specify a URL to the Python install to be downloaded and installed (again using a temp directory.) You can even use a mix... If an internet connection is available download it, if not fall back to one of the other methods. If you can come up with yet another method, it wouldn't be simple to write a script to handle it. If you really need to you can write a dynamic link library that the final NSIS installer will make calls to. If you need any more help on this subject, email me directly... Although I try to keep an eye on python-list, I can't guarantee a quick reply. > Date: Thu, 10 May 2012 16:26:25 +0200 > Subject: Creating a Windows installer for Python + a set of dependencies > From: g.rodola at gmail.com > To: python-list at python.org > > Hi all, > I need to create an installer for Windows which should be able to > install a specific version of the Python interpreter (2.7) plus a set > a dependencies such as ipython, numpy, pandas, etc. > Basically this is the same thing Active State did for their Active > Python distribution: a single bundle including interpreter + deps. > Not being a Windows user I'm not sure where to start with this except > maybe looking into NSIS (could that be of any help?). > > Thanks in advance, > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From suziemrezitti at gmail.com Thu May 10 21:45:08 2012 From: suziemrezitti at gmail.com (Suzi Mrezutttii) Date: Thu, 10 May 2012 18:45:08 -0700 (PDT) Subject: Google the video "9/11 Missing Links". Jews murdered 3000 Americans in 9/11. Message-ID: COPY THIS MESSAGE FAST BECAUSE JEWS AND TRAITORS DELETE IT FAST! JEWS MURDERED 3000 AMERICANS IN 9/11. After Jews created Israel illegally, Israel became the main base of criminal operations for the most insane type of Jews called Zionists. Israeli Jews murdered JFK in 1963 because JFK did not allow them to have atomic bombs. Read the book "Final Judgment" by Michael Piper, available online in pdf, also google for video presentation by author. Israeli Jews murdered 34 servicemen of American Navy, and seriously wounded 174, when Jews tried repeatedly to sink the USS Liberty in 1967 and blame Egypt for it. Watch online the video interviews with the actual survivors, then compare the facts to the lies spread by Jews through their propaganda outlets like wikipedia. One interview with a survivor should have been enough to turn all responsible Jews and American Traitors into fertilizer within 24 hours. Since Americans failed to listen to the USS Liberty survivors, Israeli Jews murdered 3000 Americans in 9/11, this time to make USA invade Afghanistan/Iraq for Jews, and to enable Jews to impose their Jew Laws (Jaws) like "Patriot Act". Watch online the video "9/11 Missing Links" made in cooperation with contacts inside FBI, CIA, National Security Agency, US Military, who are still loyal to USA. All Jews covered up for Israeli Zionists, with help from White Traitors in Washington DC, because all Jews always protect themselves as single Jew Tribe. Jews are not the sweet/smart/suffering individuals as they present themselves using their own Jew propaganda machines. Jews are full of hate and suffer from a whole range of genetic mental diseases like schizophrenia, paranoia, and others that make them prone to criminal/ parasitic/corruptive behavior. Banking Jews started their corruption of USA in 1913 with creation of the Fed. The Great Depression of 1930's was the direct result of Jew corruption. Jews used Great Depression as an opportunity to corrupt/ expand the federal government because parasites like Jews exploit host organisms through central systems. After Hitler came to power in 1933 and removed Jews from all important positions, Germany experienced unprecedented economic growth while the rest of the world controlled by Jews suffered through Great Depression. Jews did not like this precedent and immediately in 1933 Jews declared economic war on Germany. Hitler invaded Poland only because Poland was infested with five million Jews who constantly were harassing Germany. Jews used their media power to brainwash White Americans to fight White Germans for Jews. All the official "history" has been written by lying Jews and it should be called Jewstory instead of History. Jews are not Whites but insane mongrels who hate Whites. Jews started all the jokes about Whites like Dumb Blondes, Rednecks, Polish Jokes. The sheeple merely parroted after the Jew media. Jews are the ones who promote all those Blacks you see in the media, sports, schools, or business. Jews constantly stir up conflicts between Whites and Blacks by propagandizing the shootings of Blacks in order to take your attention away from all Jew scams. Since 9/11 Jews intensified their "Racism" tactics and their famous "Holocaust" tactics because more Americans learn every day that Jews did 9/11. Jews know they are the biggest criminals on Earth, and that is why Jews manufactured the "Holocaust" Scam where Jews masquerade as the biggest victims on Earth. Jews are Masters of biggest Lies and Deceptions. Without their control of brainwashing media, Jews are nothing more than insane rats. Only Jew scams enabled many Jews to masquerade with Ivy League diplomas, Nobel Prizes, Oscars. Jews run their college/ Awards scams like Wall Street or elections scams. Independent investigations of all Ivy League colleges would show that most Jew students are frauds with standardized tests taken by somebody else or their test results falsified by corrupt admissions offices. The biggest Jew Nobel Prize winner Einstein was a fraud and plagiarist. All you know about famous Jew "scientists" is what Jews told you, the same Jews who made you believe the "Manned Moon Landings" or "Man-Made Global Warming". Jews never invented anything but Scams and Hoaxes. Jews in Israel rank well below average in IQ scores among all nations. Basically, Israel is a hellhole where tens of billions of dollars of American taxpayers' money are wasted on worthless Jews each year. Jews control the US Government illegally. The American democracy is a myth. Most of "US Presidents" since 1913 were Jews (FDR, Eisenhower, LBJ, Obama with Jew mother) or Jew puppets. Recently, Jews in US Congress imposed on Americans yet another Jew Law (Jaw) called "National Defense Authorization Act" that threatens any American who tries to defend The US Constitution. However, the ultimate power lies in the economies, now all mortally wounded by Jews. Jews were too greedy by exporting all real American jobs and forcing Americans to live on debt for too long. Once enough good White Americans reach poverty levels, the game will be over for Jews, especially if their psychotic relatives in Israel pull another USS Liberty or 9/11. Eventually, Jews will have to take head on the real American laws like The Second Amendment of The US Constitution. From rosuav at gmail.com Thu May 10 22:48:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 12:48:26 +1000 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 5:07 AM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our > application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in > the > standalone interpreter. Greetings! The standalone interpreter - I assume you mean the interactive prompt? It has slightly different handling of things (for instance, naked expressions being written to standard output) from the more "usual" invocation of the interpreter. For your embedded Python, probably the easiest thing to do is to not try to use interactive mode, but script mode: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals) Pass it a string of Python code and a dictionary to use for globals and locals (they can be the same dict). Then when that finishes, retrieve from that dictionary some predetermined name (eg "Output"). The Python code then needs simply to assign to Output and all will work. Another way to do it is to call a function inside the Python code, and retrieve its return value. > We are using python 2.7. > > Any suggestions? Unless you have particular need to stick to the 2.x branch, I would suggest moving to 3.3; many things are easier (especially Unicode). But both work. > Also, I'm new to mailling lists, what is the proper way to reply to someone? > Should I > reply directly to someone's email adress or is there a way to answer trough > the server. The usual convention is to reply on-list, unless it's particularly private. Many mail clients will handle this conveniently; otherwise, just manually replace the To address with the list address. As long as you use reply (rather than starting a fresh email), all posts will be correctly threaded both on the list and on the synchronized newsgroup (comp.lang.python). Chris Angelico From me at marmida.com Fri May 11 00:35:44 2012 From: me at marmida.com (Michael Rene Armida) Date: Thu, 10 May 2012 21:35:44 -0700 Subject: Finding the line number of an 'else' statement via ast Message-ID: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the "else:" line, using the ast module? The grammar only includes the 'orelse' list: If(expr test, stmt* body, stmt* orelse) ...but 'orelse' is the list of statements under the 'else' token, not a node representing the token itself. I have a suspicion that this isn't possible, and shouldn't be, and the giveaway word above was "token." Because the tokens themselves aren't part of the abstract syntax tree. Here's an interactive session showing me poking around the If node: >>> import ast >>> tree = ast.parse(''' ... if True: ... pass ... else: ... pass ... ''') >>> tree.body[0].orelse [<_ast.Pass object at 0x7f1301319390>] >>> tree.body[0]._fields ('test', 'body', 'orelse') >>> for i in ast.iter_child_nodes(tree.body[0]): ... print i.__class__.__name__ ... Name Pass Pass Is my suspicion correct? Or is there a way to get the line number of that 'else:'? From stefan_ml at behnel.de Fri May 11 00:45:21 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 11 May 2012 06:45:21 +0200 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: F L, 08.05.2012 21:07: > We are trying to implement our own interactive interpreter in our > applicationusing an embedded Python interpreter. I was wondering what > would be the best way to retreive as text the result of executing > Python code. The text must be exactly the same as it would be in > thestandalone interpreter. We used to do this by changing the embedded > interpreter's sys.stdout and sys.stderrwith a FILE created in C++. We > could then execute code using the PyRun_InteractiveOnefunction and > easily retrieve the result from the FILE. The problem is, our > applicationshouldn't create any files if possible. We also tried > replacing sys.stdout and sys.stderr with a custom made Python > objectwhich could be more easily read from C++. We then used the > function PyRun_Stringto execute the code. The problem here is that using > the Py_file_input start tokendoesn't write everything we need to > sys.stdout. (i.e. executing 2+2 does not write 4).It also doesn't print > a traceback to sys.stderr when there is an exception. Using theother two > start tokens is impossible since we need to be able to execute more than > one instruction at once. We also tried using the function > PyRun_SimpleString but weencounter the same problems. As was already suggested, the PyRun_*() functions are a better choice for executing code from C code, but they will not automatically divert sys.stdout and sys.stderr for you, which are global settings of the interpreter, not local to an execution. So you will get the result of the evaluation back, but not any output that may have been printed during the execution. You have to change those yourself, as you apparently already did. However, have you tried using a pipe for them instead of a real file? That would allow you to retrieve the output without needing to pass through a file in the file system. You can also replace sys.stdout/err with arbitrary objects in Python space, which could then forward the output in any way you want. But, if you control the code that is being executed, it would really be best to *not* print anything out directly, but to use the logging module for output, where you can control much better what exactly gets propagated and to what target. And when the code fails and raises an exception, you can get at the stack trace (that the normal interpreter would just print out) using the traceback module. > Also, I'm new to mailling lists, what is the proper way to reply to > someone? Should Ireply directly to someone's email adress or is there a > way to answer trough the server. A couple of more hints in addition to what Chris Angelico said: reply below the text your are responding to (i.e. not above the text) or split it into sections and reply inline (as I did). Cut down the original text to what is needed for readers to understand the context of your answer. Write plain text mails instead of HTML mails. Your problem description was very good, BTW. It included the perfect amount of information about what you tried and what didn't work for you about it. Stefan From john.terrak at gmail.com Fri May 11 01:55:57 2012 From: john.terrak at gmail.com (John Terrak) Date: Thu, 10 May 2012 22:55:57 -0700 Subject: Newbie naive question ... int() throws ValueError Message-ID: Hi Sorry for such a naive question. I couldnt find anywhere in the documentation that int() can throw a ValueError. I checked the "The Python Language Reference", and the "The Python Standard Library " to no avail. Did I missed something? So here is the question - if it is not in the documentation - how does one find out the exceptions that are thrown by a constructor, a method or a function? Example:? int("not_an_int") >>> int("not_an_int") Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'not_an_int' >From what I gathered: class int(object): ? """ int(x[, base]) -> integer ? Convert a string or number to an integer, if possible.? A floating point ? argument will be truncated towards zero (this does not include a string ? representation of a floating point number!)? When converting a string, use ? the optional base.? It is an error to supply a base when converting a ? non-string.? If base is zero, the proper base is guessed based on the ? string content.? If the argument is outside the integer range a ? long object will be returned instead. """ Thanks for your help - and sorry again for such a naive question. John T. From maha.jabeen92 at gmail.com Fri May 11 02:04:17 2012 From: maha.jabeen92 at gmail.com (Maha Jabeen) Date: Thu, 10 May 2012 23:04:17 -0700 (PDT) Subject: "pakistani girls" "pakistani girls lahore" "pakistani girls phone numbers" "pakistani girls mobile number" "pakistani girls wallpapers" "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com References: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> <11301667.0.1332592235130.JavaMail.geo-discussion-forums@vbtw24> Message-ID: fuck you dude http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ From rosuav at gmail.com Fri May 11 02:10:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 16:10:41 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 3:55 PM, John Terrak wrote: > I couldnt find anywhere in the documentation that int() can throw a ValueError. > I checked the "The Python Language Reference", and the "The Python > Standard Library " to no avail. > Did I missed something? Unlike in Java, a function's list of things it can throw isn't part of its signature. Instead of trying to catch every possible exception, it's generally best to simply let exceptions propagate unless you KNOW you're expecting them. In the case of int(), that would mean that you catch ValueError if you're taking arbitrary strings from the user and want integers (and then you could handle the ValueError by using a default, for instance); but if you're writing a function that's documented as taking a number as a parameter, let the exception go up to the caller. If it helps, think of all Python's exceptions as deriving from RuntimeException - anything can happen, worry only about what really worries you :) > Thanks for your help - and sorry again for such a naive question. It's a perfectly legitimate question, and you clearly did read the docs before asking. Nothing to apologize for there! Chris Angelico From maha.jabeen92 at gmail.com Fri May 11 02:13:34 2012 From: maha.jabeen92 at gmail.com (Maha Jabeen) Date: Thu, 10 May 2012 23:13:34 -0700 (PDT) Subject: Pakistani Girls Mopbile Number For Friendship Message-ID: <5f80460b-67f1-4417-b36a-9e53a6af8c35@nl1g2000pbc.googlegroups.com> http://numbersofgirlsinpakistan.blogspot.com/ visit http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ pakistani girl 0.14 550000 18100 pakistani girl names 0.17 18100 1300 pakistani girls 0.15 673000 22200 pakistani girls names 0.17 18100 1300 beautiful pakistani girls 0.23 14800 390 pakistani girl photo 0.28 40500 720 pakistani girls pictures 0.21 74000 1300 pakistani girls photos 0.21 49500 1000 pakistani girls for marriage 0.84 5400 260 pakistani girls pic 0.21 22200 390 pakistani girls phone numbers 0.74 3600 170 pakistani girls photo 0.29 40500 720 pakistani girls mobile numbers 0.61 74000 260 pakistani girls images 0.29 33100 590 pakistani girl number 0.61 74000 480 pakistani girls picture 0.27 40500 720 pakistani girl name 0.16 18100 1000 pakistani girls dating 0.71 1000 91 pakistani girl pictures 0.22 60500 1300 pakistani girl pic 0.22 18100 320 pakistani girls in usa 0.69 480 110 pakistani girls chat 0.61 5400 140 pakistani girl picture 0.29 40500 590 pakistani girls in usa for marriage 0.92 210 73 pakistani girl pics 0.17 40500 720 beautiful girl 0.07 1830000 301000 pretty pakistani girls 0.05 720 73 pakistani girl images 0.29 33100 590 pakistani girl wallpaper 0.3 8100 73 pakistani girl video 0.06 27100 720 pakistani girls numbers 0.6 90500 480 pakistani girl photos 0.22 49500 880 pakistani girls marriage 0.84 5400 260 pakistani girls phone number 0.74 3600 170 pakistani names for girls 0.17 18100 1300 pakistani girls feet 0.04 1300 58 pakistani girls number 0.6 90500 480 pakistani hot girl 0.12 27100 1000 pakistani girls scandals 0.04 3600 91 pakistani girls mobile number 0.62 74000 260 pakistani girls pics 0.16 40500 880 pakistani girls numbers for friendship 0.54 3600 46 dating pakistani girls 0.71 1000 91 hot pakistani girl 0.12 27100 1000 pics of pakistani girls 0.16 40500 880 meet pakistani girls 0.84 170 16 chat with pakistani girls 0.61 5400 140 indian pakistani girls 0.07 14800 880 pakistani girls friendship 0.76 8100 110 hot pakistani girls pics 0.21 3600 73 pictures of pakistani girls 0.21 74000 1300 cute pakistani girl 0.09 6600 210 pakistani girls name 0.16 18100 1000 pakistani girls videos 0.06 40500 880 pakistani girls video 0.06 27100 720 pakistani girl for marriage 0.83 5400 260 pakistani punjabi girls 0.14 880 36 pakistani dance 0.06 40500 1600 pakistani girls wallpapers 0.3 8100 73 young pakistani girls 0.06 4400 210 cute pakistani girls 0.11 6600 210 pakistani girl scandal 0.03 5400 140 pretty pakistani girl 0.05 720 73 pakistani girls online 0.58 2400 58 pakistani girls mms 0.04 2400 91 pakistani beautiful girls 0.23 14800 390 pakistani baby girl names 0.22 1000 73 pakistani girl mobile number 0.63 74000 210 pakistani girls dance 0.05 4400 140 pakistani girl feet 0.04 590 36 pakistani girls kissing 0.06 5400 140 hot pakistani girls photos 0.25 4400 91 pakistani girl phone number 0.76 3600 170 pakistani girls clothes 0.8 2900 140 beautiful girls 0.08 2240000 368000 japanese girls 0.09 1500000 246000 pia 0.06 6120000 823000 desi 0.04 13600000 1220000 russian girls 0.41 673000 110000 pretty girls 0.06 1000000 450000 pakistani girls photo album 0.46 390 0 pakistani girls scandal 0.04 4400 140 hot girl 0.06 6120000 1830000 pakistani food 0.14 49500 12100 chinese girls 0.2 450000 110000 pakistani girl chat 0.76 4400 110 pakistani clothes 0.82 165000 22200 ptv 0.12 1500000 90500 pak 0.18 9140000 1500000 urdu news 0.04 1000000 40500 pakistani news 0.04 550000 90500 pakistani girl kissing 0.06 4400 140 desibaba 0.04 246000 6600 pakistani girls kiss 0.07 2400 58 thai girls 0.19 450000 60500 pakistani girls gallery 0.18 1900 46 desibaba.com 0.04 49500 880 pakistani girls dress design 0.72 320 0 desi girls 0.06 550000 27100 russian girl 0.38 673000 110000 pakistani dresses 0.84 165000 22200 pakistani women 0.23 90500 9900 desi girl 0.06 550000 27100 hotgirl 0.04 1830000 368000 desi baba 0.04 301000 6600 pakistani fashion 0.58 74000 6600 pakistani culture 0.07 14800 3600 arab girls 0.08 550000 49500 girl baby names 0.27 1220000 450000 baby girl names 0.27 1220000 450000 nice girls 0.08 550000 74000 russian brides 0.82 201000 74000 pakistani songs 0.09 450000 9900 photos of pakistani girls 0.21 49500 1000 pakistani music 0.11 301000 8100 pakistani girls for friendship 0.76 8100 110 geo news urdu 0.06 165000 2900 beautiful pakistani girls pictures 0.36 4400 58 british pakistani girls 0.06 1600 46 pakistani college girls 0.12 14800 320 pakistani girl hot 0.12 27100 1000 baby names girl 0.27 1220000 450000 bad girl 0.03 1830000 368000 pakistani movies 0.1 450000 14800 pakistani models 0.05 74000 4400 muslim girls 0.17 368000 27100 baby names meaning 0.19 450000 201000 female baby names 0.22 368000 135000 beautiful pakistani girl 0.22 14800 390 pakistani girls cell numbers 0.54 18100 140 pakistani tv 0.13 201000 18100 pakistani chat 0.41 74000 2900 muslim girl 0.15 368000 33100 pakistani mujra 0.1 135000 3600 pakistani girls hot 0.13 40500 1300 male baby names 0.22 246000 110000 hottest pakistani girls 0.04 480 22 pakistani girls blog 0.2 880 36 pakistani girl raped 0.03 1600 73 punjabi girls 0.13 135000 6600 desigirl 0.05 201000 9900 hot pakistani girl photo 0.22 1900 46 russian ladies 0.71 301000 90500 pakistani dress 0.79 165000 18100 pakistani beauty girls 0.16 1600 58 baby name list 0.27 33100 8100 pakistani song 0.08 450000 9900 pakistannews 0.13 3600 720 pakistani tv channels 0.34 49500 2900 ptv home 0.07 165000 1600 pixpux 0.04 27100 390 pakistani girls mobile no 0.55 74000 170 online girls 0.31 2740000 550000 pakistani brides 0.64 49500 5400 baby names with meaning 0.19 450000 201000 youtube pakistani 0.05 110000 4400 bangladeshi girls 0.2 135000 6600 pakista 0.07 33100 1900 pakistani girl dance 0.04 4400 110 girl baby name 0.25 823000 246000 pakistani clothes for girls 0.8 2900 140 pakistani girls image 0.35 8100 110 pakistani girls wallpaper 0.31 8100 73 pakistani girls mobile numbers 2011 0.51 1900 5 pakistani school girls 0.16 9900 260 pakistani girl image 0.19 6600 110 pakistani girl kiss 0.06 1900 58 youtube pakistani girls 0.09 2900 58 pakistani girls mobile number list 0.54 880 0 indiangirl 0.05 550000 60500 bangladeshi girl 0.2 135000 6600 pakistani baby names 0.21 3600 390 popular pakistani girl names 0.08 91 28 beautiful pakistani women 0.15 3600 320 pakistani chat rooms 0.51 33100 880 afghani girl 0.13 18100 1900 beautiful pakistani girls pics 0.32 2400 36 pakstan 0.11 18100 720 pakistani woman 0.18 60500 8100 meaning of girl names 0.13 201000 60500 pakistani boy names 0.15 4400 480 hot pakistani girls pictures photos 0.25 3600 91 single pakistani girls 0.91 140 16 pakistani cute girls 0.11 6600 210 pakistani girls exbii 0.01 880 28 pakestan 0.08 6600 590 baby name girl 0.25 823000 246000 images of pakistani girls 0.29 33100 590 pakistani names for boys 0.15 4400 590 desi pakistani girls 0.13 6600 170 names of baby girls 0.27 1220000 450000 beautifull pakistani girls 0.26 720 12 parkistan 0.09 3600 390 name for baby girl 0.25 823000 246000 pakisan 0.08 8100 590 pakistani desi girls 0.13 6600 170 baby boy names with meaning 0.28 49500 14800 pakistn 0.11 9900 480 pakitan 0.08 12100 720 pakistani girls hot photos 0.25 4400 91 girl names with meaning 0.13 201000 60500 pakistansong 0.11 5400 73 baby girl names list 0.44 9900 2400 babies names meaning 0.22 27100 4400 pakistani beautiful girl 0.22 14800 390 pakistani girls college 0.12 14800 320 youtubepakistan 0.03 2400 110 pakistani girls in bikini 0.1 1000 36 pakistani dating girls 0.71 1000 91 baby girl names meanings 0.26 60500 14800 islamic female names 0.15 110000 4400 pakistani girls club 0.06 880 36 cute pakistani girls pics 0.12 1000 16 girls mobile numbers 0.58 450000 3600 pakist 0.07 18100 1600 girls name list 0.2 49500 14800 pakistantv 0.17 1300 91 pakistani school girl 0.14 12100 320 girls name meaning 0.14 110000 33100 pakistanigirls 0.44 3600 110 pakistani single girls 0.91 140 16 name with meaning 0.09 6120000 2240000 pakistani mujra girls 0.04 1600 46 popular pakistani boy names 0.04 73 22 pakistani girls in america 0.22 140 22 pakistani beautiful girls wallpaper 0.33 880 0 pakistanimujra 0.15 22200 480 xnxxpakistan 0.27 1600 73 baby names female 0.22 368000 135000 pakistani girls mobile numbers for friendship 0.56 3600 12 girls names with meaning 0.14 201000 74000 pakistani girls dancing 0.04 3600 110 www.pakistani girl 0.32 6600 110 young pakistani girl 0.05 3600 170 pak girls 0.16 33100 880 hot girl youtube 0.02 18100 3600 pakistani desi girl 0.15 5400 140 pakistani boys names 0.15 4400 590 unique pakistani baby names 0.16 22 0 list of baby names girls 0.44 9900 2400 pakistani dresses for girls 0.77 3600 170 mobile numbers of pakistani girls 0.61 74000 260 boys names with meaning 0.16 135000 49500 baby name with meaning 0.16 301000 135000 baby name girls 0.25 823000 246000 girl babies names 0.33 40500 9900 names for a girl baby 0.27 1220000 450000 name of baby girl 0.25 823000 246000 girl pakistani 0.14 550000 18100 pak girl 0.12 27100 880 girls names and meaning 0.14 201000 74000 pakistani girls hot pics 0.21 3600 73 pakistani male names 0.12 2900 320 pakistani baby boy names 0.33 480 58 pakistane 0.15 40500 1000 name of meaning 0.09 6120000 2240000 baby name for girl 0.25 823000 246000 pakistani google 0.14 4400 320 gorgeous pakistani girls 0.09 110 12 pakistanigirl 0.41 2400 91 female baby names list 0.4 4400 1300 names of girl 0.13 5000000 1830000 pakistani sax 0.23 3600 58 names of baby girl 0.27 1220000 450000 pakistani women culture 0.3 320 170 pakistani cute girl 0.09 6600 210 pakistani muslim girls 0.16 18100 1000 female baby name 0.11 165000 49500 female pakistani names 0.16 18100 1000 pakistangirl 0.27 1600 46 names for girl babies 0.33 40500 9900 baby names & meaning 0.19 450000 201000 pakistani collage girls 0.14 1600 28 pakistani beautiful girls pictures 0.36 4400 58 pakistangirls 0.12 27100 880 list baby girl names 0.44 9900 2400 name girl baby 0.25 823000 246000 girls name and meaning 0.14 110000 33100 girls name with meaning 0.14 110000 33100 pakistani beauty girl 0.21 1000 28 name of baby girls 0.25 823000 246000 girl baby names with a 0.27 1220000 450000 pakistani grils 0.25 5400 140 pakistani hairstyles for girls 0.14 1300 28 pakistani dress for girls 0.73 4400 140 pakistani sweet girls 0.08 720 12 pakistani kissing 0.04 12100 320 pakistani ladies 0.59 8100 320 desi pakistani 0.34 49500 5400 hot pakistani guy 0.05 320 73 pakistani boys name 0.15 2900 260 pakistani pretty girls 0.05 720 73 pakistani names and meanings 0.18 1900 140 pakistani muslim girl names 0.17 14800 880 pakistani local girls 0.49 2400 36 girl baby name list 0.36 6600 1000 you tube pakistani 0.05 74000 2900 pakistani indian girls 0.07 14800 880 pakistani girl wallpapers 0.3 8100 58 www.pakistani girls 0.44 8100 140 attractive girls names 0.05 590 320 pakistani saxy girls 0.55 590 0 pakistani girl friendship 0.77 5400 91 female baby names meanings 0.19 18100 5400 name of girls baby 0.25 823000 246000 meaning of names baby 0.19 450000 201000 baby names girl a 0.27 1220000 450000 pakgirl 0.13 1000 28 pakistani dancing 0.04 18100 720 beautiful for women 0.16 1220000 450000 pakistani desi 0.34 49500 5400 list of female baby names 0.4 4400 1300 list of male baby names 0.38 2900 1000 girl name with meaning 0.12 110000 33100 baby girls name list 0.36 5400 1000 girl name and meaning 0.12 110000 33100 list of names for baby girls 0.44 9900 2400 islam girl names 0.1 135000 6600 names for girl baby 0.27 1220000 450000 boy baby names with meaning 0.28 49500 14800 girl pakistani names 0.17 18100 1300 boy baby names and meaning 0.28 49500 14800 new girls name 0.23 18100 1900 girls pakistani 0.15 673000 22200 wallpapers pakistani girls 0.3 8100 73 pakistani beautiful womens 0.34 170 0 pakistani hair styles for girls 0.15 880 16 pakistani shalwar kameez for girls 0.58 880 28 girl name baby 0.25 823000 246000 male baby names meanings 0.29 18100 6600 muslim pakistani names 0.16 18100 1000 www.pakistani girls mobile numbers 0.7 1300 0 baby boy name with meaning 0.2 27100 5400 girl meaning names 0.13 201000 60500 list of baby girls name 0.36 5400 1000 baby names from a 0.22 6120000 2740000 wallpaper pakistani girl 0.3 8100 73 email address of pakistani girls 0.61 590 0 pakistani girl slutload 0.01 880 16 baby names for boys with meaning 0.31 49500 12100 pixpux pakistani girls 0.2 320 0 names girl baby 0.27 1220000 450000 list of baby girl name 0.36 6600 1000 meaning of pakistani names 0.16 2400 140 pakistani girls mobile numbers list 0.58 880 0 islamic girl baby names 0.18 27100 2400 beautiful pakistani woman 0.17 2900 260 cell numbers of pakistani girls 0.54 18100 140 name for girl baby 0.25 823000 246000 girl baby name s 0.06 18100 6600 local pakistani girls 0.49 2400 36 desi pakistani girl 0.15 5400 140 baby names boy meaning 0.28 49500 14800 boy name with meaning 0.12 74000 22200 pakistani boy name 0.15 2900 260 new pakistani names 0.31 390 28 pakistani girls for dating 0.71 1000 91 hot pakistani video 0.11 12100 260 pakistani boy baby names 0.33 480 58 women pakistani 0.23 90500 9900 name of the meaning 0.09 6120000 2240000 phone numbers of pakistani girls 0.74 3600 170 names of girl babies 0.33 40500 9900 cool pakistani girls 0.19 320 0 names for female babies 0.3 9900 2400 images pakistani girls 0.29 33100 590 pakistani baby names for boys 0.34 480 58 youtube girl hot 0.02 18100 3600 pakistani girls online chat 0.88 590 5 baby girls name meaning 0.22 33100 8100 wallpapers of pakistani girls 0.3 8100 73 search for girl 0.24 110000 40500 name of the baby girl 0.25 823000 246000 free chat with pakistani girls 0.81 480 12 free chat pakistani girls 0.81 480 12 meet pakistani girls online 0.97 36 0 name & meaning 0.09 6120000 2240000 new pakistani girls 0.29 1900 73 pakistani girls beautiful 0.23 14800 390 wallpaper of pakistani girl 0.3 8100 73 cute pakistani girls images 0.16 590 12 wallpaper pakistani girls 0.31 8100 73 pakistani girls dress 0.73 4400 140 numbers of pakistani girls 0.6 90500 480 beautiful pakistani girls images 0.39 1900 28 teenage pakistani girls 0.12 1000 36 online pakistani girls 0.58 2400 58 pakistani school girls pictures 0.24 880 16 smart pakistani girls 0.14 210 0 simple pakistani girl 0.15 590 0 you tube girls dance 0.01 90500 1600 pakistani girls fashion 0.52 1300 16 pakistani school girls photos 0.25 880 12 pakistani girls in bra 0.09 1000 16 google pakistani girls 0.3 170 0 desi pakistani girls pictures 0.16 1000 16 pakistani girl in bra 0.07 880 16 pakistani saxy girl 0.46 590 0 pakistani chat girls 0.61 5400 140 beautiful pakistani girls photo 0.4 2400 36 mobile no of pakistani girls 0.55 74000 170 pakistani girls wallpapers hot 0.18 480 0 phone number of pakistani girls 0.74 3600 170 pakistani girls in hijab 0.07 480 16 pakistani girls chatting 0.74 880 16 pakistani girls photo gallery 0.27 1000 22 pakistani girls chat rooms 0.69 1600 0 pakistani girle 0.27 1000 22 pakistani girl pitcher 0.57 480 0 pakistani girl marriage 0.83 5400 260 pakistani girls email address 0.61 590 0 pakistani s girl 0.05 720 58 british pakistani girl 0.05 1600 46 picture of pakistani girls 0.27 40500 720 mobile phone numbers of pakistani girls 0.8 590 16 pakistani girls on date 0.54 480 36 pakistani girl in bikini 0.08 880 28 pakistani desi girls picture 0.17 590 5 indian pakistani girl 0.06 12100 720 pakistani girls photos pictures 0.21 49500 880 pic of pakistani girls 0.21 22200 390 sweet pakistani girl 0.07 720 12 pakistani girl dating 0.91 880 91 pictures of beautiful pakistani girls 0.36 4400 58 pakistani girls cleavage 0.01 390 0 beautiful pakistani girls photos 0.34 2900 46 image of pakistani girls 0.35 8100 110 pakistani girl id 0.19 1300 22 pakistani girls mobile phone numbers 0.8 590 16 pakistanis girls 0.14 110000 4400 pakistani girls picture gallery 0.24 480 0 pakistani girles 0.28 880 12 muslim pakistani girls 0.16 18100 1000 wallpaper of pakistani girls 0.31 8100 73 pakistani date girls 0.54 480 36 pakistani girls hostel 0.06 720 12 free pakistani girls 0.14 6600 210 pakistani girls id 0.2 1600 28 cute pakistani girl pictures 0.12 1600 28 pakistani girls for sale 0.43 73 0 pakistani girls looking for marriage 0.93 140 12 beautiful pakistani girls wallpaper 0.33 880 0 pakistani girls picturs 0.27 390 0 pakistani girls on beach 0.09 390 12 beautiful pakistani girl photo 0.4 2400 36 pakistani girls breast 0.04 1000 22 pakistani girl s 0.05 720 58 indian and pakistani girls 0.07 14800 880 hot pakistani girls wallpapers 0.18 480 0 beautiful pakistani girls wallpapers 0.32 880 0 beutiful pakistani girls 0.2 320 0 pakistani girls eyes 0.04 140 16 photo pakistani girl 0.28 40500 720 dirty pakistani girls 0.05 480 28 pakistani girl friend 0.29 4400 170 pakistani girl school 0.14 12100 320 contact numbers of pakistani girls 0.74 4400 170 all pakistani girls 0.14 1000 22 pakistani girls friend ship 0.79 1600 28 pakistani girls bra 0.09 1000 16 image pakistani girls 0.35 8100 110 pakistani girls movies 0.07 18100 390 chat with pakistani girl 0.76 4400 110 pakistany girls 0.22 480 22 pakistani girl six 0.43 590 0 pakistani girls bikini 0.1 1000 36 pakistani girls dresses 0.77 3600 170 attractive pakistani girl 0.09 110 0 pakistani girls pitcher 0.56 480 0 pakistani girl cleavage 0 320 0 pakistani girls hot images 0.21 1600 46 local pakistani girl 0.52 1900 28 pakistani girl bra 0.07 880 16 pakistani girls clips 0.08 9900 170 dasi pakistani girl 0.14 260 0 beautiful pakistani girl wallpaper 0.34 720 0 pakistani girls hot pictures 0.25 5400 110 pakistani girls names in urdu 0.23 390 16 pakistani girls in saree 0.19 170 0 pakistani girls in school 0.16 9900 260 pakistani girl online 0.56 1900 46 beauty of pakistani girls 0.16 1600 58 pakistany girl 0.18 390 22 pakistani girls school 0.16 9900 260 best pakistani girls 0.14 1300 46 nice pakistani girls 0.26 3600 140 pakistani girls in salwar kameez 0.69 1000 36 pakistani girls phone no 0.7 2900 140 pakistani girl beautiful 0.22 14800 390 new pakistani girl 0.19 1600 91 pakistani girls mobile phone number 0.79 590 16 pakistani girls hot wallpapers 0.18 480 0 pakistani girls hot pic 0.18 1900 36 image of pakistani girl 0.19 6600 110 beautiful pakistani girls pic 0.42 1000 12 hot pakistani girl images 0.22 1300 36 pakistani girls vagina 0.03 170 0 pakistani girls in college 0.12 14800 320 pakistani girls six 0.48 590 0 cool pakistani girl 0.19 260 0 photo of pakistani girls 0.29 40500 720 pakistani girls without clothes 0.1 480 0 pakistani girls bathing 0.03 390 28 innocent pakistani girls 0.05 320 0 image pakistani girl 0.19 6600 110 pakistani girls models 0.07 720 22 pakistani girls breasts 0.03 2400 73 images of beautiful pakistani girls 0.39 1900 28 hot desi pakistani girls 0.06 590 12 wet pakistani girls 0.04 260 0 pakistani girls fight 0.03 390 0 pakistani girls model 0.06 880 22 hot pakistani girls images 0.21 1600 46 pakistani girl bikini 0.08 880 28 pakistani picture girls 0.27 40500 720 hot pakistani girls pictures 0.25 5400 110 chat pakistani girl 0.76 4400 110 pakistani girl model 0.06 720 22 pics of beautiful pakistani girls 0.32 2400 36 pakistani free girls 0.14 6600 210 pakistani girl dancing 0.03 3600 110 pakistani girls no 0.55 74000 390 hot pakistani girls pic 0.18 1900 36 pakistani girl hot image 0.3 260 0 pakistani girls hot photo 0.41 2400 58 hot pakistani girls photo 0.41 2400 58 pakistani girl breast 0.04 880 16 desi girls pakistani 0.13 6600 170 pakistani girls mobile numbers friendship 0.56 3600 12 cute pakistani girls pictures 0.12 1900 28 image girls pakistani 0.35 8100 110 real pakistani girls 0.1 1900 28 nangi pakistani girls 0.14 480 0 names of pakistani boys 0.15 4400 590 hot pics of pakistani girls 0.21 3600 73 pakistani girls chat room 0.69 1600 12 pakistani girls shalwar kameez 0.58 880 28 new pakistani boys names 0.36 91 0 hot pakistani girl image 0.3 260 0 pakistani girls scandle 0.04 720 0 pakistani girl in saree 0.15 140 0 pakistani girls beauty 0.16 1600 58 girls pictures pakistani 0.21 74000 1300 online chat with pakistani girls 0.88 590 5 unique pakistani names 0.12 110 16 chatting with pakistani girls 0.74 880 16 new pakistani baby names 0.38 91 5 youtube hot pakistani 0.04 2900 58 pakistani pictures girls 0.21 74000 1300 baby name & meaning 0.16 301000 135000 pakistani girls hot image 0.33 320 0 pakistani baby girls name 0.17 590 36 pakistani girl games 0.14 390 12 list of names of baby girl 0.44 9900 2400 name of the girl baby 0.25 823000 246000 most beautiful pakistani girl 0.12 720 12 sweet pakistani girls 0.08 720 12 pakistani girl sara 0.02 46 0 chat online with pakistani girls 0.88 590 5 chat pakistani girls 0.61 5400 140 pakistani girl chat room 0.67 1300 0 chat with pakistani girls online 0.88 590 5 friendship with pakistani girls 0.76 8100 110 most beautiful pakistani girls 0.15 720 16 online chat pakistani girls 0.88 590 5 online pakistani girls chat 0.88 590 5 mobile number of pakistani girls 0.62 74000 260 pakistani beautiful girls wallpapers 0.32 880 0 pakistani punjabi girl 0.12 880 46 pakistani wallpapers girls 0.3 8100 73 find pakistani girls 0.49 260 22 pakistani girls contact numbers 0.74 4400 170 pakistani girl numbers 0.61 74000 390 beautiful pakistani muslim girls 0.19 91 0 pakistani girls friendship mobile number 0.62 3600 12 pakistani girls on line 0.54 1300 16 pakistani hostel girls 0.06 720 12 hot pakistani college girls 0.08 720 16 pakistani girls cell numbers for friendship 0.63 2900 12 hot pakistani desi girls 0.06 590 12 chat rooms pakistani girls 0.69 1600 0 friendship pakistani girls 0.76 8100 110 pakistani girls cell number 0.55 18100 140 pakistani girl chatting 0.79 880 12 pakistani girls in home 0.05 1300 28 pakistani hot guy 0.05 320 73 pakistani simple girls 0.16 590 0 pakistani girls mobile 0.59 90500 260 pakistani collage girl 0.14 1600 28 pakistani girls in new york 0.43 36 16 pakistani cute girls pictures 0.12 1900 28 pakistani girls in jeans 0.24 260 0 date pakistani girls 0.54 480 36 friendship in pakistani girls 0.76 8100 110 pakistani schools girls 0.16 1600 58 pakistani girls mobile number for friendship 0.62 3600 12 pakistani girl photo album 0.49 390 0 pakistani girl for friendship 0.77 5400 91 pakistani girls email 0.48 880 12 pakistani girls to marry 0.28 320 36 pakistani local girls pictures 0.57 1000 12 pakistani good girls 0.1 260 16 pakistani college girls images 0.26 1000 16 pakistani friendship girls 0.76 8100 110 pakistani college girls hot 0.08 720 16 pakistani local girl 0.52 1900 28 pakistani model girls 0.06 880 22 hot pakistani school girls 0.1 480 12 pakistani wallpaper girls 0.31 8100 73 pakistani village girls 0.04 590 22 pakistani images girls 0.29 33100 590 pakistani sixy girl 0.4 260 0 pakistani desi girls pictures 0.16 1000 16 pakistani christian girls 0.54 170 12 pakistani muslim girl 0.16 18100 1000 pakistani sweet girl 0.07 720 12 pakistani simple girl 0.15 590 0 pakistani bikini girl 0.08 880 28 pakistani girl mobile numbers 0.63 74000 210 pakistani girl names with meaning 0.15 1000 28 pakistani beautiful girls images 0.39 1900 28 pakistani online girls 0.58 2400 58 pakistani girls for chat 0.61 5400 140 picture pakistani girls 0.27 40500 720 pakistani muslim girls names 0.16 14800 880 beautiful pictures of pakistani girls 0.36 4400 58 pakistani hot girl image 0.3 260 0 scandals of pakistani girls 0.04 3600 91 pakistani desi girls images 0.21 480 0 pakistani model girl 0.06 720 22 pakistani beautiful girls pics 0.32 2400 36 cute pakistani baby girls 0.07 260 0 pakistani dresses girls 0.77 3600 170 mobile number pakistani girls 0.62 74000 260 pakistani wedding girls 0.36 1300 28 pakistani college girls photos 0.23 1600 22 pakistani games for girls 0.14 1300 28 pakistani nice girl 0.24 3600 140 pakistani girls youtube 0.09 2900 58 pakistani beautiful girls pic 0.42 1000 12 pakistani marriage girls 0.84 5400 260 pakistani bad girl 0.09 590 28 pakistani university girls 0.09 1300 28 cell no of pakistani girls 0.56 14800 91 youtube pakistani girl 0.08 2400 58 pakistani smart girls 0.14 210 0 pakistani beautifull girls 0.26 720 12 pakistani boys and girls 0.03 3600 170 pakistani home girls 0.05 1300 28 pakistani girl email address 0.64 480 0 pakistani girls chat online 0.88 590 5 pakistani girls chating 0.88 210 0 pakistani girls mujra 0.04 1600 46 hot pakistani school girl 0.06 480 0 pakistani girl mobile no 0.56 60500 140 pakistani british girls 0.06 1600 46 pakistani beautiful girls photos 0.34 2900 46 pakistani smart girl 0.07 210 0 pakistani girls for chatting 0.74 880 16 pakistani hot girl photo 0.22 1900 46 pakistani student girls 0.1 320 0 hot pakistani college girl 0.06 720 16 beautiful pakistani girls picture 0.41 2400 36 chating with pakistani girls 0.88 210 0 pakistani girl cell number 0.55 9900 110 pakistani girls wedding pictures 0.28 170 0 pakistani models girls 0.07 720 22 pakistani beutiful girls 0.2 320 0 pakistani lahori girls 0.18 320 0 pakistani teenage girls 0.12 1000 36 pakistani muslim girls photo 0.35 210 12 pakistani girls in saudi 0.12 320 16 pakistani dancing girls 0.04 3600 110 pakistani colleges girls 0.27 390 0 pakistani beautiful girls picture 0.41 2400 36 pakistani beautiful girl wallpaper 0.34 720 0 pakistani college girls pictures 0.24 1900 28 number of pakistani girls 0.6 90500 480 pakistani nangi girls 0.14 480 0 pakistani private girls 0.23 880 12 pakistani girl photo gallery 0.32 880 16 pakistani college girls pics 0.2 1600 22 pakistani girl dress 0.75 2400 91 pakistani college girls photo 0.27 880 12 pakistani beautiful girls photo 0.4 2400 36 pakistani girls numbers mobile 0.61 74000 260 pakistani school girls kissing 0.06 170 0 cute pakistani college girls 0.06 140 0 From varma.nikhil22 at gmail.com Fri May 11 05:55:24 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Fri, 11 May 2012 15:25:24 +0530 Subject: increment date present list of tuple by weeks python Message-ID: Hi All I have a list like this :- [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] how can i increment date in the above list for the next months on weekly basis ? [ ('7 May monday AM Neuropancreatic'),('14May monday AM Neuropancreatic')('21 May monday AM Neuropancreatic')('28 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular'),('15 May monday AM Neuropancreatic'),('22 May monday AM Neuropancreatic'),('29 May monday AM Neuropancreatic')] Thanks -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri May 11 06:14:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 11:14:16 +0100 Subject: increment date present list of tuple by weeks python In-Reply-To: References: Message-ID: On 11/05/2012 10:55, Nikhil Verma wrote: > Hi All > > > I have a list like this :- > > [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] > > how can i increment date in the above list for the next months on weekly > basis ? > > [ ('7 May monday AM Neuropancreatic'),('14May monday AM > Neuropancreatic')('21 May monday AM Neuropancreatic')('28 May monday AM > Neuropancreatic'), > ('8 May tuesday PM Cardiovascular'),('15 May monday AM > Neuropancreatic'),('22 May monday AM Neuropancreatic'),('29 May monday AM > Neuropancreatic')] > > > Thanks > See http://docs.python.org/library/time.html#time.strptime and it's cousin strftime, and http://docs.python.org/library/datetime.html#module-datetime date and timedelta types. -- Cheers. Mark Lawrence. From sandeep0242 at gmail.com Fri May 11 06:38:28 2012 From: sandeep0242 at gmail.com (googlewellwisher) Date: Fri, 11 May 2012 03:38:28 -0700 (PDT) Subject: Clicking a sub menu item Message-ID: <76acd538-2825-4c1e-8cc0-c182193f4c14@l4g2000pbv.googlegroups.com> Hello, Im a newbie to automation testing.Im using python scripting in selenium to automate a website. Now im facing a difficulty in clicking a submenu item.I have 5 buttons in the main menu.I am able to click each of the menu button using self.driver.find_element_by_id("MainMenuButton1").click() But how can I click the MenuButton1_Submenu button? For this purpose I think I have to move hover the menu button and wait for some time, then click the submenus using their ids or whatever property.Is this the right way to click the sub menu items? If yes can abybody provide me the code for mouse hover a control? If this is not the right procedure please provide me with appropriate code to click on a sub menu item? From breamoreboy at yahoo.co.uk Fri May 11 06:43:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 11:43:55 +0100 Subject: Finding the line number of an 'else' statement via ast In-Reply-To: References: Message-ID: On 11/05/2012 05:35, Michael Rene Armida wrote: > Given this source: > > def do_something(val): > if val: > return 'a' > else: > return 'b' > > How do I get the line number of the "else:" line, using the ast > module? The grammar only includes the 'orelse' list: > > If(expr test, stmt* body, stmt* orelse) > > ...but 'orelse' is the list of statements under the 'else' token, not > a node representing the token itself. > > I have a suspicion that this isn't possible, and shouldn't be, and the > giveaway word above was "token." Because the tokens themselves aren't > part of the abstract syntax tree. > > Here's an interactive session showing me poking around the If node: > >>>> import ast >>>> tree = ast.parse(''' > ... if True: > ... pass > ... else: > ... pass > ... ''') >>>> tree.body[0].orelse > [<_ast.Pass object at 0x7f1301319390>] >>>> tree.body[0]._fields > ('test', 'body', 'orelse') >>>> for i in ast.iter_child_nodes(tree.body[0]): > ... print i.__class__.__name__ > ... > Name > Pass > Pass > > > Is my suspicion correct? Or is there a way to get the line number of > that 'else:'? Get the line number of the first pass and add one? -- Cheers. Mark Lawrence. From varma.nikhil22 at gmail.com Fri May 11 07:13:35 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Fri, 11 May 2012 16:43:35 +0530 Subject: How can we covert string into Datetime object Message-ID: Hi All I was going through this link http://docs.python.org/library/datetime.html#strftime-strptime-behavior. I practised strftime() and strptime() functions. Finally i stuck into a situation where i want to get the datetime object so that i can save it in my db. What i want is :- I have a string let say date_created = '11 May Friday PM ' and i want to convert it into datetime object like this datetime.datetime(2012, 5, 11, 4, 12, 44, 24734) Thanks in advance. Any help will be appreciated -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Fri May 11 07:16:48 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 13:16:48 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <20120511001535.GA8056@cskk.homeip.net> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> > This issue bit me once too often a few months ago, and now I have a class called > "O" from which I often subclass instead of from "object". > Its main purpose is a friendly __str__ method, though it also has a friendly __init__. > > Code: > > class O(object): > ''' A bare object subclass to allow storing arbitrary attributes. > It also has a nicer default str() action, and an aggressive repr(). > ''' > > def __init__(self, **kw): > ''' Initialise this O. > Fill in attributes from any keyword arguments if supplied. > This call can be omitted in subclasses if desired. > ''' > for k in kw: > setattr(self, k, kw[k]) > > def __str__(self): > return ( "<%s %s>" > % ( self.__class__.__name__, > ",".join([ "%s=%s" % (attr, getattr(self, attr)) > for attr in sorted(dir(self)) if attr[0].isalpha() > ]) > ) > ) This is a very interesting solution. I think it might be better suited (for my purpose) to __repr__ rather than __str__, mostly because I still lose control of the order the attributes appear. I really like the general idea of subclassing object though, because I often have classes with dozens of attributes and __init__ gets very messy. Chris' dynamically generated format string looks to be my best bet in the absence of a perfect solution. Cheers, Drea From python at mrabarnett.plus.com Fri May 11 07:51:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 May 2012 12:51:06 +0100 Subject: How can we covert string into Datetime object In-Reply-To: References: Message-ID: <4FACFD2A.8060607@mrabarnett.plus.com> On 11/05/2012 12:13, Nikhil Verma wrote: > Hi All > > I was going through this link > http://docs.python.org/library/datetime.html#strftime-strptime-behavior. > I practised strftime() and strptime() functions. > > Finally i stuck into a situation where i want to get the datetime > object so that i can save it in my db. > What i want is :- > > I have a string let say > date_created = '11 May Friday PM ' > > and i want to convert it into datetime object like this > datetime.datetime(2012, 5, 11, 4, 12, 44, 24734) > > Thanks in advance. Any help will be appreciated > As it says in the documentation: %d matches the day of the month %B matches the name of the month %A matches the day of the week %p matches AM/AM so: >>> datetime.datetime.strptime('11 May Friday PM', '%d %B %A %p') datetime.datetime(1900, 5, 11, 0, 0) (I've stripped off the trailing space.) Note that as you haven't supplied a year, the year defaults to 1900, and as you haven't supplied an hour but only "PM", the hour defaults to 0 (and there's no way to tell whether it was AM or PM). (The minutes and seconds also default to 0.) You can't convert something as vague as '11 May Friday PM' to a datetime object. If all of the times are just AM/PM you could try appending an hour (eg '12') before parsing and ignore it when you convert it back to a string for display. From d at davea.name Fri May 11 07:58:18 2012 From: d at davea.name (Dave Angel) Date: Fri, 11 May 2012 07:58:18 -0400 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FACFEDA.1040808@davea.name> On 05/11/2012 07:16 AM, Andreas Tawn wrote: >> >> This is a very interesting solution. >> >> I think it might be better suited (for my purpose) to __repr__ rather than __str__, mostly because I still lose control of the order the attributes appear. I have no idea why using __repr__ versus __str__ would make any difference in the order of the attributes. They're going to come out in the order you specify, regardless of what you name your method. If you don't like the arbitrary order you get from the dictionary, then either sort it, or provide an explicit list. -- DaveA From jaroslav.dobrek at gmail.com Fri May 11 08:04:10 2012 From: jaroslav.dobrek at gmail.com (Jaroslav Dobrek) Date: Fri, 11 May 2012 05:04:10 -0700 (PDT) Subject: parallel subprocess.getoutput Message-ID: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Hello, I wrote the following code for using egrep on many large files: MY_DIR = '/my/path/to/dir' FILES = os.listdir(MY_DIR) def grep(regex): i = 0 l = len(FILES) output = [] while i < l: command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + FILES[i] result = subprocess.getoutput(command) if result: output.append(result) i += 1 return output Yet, I don't think that the files are searched in parallel. Am I right? How can I search them in parallel? Jaroslav From jaroslav.dobrek at gmail.com Fri May 11 08:11:06 2012 From: jaroslav.dobrek at gmail.com (Jaroslav Dobrek) Date: Fri, 11 May 2012 05:11:06 -0700 (PDT) Subject: parallel subprocess.getoutput References: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Message-ID: <3cad8848-3a31-4570-9b17-c436c1e3ff4b@w10g2000vbc.googlegroups.com> Sorry, for code-historical reasons this was unnecessarily complicated. Should be: MY_DIR = '/my/path/to/dir' FILES = os.listdir(MY_DIR) def grep(regex): output = [] for f in FILES: command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + f result = subprocess.getoutput(command) if result: output.append(result) return output From askutt at gmail.com Fri May 11 08:39:00 2012 From: askutt at gmail.com (Adam Skutt) Date: Fri, 11 May 2012 05:39:00 -0700 (PDT) Subject: parallel subprocess.getoutput References: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Message-ID: On May 11, 8:04?am, Jaroslav Dobrek wrote: > Hello, > > I wrote the following code for using egrep on many large files: > > MY_DIR = '/my/path/to/dir' > FILES = os.listdir(MY_DIR) > > def grep(regex): > ? ? i = 0 > ? ? l = len(FILES) > ? ? output = [] > ? ? while i < l: > ? ? ? ? command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + > FILES[i] > ? ? ? ? result = subprocess.getoutput(command) > ? ? ? ? if result: > ? ? ? ? ? ? output.append(result) > ? ? ? ? i += 1 > ? ? return output > > Yet, I don't think that the files are searched in parallel. Am I > right? How can I search them in parallel? subprocess.getoutput() blocks until the command writes out all of its output, so no, they're not going to be run in parallel. You really shouldn't use it anyway, as it's very difficult to use it securely. Your code, as it stands, could be exploited if the user can supply the regex or the directory. There are plenty of tools to do parallel execution in a shell, such as: http://code.google.com/p/ppss/. I would use one of those tools first. Nevertheless, if you must do it in Python, then the most portable way to accomplish what you want is to: 0) Create a thread-safe queue object to hold the output. 1) Create each process using a subprocess.Popen object. Do this safely and securely, which means NOT passing shell=True in the constructor, passing stdin=False, and passing stderr=False unless you intend to capture error output. 2) Spawn a new thread for each process. That thread should block reading the Popen.stdout file object. Each time it reads some output, it should then write it to the queue. If you monitor stderr as well, you'll need to spawn two threads per subprocess. When EOF is reached, close the descriptor and call Popen.wait() to terminate the process (this is trickier with two threads and requires additional synchronization). 3) After spawning each process, monitor the queue in the first thread and capture all of the output. 4) Call the join() method on all of the threads to terminate them. The easiest way to do this is to have each thread write a special object (a sentinel) to the queue to indicate that it is done. If you don't mind platform specific code (and it doesn't look like you do), then you can use fcntl.fcntl to make each file-object non- blocking, and then use any of the various asynchronous I/O APIs to avoid the use of threads. You still need to clean up all of the file objects and processes when you are done, though. From darnold992000 at yahoo.com Fri May 11 09:29:22 2012 From: darnold992000 at yahoo.com (darnold) Date: Fri, 11 May 2012 06:29:22 -0700 (PDT) Subject: which book? References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> Message-ID: <1b8fe79d-60e2-4713-ba1a-7ad442b2e4a3@s9g2000vbg.googlegroups.com> On May 10, 4:58?am, d.po... at gmail.com wrote: > On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote: > > > I am going to learn python for some plot issues. which book or sources, do you recommend please? > > The tutorial is pretty good if you already know how to program. > > I also heard a lot of good things on "Python Essential Reference". > > Thanks. > Could you please pass the line for tutorial? i believe that would be the tutorial at http://docs.python.org/tutorial/ . From andreas.tawn at ubisoft.com Fri May 11 10:32:35 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 16:32:35 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <4FACFEDA.1040808@davea.name> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> > I have no idea why using __repr__ versus __str__ would make any difference in the > order of the attributes. They're going to come out in the order you specify, > regardless of what you name your method. If you don't like the arbitrary order you > get from the dictionary, then either sort it, or provide an explicit list. Only that, as the docs say, __repr__ should represent the entire object that could be used to build a new object with the same value. For that task the order of the attributes is immaterial. I want __str__ to give me something easily readable and ordered in a way that's conveys some meaning about the attributes. It's also helpful to not have to display every attribute, of which there may be dozens. From breamoreboy at yahoo.co.uk Fri May 11 10:40:46 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 15:40:46 +0100 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On 11/05/2012 15:32, Andreas Tawn wrote: > It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? -- Cheers. Mark Lawrence. From tjreedy at udel.edu Fri May 11 10:58:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 May 2012 10:58:51 -0400 Subject: Finding the line number of an 'else' statement via ast In-Reply-To: References: Message-ID: On 5/11/2012 12:35 AM, Michael Rene Armida wrote: > Given this source: > > def do_something(val): > if val: > return 'a' > else: > return 'b' > > How do I get the line number of the "else:" line, using the ast > module? The grammar only includes the 'orelse' list: > > If(expr test, stmt* body, stmt* orelse) > > ...but 'orelse' is the list of statements under the 'else' token, not > a node representing the token itself. > > I have a suspicion that this isn't possible, and shouldn't be, and the > giveaway word above was "token." Because the tokens themselves aren't > part of the abstract syntax tree. The main reason to record line numbers in the parse tree and hence the CPython code object is to print the line number and corresponding line in exception tracebacks. Since 'else:' on a line by itself is not a statement in itself and does not contain an expression that could raise, there is no need to record a line number. So I would not be surprised if it is not directly recorded. 'else: 1/0' and "elif 1/0" will have recorded line numbers. If you can get the last line of the if-block and first line of the else-block, and there is a gap, you might guess that the else is in between ;-). -- Terry Jan Reedy From jeanmichel at sequans.com Fri May 11 11:09:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 11 May 2012 17:09:24 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FAD2BA4.6000701@sequans.com> Mark Lawrence wrote: > On 11/05/2012 15:32, Andreas Tawn wrote: > >> It's also helpful to not have to display every attribute, of which >> there may be dozens. > > Do I detect a code smell here? > I think so, Murphy's law dictates that the attribute you're interested in will not be displayed anyway. JM From andreas.tawn at ubisoft.com Fri May 11 11:10:50 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 17:10:50 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597B2B@PDC-MAIL-CMS01.ubisoft.org> > > It's also helpful to not have to display every attribute, of which there may be > dozens. > > Do I detect a code smell here? Possibly. I'll often try to subdivide into several simpler types, but sometimes that makes the code more complex than it needs to be. From andreas.tawn at ubisoft.com Fri May 11 11:24:46 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 17:24:46 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <4FAD2BA4.6000701@sequans.com> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> <4FAD2BA4.6000701@sequans.com> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597B51@PDC-MAIL-CMS01.ubisoft.org> > >> It's also helpful to not have to display every attribute, of which > >> there may be dozens. > > > > Do I detect a code smell here? > > > I think so, Murphy's law dictates that the attribute you're interested in will not be > displayed anyway. That's what __repr__'s for. From sageandecho at gmail.com Fri May 11 11:25:20 2012 From: sageandecho at gmail.com (Coyote) Date: Fri, 11 May 2012 08:25:20 -0700 (PDT) Subject: Newby Python Programming Question Message-ID: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Folks, I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. I have two programs. The first is in a file I named file_utils.py: def pwd(): import os print os.getcwd() The second is in a file I named pwd.py: import os print os.getcwd() Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory: >>>from file_utils import pwd >>>pwd() C:\Users\coyote\pyscripts But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? Thanks! Cheers, David From tjreedy at udel.edu Fri May 11 11:51:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 May 2012 11:51:47 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On 5/11/2012 1:55 AM, John Terrak wrote: > I couldnt find anywhere in the documentation that int() can throw a ValueError. > I checked the "The Python Language Reference", and the "The Python > Standard Library " to no avail. > Did I missed something? To add to Chris' answer: If the domain of a function is truly all Python objects, it cannot raise an error. I believe id(x) is such an example. Even if the domain is intended to be all Python objects, you cannot be sure if the function uses any special method defined on the object or its class. For examples, type(x) *should* always work, but I would not be surprised if a buggy __getattribute__ method or buggy metaclass could result in an exception instead. If the arguments for a function include a function, for example map(f, 'abc'), then the passed function can raise any exception and hence the called function will pass along the exception unless, unusually, it catches it. As to your specific question, if the domain of a function is a subset of types and values of allowed types, then you should expect that it can raise either TypeError or ValueError. If the domain > So here is the question - if it is not in the documentation - how does > one find out the > exceptions that are thrown by a constructor, a method or a function? One way is to try specific examples, as you did. Following what Chris said, especially do that for bad input whose exception you want to catch. Sometimes this is faster than trying to find the answer in the doc, and it gives the actual answer rather than the intended answer. > Example: int("not_an_int") >>>> int("not_an_int") > Traceback (most recent call last): > File "", line 1, in > ValueError: invalid literal for int() with base 10: 'not_an_int' Some strings are legal input, hence not a TypeError, but not all, hence ValueError. >> From what I gathered: > class int(object): > """ int(x[, base]) -> integer > > Convert a string or number to an integer, if possible. A floating point > argument will be truncated towards zero (this does not include a string > representation of a floating point number!) When converting a string, use > the optional base. It is an error to supply a base when converting a > non-string. If base is zero, the proper base is guessed based on the > string content. If the argument is outside the integer range a > long object will be returned instead. """ 'error' should say 'TypeError' as it is a TypeError to provide the wrong number of args. However, the current 3.3 manual entry is more accurate and informative, starting with the signature. -- Terry Jan Reedy From lists at cheimes.de Fri May 11 12:15:05 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 11 May 2012 18:15:05 +0200 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: Am 11.05.2012 17:51, schrieb Terry Reedy: > If the domain of a function is truly all Python objects, it cannot raise > an error. I believe id(x) is such an example. Even id() can raise an exception, for example MemoryError when you are running out of memory. Christian From rosuav at gmail.com Fri May 11 12:23:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 02:23:04 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 2:15 AM, Christian Heimes wrote: > Am 11.05.2012 17:51, schrieb Terry Reedy: >> If the domain of a function is truly all Python objects, it cannot raise >> an error. I believe id(x) is such an example. > > Even id() can raise an exception, for example MemoryError when you are > running out of memory. KeyboardInterrupt can also be raised at (effectively) any time, but I'm not sure that that really counts as id() raising the exception. If I understand it correctly, MemoryError would be because the interpreter can't allocate an int object for id's return value. But these are definitely part of why you don't just catch all exceptions. Hmm. What happens if the interpreter can't construct a MemoryError exception? ChrisA From maarten.sneep at knmi.nl Fri May 11 12:38:29 2012 From: maarten.sneep at knmi.nl (Maarten) Date: Fri, 11 May 2012 09:38:29 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> On Friday, May 11, 2012 5:25:20 PM UTC+2, Coyote wrote: > I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. Welcome here. > I have two programs. The first is in a file I named file_utils.py: > > def pwd(): > import os > print os.getcwd() Move the import tot the root level of the file: import os def pwd(): print(os.getcwd()) (and print() is a function these days) > The second is in a file I named pwd.py: > > import os > print os.getcwd() > > Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory. > > But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? I'd say this is a bug or feature of the IDE. If I use ipython I get: In [1]: %run mypwd /nobackup/users/maarten/tmp/coyote I tried to use Eclipse, but I don't think I'll do that again. I otherwise never use an IDE, it makes me confused. I don't know what the IDE is doing. Note that there is a standard module (at least on unix/linux) with the name pwd, but I guess that the IDE is not confused. I do recommend you read http://docs.python.org/howto/doanddont.html as a starting point to avoid learning some bad habits, especially on importing. You probably already found https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html For scripts that are intended to be run from the command line, I use: #!/usr/bin/env python import os def pwd(): return os.getcwd() if __name__ == "__main__": print(pwd()) This will allow you to import the module (without side effects) and call the function, as well as 'running' the file. This increases the usefullness of the module. There are other advantages, especially when the scripts involves (many) variables. Maarten From ethan at stoneleaf.us Fri May 11 12:41:49 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 May 2012 09:41:49 -0700 Subject: __all__, public API, private stuff, and leading _ Message-ID: <4FAD414D.1020209@stoneleaf.us> Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? ~Ethan~ From emile at fenx.com Fri May 11 13:01:15 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 11 May 2012 10:01:15 -0700 Subject: __all__, public API, private stuff, and leading _ In-Reply-To: <4FAD414D.1020209@stoneleaf.us> References: <4FAD414D.1020209@stoneleaf.us> Message-ID: On 5/11/2012 9:41 AM Ethan Furman said... > Style question: > > Since __all__ (if defined) is the public API, if I am using that should > I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the internal vs exposed nature of things. Emile From ian.g.kelly at gmail.com Fri May 11 13:12:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 May 2012 11:12:43 -0600 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 10:23 AM, Chris Angelico wrote: > Hmm. What happens if the interpreter can't construct a MemoryError exception? I believe that a MemoryError instance is pre-allocated for just this scenario. You can see it in the result of gc.get_objects(). >>> [x for x in gc.get_objects() if isinstance(x, MemoryError)] [MemoryError()] Cheers, Ian From rosuav at gmail.com Fri May 11 13:27:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 03:27:48 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 3:12 AM, Ian Kelly wrote: > I believe that a MemoryError instance is pre-allocated for just this > scenario. Ah, wise move. It's one of those largely-imponderables, like figuring out how to alert the sysadmin to a router failure. ChrisA From jeanpierreda at gmail.com Fri May 11 13:36:06 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 11 May 2012 13:36:06 -0400 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: > However, have you tried using a pipe for them instead of a real file? That > would allow you to retrieve the output without needing to pass through a > file in the file system. You can also replace sys.stdout/err with arbitrary > objects in Python space, which could then forward the output in any way you > want. Surely a pipe would cause a deadlock if the pipe fills up if Python and the C program are running in the same process/thread? I'm not too familiar with these sorts of things. -- Devin From david at idlcoyote.com Fri May 11 14:00:51 2012 From: david at idlcoyote.com (Coyote) Date: Fri, 11 May 2012 11:00:51 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> Message-ID: <31904384.15.1336759251460.JavaMail.geo-discussion-forums@yneh4> Maarten writes: > I do recommend you read http://docs.python.org/howto/doanddont.html as a starting point to avoid learning some bad habits, especially on importing. You probably already found https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html Yikes! I'm sure that first reference is in English, but I don't have much of an idea what it means yet. :-) I have found the second reference very helpful. I've bookmarked both of these for future consideration. Thanks for your good advice. Cheers, David From rosuav at gmail.com Fri May 11 14:05:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 04:05:00 +1000 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 3:36 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: >> However, have you tried using a pipe for them instead of a real file? That >> would allow you to retrieve the output without needing to pass through a >> file in the file system. You can also replace sys.stdout/err with arbitrary >> objects in Python space, which could then forward the output in any way you >> want. > > Surely a pipe would cause a deadlock if the pipe fills up if Python > and the C program are running in the same process/thread? Yes, it would; how much data are you looking at retrieving, and is it all at script-end or do you need to process it concurrently? If the latter, then your two best options are a pipe (and running the Python script in another thread, possibly a separate process) or a callback of some sort (in which case the script hands you a line or block of output and says "Deal with this and get back to me") - eg by replacing sys.stdout, or defining a function that the Python script calls explicitly. This is starting to sound similar to something I did at work. A C++ program uses a block of Python code as a sort of uber-config-file. It would initialize the Python environment, import some modules, etc, once, and keep the globals around (this allows Python globals to be retained). Every time script-configurable code is to be run: 1) Prepare a dictionary called Input with a whole lot of parameters/information/etc 2) Create an empty dictionary and call it Output 3) Execute a block of code (retrieved from the database) 4) Inspect the Output dictionary and use that to control subsequent behaviour. As a concept, it worked quite well. I do not, however, advise doing this if your Python scripts come from untrusted sources, as it is impossible to guarantee safety. (For that reason we actually shifted to Javascript for that project.) But if you're using this as a powerful and simple config-file and you know you can trust everything that will be run, then it's a pretty awesome way of doing things. It takes deliberately malicious code to break the system. ChrisA From ethan at stoneleaf.us Fri May 11 14:26:40 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 May 2012 11:26:40 -0700 Subject: __all__, public API, private stuff, and leading _ In-Reply-To: References: <4FAD414D.1020209@stoneleaf.us> Message-ID: <4FAD59E0.7090801@stoneleaf.us> Emile van Sebille wrote: > On 5/11/2012 9:41 AM Ethan Furman said... >> Style question: >> >> Since __all__ (if defined) is the public API, if I am using that should >> I also still use a leading underscore on my private data/functions/etc? > > I would, even if only to alert any future maintainer of the internal vs > exposed nature of things. I find that a persuasive argument, thanks. ~Ethan~ From vacu001 at gmail.com Fri May 11 14:58:01 2012 From: vacu001 at gmail.com (vacu) Date: Fri, 11 May 2012 11:58:01 -0700 (PDT) Subject: %d not working in re at Python 2.7? Message-ID: I am frustrated to see %d not working in my Python 2.7 re.search, like this example: >>> (re.search('%d', "asdfdsf78asdfdf")).group(0) Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'group' \d works fine: >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) '78' And google search ignores % in their search, so I failed to find answer from Python mailing list or web, Do you have any idea what's problem here? Thanks a head Vacu From john.terrak at gmail.com Fri May 11 15:01:15 2012 From: john.terrak at gmail.com (John Terrak) Date: Fri, 11 May 2012 12:01:15 -0700 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: Thank you all for your help. Greatly appreciated. John From jason at deadtreepages.com Fri May 11 15:32:35 2012 From: jason at deadtreepages.com (Jason) Date: Fri, 11 May 2012 12:32:35 -0700 (PDT) Subject: specify end of line character for readline Message-ID: <485824.173.1336764755682.JavaMail.geo-discussion-forums@yngp11> Is there any way to specify the end of line character to use in file.readline() ? I would like to use '\r\n' as the end of line and allow either \r or \n by itself within the line. Thanks, Jason From jeanpierreda at gmail.com Fri May 11 15:34:34 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 11 May 2012 15:34:34 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: > Unlike in Java, a function's list of things it can throw isn't part of > its signature. Instead of trying to catch every possible exception, > it's generally best to simply let exceptions propagate unless you KNOW > you're expecting them. How am I supposed to know to expect them, if they are undocumented? Trial and error? That seems like a poor replacement for documented error conditions. -- Devin From raunakgup90 at gmail.com Fri May 11 15:41:31 2012 From: raunakgup90 at gmail.com (raunakgup90 at gmail.com) Date: Fri, 11 May 2012 12:41:31 -0700 (PDT) Subject: Sharing Data in Python Message-ID: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> I have some Pickled data, which is stored on disk, and it is about 100 MB in size. When my python program is executed, the picked data is loaded using the cPickle module, and all that works fine. If I execute the python multiple times using python main.py for example, each python process will load the same data multiple times, which is the correct behaviour. How can I make it so, all new python process share this data, so it is only loaded a single time into memory? asked the same question on SO, but could not get any constructive responses.. http://stackoverflow.com/questions/10550870/sharing-data-in-python/10551845 From leomcallister at gmail.com Fri May 11 15:53:19 2012 From: leomcallister at gmail.com (leomcallister at gmail.com) Date: Fri, 11 May 2012 12:53:19 -0700 (PDT) Subject: Scrapy - importing files from local, rather than www In-Reply-To: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> References: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> Message-ID: <29279774.1982.1336765999380.JavaMail.geo-discussion-forums@vbki8> You can try running Python's web server on the folder (python -m SimpleHTTPServer) and point Scrapy to it. On Monday, May 7, 2012 4:57:22 AM UTC-3, nbw wrote: > Hi everyone, I'm new to Python (loving it!) and Scrapy. I have a > question I just can't seem to get my head around. I can get a simple > Scrapy spider to pick up URLs and download them fine, but the HTML > files I have are stored locally. The reason for this, is for some > reason when I "Save As" the pages I get everything, whereas if Scrapy > runs over them it seems to miss certain areas where there's > Javascript. > > So, I have them sitting in a directory (C:/scrapy_test) but can't for > the life of me get Scrapy to find them. Is there anyone who's had this > problem and solved it, or can help? > > Any help is much appreciated. > Kind regards, > nbw From georgeryoung at gmail.com Fri May 11 17:29:39 2012 From: georgeryoung at gmail.com (gry) Date: Fri, 11 May 2012 14:29:39 -0700 (PDT) Subject: tiny script has memory leak Message-ID: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 [gcc-4_3-branch revision 141291]] I thought this script would be very lean and fast, but with a large value for n (like 150000), it uses 26G of virtural memory, and things start to crumble. #!/usr/bin/env python '''write a file of random integers. args are: file-name how-many''' import sys, random f = open(sys.argv[1], 'w') n = int(sys.argv[2]) for i in xrange(n): print >>f, random.randint(0, sys.maxint) f.close() What's using so much memory? What would be a better way to do this? (aside from checking arg values and types, I know...) From cmpython at gmail.com Fri May 11 17:57:10 2012 From: cmpython at gmail.com (CM) Date: Fri, 11 May 2012 14:57:10 -0700 (PDT) Subject: Newby Python Programming Question References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: On May 11, 11:25?am, Coyote wrote: > Folks, > > I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. > > I have two programs. The first is in a file I named file_utils.py: > > ? ?def pwd(): > ? ? ? ?import os > ? ? ? ?print os.getcwd() > > The second is in a file I named pwd.py: > > ? ?import os > ? ?print os.getcwd() > > Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory: > > ? ?>>>from file_utils import pwd > ? ?>>>pwd() > ? ?C:\Users\coyote\pyscripts > > But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? I don't know Spyder IDE, but I don't think this should happen; could there just be a simple mistake? Because you first refer to the .py file as 'file_utils.py' but then you refer to the file as 'pwd.py'...which is also the name of your function. Room for confusion...so could you test this by saving only your one function (below), give the .py a new name to avoid confusion (like test_pwd.py) and then running *that* through Spyder IDE? def pwd(): import os print os.getcwd() From david at idlcoyote.com Fri May 11 18:25:40 2012 From: david at idlcoyote.com (Coyote) Date: Fri, 11 May 2012 15:25:40 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> CM writes: > I don't know Spyder IDE, but I don't think this should happen; could > there just be a simple mistake? Because you first refer to the .py > file as 'file_utils.py' but then you refer to the file as > 'pwd.py'...which is also the name of your function. Room for > confusion...so could you test this by saving only your one function > (below), give the .py a new name to avoid confusion (like test_pwd.py) > and then running *that* through Spyder IDE? > > def pwd(): > import os > print os.getcwd() I probably explained the situation badly. I have a file pwd.py with these two lines of code in it: import os print os.getcwd() If I start a new Spyder IDL session and "run" this file by choosing RUN from the menu bar, the directory is printed twice. This appears to me now to be an IDE error, because if I use a runfile command, the directory is printed only once, as I expect. >>>runfile('pwd.py') C:\Users\coyote\pyscripts I've been playing around with a couple of IDEs because I liked the one I used with IDL and I wanted to use something similar for Python. The IDLDE was an Eclipse variant, but I've tried installing Eclipse before for something else and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. Unless, of course, I need a good excuse to head over to the Rio for the margaritas. :-) Cheers, David From cs at zip.com.au Fri May 11 18:44:34 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 12 May 2012 08:44:34 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: Message-ID: <20120511224434.GA27120@cskk.homeip.net> On 11May2012 15:40, Mark Lawrence wrote: | On 11/05/2012 15:32, Andreas Tawn wrote: | > It's also helpful to not have to display every attribute, of which there may be dozens. | | Do I detect a code smell here? Not necessarily. (Well, yeah, "dozens" may indicate time to partition stuff.) My "O" class (back in the thread) deliberately shows only the [a-z]* attributes so the user gets the public object state without the noise of private attributes. For __repr__ I might print everything. Haven't gone that far yet. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ That is 27 years ago, or about half an eternity in computer years. - Alan Tibbetts From miki.tebeka at gmail.com Fri May 11 20:30:49 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 11 May 2012 17:30:49 -0700 (PDT) Subject: Sharing Data in Python In-Reply-To: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> References: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> Message-ID: <1735448.70.1336782649463.JavaMail.geo-discussion-forums@vbfx1> > How can I make it so, all new python process share this data, so it is only loaded a single time into memory? You can have one process as server and client ask for parts of data. You might be able to do something smart with mmap but I can't think of a way. I Linux systems, if you first load the data and then fork, the OS will keep all the read only data shared. From rosuav at gmail.com Fri May 11 23:21:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 13:21:14 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 5:34 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: >> Unlike in Java, a function's list of things it can throw isn't part of >> its signature. Instead of trying to catch every possible exception, >> it's generally best to simply let exceptions propagate unless you KNOW >> you're expecting them. > > How am I supposed to know to expect them, if they are undocumented? > Trial and error? That seems like a poor replacement for documented > error conditions. Expect exceptions any time anything goes wrong. Don't try to code to prevent them. Here's an example. Suppose you write a function that takes a number and returns that many copies of your club's charter. (Yeah, pretty stupid, but examples usually are!) def charter(copies): return _chartertext * copies Does this function need to catch any exceptions? No. Can that expression throw exceptions? Totally! You might be given a non-number (can't give "foo" copies); you might get a floating point (can't get three-and-a-half copies); your charter text might have been replaced with a pizza; the user might hit Ctrl-C right while it's copying; the number might be so large that you run out of memory; all sorts of things. But they're not your problems - they're your caller's problems. If you caught all those exceptions, what would you do? You'd have to signal the error conditions yourself, which probably means... raising an exception. There are times when you want to catch all exceptions, though. Top-level code will often want to replace exception tracebacks with error messages appropriate to some external caller, or possibly log the exception and return to some primary loop. Otherwise, though, most code will just let unexpected exceptions through. This is one of those massively freeing leaps of thinking. Java binds you to a bureaucracy of catching exceptions or declaring them (but then still has RuntimeException - and I'm sure there've been MANY programmers who just derive all their exceptions from that); Python sets you free to care only about what you want to care about. ChrisA From jeanpierreda at gmail.com Sat May 12 00:11:18 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 12 May 2012 00:11:18 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 11:21 PM, Chris Angelico wrote: > There are times when you want to catch all exceptions, though. > Top-level code will often want to replace exception tracebacks with > error messages appropriate to some external caller, or possibly log > the exception and return to some primary loop. Otherwise, though, most > code will just let unexpected exceptions through. I'm not talking about unexpected exceptions. I'm saying, if I expect invalid input for int, where should I go to find out how to deal with said invalid input properly? How do I know that int raises ValueError on failure, and not, for example, something like ArgumentError (something that Python doesn't have) or (like chr) TypeError? Apparently the answer is to read the documentation for ValueError. It's a bit like putting the documentation on the return type for `map` in the list documentation. Kinda hard to get there without already knowing the answer. -- Devin From rosuav at gmail.com Sat May 12 01:50:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 15:50:56 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 2:11 PM, Devin Jeanpierre wrote: > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? Ah, I see what you mean. The easiest way to find out what exception gets thrown is to try it. For obvious things like int("foo") you can simply test it in the interactive interpreter; unusual cases you'll discover as you run your script. ChrisA From anthony at xtfx.me Sat May 12 03:10:01 2012 From: anthony at xtfx.me (anthony at xtfx.me) Date: Sat, 12 May 2012 00:10:01 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> Message-ID: <15657786.192.1336806601102.JavaMail.geo-discussion-forums@yngo1> On Thursday, May 10, 2012 3:06:47 AM UTC-5, james hedley wrote: > > i have not banned anything, or even alluded to it, whatsoever. i asked that > > one specific mail not be commented upon > > OK, sorry if I misunderstood, but that's still suppression in my book. James, how can you realistically condemn a simple request with such colorful words, now and in previous messages, yet simultaneously claim to support Luke's many impositions ... https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/ZTK-9bZ5TisJ https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/xp63LbOYO6oJ ... i could easily drum up a hundred more, if i were both inclined and extremely bored. i have been in contact by other users who claim a similar state as yourself, and frankly, everyone save yourself expresses a far more genuine interest ... your comments are riddled with dissonance ... > > reading your accounts strewn about is interesting, what exactly are *your* motives? > > My motives are as I've stated; I'm a commercial user with products in development > which use Pyjamas and that I have a long-term stake in. With a bit of thought, anyone > should see why I value stability and continued viability. It's a long game but the > potential payback to pyjamas could be huge *if* it can keep commercial users on board. > This is where the existential threat to pyjamas comes from and why I and many others > consider the takeover to be reckless and unjustified. perhaps. in retrospect i would have approached some aspects a bit differently. interestingly ... things seem to be panning out in ways that will benefit all ... isn't that right, James? to be honest though, of all the commercial users i'm aware, none have responded as you describe. this was not a lone wolf operation, and neither are discussions in flight. i think if you temper your reactions, and turn down the volume, you will find that things are shaping up rather well ... i am very much aware of the events unfolding, as are you. whilst you paint me the enemy, new paths have been opened ... achievement? unlocked! > > Luke is a talented developer, there is no doubt of this, but he is one of the most > > socially inept persons i have ever encountered > > I don't think this is the right place to bash people or even defend them on a personal > level. i'm doing neither. this is an mere observation after multiple years of interaction, and my own research into past endeavors. > We get it though. You didn't get along with the guy. well, no, i don't think you get it ... are you paying attention, at all? i got along with him just fine; i've already detailed this elsewhere. > > the idea was to retain Luke > > I'm sorry but I don't believe this. Luke can speak for himself of course but this is > not how you keep people on-board. well, don't then :-( ... but several did, and it's the cross-my-heart-pinky-swear'in truth. after many months of lengthy discussion it felt right. after 10 minutes of reactionary thought it feels less right to you ... that's certainly understandable, and maybe even correct. was it *really* the right thing to do? maybe not, this was unprecedented. already however, great things are in motion, and i feel good about the feedback received, outside and in. > > he decided to play legal threats as the first card > > He's claimed that you lifted data from his server without permission. I'm not commenting > on that, but if it's true then this is a massive roadblock in the viability of the > project. I for one don't want to be involved in it. Can you picture the scene where a > developer or businessperaon goes into a meeting with very senior, very conservative > executives trying to pitch a product, and it turns out there are serious legal concerns > surrounding the technology platform? unrelated ... the technology is freely available. > If it isn't true then perhaps you should put people's minds at rest by giving a detailed > explanation of the whole mail server situation, including where the data originated, where > it is now, how it got there and why the accidental mailing of so many people occurred. acting as an agent of the organization, i reinstated services people had purposefully subscribed to, in accordance with an infrastructure transition. these were pre-existing relationships to a service i managed. alas, i was unaware of the reasons to -- or existence of -- joining a list, but opting for "nomail" ... thus the state was reset, ie. resuming reception thereto. following this realization, all existing members were simply requested to join a new list at their willful discretion. data was/is neither leaked nor compromised in any way. if anything, organization leaders failed to register with the Ministry their collection of personal data, and also failed to train agents on proper handling, if need be. ... that's the official statement, but like i said 100 times, i don't give a {explicit deleted} about this, and never wanted to: i seek the best for everyone. this thought stream is more likely a shoot yourself in the foot kind of path ... and not my own. while i do sincerely apologize to those affected/upset, the reality is a handful of people received a handful of mail, in a good faith attempt to reinstate a service they had both requested and retained. this was subsequently ceased once it was clear there was an issue with the latter, and a final, good faith attempt was made to detail and offer resumed services elsewhere ... so what? lets hypothetically suggest there was some transgression, people/Luke/whomever feverishly pursue, and the book get thrown my way ... what will anyone have gained? nothing. all that results is my life gets difficult, my fiance in final year of grad school is possibly compromised due to finances, and my toddler son must endure any hardship along with us ... more blood please? or revenge? or [...]? there is a positive resolution for everyone, and it will be found. > > indeed, you have witnessed little chatter > > I'd invite anyone to review the pyjamas list for the last 7 days before they make > up their minds. Some of the statements I've seen have been regrettable. i don't know what you're referring to, or even talking about, at all. things have been rather peachy keen ... we even had some emerge from the shadows! ;-) > > by realizing this is not as black-and-white as you's like it to be. > > I have an ethical objection here, but moreover; it clearly just runs against my > interests to support your actions. I'm not sure you considered the commercial users > here, and with respect nor do I really get the impression you've understood it, still. alright ... i *am* a commercial user. while the events may run afoul something, it certainly isn't your interests. when i give presentations, and early questions are not about the project, but some particular member, that signifies a problem ... i'll let you fill in the gaps. > By the way; I'm not associated with Luke at all. I've emailed him off-list a few times > this week to discuss some angles to do with my work, but that's it. "it" you say? ok ... > In fact, I support Kees' proposition that Pyjamas should seek sponsorship from the > Python/Apache/Free Software Foundation. This would resolve questions of legitimacy and > leadership. > > In my ideal outcome, we could tailor pyjamas more to business use; e.g. > tidying up any license issues, offering a commercial support contract (this will help > mitigate the damage done to perceptions of credibility), publishing a commercial > use policy (one of the foundations could offer support with this I hope). oddly enough, your goals are inline with the advancements being made, and the some of the inadequacies behind the transition. understand that several inconsistencies were *introduced* by former leadership, and are only now being reconciled. regardless of your stance on the actual methods employed, you stand to benefit, and i daresay, *WILL* benefit. we are on the same side, James. contingent upon acceptance of an agreeable resolution, i am more than happy to transfer assets to the PSF, so we can simply absolve each other and get back to writing some damn code. however, such decisions will be made with the same care and consideration as those which brought us here ... i'm not in a hurry to witness the very encumbrances i worked hard -- and received much flak -- be reinstated. so far so good ... let's just continue working toward that goal, together. i am tight on time and resources, so this is be my last correspondence here ... best to everyone. -- C Anthony From alec.taylor6 at gmail.com Sat May 12 04:30:32 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 May 2012 18:30:32 +1000 Subject: Python web-framework with the widest scalability? Message-ID: I am building a project requiring high performance and scalability, entailing: - Role-based authenticationwith API-keylicensing to access data of specific users - API exposed with REST (XML, JSON ), XMLRPC, JSONRPC and SOAP - "Easily" configurable getters and settersto create APIs accessing the same data but with input/output in different schemas A conservative estimate of the number of tables?often whose queries require joins?is: 20. Which database type?e.g.: NoSQL or DBMS ?key-value data store or object-relational database ?e.g.: Redis or PostgreSQL?and web-framework ?e.g. Django , Web2Pyor Flask ?would you recommend? -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Sat May 12 04:32:09 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 May 2012 01:32:09 -0700 (PDT) Subject: Python web-framework+db with the widest scalability? Message-ID: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> I am building a project requiring high performance and scalability, entailing: ? Role-based authentication with API-key licensing to access data of specific users ? API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP ? "Easily" configurable getters and setters to create APIs accessing the same data but with input/output in different schemas A conservative estimate of the number of tables?often whose queries require joins?is: 20. Which database type?e.g.: NoSQL or DBMS?key-value data store or object-relational database?e.g.: Redis or PostgreSQL?and web-framework?e.g. Django, Web2Py or Flask?would you recommend? Thanks for all suggestions, Alec Taylor From elektrrrus at gmail.com Sat May 12 06:38:58 2012 From: elektrrrus at gmail.com (elektrrrus at gmail.com) Date: Sat, 12 May 2012 03:38:58 -0700 (PDT) Subject: Python web-framework+db with the widest scalability? In-Reply-To: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> References: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> Message-ID: <29590505.429.1336819138658.JavaMail.geo-discussion-forums@vbez20> Hi, >From my experience while NoSQL databases are very fast and scalable, there is lack of _good_ support for popular frameworks. I've try with django and mongoengine, but results was poor. In my company we're building now large api-driven application with django and postgresql as a base. Django has two great api engines - piston and tastypie. Consider looking to nosql eg. mongodb as caching engine and session storage. Django is mature and stable framework, it has some limitations but there are good and documented use cases for doing almost everything You may need. Look also at server layer - popular apache and cgi-like solutions has very poor performance. Maybe You have use-cases to develop with messages queues like celery. W dniu sobota, 12 maja 2012 10:32:09 UTC+2 u?ytkownik Alec Taylor napisa?: > I am building a project requiring high performance and scalability, entailing: > > ? Role-based authentication with API-key licensing to access data of specific users > ? API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP > ? "Easily" configurable getters and setters to create APIs accessing the same data but with input/output in different schemas > > A conservative estimate of the number of tables?often whose queries require joins?is: 20. > > Which database type?e.g.: NoSQL or DBMS?key-value data store or object-relational database?e.g.: Redis or PostgreSQL?and web-framework?e.g. Django, Web2Py or Flask?would you recommend? > > Thanks for all suggestions, > > Alec Taylor From research at johnohagan.com Sat May 12 06:41:30 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 12 May 2012 20:41:30 +1000 Subject: Minor gripe about module names Message-ID: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Not sure if this is only package-manager specific, but occasionally I come across a module that sounds interesting, install it (in my case by apt-get), and then can't find it, because the actual module has a different name from what it says on the package - unlike the majority, which if they are called "python-whatever", are imported using "import whatever". Today's example was python-ecasound, which after some fruitless guessing followed by scanning the hundreds of entries returned by help('modules') and trying to import anything with a promising filename, turned out to really be called pyeca. Are there any rules about this kind of thing? (I did say "minor gripe".) -- John From rosuav at gmail.com Sat May 12 06:51:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 20:51:23 +1000 Subject: Minor gripe about module names In-Reply-To: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> References: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Message-ID: On Sat, May 12, 2012 at 8:41 PM, John O'Hagan wrote: > Not sure if this is only package-manager specific, but occasionally I come > across a module that sounds interesting, install it (in my case by apt-get), > and then can't find it, because the actual module has a different name from > what it says on the package - unlike the majority, which if they are called > "python-whatever", are imported using "import whatever". You import based on the filename, so all you need is the list of files from the package: $ dpkg -L python-ecasound This works only after the package has been installed successfully. Not a solution to your problem, but possibly a viable workaround. ChrisA From python.list at tim.thechases.com Sat May 12 07:45:15 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 12 May 2012 06:45:15 -0500 Subject: Minor gripe about module names In-Reply-To: References: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Message-ID: <4FAE4D4B.2000300@tim.thechases.com> On 05/12/12 05:51, Chris Angelico wrote: > On Sat, May 12, 2012 at 8:41 PM, John O'Hagan > wrote: >> Not sure if this is only package-manager specific, but >> occasionally I come across a module that sounds interesting, >> install it (in my case by apt-get), and then can't find it, >> because the actual module has a different name from what it >> says on the package - unlike the majority, which if they are >> called "python-whatever", are imported using "import >> whatever". > > $ dpkg -L python-ecasound > > This works only after the package has been installed > successfully. Not a solution to your problem, but possibly a > viable workaround. I use the dpkg method on my Debian-based systems, but (1) I never remember the syntax and only occasionally need it, so I have to look it up EVERY time and (2) it can return a lot of chaff if the module includes auxiliary files. If only we had some way to develop a simple program that knew about where Python modules were stored... ;-) ===================================== import os import sys if len(sys.argv) < 2: print("Usage:") print("%s module_text [or_module_text ...]" % argv[0]) sys.exit(1) mods_to_find = [s.lower() for s in sys.argv[1:]] for d in sys.path: if os.path.isdir(d): for modname in os.listdir(d): for piece in mods_to_find: if piece in modname.lower(): print(os.path.join(d, modname)) else: sys.stderr.write("Unable to check %r\n" % d) ====================================== should about do the trick and return less chaff. Could be tweaked to refine even further. Or to deduplicate results if the same file is found due to search criteria. -tkc From jeandaniel.browne at gmail.com Sat May 12 08:17:40 2012 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sat, 12 May 2012 14:17:40 +0200 Subject: Good data structure for finding date intervals including a given date Message-ID: Hello, I have a long list of n date intervals that gets added or suppressed intervals regularly. I am looking for a fast way to find the intervals containing a given date, without having to check all intervals (less than O(n)). Do you know the best way to do this in Python with the stdlib? A variant of the red black trees can do the job quickly [1], is this a good enough use case to discuss the inclusion of a red black tree implementation in the stdlib? This has been discussed here: http://bugs.python.org/issue1324770 , and lack of good use case was the reason the bug was closed. A dict implemented with red black trees is slower (but not too slow) at inserting, searching and deleting but the dict is always kept ordered. Bigger projects have their own implementation of ordered dict so such datastructures in the standard library would help the porting of the project to other platforms. Take the example of the zodb and the C-only implementation of the btree: btree in the stdlib in Python would help the porting to GAE or pypy [2]. Cheers, [1] in the "Cormen" book: http://en.wikipedia.org/wiki/Introduction_to_Algorithms [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency From zahlman at gmail.com Sat May 12 08:27:14 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:27:14 -0400 Subject: Fwd: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: I really wish gmail picked up the mailing list as a default reply-to address... ---------- Forwarded message ---------- From: Karl Knechtel Date: Sat, May 12, 2012 at 8:25 AM Subject: Re: Newbie naive question ... int() throws ValueError To: Devin Jeanpierre On Sat, May 12, 2012 at 12:11 AM, Devin Jeanpierre wrote: > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? > > Apparently the answer is to read the documentation for ValueError. The easiest way is to try it. In fact, in most cases, this will be easier than looking it up in the documentation could ever be, because looking something up in documentation requires you to read through a bunch of documentation until you find key info like 'raises FooError in bar circumstance', and then interpret it; by trial and error, you see exactly what happens right away, and you can do it by just banging out a couple of lines on the REPL. You should have already read the documentation for things like ValueError as a part of learning the language (i.e. the first time something raised a ValueError and you wanted to know what that meant); or at the very least you should have a good idea of what the "standard" exceptions are all named, and *develop an intuition* for which apply to what circumstances. As noted by others, you should not expect `int` to throw a `TypeError` when fed a bad string, because a `TypeError` means "something is wrong with the type of some object", and the problem with the bad string isn't that it's a string (its type), but that the string contents are not interpretable as int (its value, hence ValueError). -- ~Zahlman {:> -- ~Zahlman {:> From zahlman at gmail.com Sat May 12 08:30:44 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:30:44 -0400 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel wrote: > I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). Since you say "intervals" in plural here, I assume that they can overlap? -- ~Zahlman {:> From zahlman at gmail.com Sat May 12 08:36:02 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:36:02 -0400 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote: > And there's also something like... > > return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) > > which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) > > Is there a better way? If you don't care about being able to change the attributes dynamically, define the `__slots__` of your class, and then you can use return '\n'.join('%s: %s' % (name, getattr(self, name)) for name in self.__slots__) Calling `getattr` is probably more Pythonic than looking things up in `__dict__`, string formatting can take care of "casting" (converting, really) for you, and the nested `join` is really overkill :) Anyway the main point is that `__slots__` is a list, and thus has a defined order. > > p.s. I may want to substitute __repr__ for __str__ perhaps? Depending. Sometimes you want them to behave the same way. Since functions are objects, this is as simple as `__repr__ = __str__`. :) p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal interest (or perhaps both)? -- ~Zahlman {:> From breamoreboy at yahoo.co.uk Sat May 12 08:45:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 May 2012 13:45:24 +0100 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 12/05/2012 13:17, Jean-Daniel wrote: > Hello, > Do you know the best way to do this in Python with the stdlib? Sorry, not part of the stdlib but search for red black tree here http://pypi.python.org/pypi. While you're there also take a look at the blist package. -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Sat May 12 08:49:41 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 12 May 2012 07:49:41 -0500 Subject: Python web-framework with the widest scalability? In-Reply-To: References: Message-ID: <4FAE5C65.2010202@tim.thechases.com> On 05/12/12 03:30, Alec Taylor wrote: > I am building a project requiring high performance and scalability, > entailing: Most of the frameworks are sufficiently scalable. Scalability usually stems from design decisions (architecture and algorithm) and caching, and you'll usually hit bandwidth or algorithm/architecture limits long before the frameworks are your primary bottleneck. -tkc From ethan at stoneleaf.us Sat May 12 09:10:13 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 12 May 2012 06:10:13 -0700 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FAE6135.7070500@stoneleaf.us> Karl Knechtel wrote: > On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote: >> And there's also something like... >> >> return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) >> >> which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) >> >> Is there a better way? > > If you don't care about being able to change the attributes > dynamically, define the `__slots__` of your class [...] Firstly, __slots__ is a tuple. Secondly, this is bad advice. __slots__ is there as a memory optimization for classes that will have thousands of instances and do not need the ability to have arbitrary attributes added after creation. __slots__ is an advanced feature, and as such is easier to get wrong. It is *not* there to make __str__ nor __repr__ easier to write. 8<----------------------------------------------------------------------- Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Test1(object): ... __slots__ = ('item', 'size') ... desc = 'class-only attribute' ... >>> t1 = Test1() >>> t1.desc = 'read-only attribute' # fails because 'desc' is # not in __slots__ Traceback (most recent call last): File "", line 1, in AttributeError: 'Test1' object attribute 'desc' is read-only >>> print t1.item # fails because 'item' was # not set Traceback (most recent call last): File "", line 1, in AttributeError: item >>> class Test2(Test1): ... def __init__(self, price): ... self.price = price ... >>> t2 = Test2(7.99) # __slots__ not defined in # subclass, optimizations lost >>> t2.oops = '__slots__ no longer active' >>> print t2.oops __slots__ no longer active 8<----------------------------------------------------------------------- ~Ethan~ From ethan at stoneleaf.us Sat May 12 09:13:34 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 12 May 2012 06:13:34 -0700 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: <4FAE61FE.6070402@stoneleaf.us> Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 11:21 PM, Chris Angelico wrote: >> There are times when you want to catch all exceptions, though. >> Top-level code will often want to replace exception tracebacks with >> error messages appropriate to some external caller, or possibly log >> the exception and return to some primary loop. Otherwise, though, most >> code will just let unexpected exceptions through. > > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? > > Apparently the answer is to read the documentation for ValueError. > > It's a bit like putting the documentation on the return type for `map` > in the list documentation. Kinda hard to get there without already > knowing the answer. Unit tests. :) ~Ethan~ From contropinion at gmail.com Sat May 12 09:30:04 2012 From: contropinion at gmail.com (contro opinion) Date: Sat, 12 May 2012 09:30:04 -0400 Subject: to solve the simple equation Message-ID: there is a simple equation, 50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0 i input : >>> from sympy import * >>> x=Symbol('x') >>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 332, in solve result = tsolve(f, *symbols) File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve "(tsolve: at least one Function expected at this point") NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve "(tsolve: at least one Function expected at this point") NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point 1.how can i solve it with sympy? 2.how can i solve it with other package? -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.s.mcgee115 at gmail.com Sat May 12 10:09:09 2012 From: j.s.mcgee115 at gmail.com (Josh McGee) Date: Sat, 12 May 2012 07:09:09 -0700 (PDT) Subject: %d not working in re at Python 2.7? In-Reply-To: References: Message-ID: <8356205.412.1336831749576.JavaMail.geo-discussion-forums@pbcoz4> % On Friday, May 11, 2012 11:58:01 AM UTC-7, vacu wrote: > I am frustrated to see %d not working in my Python 2.7 re.search, like > this example: > > >>> (re.search('%d', "asdfdsf78asdfdf")).group(0) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'group' > > > \d works fine: > > >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) > '78' > > > And google search ignores % in their search, so I failed to find > answer from Python mailing list or web, > Do you have any idea what's problem here? > > Thanks a head > Vacu %d and %s and such are format strings, not regex. From jeandaniel.browne at gmail.com Sat May 12 10:18:07 2012 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sat, 12 May 2012 16:18:07 +0200 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: > Since you say "intervals" in plural here, I assume that they can overlap? Yes, For instance, there are the following intervals : [[1, 10], [4, 7], [6, 15], [11, 17]] asking for the intervals including 5, the returned value should be [[1, 10], [4, 7]] The idea here to make it fast is to have done some preprocessing at insertion time, so that not all intervals are processed at query time. On Sat, May 12, 2012 at 2:30 PM, Karl Knechtel wrote: > On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel > wrote: >> I am looking for a fast way to find the intervals >> containing a given date, without having to check all intervals (less >> than O(n)). > > Since you say "intervals" in plural here, I assume that they can overlap? > > -- > ~Zahlman {:> > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Sat May 12 10:58:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 12 May 2012 10:58:56 -0400 Subject: to solve the simple equation In-Reply-To: References: Message-ID: On 5/12/2012 9:30 AM, contro opinion wrote: > there is a simple equation, > 50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0 > i input : >>>> from sympy import * >>>> x=Symbol('x') >>>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) > Traceback (most recent call last): > File"", line 1, in > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 332, in solve > result = tsolve(f, *symbols) > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve > "(tsolve: at least one Function expected at this point") > NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point > > tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) > Traceback (most recent call last): > File"", line 1, in > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve > "(tsolve: at least one Function expected at this point") > NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point > > 1.how can i solve it with sympy? Read the sympy doc and learn how to make a Function and use tsolve correctly? -- Terry Jan Reedy From ndbecker2 at gmail.com Sat May 12 14:23:50 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 12 May 2012 14:23:50 -0400 Subject: Good data structure for finding date intervals including a given date References: Message-ID: Probably boost ITL (Interval Template Library) would serve as a good example. I noticed recently someone created an interface for python. From jeanpierreda at gmail.com Sat May 12 14:25:17 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 12 May 2012 14:25:17 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 8:27 AM, Karl Knechtel wrote: > I really wish gmail picked up the mailing list as a default reply-to address... There is some labs thing that makes "reply to all" the default if you click the button on the top-right. Unfortunately, that applies for non-mailing-lists too... > The easiest way is to try it. In fact, in most cases, this will be > easier than looking it up in the documentation could ever be, because > looking something up in documentation requires you to read through a > bunch of documentation until you find key info like 'raises FooError > in bar circumstance', and then interpret it; by trial and error, you > see exactly what happens right away, and you can do it by just banging > out a couple of lines on the REPL. Eh, this doesn't make sense. Before I would ever try the int() function, I would've read about it in the documentation -- otherwise how would I know what it does at all? How would I even know that it exists? What having to try-it-and-see does is give me extra steps to know what it does. Instead of only reading the documentation, now I have to both read the documentation *and* try it out in the interactive interpreter to see its behaviour in a bunch of undocumented error cases. What should actually happen is that the error cases should be documented explicitly, so that I don't have to run around in the REPL or orthogonal bits of documentation trying to figure out the behaviour of the function. > You should have already read the documentation for things like > ValueError as a part of learning the language (i.e. the first time > something raised a ValueError and you wanted to know what that meant); > or at the very least you should have a good idea of what the > "standard" exceptions are all named, and *develop an intuition* for > which apply to what circumstances. As noted by others, you should not > expect `int` to throw a `TypeError` when fed a bad string, because a > `TypeError` means "something is wrong with the type of some object", > and the problem with the bad string isn't that it's a string (its > type), but that the string contents are not interpretable as int (its > value, hence ValueError). And yet this is what ord does. Every rule has an exception. I concede that reading the docs on ValueError is probably worth doing the first time you see it. Although, it's also one of those exceptions that has a "clear" name, so it isn't something everyone will do. I'm not sure if I ever did it. And certainly the OP never looked there. -- Devin From sverreodegard at gmail.com Sat May 12 15:40:28 2012 From: sverreodegard at gmail.com (Sverre) Date: Sat, 12 May 2012 12:40:28 -0700 (PDT) Subject: Are there any instrumentation widgets for wxpython or tkinter? Message-ID: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> I searched for widgets used for PLC automation or lab instrumentation like gauges, led's etc. in the net, but didn't found anything because of those massive link spam sites. In the case there isn't any solution, with which toolkit would it be easiest to build gauges? From bheese at optonline.net Sat May 12 18:50:48 2012 From: bheese at optonline.net (Brian Heese) Date: Sat, 12 May 2012 18:50:48 -0400 Subject: Opening a csv file in python on a mac Message-ID: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> I created a csv file called python test file.csv. It is stored on my Desktop directory. When I try to open it using the command open ('Desktop python test file.csv') I get the following error: "No such file or directory". The same thing happens if I use open ('python test file.csv'). What I am I doing wrong? From rosuav at gmail.com Sat May 12 18:53:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 May 2012 08:53:20 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sun, May 13, 2012 at 4:25 AM, Devin Jeanpierre wrote: > What having to try-it-and-see does is give me extra steps to know what > it does. Instead of only reading the documentation, now I have to both > read the documentation *and* try it out in the interactive interpreter > to see its behaviour in a bunch of undocumented error cases. Point to note: The Python documentation tells you about the language. Trying it in the interpreter tells you about your implementation. There can be differences. I doubt there will be in something as simple as casting to int, but in other functions, it wouldn't surprise me to find that CPython (the one that most people think of as Python) and IronPython, PyPy, or Jython have differences in what they can throw. ChrisA From alec.taylor6 at gmail.com Sat May 12 21:01:07 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 13 May 2012 11:01:07 +1000 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: Import csv Lookup usage in the python docs On 13/05/2012 9:22 AM, "Brian Heese" wrote: > I created a csv file called python test file.csv. It is stored on my > Desktop directory. When I try to open it using the command open ('Desktop > python test file.csv') I get the following error: "No such file or > directory". The same thing happens if I use open ('python test file.csv'). > What I am I doing wrong? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sat May 12 21:06:21 2012 From: d at davea.name (Dave Angel) Date: Sat, 12 May 2012 21:06:21 -0400 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: <4FAF090D.9080108@davea.name> On 05/12/2012 06:50 PM, Brian Heese wrote: > I created a csv file called python test file.csv. It is stored on my Desktop directory. When I try to open it using the command open ('Desktop python test file.csv') I get the following error: "No such file or directory". The same thing happens if I use open ('python test file.csv'). What I am I doing wrong? It is totally unclear just where you "used" these "commands." Please identify your OS and python version, and paste a complete log of what you typed and saw on your console. Do NOT retype it, copy/paste it. -- DaveA From python at mrabarnett.plus.com Sat May 12 21:33:05 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 13 May 2012 02:33:05 +0100 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: <4FAF0F51.50105@mrabarnett.plus.com> On 12/05/2012 23:50, Brian Heese wrote: > I created a csv file called python test file.csv. It is stored on my > Desktop directory. When I try to open it using the command open > ('Desktop python test file.csv') I get the following error: "No such > file or directory". The same thing happens if I use open ('python > test file.csv'). What I am I doing wrong? You should provide the full absolute path of the file. 'python test file.csv' is the name of the file, but it doesn't say where it is, and 'Desktop python test file.csv' is also just a name. (Is the file called 'Desktop python test file.csv'? No. It's called 'python test file.csv' and it's in the 'Desktop' directory, wherever that is.) From neolo12 at yandex.ru Sun May 13 03:14:31 2012 From: neolo12 at yandex.ru (jimmy970) Date: Sun, 13 May 2012 00:14:31 -0700 (PDT) Subject: http://porn-extreme.2304310.n4.nabble.com/ In-Reply-To: <1335955532204-4945863.post@n6.nabble.com> References: <1334334574674-4879088.post@n6.nabble.com> <1334385003417-4880911.post@n6.nabble.com> <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> <1335847182281-4942868.post@n6.nabble.com> <1335955532204-4945863.post@n6.nabble.com> Message-ID: <1336893271019-4974351.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4974351.html Sent from the Python - python-list mailing list archive at Nabble.com. From alec.taylor6 at gmail.com Sun May 13 08:29:57 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 13 May 2012 22:29:57 +1000 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. If you are looking for the best possible self-sorting structure for searching, then perhaps you are looking for what's outlined in the 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) Expected Time and Linear Space[3]. [1] http://www.python.org/getit/releases/3.1/ [2] http://www.python.org/getit/releases/2.7.3/ [3] http://dl.acm.org/citation.cfm?id=645413.652131 On Sat, May 12, 2012 at 10:17 PM, Jean-Daniel wrote: > > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). > > Do you know the best way to do this in Python with the stdlib? > > A variant of the red black trees can do the job quickly [1], is this a > good enough use case to discuss the inclusion of a red black tree > implementation in the stdlib? > > This has been discussed here: http://bugs.python.org/issue1324770 , > and lack of good use case was the reason the bug was closed. A dict > implemented with red black trees is slower (but not too slow) at > inserting, searching and deleting but the dict is always kept ordered. > Bigger projects have their own implementation of ordered dict so such > datastructures in the standard library would help the porting of the > project to other platforms. Take the example of the zodb and the > C-only implementation of the btree: btree in the stdlib in Python > would help the porting to GAE or pypy [2]. > > Cheers, > > [1] in the "Cormen" book: > http://en.wikipedia.org/wiki/Introduction_to_Algorithms > [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency > -- > http://mail.python.org/mailman/listinfo/python-list From davidgshi at yahoo.co.uk Sun May 13 09:25:54 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Sun, 13 May 2012 14:25:54 +0100 (BST) Subject: How to call and execute C code in Python? In-Reply-To: References: Message-ID: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Can anyone tell me how to call and exectute C code in Python? Regards. David ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Friday, 11 May 2012, 5:35 Subject: Python-list Digest, Vol 104, Issue 57 ----- Forwarded Message ----- 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. Looking for video/slides from PyCon 2011... (Monte Milanuk) ? 2. Re: Dealing with the __str__ method in classes with lots of ? ? ? attributes (Cameron Simpson) ? 3. RE: Open Source: you're doing it wrong - the Pyjamas hijack ? ? ? (Adrian Hunt) ? 4. RE: Creating a Windows installer for Python + a set of ? ? ? dependencies (Adrian Hunt) ? 5. Re: Open Source: you're doing it wrong - the Pyjamas hijack ? ? ? (Chris Angelico) ? 6. Re: Retrieving result from embedded execution (Chris Angelico) ? 7. Finding the line number of an 'else' statement via ast ? ? ? (Michael Rene Armida) ...specifically the two lectures on creating GUI applications with Python + QT http://us.pycon.org/2011/schedule/presentations/207/ Various searches on the 'Net don't seem to be turning up much... kinda curious as to why? Anyone here know? TIA, Monte On 10May2012 15:33, Andreas Tawn wrote: | Say I've got a class... | | class test(object): |? ? def __init__(self): |? ? ? ? self.foo = 1 |? ? ? ? self.bar = 2 |? ? ? ? self.baz = 3 | | I can say... | | def __str__(self): |? ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) | | and everything's simple and clean and I can vary the formatting if I need to. | | This gets ugly when the class has a lot of attributes because the string construction gets very long. This issue bit me once too often a few months ago, and now I have a class called "O" from which I often subclass instead of from "object". Its main purpose is a friendly __str__ method, though it also has a friendly __init__. Code: ? ? class O(object): ? ? ? ''' A bare object subclass to allow storing arbitrary attributes. ? ? ? ? ? It also has a nicer default str() action, and an aggressive repr(). ? ? ? ''' ? ? ? def __init__(self, **kw): ? ? ? ? ''' Initialise this O. ? ? ? ? ? ? Fill in attributes from any keyword arguments if supplied. ? ? ? ? ? ? This call can be omitted in subclasses if desired. ? ? ? ? ''' ? ? ? ? for k in kw: ? ? ? ? ? setattr(self, k, kw[k]) ? ? ? def __str__(self): ? ? ? ? return ( "<%s %s>" ? ? ? ? ? ? ? ? % ( self.__class__.__name__, ? ? ? ? ? ? ? ? ? ? ",".join([ "%s=%s" % (attr, getattr(self, attr)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for attr in sorted(dir(self)) if attr[0].isalpha() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ]) ? ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ) So I have some code thus: ? from cs.misc import O ? ...... ? class FilterModes(O): ? ? def __init__(self, **kw): ? ? ? ? # special case one parameter ? ? ? ? self._maildb_path = kw.pop('maildb_path') ? ? ? ? self._maildb_lock = allocate_lock() ? ? ? ? O.__init__(self, **kw) ? ...... ? filter_modes = FilterModes(justone=justone, ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay=delay, ? ? ? ? ? ? ? ? ? ? ? ? ? ? no_remove=no_remove, ? ? ? ? ? ? ? ? ? ? ? ? ? ? no_save=no_save, ? ? ? ? ? ? ? ? ? ? ? ? ? ? maildb_path=os.environ['MAILDB'], ? ? ? ? ? ? ? ? ? ? ? ? ? ? maildir_cache={}) This removes a lot of guff from some common procedures. Hope this helps, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's a fine line between pathos and pathetic. ? ? ? ? - David Stivers stiv at stat.rice.edu DoD #857 lol, Cheers Chris. Just so you know, I care about what and how I write... I almost always run my emails though a word-processor before sending. And, that has paid off for me: thanks to MS Word, MS Works and Open Office, I have better understanding of "correct" punctuation use (if not spelling and grammar) than most school leavers!!! PS. It hasn't gone a miss that you are one of the core python-list responders (and I bet this goes for most of the python-list users): your responses, time and knowledge is appreciated... Thank you. > Date: Fri, 11 May 2012 09:57:49 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > > have ever had any prior contact with) about releasing code under a > > license... And, what I said stands: once anyone releases code, they are > > bound by the license they released it under as much as anyone else that may > > use it and cannot then withdraw that code from the domain they released it > > to (except by maybe creating a new and different version.) > > And that's absolutely correct. Open source licenses are deliberately > worded to guarantee rights in perpetuity, so there's no way to > withdraw it or change the license (though of course a copyright owner > can release the same code under an additional license). > > > Being dyslexic, my message (and this one) may not be worded in the best way > > but that is no reason to start on me! > > Your message is fine. Believe you me, I'd much rather read a message > posted by a non-native English speaker, or a dyslexic person, or > someone who has a clinical aversion to the letter 'q', than someone > who's simply sloppy and doesn't care about their language at all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list Hi there, I've use NSIS for quite a few projects... NSIS will do it with ease. You write a script that gets "compiled" into a install exe and the scripting language is not too hard to learn. You can do it in several different ways: 1. You can include the Python installer as a file compressed into your installer (that is decompressed to a temp directory before being run.) 2. The Python installer could be a included along side you installer and run as needed 3. You can specify a URL to the Python install to be downloaded and installed (again using a temp directory.) You can even use a mix... If an internet connection is available download it, if not fall back to one of the other methods. If you can come up with yet another method, it wouldn't be simple to write a script to handle it.? If you really need to you can write a dynamic link library that the final NSIS installer will make calls to. If you need any more help on this subject, email me directly... Although I try to keep an eye on python-list, I can't guarantee a quick reply. > Date: Thu, 10 May 2012 16:26:25 +0200 > Subject: Creating a Windows installer for Python + a set of dependencies > From: g.rodola at gmail.com > To: python-list at python.org > > Hi all, > I need to create an installer for Windows which should be able to > install a specific version of the Python interpreter (2.7) plus a set > a dependencies such as ipython, numpy, pandas, etc. > Basically this is the same thing Active State did for their Active > Python distribution: a single bundle including interpreter + deps. > Not being a Windows user I'm not sure where to start with this except > maybe looking into NSIS (could that be of any help?). > > Thanks in advance, > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > -- > http://mail.python.org/mailman/listinfo/python-list On Fri, May 11, 2012 at 10:21 AM, Adrian Hunt wrote: > lol, Cheers Chris. > > Just so you know, I care about what and how I write... I almost always run > my emails though a word-processor before sending. And, that has paid off for > me: thanks to MS Word, MS Works and Open Office, I have better understanding > of "correct" punctuation use (if not spelling and grammar) than most school > leavers!!! Absolutely. Taking care puts you miles ahead of the average (unfortunately for the average). I was home educated, and taught to value correctness, so I tend to speak and write more carefully than most do (people say I sound British for some reason - my accent doesn't sound Australian). That's why I tend to do a lot (note, not "alot", though the cute drawings are fun) of copyediting. > PS. It hasn't gone a miss that you are one of the core python-list > responders (and I bet this goes for most of the python-list users): your > responses, time and knowledge is appreciated... Thank you. Thanks! I'm just a guy who types fast, mainly; but I've been coding for about twenty years, and I'm always happy to help people. But this list is more for me to learn than for me to share. I've learned no end of things from these threads - it's awesome! ChrisA On Wed, May 9, 2012 at 5:07 AM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our > application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in > the > standalone interpreter. Greetings! The standalone interpreter - I assume you mean the interactive prompt? It has slightly different handling of things (for instance, naked expressions being written to standard output) from the more "usual" invocation of the interpreter. For your embedded Python, probably the easiest thing to do is to not try to use interactive mode, but script mode: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals) Pass it a string of Python code and a dictionary to use for globals and locals (they can be the same dict). Then when that finishes, retrieve from that dictionary some predetermined name (eg "Output"). The Python code then needs simply to assign to Output and all will work. Another way to do it is to call a function inside the Python code, and retrieve its return value. > We are using python 2.7. > > Any suggestions? Unless you have particular need to stick to the 2.x branch, I would suggest moving to 3.3; many things are easier (especially Unicode). But both work. > Also, I'm new to mailling lists, what is the proper way to reply to someone? > Should I > reply directly to someone's email adress or is there a way to answer trough > the server. The usual convention is to reply on-list, unless it's particularly private. Many mail clients will handle this conveniently; otherwise, just manually replace the To address with the list address. As long as you use reply (rather than starting a fresh email), all posts will be correctly threaded both on the list and on the synchronized newsgroup (comp.lang.python). Chris Angelico Given this source: def do_something(val): ? ? if val: ? ? ? ? return 'a' ? ? else: ? ? ? ? return 'b' How do I get the line number of the "else:" line, using the ast module?? The grammar only includes the 'orelse' list: ? ? If(expr test, stmt* body, stmt* orelse) ...but 'orelse' is the list of statements under the 'else' token, not a node representing the token itself. I have a suspicion that this isn't possible, and shouldn't be, and the giveaway word above was "token."? Because the tokens themselves aren't part of the abstract syntax tree. Here's an interactive session showing me poking around the If node: >>> import ast >>> tree = ast.parse(''' ... if True: ...? ? pass ... else: ...? ? pass ... ''') >>> tree.body[0].orelse [<_ast.Pass object at 0x7f1301319390>] >>> tree.body[0]._fields ('test', 'body', 'orelse') >>> for i in ast.iter_child_nodes(tree.body[0]): ...? ? print i.__class__.__name__ ... Name Pass Pass Is my suspicion correct?? Or is there a way to get the line number of that 'else:'? -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Sun May 13 09:30:34 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 13 May 2012 14:30:34 +0100 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 13 May 2012 13:29, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. I don't think that'll help the OP. Python's OrderedDict keeps track of the order in which the keys were inserted into the dictionary (a bit like a list), it doesn't keep the keys sorted. > If you are looking for the best possible self-sorting structure for > searching, then perhaps you are looking for what's outlined in the > 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) > Expected Time and Linear Space[3]. I can't access it but it seems to me it's not about self sorted data structures, which is what the OP is looking for. -- Arnaud From emile at fenx.com Sun May 13 11:29:37 2012 From: emile at fenx.com (Emile van Sebille) Date: Sun, 13 May 2012 08:29:37 -0700 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 5/12/2012 5:17 AM Jean-Daniel said... > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). ISTM the fastest way is to retrieve the list of intervals from a dict using the date as a key. You don't say how long your list of intervals is, nor how large each interval can be so I don't have enough info to determine the setup reqs, but I'd suspect that a list of tens of thousands of intervals covering ranges of days to weeks would be doable. If instead you're talking about millions of ranges covering years to decades I'd start elsewhere. Emile From rosuav at gmail.com Sun May 13 11:39:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 May 2012 01:39:42 +1000 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: > Can anyone tell me how to call and exectute C code in Python? Browse the documentation about Extending and Embedding Python, there's an extensive API. Chris Angelico From stefan_ml at behnel.de Sun May 13 11:58:32 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 17:58:32 +0200 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: David Shi, 13.05.2012 15:25: > Can anyone tell me how to call and exectute C code in Python? Take a look at Cython, a Python-like language that supports native calls to and from C/C++ code. It translates your code into very efficient C code, so the wrapping code tends to be very fast (often faster than hand written C code). http://cython.org/ Here are a couple of examples: http://docs.cython.org/src/tutorial/external.html There's also the "ctypes" package in the standard library, which is usable for simple wrapping cases that are not performance critical. Stefan From breamoreboy at yahoo.co.uk Sun May 13 13:23:45 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:23:45 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 16:39, Chris Angelico wrote: > On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >> Can anyone tell me how to call and exectute C code in Python? > > Browse the documentation about Extending and Embedding Python, there's > an extensive API. > > Chris Angelico I like your response, my first thought was to say "yes" :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun May 13 13:27:28 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:27:28 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 16:58, Stefan Behnel wrote: > David Shi, 13.05.2012 15:25: >> Can anyone tell me how to call and exectute C code in Python? > > Take a look at Cython, a Python-like language that supports native calls to > and from C/C++ code. It translates your code into very efficient C code, so > the wrapping code tends to be very fast (often faster than hand written C > code). > > http://cython.org/ > > Here are a couple of examples: > > http://docs.cython.org/src/tutorial/external.html > > There's also the "ctypes" package in the standard library, which is usable > for simple wrapping cases that are not performance critical. > > Stefan > Stefan, you appear to have a lot to do with Cython. It would be polite to mention this when replying. -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Sun May 13 13:38:55 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 19:38:55 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:23: > On 13/05/2012 16:39, Chris Angelico wrote: >> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Browse the documentation about Extending and Embedding Python, there's >> an extensive API. > > I like your response, my first thought was to say "yes" :) It has a serious learning curve all by itself, though, with a lot of major pitfalls not only for new users. It also requires C fluency, which not everyone has or wants to learn just to be able to talk to existing C code. And even when you're up to speed with all that, you will waste a substantial part of your time debugging crashes, making your code reference leak free and eventually maintaining it and porting it to different CPython versions and platforms. Time that IMHO is much better spent adding features and tuning the code for performance. Stefan From stefan_ml at behnel.de Sun May 13 13:42:35 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 19:42:35 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:27: > On 13/05/2012 16:58, Stefan Behnel wrote: >> David Shi, 13.05.2012 15:25: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Take a look at Cython, a Python-like language that supports native calls to >> and from C/C++ code. It translates your code into very efficient C code, so >> the wrapping code tends to be very fast (often faster than hand written C >> code). >> >> http://cython.org/ >> >> Here are a couple of examples: >> >> http://docs.cython.org/src/tutorial/external.html >> >> There's also the "ctypes" package in the standard library, which is usable >> for simple wrapping cases that are not performance critical. > > Stefan, you appear to have a lot to do with Cython. It would be polite to > mention this when replying. Well, my name is pretty far up both on the project home page and on PyPI, so it's not like I'm hiding this information. But sure, I'm one of the core developers and initial founders of the project. So I can assure you that I know what I'm talking about. Stefan From breamoreboy at yahoo.co.uk Sun May 13 13:44:50 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:44:50 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 18:38, Stefan Behnel wrote: > Mark Lawrence, 13.05.2012 19:23: >> On 13/05/2012 16:39, Chris Angelico wrote: >>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>> Can anyone tell me how to call and exectute C code in Python? >>> >>> Browse the documentation about Extending and Embedding Python, there's >>> an extensive API. >> >> I like your response, my first thought was to say "yes" :) > > It has a serious learning curve all by itself, though, with a lot of major > pitfalls not only for new users. It also requires C fluency, which not > everyone has or wants to learn just to be able to talk to existing C code. > And even when you're up to speed with all that, you will waste a > substantial part of your time debugging crashes, making your code reference > leak free and eventually maintaining it and porting it to different CPython > versions and platforms. Time that IMHO is much better spent adding features > and tuning the code for performance. > > Stefan > Haven't the faintest idea what you're on about so please explain. -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Sun May 13 14:14:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 20:14:26 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:44: > On 13/05/2012 18:38, Stefan Behnel wrote: >> Mark Lawrence, 13.05.2012 19:23: >>> On 13/05/2012 16:39, Chris Angelico wrote: >>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>>> Can anyone tell me how to call and exectute C code in Python? >>>> >>>> Browse the documentation about Extending and Embedding Python, there's >>>> an extensive API. >>> >>> I like your response, my first thought was to say "yes" :) >> >> It has a serious learning curve all by itself, though, with a lot of major >> pitfalls not only for new users. It also requires C fluency, which not >> everyone has or wants to learn just to be able to talk to existing C code. >> And even when you're up to speed with all that, you will waste a >> substantial part of your time debugging crashes, making your code reference >> leak free and eventually maintaining it and porting it to different CPython >> versions and platforms. Time that IMHO is much better spent adding features >> and tuning the code for performance. > > Haven't the faintest idea what you're on about so please explain. Sure. Learning curve and pitfalls: almost all C-API code I've seen from new users had at least one reference leak, usually more than one. This even happens to core developers from time to time, so I think it's reasonable to assume that pretty much all users of the C-API have produced at least one reference leak in their time as programmers and at least some do so frequently while learning to use it. I call that a common pitfall. C fluency: obviously, you need to be able to (and want to) write C if you want to make effective use of CPython's C-API from C code. Not every Python developer knows C, and why should they? Wasting time debugging crashes and making your code reference leak free: well, if you have ref-counting bugs in your code, you have to find them and fix them. First of all, you have to know they are there, which isn't always obvious, especially for leaks. The problem with ref-counting bugs is that the effects (even crashes) are not local in most cases but can happen anywhere in your program at unpredictable times, so you will spend more time on average debugging them than with other, more local bugs. Wasting time maintaining: arguably, maintaining C code requires more work than maintaining Python code. That's why we use high-level languages in the first place, isn't it? Wasting time porting: well, the C-API has subtle to major differences between CPython versions, so you not only have to learn "the" C-API, but the differences between these C-APIs, then write or adapt your code in order to make it work with different versions. Also, being able to write C code doesn't mean that that code will compile and run with different C compilers and on different platforms, so more work on that front. Spending more time adding features and tuning code instead: well, we designed Cython to relieve programmers from all of the above, so that they can focus on functionality and performance. And it's pretty good in that (you may want to read the testimonials on our project home page). Basically, the idea is that we write C so you don't have to. Is it clearer what I mean now? Stefan From breamoreboy at yahoo.co.uk Sun May 13 14:25:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 19:25:25 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 19:14, Stefan Behnel wrote: > Mark Lawrence, 13.05.2012 19:44: >> On 13/05/2012 18:38, Stefan Behnel wrote: >>> Mark Lawrence, 13.05.2012 19:23: >>>> On 13/05/2012 16:39, Chris Angelico wrote: >>>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>>>> Can anyone tell me how to call and exectute C code in Python? >>>>> >>>>> Browse the documentation about Extending and Embedding Python, there's >>>>> an extensive API. >>>> >>>> I like your response, my first thought was to say "yes" :) >>> >>> It has a serious learning curve all by itself, though, with a lot of major >>> pitfalls not only for new users. It also requires C fluency, which not >>> everyone has or wants to learn just to be able to talk to existing C code. >>> And even when you're up to speed with all that, you will waste a >>> substantial part of your time debugging crashes, making your code reference >>> leak free and eventually maintaining it and porting it to different CPython >>> versions and platforms. Time that IMHO is much better spent adding features >>> and tuning the code for performance. >> >> Haven't the faintest idea what you're on about so please explain. > > Sure. > > Learning curve and pitfalls: almost all C-API code I've seen from new users > had at least one reference leak, usually more than one. This even happens > to core developers from time to time, so I think it's reasonable to assume > that pretty much all users of the C-API have produced at least one > reference leak in their time as programmers and at least some do so > frequently while learning to use it. I call that a common pitfall. > > C fluency: obviously, you need to be able to (and want to) write C if you > want to make effective use of CPython's C-API from C code. Not every Python > developer knows C, and why should they? > > Wasting time debugging crashes and making your code reference leak free: > well, if you have ref-counting bugs in your code, you have to find them and > fix them. First of all, you have to know they are there, which isn't always > obvious, especially for leaks. The problem with ref-counting bugs is that > the effects (even crashes) are not local in most cases but can happen > anywhere in your program at unpredictable times, so you will spend more > time on average debugging them than with other, more local bugs. > > Wasting time maintaining: arguably, maintaining C code requires more work > than maintaining Python code. That's why we use high-level languages in the > first place, isn't it? > > Wasting time porting: well, the C-API has subtle to major differences > between CPython versions, so you not only have to learn "the" C-API, but > the differences between these C-APIs, then write or adapt your code in > order to make it work with different versions. Also, being able to write C > code doesn't mean that that code will compile and run with different C > compilers and on different platforms, so more work on that front. > > Spending more time adding features and tuning code instead: well, we > designed Cython to relieve programmers from all of the above, so that they > can focus on functionality and performance. And it's pretty good in that > (you may want to read the testimonials on our project home page). > Basically, the idea is that we write C so you don't have to. > > Is it clearer what I mean now? > > Stefan > No, I'm completely baffled. My response to Chris Angelico was simple and you've gone off at a complete tangent whilst writing "War and Peace". Or is it a simple matter that my newsreader is better than your newsreader? -- Cheers. Mark Lawrence. p.s. completely off topic, but will be back later, just going off to extract the urine from Manchester United fans. From stefan_ml at behnel.de Sun May 13 14:31:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 20:31:26 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 20:25: > My response to Chris Angelico was simple and > you've gone off at a complete tangent whilst writing "War and Peace". Or is > it a simple matter that my newsreader is better than your newsreader? Ah, sorry. I didn't know we were discussing at *that* level. Stefan From bob.grommes at gmail.com Sun May 13 15:11:21 2012 From: bob.grommes at gmail.com (Bob Grommes) Date: Sun, 13 May 2012 12:11:21 -0700 (PDT) Subject: Hashability questions Message-ID: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library. As such, I've done the following for starters: def __str__(self): return str(type(self)) # def __eq__(self,other): # return hash(self) == hash(other) The commented-out method is what I'm questioning. As-is, I can do the following from my test harness: u = Utility() print(str(u)) print(hash(u)) u2 = Utility() print(hash(u2)) print(hash(u) == hash(u2)) However if I uncomment the above _eq_() implementation, I get the following output: Traceback (most recent call last): File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in print(hash(u)) TypeError: unhashable type: 'Utility' Process finished with exit code 1 Obviously there is some sort of default implementation of __hash__() at work and my implementation of _eq_() has somehow broken it. Can anyone explain what's going on? From tjreedy at udel.edu Sun May 13 16:10:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 May 2012 16:10:22 -0400 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 5/13/2012 9:25 AM, David Shi wrote: > Can anyone tell me how to call and exectute C code in Python? > > Regards. > > David > > ------------------------------------------------------------------------ > *From:* "python-list-request at python.org" > *To:* python-list at python.org > *Sent:* Friday, 11 May 2012, 5:35 > *Subject:* Python-list Digest, Vol 104, Issue 57 > > ----- Forwarded Message ----- [snip the remaining hundread of lines of the digist] David, please post just your message as a new thread and do not include the whole digist. -- Terry Jan Reedy From massi_srb at msn.com Sun May 13 17:14:58 2012 From: massi_srb at msn.com (Massi) Date: Sun, 13 May 2012 14:14:58 -0700 (PDT) Subject: Yet another "split string by spaces preserving single quotes" problem Message-ID: <0470db1a-5399-408d-bab4-18937bd21a08@n16g2000vbn.googlegroups.com> Hi everyone, I know this question has been asked thousands of times, but in my case I have an additional requirement to be satisfied. I need to handle substrings in the form 'string with spaces':'another string with spaces' as a single token; I mean, if I have this string: s ="This is a 'simple test':'string which' shows 'exactly my' problem" I need to split it as follow (the single quotes must be mantained in the splitted list): ["This", "is", "a", "'simple test':'string which'", "shows", "'exactly my'", "problem"] Up to know I have written some ugly code which uses regular expression: splitter = re.compile("(?=\s|^)('[^']+') | ('[^']+')(?=\s|$)") temp = [t for t in splitter.split(s) if t not in [None, '']] print temp t = [] for i, p in enumerate(temp) : for x in ([p] if (p[0] == "'" and p[1] == "'") else p.split(' ')) : t.append(x) But it does not handle "colon" case. Any hints? Thanks in advance! From adminlewis at gmail.com Sun May 13 17:25:15 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 13 May 2012 23:25:15 +0200 Subject: write a bot Message-ID: Hi, I want write a bot in python, it should explore a site, click links and extract some info. I know mechanize but I would like to know if there is something better for performance. Thanks a lot lewis. -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From cjw at ncf.ca Sun May 13 17:27:14 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 13 May 2012 17:27:14 -0400 Subject: .py to .pyc Message-ID: Is there some way to ensure that a .pyc file is produced when executing a .py file? It seems that for small files the .pyc file is not produced. Colin W. From irmen.NOSPAM at xs4all.nl Sun May 13 17:36:02 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 13 May 2012 23:36:02 +0200 Subject: .py to .pyc In-Reply-To: References: Message-ID: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> On 13-5-2012 23:27, Colin J. Williams wrote: > Is there some way to ensure that a .pyc file is produced when executing a .py file? > > It seems that for small files the .pyc file is not produced. > > Colin W. All modules no matter how small produce a .pyc file *when they are imported*. If you start a module directly though, no .pyc is produced. (Notice that Python 3 puts the pyc files in a subdirectory.) Why do you care anyway? Pyc files are an implementation detail. Irmen From cjw at ncf.ca Sun May 13 17:43:12 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 13 May 2012 17:43:12 -0400 Subject: .py to .pyc Message-ID: Is there some way to ensure that a .pyc file is produced when executing a .py file? It seems that for small files the .pyc file is not produced. Colin W. PLEASE IGNORE - I was in the wrong directory. Colin W. From rosuav at gmail.com Sun May 13 17:45:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 May 2012 07:45:13 +1000 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Mon, May 14, 2012 at 3:23 AM, Mark Lawrence wrote: > On 13/05/2012 16:39, Chris Angelico wrote: >> >> On Sun, May 13, 2012 at 11:25 PM, David Shi ?wrote: >>> >>> Can anyone tell me how to call and exectute C code in Python? >> >> >> Browse the documentation about Extending and Embedding Python, there's >> an extensive API. >> >> Chris Angelico > > I like your response, my first thought was to say "yes" :) Hehe. Never ask a geek a yes-no question, eh. Regarding Cython vs direct use of the API: I cannot in good faith recommend Cython, as I've never used it, but it very likely could be the right option. However, my answer to a vague and nonspecific question would still have been a simple pointer to documentation, whether to Cython's or to the underlying API. To the OP: Be more specific about what you're trying to do, and you'll likely get more helpful answers. :) Incidentally, one of the easiest ways to deal with refcounting imho is to write a thin C++ layer around the PyObject* for locally owned references. Of course, that works only if you're writing C++ code, but it did save me a lot of hassle when I was embedding Python in C++. ChrisA From python.list at tim.thechases.com Sun May 13 18:00:49 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 13 May 2012 17:00:49 -0500 Subject: .py to .pyc In-Reply-To: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> Message-ID: <4FB02F11.9060406@tim.thechases.com> On 05/13/12 16:36, Irmen de Jong wrote: > Why do you care anyway? Pyc files are an implementation detail. I could see wanting to pre-compile .pyc files for performance if they'll then be stored on a read-only medium (a CD/DVD, a RO network share, or a RO drive partition all come to mind). You can read up on forcing the compile at http://effbot.org/zone/python-compile.htm#compiling-python-modules -tkc From jeanpierreda at gmail.com Sun May 13 19:19:56 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 13 May 2012 19:19:56 -0400 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Sun, May 13, 2012 at 11:58 AM, Stefan Behnel wrote: > David Shi, 13.05.2012 15:25: >> Can anyone tell me how to call and exectute C code in Python? > > Take a look at Cython, a Python-like language that supports native calls to > and from C/C++ code. It translates your code into very efficient C code, so > the wrapping code tends to be very fast (often faster than hand written C > code). More than just speed -- it's, IME, way easier to use and debug than ctypes (thanks to having incredible gdb support and compiler warnings). I swear, this is black magic: http://docs.cython.org/src/userguide/debugging.html Now if only my editor would bold those "cdef"s... :) -- Devin From steve+comp.lang.python at pearwood.info Sun May 13 20:03:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2012 00:03:54 GMT Subject: .py to .pyc References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> Message-ID: <4fb04bea$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 May 2012 23:36:02 +0200, Irmen de Jong wrote: > On 13-5-2012 23:27, Colin J. Williams wrote: >> Is there some way to ensure that a .pyc file is produced when executing >> a .py file? >> >> It seems that for small files the .pyc file is not produced. >> >> Colin W. > > All modules no matter how small produce a .pyc file *when they are > imported*. If you start a module directly though, no .pyc is produced. > (Notice that Python 3 puts the pyc files in a subdirectory.) That's only the case for Python 3.2 and higher, not 3.1. You can also use this: python -m compileall to produce .pyc files without waiting for them to be imported. -- Steven From xxxxxxxx at xxxxxx.xxx Sun May 13 20:50:23 2012 From: xxxxxxxx at xxxxxx.xxx (TommyVee) Date: Sun, 13 May 2012 20:50:23 -0400 Subject: Need to get Tags and Values from Dom Message-ID: <4fb056d7$0$370$607ed4bc@cv.net> I have a very simple XML document that I need to "walk", and I'm using xml.dom.minidom. No attributes, just lots of nested tags and associated values. All I'm looking to do is iterate through each of the highest sibling nodes, check what the tag is, and process its value accordingly. If a node has children, same thing - iterate through the nodes, check the tags and process the values accordingly. I see where each node object has a "childNodes" attribute, so I can drill down the tree. But what are the node attributes which indicate Tag and Value? I thought it would have been nodeName and nodeValue, but that doesn't seem to be. Does anyone know? Thanks in advance, TommyVee From emile at fenx.com Sun May 13 21:06:33 2012 From: emile at fenx.com (Emile van Sebille) Date: Sun, 13 May 2012 18:06:33 -0700 Subject: write a bot In-Reply-To: References: Message-ID: On 5/13/2012 2:25 PM admin lewis said... > Hi, > I want write a bot in python, it should explore a site, click links > and extract some info. I know mechanize but I would like to know if > there is something better for performance. Have you looked into Scrapy? http://scrapy.org Emile From adminlewis at gmail.com Mon May 14 00:29:05 2012 From: adminlewis at gmail.com (admin lewis) Date: Mon, 14 May 2012 06:29:05 +0200 Subject: write a bot In-Reply-To: References: Message-ID: 2012/5/14 Emile van Sebille : > On 5/13/2012 2:25 PM admin lewis said... > >> Hi, >> I want write a bot in python, it should explore a site, click links >> and extract some info. I know mechanize but I would like to know if >> there is something better for performance. > > > Have you looked into Scrapy? ?http://scrapy.org No, and it looks exactly what I'm looking for. thanks :) > > Emile > luigi -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From kushal.kumaran+python at gmail.com Mon May 14 00:42:57 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 14 May 2012 10:12:57 +0530 Subject: Looking for video/slides from PyCon 2011... In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 5:42 AM, Monte Milanuk wrote: > ...specifically the two lectures on creating GUI applications with Python + > QT > > http://us.pycon.org/2011/schedule/presentations/207/ > > Various searches on the 'Net don't seem to be turning up much... kinda > curious as to why? > > Anyone here know? > Is it one of the videos at http://blip.tv/pycon-us-videos-2009-2010-2011 -- regards, kushal From kushal.kumaran+python at gmail.com Mon May 14 00:44:19 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 14 May 2012 10:14:19 +0530 Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb056d7$0$370$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> Message-ID: On Mon, May 14, 2012 at 6:20 AM, TommyVee wrote: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. ?No attributes, just lots of nested tags and associated > values. ?All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. ?If > a node has children, same thing - iterate through the nodes, check the tags > and process the values accordingly. ?I see where each node object has a > "childNodes" attribute, so I can drill down the tree. ?But what are the node > attributes which indicate Tag and Value? ?I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. ?Does anyone know? > A sample of the document you are trying to parse will help people answer. -- regards, kushal From stefan_ml at behnel.de Mon May 14 02:50:31 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 14 May 2012 08:50:31 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Devin Jeanpierre, 14.05.2012 01:19: > Now if only my editor would bold those "cdef"s... :) Cython syntax support in editors is definitely not ubiquitous, but it's getting more and more widespread, so you may be lucky at some point (or find a way to add it yourself). Pygments also does a pretty good job on it for documentation and talk slides, but what I find really cool is that even major IDEs have started to pick it up, namely WingIDE, PyCharm (Jetbrains) and PyDev (Eclipse). From the PyCharm developers, I heard that it was one of the most heavily requested features for them, and they got it pretty much right (didn't try the others). Stefan From stefan_ml at behnel.de Mon May 14 02:54:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 14 May 2012 08:54:26 +0200 Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb056d7$0$370$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> Message-ID: TommyVee, 14.05.2012 02:50: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. No attributes, just lots of nested tags and associated > values. All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. > If a node has children, same thing - iterate through the nodes, check the > tags and process the values accordingly. I see where each node object has > a "childNodes" attribute, so I can drill down the tree. But what are the > node attributes which indicate Tag and Value? I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. Does anyone know? Use the xml.etree.ElementTree module instead. It makes this kind of work really easy, e.g.: import xml.etree.cElementTree as ET # using fast C accelerator module root = ET.parse("afile.xml").getroot() for child in root: if child.tag == 'abc': print("abc tag found") else: print("other tag found") There's also an incremental iterparse() function, in case your documents are large. Stefan From mailinglists at xgm.de Mon May 14 05:15:57 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Mon, 14 May 2012 11:15:57 +0200 Subject: Remove root handler from logger Message-ID: <1694679.NInCbTCQzc@horus> Hello, I configure my logging on application startup like that: logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile) ch = logging.StreamHandler() ch.setFormatter(logging.Formatter(FORMAT)) logging.getLogger().addHandler(ch) In one module of my application I want a logger that does not log to logfile but to another file. How can I get a logger that is either plain (no handlers attached) or remove a handler? The handlers that are derived from the root logger are not shown in handlers: (Pdb) logger1.handlers [] (Pdb) logging.getLogger().handlers [, ] How can I remove the FileHandler and StreamHandler from logger1 without affecting the root logger? logger1.removeHandler() does not work since there are no handlers on logger1. Thanks, Florian From andreas.tawn at ubisoft.com Mon May 14 05:16:40 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Mon, 14 May 2012 11:16:40 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A71AA746E2@PDC-MAIL-CMS01.ubisoft.org> > p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal interest (or > perhaps both)? We do use Python a fair bit, mostly for build systems and data mining, but also because it's the built-in script language for Motionbuilder. From neolo12 at yandex.ru Tue May 1 00:39:42 2012 From: neolo12 at yandex.ru (jimmy970) Date: Mon, 30 Apr 2012 21:39:42 -0700 (PDT) Subject: porn-extreme In-Reply-To: <1335623703913-4936643.post@n6.nabble.com> References: <1334088832274-4776849.post@n6.nabble.com> <1334263544723-4864079.post@n6.nabble.com> <1334334574674-4879088.post@n6.nabble.com> <1334385003417-4880911.post@n6.nabble.com> <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> Message-ID: <1335847182281-4942868.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4942868.html Sent from the Python - python-list mailing list archive at Nabble.com. From deuteros at xrs.net Tue May 1 00:50:48 2012 From: deuteros at xrs.net (deuteros) Date: Tue, 1 May 2012 04:50:48 +0000 (UTC) Subject: Trouble splitting strings with consecutive delimiters Message-ID: I'm using regular expressions to split a string using multiple delimiters. But if two or more of my delimiters occur next to each other in the string, it puts an empty string in the resulting list. For example: re.split(':|;|px', "width:150px;height:50px;float:right") Results in ['width', '150', '', 'height', '50', '', 'float', 'right'] Is there any way to avoid getting '' in my list without adding px; as a delimiter? From drsalists at gmail.com Tue May 1 01:25:39 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 30 Apr 2012 22:25:39 -0700 Subject: Sort comparison Message-ID: A while back I did a sort algorithm runtime comparison for a variety of sorting algorithms, and then mostly sat on it. Recently, I got into a discussion with someone on stackoverflow about the running time of radix sort. I realize it's commonly said that radixsort is n*k rather than n*log(n). I've been making that case that in real life, frequently k==log(n). Anyway, here's the comparison, with code and graph: http://stromberg.dnsalias.org/~strombrg/sort-comparison/ (It's done in Pure python and Cython, with a little m4). Interesting, BTW, that an unstable quicksort in Cython was approaching timsort as a C extension module in performance, even though timsort in Cython wasn't that performant. It makes one wonder if a highly optimized quicksort as a C extension module wouldn't outperform timsort in the standard library. Yes, I know, we've committed to keeping list_.sort() stable now, and quicksort normally isn't stable. Also, before timsort, did CPython use quicksort? I'd be a little surprised if it hadn't, since people used to say quicksort was the best thing around in practice. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue May 1 01:54:04 2012 From: nagle at animats.com (John Nagle) Date: Mon, 30 Apr 2012 22:54:04 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: On 4/30/2012 8:19 AM, deltaquattro at gmail.com wrote: > Hi, > > I would like to automate the following task under Linux. I need to create a set of directories such as > > 075 > 095 > 100 > 125 > > The directory names may be read from a text file foobar, which also contains a number corresponding to each dir, like this: > > 075 1.818 > 095 2.181 > 100 2.579 > 125 3.019 > > > In each directory I must copy a text file input.in. This file contains two lines which need to be edited: Learn how to use a database. Creating and managing a big collection of directories to handle small data items is the wrong approach to data storage. John Nagle From frank at chagford.com Tue May 1 02:12:42 2012 From: frank at chagford.com (Frank Millman) Date: Mon, 30 Apr 2012 23:12:42 -0700 (PDT) Subject: Some posts do not show up in Google Groups References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> Message-ID: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> On Apr 30, 8:20?am, Frank Millman wrote: > Hi all > > For a while now I have been using Google Groups to read this group, but on the odd occasion when I want to post a message, I use Outlook Express, as I know that some people reject all messages from Google Groups due to the high spam ratio (which seems to have improved recently, BTW). > > From time to time I see a thread where the original post is missing, but the follow-ups do appear. My own posts have shown up with no problem. > > Now, in the last month, I have posted two messages using Outlook Express, and neither of them have shown up in Google Groups. I can see replies in OE, so they are being accepted. I send to the group gmane.comp.python.general. > > Does anyone know a reason for this, or have a solution? > > Frank Millman Thanks for the replies. I am also coming to the conclusion that Google Groups is no longer fit-for-purpose. Ironically, here are two replies that I can see in Outlook Express, but do not appear in Google Groups. Reply from Benjamin Kaplan - > I believe the mail-to-news gateway has trouble with HTML messages. Try sending everything as plain text and see if that works. I checked, and all my posts were sent in plain text. Reply from Terry Reedy - > Read and post through news.gmane.org I have had a look at this before, but there is one thing that Google Groups does that no other reader seems to do, and that is that messages are sorted according to thread-activity, not original posting date. This makes it easy to see what has changed since the last time I checked. All the other ones I have looked at - Outlook Express, Thunderbird, and gmane.org, sort by original posting date, so I have to go backwards to see if any threads have had any new postings. Maybe there is a setting that I am not aware of. Can anyone enlighten me? Thanks Frank From jpiitula at ling.helsinki.fi Tue May 1 02:14:54 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 01 May 2012 09:14:54 +0300 Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: deuteros writes: > I'm using regular expressions to split a string using multiple > delimiters. But if two or more of my delimiters occur next to each > other in the string, it puts an empty string in the resulting > list. For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; > as a delimiter? You could use a sequence of such delimiters. >>> re.split('(?::|;|px)+', "width:150px;height:50px;float:right") ['width', '150', 'height', '50', 'float', 'right'] Consider splitting twice instead: first into key-value substrings at semicolons, and those into key-value pairs at colons. Here as a dict. Better handle the units after that. >>> dict(kv.split(':') for kv in "width:150px;height:50px;float:right".split(';')) {'width': '150px', 'float': 'right', 'height': '50px'} You might also want to accept whitespace as part of the delimiters. (There might be a parser for such data formats somewhere in the library already. CSV?) From russ.paielli at gmail.com Tue May 1 02:56:48 2012 From: russ.paielli at gmail.com (Russ P.) Date: Mon, 30 Apr 2012 23:56:48 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> On Apr 29, 5:17?pm, someone wrote: > On 04/30/2012 12:39 AM, Kiuhnm wrote: > > >> So Matlab at least warns about "Matrix is close to singular or badly > >> scaled", which python (and I guess most other languages) does not... > > > A is not just close to singular: it's singular! > > Ok. When do you define it to be singular, btw? > > >> Which is the most accurate/best, even for such a bad matrix? Is it > >> possible to say something about that? Looks like python has a lot more > >> digits but maybe that's just a random result... I mean.... Element 1,1 = > >> 2.81e14 in Python, but something like 3e14 in Matlab and so forth - > >> there's a small difference in the results... > > > Both results are *wrong*: no inverse exists. > > What's the best solution of the two wrong ones? Best least-squares > solution or whatever? > > >> With python, I would also kindly ask about how to avoid this problem in > >> the future, I mean, this maybe means that I have to check the condition > >> number at all times before doing anything at all ? How to do that? > > > If cond(A) is high, you're trying to solve your problem the wrong way. > > So you're saying that in another language (python) I should check the > condition number, before solving anything? > > > You should try to avoid matrix inversion altogether if that's the case. > > For instance you shouldn't invert a matrix just to solve a linear system. > > What then? > > Cramer's rule? If you really want to know just about everything there is to know about a matrix, take a look at its Singular Value Decomposition (SVD). I've never used numpy, but I assume it can compute an SVD. From ian.g.kelly at gmail.com Tue May 1 03:21:50 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 May 2012 01:21:50 -0600 Subject: Sort comparison In-Reply-To: References: Message-ID: On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg wrote: > > A while back I did a sort algorithm runtime comparison for a variety of > sorting algorithms, and then mostly sat on it. > > Recently, I got into a discussion with someone on stackoverflow about the > running time of radix sort. > > I realize it's commonly said that radixsort is n*k rather than n*log(n). > I've been making that case that in real life, frequently k==log(n). > > Anyway, here's the comparison, with code and graph: > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ It can be difficult to distinguish O(n) from O(n log n) on a log-log plot, so I don't think that graph makes your point very well. > Interesting, BTW, that an unstable quicksort in Cython was approaching > timsort as a C extension module in performance, even though timsort in > Cython wasn't that performant.? It makes one wonder if a highly optimized > quicksort as a C extension module wouldn't outperform timsort in the > standard library. > > Yes, I know, we've committed to keeping list_.sort() stable now, and > quicksort normally isn't stable. > > Also, before timsort, did CPython use quicksort?? I'd be a little surprised > if it hadn't, since people used to say quicksort was the best thing around > in practice. Based on a little googling, it was quicksort prior to 1.5.2, then it was changed to a highly optimized samplesort (a quicksort variant) / insertion sort hybrid until the current timsort was implemented in 2.3. Cheers, Ian From jabba.laci at gmail.com Tue May 1 03:35:43 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 09:35:43 +0200 Subject: geoinfo with python Message-ID: Hi, I want to figure out where a host is located, in which country. There are sites that look up this information (e.g. http://geoip.flagfox.net/). Before writing a scraper, I would like to ask if you know a python API for this task. Thanks, Laszlo From albert at spenarnc.xs4all.nl Tue May 1 06:49:41 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 May 2012 10:49:41 GMT Subject: why () is () and [] is [] work in other way? References: <4f958600$0$1382$4fafbaef@reader1.news.tin.it> <7xvckq4c2j.fsf@ruckus.brouhaha.com> Message-ID: In article <7xvckq4c2j.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Kiuhnm writes: >> I can't think of a single case where 'is' is ill-defined. > >If I can't predict the output of > > print (20+30 is 30+20) # check whether addition is commutative > print (20*30 is 30*20) # check whether multiplication is commutative > >by just reading the language definition and the code, I'd have to say >"is" is ill-defined. The output depends whether the compiler is clever enough to realise that the outcome of the expressions is the same, such that only one object needs to be created. What is ill here is the users understanding of when it is appropriate to use "is". Asking about identity of temporary objects fully under control of the compiler is just sick. 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 deltaquattro at gmail.com Tue May 1 06:51:57 2012 From: deltaquattro at gmail.com (deltaquattro at gmail.com) Date: Tue, 1 May 2012 03:51:57 -0700 (PDT) Subject: Create directories and modify files with Python In-Reply-To: <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> Message-ID: <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Il giorno marted? 1 maggio 2012 01:57:12 UTC+2, Irmen de Jong ha scritto: > > Hi, 0 I would like to automate some simple tasks I'm doing by hand. Given a text file > > foobar.fo: > > [...] > > > At first, I tried to write a bash script to do this. However, when and if the script > > will work, I'll probably want to add more features to automate some other tasks. So I > > thought about using some other language, to have a more flexible and mantainable > > code. I've been told that both Python and perl are well suited for such tasks, but > > unfortunately I know neither of them. Can you show me how to write the script in > > Python? Thanks, > > Err.. if you don't know Python, why do you think a Python script will be more flexible > and maintainable for you? > Eheh :) good question. The point is that, when in the past I chose to use only languages that I know, I always ended up with one of these two solutions: 1) write a "simple" shell script, which three years from now will make me curse in Sumeric because I can't make heads or tails of it. Been there, done that. 2) with time, the shell script may become larger and require some mathematics. For example, the second column of foobar.fo consists of mass flows, which today I get from another code, but that I could compute in the script. At this point, I go for a Fortran/C code, which takes me longer to write. Now I'd like to try another road. The problem is that each time I stumble upon a good chance to learn Python, I never have enough time to learn the language from zero, and I end up with one of two solutions above. If you can provide me with a working solution or at least some code to start with, I should be able to solve my immediate problem, and then have time to learn some more (that's how I learned shell scripting). The (possibly wrong) underlying assumption is that the problem is simple enough for one of you Python experts to solve easily, without wasting too much of his/her time. Anyway, I'm willing to pay a reasonable fee for help, provided you have Paypal. > But if you really want to go this way (and hey, why not) then first you'll have to learn > some basic Python. A good resource for this might be: http://learnpythonthehardway.org/ Ehm...name's not exactly inspiring for a newbie who's short on time :) > > Focus on file input and output, string manipulation, and look in the os module for stuff > to help scanning directories (such as os.walk). > > Irmen Thanks for the directions. By the way, can you see my post in Google Groups? I'm not able to, and I don't know why. Sergio From jabba.laci at gmail.com Tue May 1 07:01:45 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 13:01:45 +0200 Subject: geoinfo with python In-Reply-To: References: Message-ID: I've found a web service for the task: http://www.geoplugin.com/webservices . It can produce JSON output too. Laszlo On Tue, May 1, 2012 at 09:35, Jabba Laci wrote: > Hi, > > I want to figure out where a host is located, in which country. There > are sites that look up this information (e.g. > http://geoip.flagfox.net/). Before writing a scraper, I would like to > ask if you know a python API for this task. > > Thanks, > > Laszlo From __peter__ at web.de Tue May 1 07:45:34 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 May 2012 13:45:34 +0200 Subject: Create directories and modify files with Python References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: deltaquattro at gmail.com wrote: > At this point, I go for a Fortran/C code, which takes me longer to write. If you already have a basic programming knowledge the tutorial that comes with Python should be an excellent starting point: http://docs.python.org/py3k/tutorial/index.html > Now I'd like to try another road. The problem is that each time I stumble > upon a good chance to learn Python, I never have enough time to learn the > language from zero, and I end up with one of two solutions above. If you > can provide me with a working solution or at least some code to start > with, I should be able to solve my immediate problem, and then have time > to learn some more (that's how I learned shell scripting). The (possibly > wrong) underlying assumption is that the problem is simple enough for one > of you Python experts to solve easily, without wasting too much of his/her > time. Anyway, I'm willing to pay a reasonable fee for help, provided you > have Paypal. While some people here might welcome a few extra bucks that's generally not the reason we are posting here. The idea is more about peers helping peers and sometimes learning something useful for themselves. In that spirit I'd like to make an alternative offer: put some effort into the job yourself, write a solution in bash and post it here. I (or someone else) will then help you translate it into basic Python. That will typically attract others who know how to make it shorter, simpler, or more general (or to turn it into a showcase for Python's more advanced features or their favourite programming paradigm). You'll end up with a usable starting point for further endeavours into the language, no money involved. From lkcl at lkcl.net Tue May 1 08:06:15 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Tue, 1 May 2012 13:06:15 +0100 Subject: pyjamas 0.8.1 - help requested for testing to reach stable release Message-ID: hi folks, got a small favour to ask of the python community - or, more specifically, i feel compelled to alert the python community to "a need" with which you may be able to help: we're due for another release, and it's becoming an increasingly-large task. given the number of examples requiring testing (75+) the number of browsers (15+) and desktop engines (3 so far, on 3 different OSes) that pyjamas supports is just... overwhelming for any one individual to even contemplate tackling. for the pyjamas 0.6 release, for example, i spent three weeks straight, just doing testing. from that experience i decided to set a rule, which is very straightforward: ask for help in testing, set a (reasonably firm) deadline for a release date, and then whatever has been tested by contributors by that time, that becomes the stable release. thus, in this way, the community receives a stable release that is of the quality that the *community* requires. the list of platforms tested already is quite long: however it's not long _enough_! and, also, on each task, there needs to be many more examples actually tested. here's what's been done so far: http://code.google.com/p/pyjamas/issues/list?can=2&q=milestone=Release0.8.1 we need more testing on opera, more testing on safari, more versions of firefox - more of everything basically! so, this is basically more of a "notification" than it is anything else, that if you'd like to help with the responsible task of ensuring that a python compiler and GUI toolkit has a release that the python community can be proud of, that i'm placing that responsibility directly into your hands: i'm just the gatekeeper, here. lastly, i'd like to leave you with this thought. i am doing a web site for a client (a general-purpose content management system which will be released as free software at some stage). the user management roles are stored as a comma-separated list in the database (kirbybase). i needed to split the string back into a list, and before i knew it i had typed this: import string roles = map(string.strip, user['roles'].split(",")) what struck me was that, although i've been working with pyjamas for over three years, it _still_ had me doing a double-take that this is *python*, yet this will end up running in *javascript* in the actual web site. the level of pain and awkwardness that would need to be gone through in order to do the same operation in javascript, and being completely unable to actually test and develop with confidence under pyjd directly at the python interpreter, i just... i can't imagine ever going back to that. and that's just... fricking awesome, but it highlights and underscores that there's a real reason why pyjamas is worthwhile helping out with (and using). you *do not* have to learn javascript, yet can still create comprehensive web sites that will work across all modern web browsers... *if* they're tested properly :) ok enough. thanks folks. l. From __peter__ at web.de Tue May 1 08:55:13 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 May 2012 14:55:13 +0200 Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: deuteros wrote: > I'm using regular expressions to split a string using multiple delimiters. > But if two or more of my delimiters occur next to each other in the > string, it puts an empty string in the resulting list. For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? That looks like a CSS style; to parse it you should use a tool that was built for the job. The first one I came across (because it is included in the linux distro I'm using and has "css" in its name, so this is not an endorsement) is http://packages.python.org/cssutils/ >>> import cssutils >>> style = cssutils.parseStyle("width:150px;height:50px;float:right") >>> for property in style.getProperties(): ... print property.name, "-->", property.value ... width --> 150px height --> 50px float --> right OK, so you still need to strip off the unit prefix manually: >>> def strip_suffix(s, *suffixes): ... for suffix in suffixes: ... if s.endswith(suffix): ... return s[:-len(suffix)] ... return s ... >>> strip_suffix(style.float, "pt", "px") u'right' >>> strip_suffix(style.width, "pt", "px") u'150' From hoogendoorn.eelco at gmail.com Tue May 1 09:26:16 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Tue, 1 May 2012 06:26:16 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: There is linalg.pinv, which computes a pseudoinverse based on SVD that works on all matrices, regardless of the rank of the matrix. It merely approximates A*A.I = I as well as A permits though, rather than being a true inverse, which may not exist. Anyway, there are no general answers for this kind of thing. In all non-textbook problems I can think of, the properties of your matrix are highly constrained by the problem you are working on; which additional tests are required to check for corner cases thus depends on the problem. Often, if you have found an elegant solution to your problem, no such corner cases exist. In that case, MATLAB is just wasting your time with its automated checks. From franck at ditter.org Tue May 1 09:54:31 2012 From: franck at ditter.org (Franck Ditter) Date: Tue, 01 May 2012 15:54:31 +0200 Subject: Installing pygame on MacOS-X Lion with Python 3.3 Message-ID: I can't get it working : "No pygame module"... Tried without success : pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg I am using Python 3 last version on MacOS-X Lion. Where is a step-by-step installation procedure ? Thanks, franck From chess at us.ibm.com Tue May 1 10:01:11 2012 From: chess at us.ibm.com (David M Chess) Date: Tue, 1 May 2012 10:01:11 -0400 Subject: bus errors when the network interface is reset? Message-ID: We have a system running Python 2.6.6 under RHEL 6.1. A bunch of processes spend most of their time sitting in a BaseHTTPServer.HTTPServer waiting for requests. Last night an update pushed out via xcat whimsically restarted all of the network interfaces, and at least some of our processes died with bus errors (i.e. no errors or exceptions reflected up to the Python level, just a crash). This is just my initial looking into this. Seeking opinions of the form, say: Yeah, that happens, don't reset the network interfaces. Yeah, that happens, and you can prevent the crash by doing X in your OS. Yeah, that happens, and you can prevent the crash by doing X in your Python code. That wouldn't happen if you upgraded S to version V. That sounds like a new bug and/or more information is needed; please provide copious details including at least X, Y, and Z. Any thoughts or advice greatly appreciated. DC David M. Chess IBM Watson Research Center -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Tue May 1 10:18:03 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 01 May 2012 16:18:03 +0200 Subject: syntax for code blocks In-Reply-To: <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> Message-ID: <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> On 5/1/2012 5:27, alex23 wrote: > On Apr 30, 2:05 am, Peter Pearson wrote: >> Hey, guys, am I the only one here who can't even guess what >> this code does? When did Python become so obscure? > > Thankfully it hasn't. The most Pythonic way to pass around a code > block is still to use a function. "Most Pythonic" doesn't mean better, unfortunately. For instance, assume that you want to write a function that accepts a dictionary of callbacks: func(some_args, callbacks) Pythonic way ------------ def when_odd(n): pass def when_prime(n): pass def before_check(): pass def after_check(): pass func(some_args, {'when_odd' : when_odd, 'when_prime' : when_prime, 'before_check' : before_check, 'after_check' : after_check}) def when_prime(n): pass def when_perfect(n): pass def before_reduction() pass def after_reduction(): pass func(some_args, {'when_prime' : when_prime, 'when_perfect' : when_perfect, 'before_reduction' : before_reduction, 'after_reduction' : after_reduction}) My way ------ with func(some_args) << ':dict': with when_odd as 'n': pass with when_prime as 'n': pass with before_check as '': pass with after_check as '': pass with func(some_args) << ':dict': with when_prime as 'n': pass with when_perfect as 'n': pass with before_reduction as '': pass with after_reduction as '': pass Kiuhnm From jabba.laci at gmail.com Tue May 1 10:23:11 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 1 May 2012 16:23:11 +0200 Subject: For loop In-Reply-To: <4F9E7D14.1030708@kingdread.de> References: <4F9E7D14.1030708@kingdread.de> Message-ID: Hi, Try this: import sys for i in range (1, 5+1): for j in range (i): sys.stdout.write(str(i)) print "print" adds a newline character print "hi", notice the comma, it won't add newline, however it adds a space With sys.stdout.write you can print the way you want, it won't add any extra stuff (newline or space). Best, Laszlo On Mon, Apr 30, 2012 at 13:52, Daniel wrote: > You could also try http://docs.python.org/library/stdtypes.html#str.join > like this: > for i in range(5): > ? ?print "".join(str(i) for j in range(i)) > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue May 1 10:26:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 00:26:44 +1000 Subject: Create directories and modify files with Python In-Reply-To: References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: On Tue, May 1, 2012 at 9:45 PM, Peter Otten <__peter__ at web.de> wrote: > In that spirit I'd like to make an alternative offer: put some effort into > the job yourself, write a solution in bash and post it here. I (or someone > else) will then help you translate it into basic Python. That will typically > attract others who know how to make it shorter, simpler, or more general (or > to turn it into a showcase for Python's more advanced features or their > favourite programming paradigm). You'll end up with a usable starting point > for further endeavours into the language, no money involved. Seconded, and I'd recommend putting this into a FAQ. Dollars aren't the currency here, help and coding time are. Regarding the original problem: I would recommend you dedicate just one hour to learning Python. Most people should be able to find that much time, I think! As a programmer, you should be able to pick up most of Python's basics in an hour, using its own tutorial as Peter Otten posted ( http://docs.python.org/py3k/tutorial/index.html ); after that, you can probably write your script, or at very least will know which aspects of the language you love and which aspects you hate! ChrisA From rosuav at gmail.com Tue May 1 10:33:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 00:33:22 +1000 Subject: syntax for code blocks In-Reply-To: <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, May 2, 2012 at 12:18 AM, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. > > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ?pass > > def when_prime(n): > ? ?pass > > def before_check(): > ? ?pass > > def after_check(): > ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? 'after_check' : after_check}) My way: func(some_args, {'when_odd': lambda: 1, 'when_prime': lambda: 2, 'before_check': lambda: 3, 'after_check': lambda: 4}) In a language where lambda isn't restricted to a single expression (eg Javascript, Pike), this works even better, but it's still plausible for many situations. ChrisA From awilliam at whitemice.org Tue May 1 10:47:15 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 May 2012 10:47:15 -0400 Subject: Communication between C++ server and Python app In-Reply-To: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> References: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> Message-ID: <1335883635.4017.1.camel@linux-nysu.site> On Sat, 2012-04-28 at 17:45 -0700, kenk wrote: > I've got a server process written in C++ running on Unix machine. > On the same box I'd like to run multiple Python scripts that will > communicate with this server. > Can you please suggest what would be best was to achieve this ? Time to start using a message broker that can also grow to other applications. RabbitMQ. Simple, fast, and easy to manage. This allows each service to have outages without loosing information. -------------- 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 sg552 at hotmail.co.uk Tue May 1 11:09:25 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 01 May 2012 16:09:25 +0100 Subject: Some posts do not show up in Google Groups In-Reply-To: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> Message-ID: On 01/05/2012 07:12, Frank Millman wrote: > [...] > > I have had a look at this before, but there is one thing that Google > Groups does that no other reader seems to do, and that is that > messages are sorted according to thread-activity, not original posting > date. This makes it easy to see what has changed since the last time I > checked. > > All the other ones I have looked at - Outlook Express, Thunderbird, > and gmane.org, sort by original posting date, so I have to go > backwards to see if any threads have had any new postings. > > Maybe there is a setting that I am not aware of. Can anyone enlighten > me? In Thunderbird, in the list of articles, click on the box at the top right that says "Date". This will sort articles by date. If the arrow at the right hand side of the box points upwards, click the box again. This will sort articles by date with the newest at the top. Then click the leftmost box at the same height as the "Date" one, which has an icon that looks like a Tetris block; this will sort the articles into threads, with those threads that contain the most recent posts at the top of the list. At least that's how it works on my version of Thunderbird (11.0.1 and all previous versions I can remember). I don't know how one would get it to sort threads by OP date, so I don't know why it's doing that for you. Whenever I open a newsgroup in Thunderbird, I also find it useful to click the "Unread" button in the Quick Filter toolbar. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From steve+comp.lang.python at pearwood.info Tue May 1 11:11:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2012 15:11:03 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 16:18:03 +0200, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Perhaps. But this example is not one of those cases. > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > pass [snip multiple function definitions] > func(some_args, {'when_odd' : when_odd, > 'when_prime' : when_prime, > 'before_check' : before_check, > 'after_check' : after_check}) > My way > ------ > > with func(some_args) << ':dict': > with when_odd as 'n': > pass > with when_prime as 'n': > pass If you actually try that, you will see that it cannot work. You get: SyntaxError: can't assign to literal Have you actually tried to use these code blocks of yours? I asked you for a *working* example earlier, and you replied with examples that failed with multiple NameErrors and no hint as to how to fix them. And now you give an example that fails with SyntaxError. I'm reluctantly coming to the conclusion that these "code blocks" of yours simply do not work. > with before_check as '': > pass > with after_check as '': > pass You have a bug in one or more of those callbacks. Of course you do -- all non-trivial software has bugs. The question is, how are you going to find it? You can't unit-test the individual callbacks, because they don't exist in a form that can be tested. So in this case, even though Python is slightly more verbose, and forces you to have the discipline of writing named functions ahead of time, this is actually a *good* thing because it encourages you to test them. If the callbacks are trivial functions, the Pythonic way is to use lambdas: func(some_args, {'when_odd': lambda n: n-1, 'when_prime': lambda n: n**2 - 1, ...}) although I would discourage that unless they are *really* trivial. But for callbacks of any complexity, they will need to be tested, otherwise how do you know they do what you want them to do? Your code blocks make unit testing of the callbacks impossible, and for that reason the Pythonic way is better. -- Steven From steve+comp.lang.python at pearwood.info Tue May 1 11:12:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 May 2012 15:12:46 GMT Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 04:50:48 +0000, deuteros wrote: > I'm using regular expressions to split a string using multiple > delimiters. But if two or more of my delimiters occur next to each other > in the string, it puts an empty string in the resulting list. As I would expect. After all, there *is* an empty string between two delimiters. > For example: > > re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? Probably. But why not do it the easy way? items = re.split(':|;|px', "width:150px;height:50px;float:right") items = filter(None, item) In Python 3, the second line will need to be list(filter(None, item)). -- Steven From rosuav at gmail.com Tue May 1 11:28:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 01:28:51 +1000 Subject: syntax for code blocks In-Reply-To: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 2, 2012 at 1:11 AM, Steven D'Aprano wrote: > So in this case, even though Python is slightly more verbose, and forces > you to have the discipline of writing named functions ahead of time, this > is actually a *good* thing because it encourages you to test them. > > If the callbacks are trivial functions, the Pythonic way is to use > lambdas: > > func(some_args, {'when_odd': lambda n: n-1, > ? ? ? ? ? ? ? ? 'when_prime': lambda n: n**2 - 1, > ? ? ? ? ? ? ? ? ...}) > > although I would discourage that unless they are *really* trivial. But > for callbacks of any complexity, they will need to be tested, otherwise > how do you know they do what you want them to do? Agreed. At work, I'm currently shoveling through a pile of Javascript code (about 500KB of it, one file) that largely looks like this: FOO={} FOO.bar={ init:function() { // ... initialization code }, quux:function(a,b) { //code for this function }, ajaxrequest:function() { var blah,blah; blah; return { foo:function() { blah; } }; }(), bleh:blah } It's all anonymous functions assigned to member variables. It's not easy to debug, and refactoring the code into something simpler is a weeks-long job. I know it is because I've already spent two on it. Oh, and notice how ajaxrequest isn't actually declaring a function at all, it's calling a function and using its return value? Important information like that is buried away instead of being in the function signature. Plus, to make matters worse, many of the function and object names are reused, so FOO.bar.ajaxrequest.foo() is completely different from FOO.something.else.foo() and both have just "foo:function()" as their signature. Write your code out of line unless it REALLY wants to be inline. Name the functions unless they're trivial. And yes, I did say that I would do them as in-line lambdas. I don't really see much value in the callback system you have here unless either they ARE that trivial, or it's patently obvious that they need to be functions, so I still stand by what I said. ChrisA From rurpy at yahoo.com Tue May 1 11:34:57 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 1 May 2012 08:34:57 -0700 (PDT) Subject: Create directories and modify files with Python References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: On 04/30/2012 05:24 PM, deltaquattro at gmail.com wrote: > Hi, > > I would like to automate some simple tasks I'm doing by hand. Given a text file > foobar.fo: > > 073 1.819 > 085 2.132 > 100 2.456 > 115 2.789 > > I need to create the directories 073, 085, 100, 115, and copy in each directory a modified version of the text file input.in: > > . > . > . > foo = 1.5 ! edit this value > . > . > . > bar = 1.5 ! this one, too > . > . > . > > Tthe modification consists in substituting the number in the above lines with the value associated to the directory in the file foobar.fo. Thus, the input.in file in the directory 100 will be: > > . > . > . > foo = 2.456 ! edit this value > . > . > . > bar = 2.456 ! this one, too > . > . > . > > At first, I tried to write a bash script to do this. However, when and if the script will work, I'll probably want to add more features to automate some other tasks. So I thought about using some other language, to have a more flexible and mantainable code. I've been told that both Python and perl are well suited for such tasks, but unfortunately I know neither of them. Can you show me how to write the script in Python? Thanks, Perhaps something like this will get you started? To keep things simple (since this is illustrative code) there is little parameterization and no error handling. Apologies if Google screws up the formatting too bad. -------------------------------------------------------- from __future__ import print_function #1 import os def main(): listf = open ('foobar.fo') for line in listf: dirname, param = line.strip().split() #7 make_directory (dirname, param) def make_directory (dirname, param): os.mkdir (dirname) #11 tmplf = open ("input.in") newf = open (dirname + '/' + 'input.in', 'w') #13 for line in tmplf: if line.startswith ('foo = ') or line.startswith ('bar = '): #15 line = line.replace (' 1.5 ', ' '+param+' ') #16 print (line, file=newf, end='') #17 if __name__ == '__main__': main() #19 ------------------------------------------------------------ #1: Not sure whether you're using Python 2 or 3. I ran this on Python 2.7 and think it will run on Python 3 if you remove this line. #7:The strip() method removes the '\n' characters from the end of the lines as well as any other extraneous leading or trailing whitespace. The split() method here breaks the line into two pieces on the whitespace in the middle. See http://docs.python.org/library/stdtypes.html#string-methods #11: This will create subdirectory 'dirname' relative to the current directory of course. See http://docs.python.org/library/os.html#os.mkdir #13: Usually, is is more portable to use os.path.join() to concatenate path components but since you stated you are on Linux (and "/" works on Windows too), creating the path with "/" is easier to follow in this example. For open() see http://docs.python.org/library/functions.html#open #15: Depending on your data, you might want to use the re (regular expression) module here if the simple string substitution is not sufficient. #16: For simplicity I just blindly replaced the " 1.5 " text in the string. Depending of your files, you might want to parameterize this of do something more robust or sophisticated. #17: Since we did not strip the trailing '\n' of the lines we read from "input.in", we use "end=''" to prevent print from adding an additional '\n'. See http://docs.python.org/library/functions.html#print #19: This line is required to actually get your python file to do anything. :-) Hope this gets you started. I think you will find doing this kind of thing in Python is much easier in the long run than with bash scripts. A decent resource for learning the basics of Python is the standard Python tutorial: http://docs.python.org/tutorial/index.html From emile at fenx.com Tue May 1 13:06:32 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 01 May 2012 10:06:32 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: > re.split(':|;|px', "width:150px;height:50px;float:right") You could recognize that the delimiter you want to strip is in fact px; and not px in and of itself. So, try: re.split(':|px;', "width:150px;height:50px;float:right") Emile From kiuhnm03.4t.yahoo.it Tue May 1 13:07:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 01 May 2012 19:07:58 +0200 Subject: syntax for code blocks In-Reply-To: <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> On 5/1/2012 17:11, Steven D'Aprano wrote: >> My way >> ------ >> >> with func(some_args)<< ':dict': >> with when_odd as 'n': >> pass >> with when_prime as 'n': >> pass > > > If you actually try that, you will see that it cannot work. You get: > > SyntaxError: can't assign to literal If you had read the module's docstring you would know that the public version uses with when_odd << 'n': pass > Have you actually tried to use these code blocks of yours? I asked you > for a *working* example earlier, and you replied with examples that > failed with multiple NameErrors and no hint as to how to fix them. And > now you give an example that fails with SyntaxError. The examples I gave you work perfectly. It's clear that you don't even have the vaguest idea of how my module works or, otherwise, you'd know what you're doing wrong. Again, the module's docstring is your friend. > You have a bug in one or more of those callbacks. > > Of course you do -- all non-trivial software has bugs. The question is, > how are you going to find it? You can't unit-test the individual > callbacks, because they don't exist in a form that can be tested. It's easy to come up with a solution, in fact those functions /do/ exist. You would know that if you had read the documentation or even my reply to a post of yours. > So in this case, even though Python is slightly more verbose, and forces > you to have the discipline of writing named functions ahead of time, this > is actually a *good* thing because it encourages you to test them. > > If the callbacks are trivial functions, the Pythonic way is to use > lambdas: > > func(some_args, {'when_odd': lambda n: n-1, > 'when_prime': lambda n: n**2 - 1, > ...}) > > although I would discourage that unless they are *really* trivial. But > for callbacks of any complexity, they will need to be tested, otherwise > how do you know they do what you want them to do? > > Your code blocks make unit testing of the callbacks impossible, and for > that reason the Pythonic way is better. Talking with you is a real pain. You're always partial in your opinions and this urge of yours to criticize other's work makes you look dumb or hopefully just lazy. I can't stand people like you who don't even have the decency of taking the time to read the documentation of a project and just run their mouth without any concern for facts. What I can't stand is that if I won't reply to your posts other lazy people will believe the nonsense you say, but I'll have to live with that because I've wasted enough time with you. Kiuhnm From lamialily at cleverpun.com Tue May 1 13:10:16 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:10:16 -0700 Subject: Installing pygame on MacOS-X Lion with Python 3.3 In-Reply-To: References: Message-ID: <0160q792v36ve6nlecvav2jdor392grfdq@4ax.com> >I can't get it working : "No pygame module"... >Tried without success : >pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip >pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg > >I am using Python 3 last version on MacOS-X Lion. > >Where is a step-by-step installation procedure ? > >Thanks, > > franck That'd likely be because package installations are limited to the major and minor version they were built for. Those two packages, for example, were built for Python 2.7, which is significantly different from Python 3.3. I'm not seeing any 3.3 builds for Pygame *at all*, even for Windows, so you'd probably be best off moving to Python 2.7. You should be able to use Pygame freely then. ~Temia -- When on earth, do as the earthlings do. From lamialily at cleverpun.com Tue May 1 13:13:55 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:13:55 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> >> re.split(':|;|px', "width:150px;height:50px;float:right") > >You could recognize that the delimiter you want to strip is in fact px; >and not px in and of itself. > >So, try: > >re.split(':|px;', "width:150px;height:50px;float:right") > >Emile That won't work at all outside of the example case. It'd choke on any attribute seperator that didn't end in px. Honestly I'd recommend recovering the size measurement anyway, since there are pretty huge differences between each form of measurement in CSS. Seperating it from the number itself is fine and all since you probably still need to turn it into a number Python can use, but I wouldn't discard it outright. ~Temia -- When on earth, do as the earthlings do. From lamialily at cleverpun.com Tue May 1 13:31:13 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Tue, 01 May 2012 10:31:13 -0700 Subject: syntax for code blocks In-Reply-To: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: Holy crap. Easy there, tiger. I understand you're frustrated, but the people here are trying to help, even if they've decided the means of helping is trying to explain why they feel your style of development isn't the best way to do things. You're going to wear out your welcome and not get any help at all if you go ballistic like that. :/ ~Temia -- When on earth, do as the earthlings do. From emile at fenx.com Tue May 1 13:36:46 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 01 May 2012 10:36:46 -0700 Subject: Trouble splitting strings with consecutive delimiters In-Reply-To: <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> References: <4f9ffd6e$0$29965$c3e8da3$5496439d@news.astraweb.com> <5960q7ddunh6j5alk6uq69ht5affqth2ef@4ax.com> Message-ID: On 5/1/2012 10:13 AM Temia Eszteri said... >> re.split(':|px;', "width:150px;height:50px;float:right") >> >> Emile > > That won't work at all outside of the example case. It'd choke on any > attribute seperator that didn't end in px. It would certainly choke on all delimeters that are not presented in the argument. You're free to flavor to taste... Emile From malaclypse2 at gmail.com Tue May 1 13:39:29 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 1 May 2012 13:39:29 -0400 Subject: syntax for code blocks In-Reply-To: <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On Tue, May 1, 2012 at 1:07 PM, Kiuhnm wrote: > If you had read the module's docstring you would know that the public > version uses Are you aware that you've never posted a link to your module, nor it's docstrings? Are you also aware that your module is essentially unfindable on google? Certainly nothing on the first two pages of google results for 'python codeblocks' jumps out at me as a python module of that name. Perhaps you would have better luck if you either post the actual code you want people to critique, or posted a link to that code. -- Jerry From tjreedy at udel.edu Tue May 1 13:51:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 May 2012 13:51:31 -0400 Subject: Sort comparison In-Reply-To: References: Message-ID: On 5/1/2012 1:25 AM, Dan Stromberg wrote: > Anyway, here's the comparison, with code and graph: > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > > (It's done in Pure python and Cython, with a little m4). > > Interesting, BTW, that an unstable quicksort in Cython was approaching > timsort as a C extension module in performance, even though timsort in > Cython wasn't that performant. It makes one wonder if a highly > optimized quicksort as a C extension module wouldn't outperform timsort > in the standard library. Timsort is not only stable, but, by design, it is faster than quicksort for various structured data patterns, many of which are realistic in practice. For instance, you append k unordered items to n already sorted items, where k << n, so that k*log(k) is on the order of n. Timsort discovers the initial run of n sorted items, sorts the k items, and then merges. The practical time is O(n). Ditto for sorting an already sorted file in the reverse direction (timsort does an O(n) list reverse). -- Terry Jan Reedy From arnodel at gmail.com Tue May 1 13:55:40 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 1 May 2012 18:55:40 +0100 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: (sent from my phone) On May 1, 2012 6:42 PM, "Jerry Hill" wrote: > > On Tue, May 1, 2012 at 1:07 PM, Kiuhnm > wrote: > > If you had read the module's docstring you would know that the public > > version uses > > Are you aware that you've never posted a link to your module, nor it's > docstrings? Are you also aware that your module is essentially > unfindable on google? Certainly nothing on the first two pages of > google results for 'python codeblocks' jumps out at me as a python > module of that name. > > Perhaps you would have better luck if you either post the actual code > you want people to critique, or posted a link to that code. He did post a link to a blog post describing his module and also a link to the actual code, on bitbucket IIRC. Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue May 1 14:00:50 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 11:00:50 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 12:21 AM, Ian Kelly wrote: > On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg > wrote: > > > > A while back I did a sort algorithm runtime comparison for a variety of > > sorting algorithms, and then mostly sat on it. > > > > Recently, I got into a discussion with someone on stackoverflow about the > > running time of radix sort. > > > > I realize it's commonly said that radixsort is n*k rather than n*log(n). > > I've been making that case that in real life, frequently k==log(n). > > > > Anyway, here's the comparison, with code and graph: > > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > > It can be difficult to distinguish O(n) from O(n log n) on a log-log > plot, so I don't think that graph makes your point very well. > Thank you for your comment. Do you have a suggestion for a better type of graph - or other linearity/nonlinearity test? I thought that on a log-log graph, a straight line was still a straight line, but it's compressed at one end. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue May 1 14:15:34 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 01 May 2012 11:15:34 -0700 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4FA02846.7050701@stoneleaf.us> Arnaud Delobelle wrote: > On May 1, 2012 6:42 PM, "Jerry Hill" wrote: >> On Tue, May 1, 2012 at 1:07 PM, Kiuhnm wrote: >>> If you had read the module's docstring you would know that the public >>> version uses >> >> Are you aware that you've never posted a link to your module, nor it's >> docstrings? Are you also aware that your module is essentially >> unfindable on google? Certainly nothing on the first two pages of >> google results for 'python codeblocks' jumps out at me as a python >> module of that name. >> >> Perhaps you would have better luck if you either post the actual code >> you want people to critique, or posted a link to that code. > > He did post a link to a blog post describing his module and also a link > to the actual code, on bitbucket IIRC. Actually, it was Ian Kelly that posted the blog reference. ~Ethan~ From drsalists at gmail.com Tue May 1 14:24:12 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 11:24:12 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 10:51 AM, Terry Reedy wrote: > On 5/1/2012 1:25 AM, Dan Stromberg wrote: > > Anyway, here's the comparison, with code and graph: >> http://stromberg.dnsalias.org/**~strombrg/sort-comparison/ >> >> (It's done in Pure python and Cython, with a little m4). >> >> Interesting, BTW, that an unstable quicksort in Cython was approaching >> timsort as a C extension module in performance, even though timsort in >> Cython wasn't that performant. It makes one wonder if a highly >> optimized quicksort as a C extension module wouldn't outperform timsort >> in the standard library. >> > > Timsort is not only stable, but, by design, it is faster than quicksort > for various structured data patterns, many of which are realistic in > practice. For instance, you append k unordered items to n already sorted > items, where k << n, so that k*log(k) is on the order of n. Timsort > discovers the initial run of n sorted items, sorts the k items, and then > merges. The practical time is O(n). Ditto for sorting an already sorted > file in the reverse direction (timsort does an O(n) list reverse). > Yeah, I know, but thanks for making sure I did. Timsort is a quite impressive algorithm. I suspect that the "sorting a mostly-sorted list in near-linear time" attribute of Timsort tends to encourage sorting in a loop though. Usually sorting inside a loop gives a slow algorithm, even with something as nice as Timsort. -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsboost at gmail.com Tue May 1 14:43:05 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:43:05 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <7xd36qdojc.fsf@ruckus.brouhaha.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 04/30/2012 02:57 AM, Paul Rubin wrote: > someone writes: >>> A is not just close to singular: it's singular! >> Ok. When do you define it to be singular, btw? > > Singular means the determinant is zero, i.e. the rows or columns > are not linearly independent. Let's give names to the three rows: > > a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. > > Then notice that c = 2*b - a. So c is linearly dependent on a and b. > Geometrically this means the three vectors are in the same plane, > so the matrix doesn't have an inverse. Oh, thak you very much for a good explanation. >>>> Which is the most accurate/best, even for such a bad matrix? > > What are you trying to do? If you are trying to calculate stuff > with matrices, you really should know some basic linear algebra. Actually I know some... I just didn't think so much about, before writing the question this as I should, I know theres also something like singular value decomposition that I think can help solve otherwise illposed problems, although I'm not an expert like others in this forum, I know for sure :-) From newsboost at gmail.com Tue May 1 14:49:29 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:49:29 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: On 05/01/2012 08:56 AM, Russ P. wrote: > On Apr 29, 5:17 pm, someone wrote: >> On 04/30/2012 12:39 AM, Kiuhnm wrote: >>> You should try to avoid matrix inversion altogether if that's the case. >>> For instance you shouldn't invert a matrix just to solve a linear system. >> >> What then? >> >> Cramer's rule? > > If you really want to know just about everything there is to know > about a matrix, take a look at its Singular Value Decomposition (SVD). I know a bit about SVD - I used it for a short period of time in Matlab, though I'm definately not an expert in it and I don't understand the whole theory with orthogality behind making it work so elegant as it is/does work out. > I've never used numpy, but I assume it can compute an SVD. I'm making my first steps now with numpy, so there's a lot I don't know and haven't tried with numpy... From newsboost at gmail.com Tue May 1 14:52:49 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 20:52:49 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: Message-ID: On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > On 04/29/2012 07:59 PM, someone wrote: > I do not use python much myself, but a quick google showed that pyhton > scipy has API for linalg, so use, which is from the documentation, the > following code example > > X = scipy.linalg.solve(A, B) > > But you still need to check the cond(). If it is too large, not good. > How large and all that, depends on the problem itself. But the rule of > thumb, the lower the better. Less than 100 can be good in general, but I > really can't give you a fixed number to use, as I am not an expert in > this subjects, others who know more about it might have better > recommendations. Ok, that's a number... Anyone wants to participate and do I hear something better than "less than 100 can be good in general" ? If I don't hear anything better, the limit is now 100... What's the limit in matlab (on the condition number of the matrices), by the way, before it comes up with a warning ??? From ian.g.kelly at gmail.com Tue May 1 14:52:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 May 2012 12:52:53 -0600 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 12:00 PM, Dan Stromberg wrote: > > On Tue, May 1, 2012 at 12:21 AM, Ian Kelly wrote: >> >> On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg >> wrote: >> > >> > A while back I did a sort algorithm runtime comparison for a variety of >> > sorting algorithms, and then mostly sat on it. >> > >> > Recently, I got into a discussion with someone on stackoverflow about >> > the >> > running time of radix sort. >> > >> > I realize it's commonly said that radixsort is n*k rather than n*log(n). >> > I've been making that case that in real life, frequently k==log(n). >> > >> > Anyway, here's the comparison, with code and graph: >> > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ >> >> It can be difficult to distinguish O(n) from O(n log n) on a log-log >> plot, so I don't think that graph makes your point very well. > > Thank you for your comment. > > Do you have a suggestion for a better type of graph - or other > linearity/nonlinearity test? An ordinary linear-scale graph. It will only show the highest order of magnitude in any detail, but for determining asymptotic behavior that's the most interesting part anyway. O(n) should look like a straight line, and O(n log n) should curve up with a gradually increasing slope. Alternatively, calculate regressions and compare the goodness of fit. > I thought that on a log-log graph, a straight line was still a straight > line, but it's compressed at one end. The key characteristic of a log-log plot is that any curve y = ax ** b will appear as a straight line with a slope of b. So a linear curve will be a straight line with a slope of 1. A O(n log n) curve will converge to a straight line with a slope of 1 as n approaches infinity. From ramit.prasad at jpmorgan.com Tue May 1 15:04:08 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 1 May 2012 19:04:08 +0000 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <909c36bf-64b7-4b29-8a7a-d9cf1e7371ef@w9g2000pbm.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409301757@SCACMX008.exchad.jpmchase.net> >I'm making my first steps now with numpy, so there's a lot I don't know >and haven't tried with numpy... An excellent reason to subscribe to the numpy mailing list and talk on there :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From georg at python.org Tue May 1 15:43:13 2012 From: georg at python.org (Georg Brandl) Date: Tue, 01 May 2012 21:43:13 +0200 Subject: [RELEASED] Python 3.3.0 alpha 3 Message-ID: <4FA03CD1.7020605@python.org> On behalf of the Python development team, I'm happy to announce the third alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) is based on importlib by default * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * The new "faulthandler" module that helps diagnosing crashes * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From cjw at ncf.ca Tue May 1 15:59:17 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 01 May 2012 15:59:17 -0400 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 01/05/2012 2:43 PM, someone wrote: [snip] >> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >> >> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >> Geometrically this means the three vectors are in the same plane, >> so the matrix doesn't have an inverse. > Does it not mean that there are three parallel planes? Consider the example in two dimensional space. Colin W. [snip] From kbsals5179 at gmail.com Tue May 1 16:07:13 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 13:07:13 -0700 (PDT) Subject: Converting a string to list for submission to easygui multenterbox Message-ID: Please help a newbe. I have a string returned from an esygui multchoicebox that looks like this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to this: ['ksals', '', 'alsdkfj', '3', ''] This is so I can submit this to a multchoicebox with 5 fields From kbsals5179 at gmail.com Tue May 1 16:18:20 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 13:18:20 -0700 (PDT) Subject: =?UTF-8?Q?Converting_a_string_to_list_for_submission_to_easygu?= =?UTF-8?Q?i_multenterb=E2=80=8Box?= Message-ID: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Please help a newbe. I have a string returned from an esygui multchoicebox that looks like this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to this: ['ksals', '', 'alsdkfj', '3', ''] This is so I can submit this to a multenterbox with 5 fields From gordon at panix.com Tue May 1 16:26:53 2012 From: gordon at panix.com (John Gordon) Date: Tue, 1 May 2012 20:26:53 +0000 (UTC) Subject: =?UTF-8?Q?Converting_a_string_to_list_for_submission_to_easygu?= =?UTF-8?Q?i_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: In <316efebe-7f54-4054-96b1-51c7bb7b7b25 at f5g2000vbt.googlegroups.com> ksals writes: > Please help a newbe. I have a string returned from an esygui > multchoicebox that looks like > this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to > this: ['ksals', '', 'alsdkfj', '3', ''] That looks like a tuple which contains five strings. But you said it's a string, so I'll believe you. >>> x = "('ksals', '', 'alsdkfj', '3', '')" >>> print x ('ksals', '', 'alsdkfj', '3', '') >>> y = "[%s]" % x[1:-1] >>> print y ['ksals', '', 'alsdkfj', '3', ''] -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From kroger at pedrokroger.net Tue May 1 16:32:05 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Tue, 1 May 2012 17:32:05 -0300 Subject: =?utf-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?utf-8?Q?sygui_multenterb=E2=80=8Box?= In-Reply-To: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: Have you tried to use the function list?: foo = (1,2,3) list(foo) Cheers, Pedro -- http://pedrokroger.net On May 1, 2012, at 5:18 PM, ksals wrote: > Please help a newbe. I have a string returned from an esygui > multchoicebox that looks like > this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to > this: ['ksals', '', 'alsdkfj', '3', ''] > > This is so I can submit this to a multenterbox with 5 fields > > -- > http://mail.python.org/mailman/listinfo/python-list From russ.paielli at gmail.com Tue May 1 16:54:41 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 13:54:41 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: Message-ID: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> On May 1, 11:52?am, someone wrote: > On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > > > On 04/29/2012 07:59 PM, someone wrote: > > I do not use python much myself, but a quick google showed that pyhton > > scipy has API for linalg, so use, which is from the documentation, the > > following code example > > > X = scipy.linalg.solve(A, B) > > > But you still need to check the cond(). If it is too large, not good. > > How large and all that, depends on the problem itself. But the rule of > > thumb, the lower the better. Less than 100 can be good in general, but I > > really can't give you a fixed number to use, as I am not an expert in > > this subjects, others who know more about it might have better > > recommendations. > > Ok, that's a number... > > Anyone wants to participate and do I hear something better than "less > than 100 can be good in general" ? > > If I don't hear anything better, the limit is now 100... > > What's the limit in matlab (on the condition number of the matrices), by > the way, before it comes up with a warning ??? The threshold of acceptability really depends on the problem you are trying to solve. I haven't solved linear equations for a long time, but off hand, I would say that a condition number over 10 is questionable. A high condition number suggests that the selection of independent variables for the linear function you are trying to fit is not quite right. For a poorly conditioned matrix, your modeling function will be very sensitive to measurement noise and other sources of error, if applicable. If the condition number is 100, then any input on one particular axis gets magnified 100 times more than other inputs. Unless your inputs are very precise, that is probably not what you want. Or something like that. From kbsals5179 at gmail.com Tue May 1 17:09:52 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 14:09:52 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> Message-ID: <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> On May 1, 4:26?pm, John Gordon wrote: > In <316efebe-7f54-4054-96b1-51c7bb7b7... at f5g2000vbt.googlegroups.com> ksals writes: > > > Please help a newbe. ?I have a string returned from an esygui > > multchoicebox that looks like > > ? this: ?('ksals', '', 'alsdkfj', '3', '') I need to convert this to > > ? this: ?['ksals', '', 'alsdkfj', '3', ''] > > That looks like a tuple which contains five strings. ?But you said it's > a string, so I'll believe you. > > >>> x = "('ksals', '', 'alsdkfj', '3', '')" > >>> print x > > ('ksals', '', 'alsdkfj', '3', '')>>> y = "[%s]" % x[1:-1] > >>> print y > > ['ksals', '', 'alsdkfj', '3', ''] > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Edward Gorey, "The Gashlycrumb Tinies" > > The original choice looks like this when I print it: print(choice) ('ksals', '', 'alsdkfj', '3', '') I need to submit these as defaults to a multenterbox. Each entry above ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. I tried your suggestion so you must be right it is a tuple of 5 strings. But I need them to work in an instruction like fieldValues = eg.multenterbox(msg1,title, fieldNames, choice) fieldNames has 5 fields. From newsboost at gmail.com Tue May 1 17:18:08 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 23:18:08 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: On 05/01/2012 09:59 PM, Colin J. Williams wrote: > On 01/05/2012 2:43 PM, someone wrote: > [snip] >>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >>> >>> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >>> Geometrically this means the three vectors are in the same plane, >>> so the matrix doesn't have an inverse. >> > > Does it not mean that there are three parallel planes? > > Consider the example in two dimensional space. I actually drawed it and saw it... It means that you can construct a 2D plane and all 3 vectors are in this 2D-plane... From newsboost at gmail.com Tue May 1 17:21:19 2012 From: newsboost at gmail.com (someone) Date: Tue, 01 May 2012 23:21:19 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 05/01/2012 10:54 PM, Russ P. wrote: > On May 1, 11:52 am, someone wrote: >> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: >> What's the limit in matlab (on the condition number of the matrices), by >> the way, before it comes up with a warning ??? > > The threshold of acceptability really depends on the problem you are > trying to solve. I haven't solved linear equations for a long time, > but off hand, I would say that a condition number over 10 is > questionable. Anyone knows the threshold for Matlab for warning when solving x=A\b ? I tried "edit slash" but this seems to be internal so I cannot see what criteria the warning is based upon... > A high condition number suggests that the selection of independent > variables for the linear function you are trying to fit is not quite > right. For a poorly conditioned matrix, your modeling function will be > very sensitive to measurement noise and other sources of error, if > applicable. If the condition number is 100, then any input on one > particular axis gets magnified 100 times more than other inputs. > Unless your inputs are very precise, that is probably not what you > want. > > Or something like that. Ok. So it's like a frequency-response-function, output divided by input... From gordon at panix.com Tue May 1 17:29:09 2012 From: gordon at panix.com (John Gordon) Date: Tue, 1 May 2012 21:29:09 +0000 (UTC) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 at d20g2000vbh.googlegroups.com> ksals writes: > The original choice looks like this when I print it: > print(choice) > ('ksals', '', 'alsdkfj', '3', '') > I need to submit these as defaults to a multenterbox. Each entry above > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > I tried your suggestion so you must be right it is a tuple of 5 > strings. But I need them to work in an instruction like > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > fieldNames has 5 fields. If you just need to convert a tuple to a list, that's easy. Call the built-in function list() and pass the tuple as an intializer: >>> choice = ('ksals', '', 'alsdkfj', '3', '') >>> print choice ('ksals', '', 'alsdkfj', '3', '') >>> choice_list = list(choice) >>> print choice_list ['ksals', '', 'alsdkfj', '3', ''] -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ramit.prasad at jpmorgan.com Tue May 1 17:35:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 1 May 2012 21:35:29 +0000 Subject: =?utf-8?B?UkU6IENvbnZlcnRpbmcgYSBzdHJpbmcgdG8gbGlzdCBmb3Igc3VibWlzc2lv?= =?utf-8?B?biB0byBlYXN5Z3VpIG11bHRlbnRlcmLigItveA==?= In-Reply-To: <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409301A7F@SCACMX008.exchad.jpmchase.net> > > That looks like a tuple which contains five strings. > The original choice looks like this when I print it: > > print(choice) > ('ksals', '', 'alsdkfj', '3', '') Based on the print statement, choice is a tuple or a string. try doing `print(type(choice))`. On the assumption it is a tuple and not a string you can convert it by doing: choice = list(choice) If it actually is a string I would do: choice = list( ast.literal_eval( choice ) ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From robert.kern at gmail.com Tue May 1 17:45:16 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 01 May 2012 22:45:16 +0100 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 5/1/12 10:21 PM, someone wrote: > On 05/01/2012 10:54 PM, Russ P. wrote: >> On May 1, 11:52 am, someone wrote: >>> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: > >>> What's the limit in matlab (on the condition number of the matrices), by >>> the way, before it comes up with a warning ??? >> >> The threshold of acceptability really depends on the problem you are >> trying to solve. I haven't solved linear equations for a long time, >> but off hand, I would say that a condition number over 10 is >> questionable. > > Anyone knows the threshold for Matlab for warning when solving x=A\b ? I tried > "edit slash" but this seems to be internal so I cannot see what criteria the > warning is based upon... The documentation for that operator is here: http://www.mathworks.co.uk/help/techdoc/ref/mldivide.html -- 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 lkcl at lkcl.net Tue May 1 17:48:27 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Tue, 1 May 2012 22:48:27 +0100 Subject: pyjamas pyjs.org domain has been hijacked Message-ID: i have an apology to make to the python community. about 3 or 4 months ago a number of the pyjamas users became unhappy that i was sticking to software (libre) principles on the pyjamas project. they saw the long-term policy that i had set, of developing python-based pyjamas-based infrastructure (such as pygit) for pyjamas to become a demonstration of its own technology, as being unnecessarily restrictive, and for their convenience, they requested the use of non-free hosting services such as github, google groups and so on. i patiently explained why this was not acceptable as i am software (libre) developer, and advised them that if they wanted such services, perhaps they could help themselves to learn pyjamas and python by helping to improve the existing infrastructure, and that i would be happy to help them do so. many of them did not understand or accept. what i did not realise was happening, until it was announced a few hours ago, was that in the intervening time a number of the pyjamas users had got together to develop alternative infrastructure which makes use of non-free hosting facilities such as github, and that they also planned to hijack the pyjs.org domain... *without* consulting the 650 or so members on the pyjamasdev mailing list, or the python community at large. so this is rather embarrassing because i had just put out a request for help to the wider python community, with the pyjamas 0.8.1 release, when it turns out that 12 hours later the domain has been hijacked. my first apology therefore is this: i apologise to the python community for being a cause of disruption. the second apology is - if priority can ever be applied to apologies at all - is i feel somewhat more important. i am a free (libre) software developer, and i am a teacher, as many of you will know from the talks that i have given on pyjamas at various conferences. i lead by example, and it is not just free software development itself that i teach, but also free software principles. this was why i set the long-term policy that pyjamas should migrate to running on python-based server infrastructure and pyjamas-based web front-end applications, *even* for its own development, because the most fundamental way to teach is to lead by example. my apology is therefore for the disruption caused to the pyjamas project - and to the python community - as a direct consequence of me wishing to uphold software (libre) principles, and for using the pyjamas project as a way to do that. that may sound incredibly strange, especially to those people for whom software (libre) principles are something that they just accept, but it is a genuine apology, recognising that there are people for whom free software principles are not of sufficient importance to have their day-to-day development made inconvenient. i don't know what else to say, so i'll leave it at that. sorry folks. l. From kbsals5179 at gmail.com Tue May 1 17:50:51 2012 From: kbsals5179 at gmail.com (ksals) Date: Tue, 1 May 2012 14:50:51 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> Message-ID: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> On May 1, 5:29?pm, John Gordon wrote: > In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> ksals writes: > > > The original choice looks like this when I print it: > > print(choice) > > ('ksals', '', 'alsdkfj', '3', '') > > I need to submit these as defaults to a multenterbox. Each entry above > > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > > I tried your suggestion so you must be right it is a tuple of 5 > > strings. ?But I need them to work in an instruction like > > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > > fieldNames has 5 fields. > > If you just need to convert a tuple to a list, that's easy. ?Call the > built-in function list() and pass the tuple as an intializer: > > >>> choice = ('ksals', '', 'alsdkfj', '3', '') > >>> print choice > > ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) > >>> print choice_list > > ['ksals', '', 'alsdkfj', '3', ''] > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Edward Gorey, "The Gashlycrumb Tinies" > > This is a small excert to show you what I get for choice in easygui.multchoicebox(msg1, title,qstack): if choice[0] == None: print ("No entries made") break print("CHOICE IS: ",choice) ..... CHOICE IS: ('', 'ksals', '', '', '') c=list(choice) print("C IS: ",c) ..... C IS: ['(', "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", "'", ',', ' ', "'", "'", ',', ' ', "'", "'", ')'] From kiuhnm03.4t.yahoo.it Tue May 1 18:04:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 00:04:59 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: <4fa05e0a$0$1380$4fafbaef@reader2.news.tin.it> On 5/1/2012 21:59, Colin J. Williams wrote: > On 01/05/2012 2:43 PM, someone wrote: > [snip] >>> a = [1 2 3]; b = [11 12 13]; c = [21 22 23]. >>> >>> Then notice that c = 2*b - a. So c is linearly dependent on a and b. >>> Geometrically this means the three vectors are in the same plane, >>> so the matrix doesn't have an inverse. >> > > Does it not mean that there are three parallel planes? They're not parallel because our matrix has rank 2, not 1. Anyway, have a look at this: http://en.wikipedia.org/wiki/Parallelepiped#Volume It follows that our matrix A whose rows are a, b and c represents a parallelepiped. If our vectors are collinear or coplanar, the parallelepiped is degenerate, i.e. has volume 0. The converse is also true. Kiuhnm From drsalists at gmail.com Tue May 1 18:19:34 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 May 2012 15:19:34 -0700 Subject: Sort comparison In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 11:52 AM, Ian Kelly wrote: > On Tue, May 1, 2012 at 12:00 PM, Dan Stromberg > wrote: > > > > On Tue, May 1, 2012 at 12:21 AM, Ian Kelly > wrote: > >> > >> On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg > >> wrote: > >> > > >> > A while back I did a sort algorithm runtime comparison for a variety > of > >> > sorting algorithms, and then mostly sat on it. > >> > > >> > Recently, I got into a discussion with someone on stackoverflow about > >> > the > >> > running time of radix sort. > >> > > >> > I realize it's commonly said that radixsort is n*k rather than > n*log(n). > >> > I've been making that case that in real life, frequently k==log(n). > >> > > >> > Anyway, here's the comparison, with code and graph: > >> > http://stromberg.dnsalias.org/~strombrg/sort-comparison/ > >> > >> It can be difficult to distinguish O(n) from O(n log n) on a log-log > >> plot, so I don't think that graph makes your point very well. > > > > Thank you for your comment. > > > > Do you have a suggestion for a better type of graph - or other > > linearity/nonlinearity test? > > An ordinary linear-scale graph. It will only show the highest order > of magnitude in any detail, but for determining asymptotic behavior > that's the most interesting part anyway. O(n) should look like a > straight line, and O(n log n) should curve up with a gradually > increasing slope. Alternatively, calculate regressions and compare > the goodness of fit. > > > I thought that on a log-log graph, a straight line was still a straight > > line, but it's compressed at one end. > > The key characteristic of a log-log plot is that any curve y = ax ** b > will appear as a straight line with a slope of b. So a linear curve > will be a straight line with a slope of 1. A O(n log n) curve will > converge to a straight line with a slope of 1 as n approaches > infinity. > Thanks for the info. I actually feel like both the log-log graph and the linear-linear graph, tell an interesting but different part of the story, so I've kept the log-log graph and added a linear-linear graph. I also added a linear-line to the linear-linear graph, for the sake of comparison. You can see that radix sort is falling between mergesort and quicksort (both nlogn on average), and radix sort is coming up almost parallel to mergesort. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue May 1 19:05:22 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 01 May 2012 16:05:22 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> Message-ID: <7x62cfv6x9.fsf@ruckus.brouhaha.com> someone writes: > Actually I know some... I just didn't think so much about, before > writing the question this as I should, I know theres also something > like singular value decomposition that I think can help solve > otherwise illposed problems, You will probably get better advice if you are able to describe what problem (ill-posed or otherwise) you are actually trying to solve. SVD just separates out the orthogonal and scaling parts of the transformation induced by a matrix. Whether that is of any use to you is unclear since you don't say what you're trying to do. From irmen at -NOSPAM-razorvine.net Tue May 1 19:26:46 2012 From: irmen at -NOSPAM-razorvine.net (Irmen de Jong) Date: Wed, 02 May 2012 01:26:46 +0200 Subject: Create directories and modify files with Python In-Reply-To: <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> On 1-5-2012 12:51, deltaquattro at gmail.com wrote: >> But if you really want to go this way (and hey, why not) then first >> you'll have to learn some basic Python. A good resource for this >> might be: http://learnpythonthehardway.org/ > > Ehm...name's not exactly inspiring for a newbie who's short on time > :) It's just a name. That resource is generally regarded as one of the better books to learn Python for total beginners. If you can program already in another language, the standard Python tutorial might be more efficient to start from: http://docs.python.org/tutorial/ > Thanks for the directions. By the way, can you see my post in Google > Groups? I'm not able to, and I don't know why. I don't use Google groups. I much prefer a proper news agent to read my usenet newsgroups. Irmen From cs at zip.com.au Tue May 1 19:29:34 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 May 2012 09:29:34 +1000 Subject: Converting a string to =?utf-8?Q?list_?= =?utf-8?Q?for_submission_to_easygui_multenterb=E2=80=8Box?= In-Reply-To: References: Message-ID: <20120501232934.GA12072@cskk.homeip.net> Disclaimer: I have never used esygui. On 01May2012 21:29, John Gordon wrote: | In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 at d20g2000vbh.googlegroups.com> ksals writes: | > The original choice looks like this when I print it: | | > print(choice) | > ('ksals', '', 'alsdkfj', '3', '') That's just print() printing a tuple. | > I need to submit these as defaults to a multenterbox. Each entry above | > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. | > I tried your suggestion so you must be right it is a tuple of 5 | > strings. But I need them to work in an instruction like | > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) | > fieldNames has 5 fields. | | If you just need to convert a tuple to a list, that's easy. Call the | built-in function list() and pass the tuple as an intializer: Supposedly he should not need to. From: http://www.ferg.org/easygui/tutorial.html#contents_item_10.2 the sentence: "The choices are specified in a sequence (a tuple or a list)." I do not believe that ksals needs to change anything. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Uh, this is only temporary...unless it works. - Red Green From cs at zip.com.au Tue May 1 19:36:30 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 May 2012 09:36:30 +1000 Subject: Converting a string to =?utf-8?Q?list_?= =?utf-8?Q?for_submission_to_easygui_multenterb=E2=80=8Box?= In-Reply-To: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> References: <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> Message-ID: <20120501233630.GA12405@cskk.homeip.net> The tutorial suggests multchoicebox returns an interable of chosen items, in fact probably a seqeunce. So... On 01May2012 14:50, ksals wrote: | This is a small excert to show you what I get | | for choice in easygui.multchoicebox(msg1, title,qstack): | if choice[0] == None: | print ("No entries made") | break This is the wrong test. "choice" is | print("CHOICE IS: ",choice) ..... CHOICE IS: | ('', 'ksals', '', '', '') Does this really happen? This code associated with the for loop? I'd expect easygui.multchoicebox to return a list (or tuple) and "choice" to be a single string from the list. Did your print() call happen after the quoted "for" loop or after a statement like this? choice = easygui.multchoicebox(msg1, title, qstack) | c=list(choice) | print("C IS: ",c) ..... C IS: ['(', | "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", | "'", ',', ' ', "'", "'", ',', ' ', "'", "'", | ')'] Ok, that really does look like "choice" is a string. I'm really very surprised. What does this do? choices = easygui.multchoicebox(msg1, title, qstack) print("type(choices) =", type(choices)) print("choices =", repr(choices)) Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you lie to the compiler, it will get its revenge. - Henry Spencer From russ.paielli at gmail.com Tue May 1 19:38:56 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 16:38:56 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> On May 1, 4:05?pm, Paul Rubin wrote: > someone writes: > > Actually I know some... I just didn't think so much about, before > > writing the question this as I should, I know theres also something > > like singular value decomposition that I think can help solve > > otherwise illposed problems, > > You will probably get better advice if you are able to describe what > problem (ill-posed or otherwise) you are actually trying to solve. ?SVD > just separates out the orthogonal and scaling parts of the > transformation induced by a matrix. ?Whether that is of any use to you > is unclear since you don't say what you're trying to do. I agree with the first sentence, but I take slight issue with the word "just" in the second. The "orthogonal" part of the transformation is non-distorting, but the "scaling" part essentially distorts the space. At least that's how I think about it. The larger the ratio between the largest and smallest singular value, the more distortion there is. SVD may or may not be the best choice for the final algorithm, but it is useful for visualizing the transformation you are applying. It can provide clues about the quality of the selection of independent variables, state variables, or inputs. From steve+comp.lang.python at pearwood.info Tue May 1 20:09:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 00:09:07 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 May 2012 19:07:58 +0200, Kiuhnm wrote: > On 5/1/2012 17:11, Steven D'Aprano wrote: >>> My way >>> ------ >>> >>> with func(some_args)<< ':dict': >>> with when_odd as 'n': >>> pass >>> with when_prime as 'n': >>> pass >> >> >> If you actually try that, you will see that it cannot work. You get: >> >> SyntaxError: can't assign to literal > > If you had read the module's docstring What module? > you would know that the public version uses > with when_odd << 'n': > pass Then why didn't you write that instead of something that gives SyntaxError? Not once, but EIGHT times. >> Have you actually tried to use these code blocks of yours? I asked you >> for a *working* example earlier, and you replied with examples that >> failed with multiple NameErrors and no hint as to how to fix them. And >> now you give an example that fails with SyntaxError. > > The examples I gave you work perfectly. Except they don't. Look, this isn't difficult. I asked for *working* examples, you gave examples that give NameError. Some of those errors are easy to fix, e.g. by importing the random and re modules. Some of them aren't. What are "ris", "repl", "_return", "sorted1", "key"? Where do they come from? What value should I give them to make your code work? Code doesn't magically start to work because you declare that it does. Anyone who takes the time to copy and paste your examples into a fresh Python interactive session will see that they don't. Here's one of your earlier examples. I've removed the unnecessary indentation and made the obvious import, so all it takes to run it is to copy it and paste into the Python prompt: import random numbers = [random.randint(1, 100) for i in range(30)] with sorted1 << sorted(numbers) << key << 'x': if x <= 50: _return(-x) else: _return(x) print(sorted1) If you try it, you get NameError: name 'sorted1' is not defined Fix that (how?) and you'll get another NameError, for 'key', and then a third, for '_return'. The syntax isn't very clear. If I had to guess what it does, I'd predict that maybe it sorts the random list and negates everything <= 50, e.g. given input [5, 99, 34, 88, 70, 2] it returns [-2, -5, -34, 70, 88, 99]. Obviously that's wrong. You say it should return [34, 5, 2, 70, 88, 99]. The Pythonic way to get that result is: import random numbers = [random.randint(1, 100) for i in range(30)] sorted(numbers, key=lambda x: -x if x <= 50 else x) which is much more straightforward and obvious than yours, and presumably much faster. So even if I could get your example working, it would not be very persuasive. > It's clear that you don't even > have the vaguest idea of how my module works or, otherwise, you'd know > what you're doing wrong. Well duh. What module? Where do I find it? How am I supposed to know what this module is when you haven't mentioned it? Believe it or not, the world does not revolve around you. We cannot see what is in your head. If we ask for a WORKING EXAMPLE, you need to give an example that includes EVERYTHING necessary to make it work. [...] > Talking with you is a real pain. You're always partial in your opinions > and this urge of yours to criticize other's work makes you look dumb or > hopefully just lazy. > I can't stand people like you who don't even have the decency of taking > the time to read the documentation of a project and just run their mouth > without any concern for facts. What project? You're the one who doesn't tell us what project we're supposed to use, and yet *I'm* the dumb one. This is comedy gold. > What I can't stand is that if I won't reply to your posts other lazy > people will believe the nonsense you say, but I'll have to live with > that because I've wasted enough time with you. Whatever man. It's no skin off my nose. I've tried really hard to give your proposal a fair go, but my care factor is rapidly running out if you can't even be bothered to ensure your examples use legal Python syntax. -- Steven From lkcl at lkcl.net Tue May 1 21:29:03 2012 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 2 May 2012 02:29:03 +0100 Subject: pyjamas pyjs.org domain has been hijacked In-Reply-To: References: Message-ID: ... i'm reeally really sorry about this, but it suddenly dawned on me that, under UK law, a breach of the UK's data protection act has occurred, and that the people responsible for setting up the hijacked services have committed a criminal offense under UK law. ordinarily, a free software mailing list would be transferred to alternative services through the process of soliciting the users to enter into an implicit contract over a legally-enforceable reasonable amount of time, as follows: "in 30 days we will move the mailing list. anyone who doesn't want their personal data moved to the new server please say so". unfortunately, in this case, i have to advise that no such announcement had been made. although i gave permission to one of the people who has hijacked the domain my permission to aid and assist in the administration of the server, i did NOT give them permission to do anything else. unfortunately, they then abused the trust placed in them in order to gain unauthorised access to the machine. in this way, the data (ssh keys and user's email addresses) was copied WITHOUT my express permission (constituting unauthorised computer access and misuse of a computer), but worse than that WITHOUT the permission of the users who "own" their data (ssh keys and email addresses). as it's 2am here in the UK and also i will be travelling for the next couple of days, and also to preserve the state of the machine as evidence, i have had to shut down the XEN instance and will not be in a convenient position to access the email addresses in order to directly notify the users of the UK Data Protection Act breach. so for now, this announcement (to the python list, of all places) will have to do. for which i apologise, again, for having to inconvenience others who may not be interested in what has transpired. but to all concerned i apologise again, deeply, for putting everyone to trouble just because i decided to stick to free software principles. strange as that sounds. i honestly didn't see this coming. l. From wuwei23 at gmail.com Tue May 1 22:22:23 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:22:23 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <84384967-6a17-4e21-9438-95619dc4f65d@sm5g2000pbc.googlegroups.com> On May 2, 12:18?am, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Neither does "Kiuhnm prefers it". > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ? ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ? ?pass > > def when_prime(n): > ? ? ?pass > > def before_check(): > ? ? ?pass > > def after_check(): > ? ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? ? 'after_check' : after_check}) I'm sorry, when would you _ever_ do this? Why are you naming the functions twice? If you're passing in a dynamic set of functions, you'd _never know the names_, so my guess is you'd be iterating across it. If you _do_ know the names, why aren't you accessing them directly from the surrounding scope? Why aren't you including them in the function signature? Presenting bad examples as the Pythonic approach is a bit of a straw man. > My way > ------ > > with func(some_args) << ':dict': > ? ? ?with when_odd as 'n': > ? ? ? ? ?pass > ? ? ?with when_prime as 'n': > ? ? ? ? ?pass > ? ? ?with before_check as '': > ? ? ? ? ?pass > ? ? ?with after_check as '': > ? ? ? ? ?pass I'm not sure what value your code blocks really provide. 1. You're effectively making "with when_odd as 'n'" mean "def when_odd(n)" 2. The 'with code_block_name as arguments' syntax is unintuitive, to say the least. Personally, I don't see what value it provides over something more explicit and standard: def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func, arg): def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass I couldn't think of a name for the context manager...but I can't really think of a use for it either, so that seems fair. Actually, here's an even simpler example. In this case, the context manager doesn't have to interrogate the surrounding stack, but the function call itself is then explicit. class FOO(object): def __init__(self, fn): self.fn = fn def __enter__(self): return self.fn def __exit__(self, exc_type, exc_value, traceback): pass def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func) as f: def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass f(1) But again _what do you gain from this_ other than an extra layer of unnecessary complexity. From ben+python at benfinney.id.au Tue May 1 22:31:55 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 02 May 2012 12:31:55 +1000 Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87aa1r8g9w.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 01 May 2012 19:07:58 +0200, Kiuhnm wrote: > > [entitled demands] > Believe it or not, the world does not revolve around you. We cannot > see what is in your head. If we ask for a WORKING EXAMPLE, you need to > give an example that includes EVERYTHING necessary to make it work. To forestall the next obvious but wrong response: no, this is not asking to see a massive complicated module dumped on us to pore over. The term missing from Steven's request is ?minimal?. When presenting code for examination by others, we request that you present a complete, minimal, working example. Complete, so that we can take what you present and use it without guessing (likely incorrect guesses) what extra bits you did. Minimal, so that it contains *only* what is needed to demonstrate what you're trying to communicate. Yes, this probably means writing an example specifically to present to us; tough, the job falls to you if you want us to spend time on your issue. Working example: so that it actually does what you say it does, and we can verify that directly instead of speculating. > [...] > > Talking with you is a real pain. You're always partial in your > > opinions and this urge of yours to criticize other's work makes you > > look dumb or hopefully just lazy. Sometimes one side of a disagreement is just incorrect, and in those cases it's good to be partial in one's opinions and to criticise on the facts. You have entered may people's kill files, including mine, because of this inability to take criticism and this tendency to insult others baselessly. -- \ ?Holy unrefillable prescriptions, Batman!? ?Robin | `\ | _o__) | Ben Finney From wuwei23 at gmail.com Tue May 1 22:43:57 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:43:57 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: [Apologies in advance if this comes through twice] On May 2, 12:18?am, Kiuhnm wrote: > "Most Pythonic" doesn't mean better, unfortunately. Nor does it mean "Kiuhnm prefers it". > For instance, assume that you want to write a function that accepts a > dictionary of callbacks: > ? ?func(some_args, callbacks) > > Pythonic way > ------------ > > def when_odd(n): > ? ? ?pass > > def when_prime(n): > ? ? ?pass > > def before_check(): > ? ? ?pass > > def after_check(): > ? ? ?pass > > func(some_args, {'when_odd' : when_odd, > ? ? ? ? ? ? ? ? ? 'when_prime' : when_prime, > ? ? ? ? ? ? ? ? ? 'before_check' : before_check, > ? ? ? ? ? ? ? ? ? 'after_check' : after_check}) When would you _ever_ define a function like this? Why are you passing in _named_ callbacks? Are you calling them by name? Then declare them in the function signature and rely on scoping. Does func() branch on existent keys? Then don't write code like that. At the very _least_, you could change the function call to: func(some_args, locals()) But as you're _passing them in by name_ why not just make it func(some_args) and pick them up out of the scope. _No one_ writes Python code like this. Presenting bad code as "pythonic" is a bit of a straw man. > My way > ------ > > with func(some_args) << ':dict': > ? ? ?with when_odd as 'n': > ? ? ? ? ?pass > ? ? ?with when_prime as 'n': > ? ? ? ? ?pass > ? ? ?with before_check as '': > ? ? ? ? ?pass > ? ? ?with after_check as '': > ? ? ? ? ?pass This is unintuitive, to say the least. You're effectively replacing the common form of function definition with "with when_odd as 'n'", then using the surrounding context manager to limit the scope. More importantly, _you're naming your "anonymous" code blocks_, I'm guessing so that func() can choose which ones to use. But if you're naming them, why not just use a function? I'm not entirely sure what your 'solution' offers over something like: class FOO(object): def __init__(self, fn): self.fn = fn def __enter__(self): return self.fn def __exit__(self, exc_type, exc_value, traceback): pass def func(x, before_check=None, after_check=None, when_odd=None, when_prime=None): pass with FOO(func) as f: def before_check(x): pass def after_check(x): pass def when_odd(x): pass def when_prime(x): pass f(1) I called the context manager FOO because I couldn't think of a more appropriate name (contextscope?)...which is fair, as I can't think of a use for it either. If you want to automate the function call at the context manager exit, use something like this instead: class FOO(object): def __init__(self, fn, *args, **kwargs): self.fn = fn self.args = args self.kwargs = kwargs def __enter__(self): f = inspect.currentframe(1) self.scope_before = dict(f.f_locals) def __exit__(self, exc_type, exc_value, traceback): f = inspect.currentframe(1) scope_after = dict(f.f_locals) scope_context = set(scope_after) - set(self.scope_before) clocals = dict( [(k, scope_after[k]) for k in scope_context] ) self.kwargs.update(clocals) self.fn(*self.args, **self.kwargs) Maybe there is a compelling use case for code blocks but your toy example certainly isn't it. From wuwei23 at gmail.com Tue May 1 22:50:46 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 1 May 2012 19:50:46 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On May 2, 12:43?pm, alex23 wrote: > I'm not entirely sure what your 'solution' offers over something like: > > class FOO(object): > ? ? def __init__(self, fn): > ? ? ? ? self.fn = fn > > ? ? def __enter__(self): > ? ? ? ? return self.fn > > ? ? def __exit__(self, exc_type, exc_value, traceback): > ? ? ? ? pass > > def func(x, before_check=None, after_check=None, when_odd=None, > when_prime=None): > ? ? pass Sorry, the func definition was meant to be: def func(x): # before_check, after_check, when_odd, when_prime used internally pass From samuelmarks at gmail.com Wed May 2 00:11:04 2012 From: samuelmarks at gmail.com (samuelmarks at gmail.com) Date: Tue, 1 May 2012 21:11:04 -0700 (PDT) Subject: Designing and Building an API converter Message-ID: <33200364.1541.1335931864469.JavaMail.geo-discussion-forums@pbgg7> How would I go about building an API converter? I have multiple different APIs with different schemas serialised in XML or JSON which I need to output as a standardised schema. Other features needed: - Authentication (i.e.: can't get/set data unless you're from a certain DNS xor have the correct user+pass) - Role/Scope limitation (i.e.: you can't access everything in our database, only what your role allows for) Is this the sort of problem I would use Slumber (http://slumber.in/) for? Or would there be a different library you'd recommend? Thanks for all suggestions, Alec Taylor From newsboost at gmail.com Wed May 2 02:00:44 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 08:00:44 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <7x62cfv6x9.fsf@ruckus.brouhaha.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: On 05/02/2012 01:05 AM, Paul Rubin wrote: > someone writes: >> Actually I know some... I just didn't think so much about, before >> writing the question this as I should, I know theres also something >> like singular value decomposition that I think can help solve >> otherwise illposed problems, > > You will probably get better advice if you are able to describe what > problem (ill-posed or otherwise) you are actually trying to solve. SVD I don't understand what else I should write. I gave the singular matrix and that's it. Nothing more is to say about this problem, except it would be nice to learn some things for future use (for instance understanding SVD more - perhaps someone geometrically can explain SVD, that'll be really nice, I hope)... > just separates out the orthogonal and scaling parts of the > transformation induced by a matrix. Whether that is of any use to you > is unclear since you don't say what you're trying to do. Still, I dont think I completely understand SVD. SVD (at least in Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I would better understand it with geometric examples, if one would be so kind to maybe write something about that... I can plot 3D vectors in matlab, very easily so maybe I better understand SVD if I hear/read the geometric explanation (references to textbook/similar is also appreciated). From newsboost at gmail.com Wed May 2 02:03:17 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 08:03:17 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On 05/02/2012 01:38 AM, Russ P. wrote: > On May 1, 4:05 pm, Paul Rubin wrote: >> someone writes: >>> Actually I know some... I just didn't think so much about, before >>> writing the question this as I should, I know theres also something >>> like singular value decomposition that I think can help solve >>> otherwise illposed problems, >> >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD >> just separates out the orthogonal and scaling parts of the >> transformation induced by a matrix. Whether that is of any use to you >> is unclear since you don't say what you're trying to do. > > I agree with the first sentence, but I take slight issue with the word > "just" in the second. The "orthogonal" part of the transformation is > non-distorting, but the "scaling" part essentially distorts the space. > At least that's how I think about it. The larger the ratio between the > largest and smallest singular value, the more distortion there is. SVD > may or may not be the best choice for the final algorithm, but it is > useful for visualizing the transformation you are applying. It can > provide clues about the quality of the selection of independent > variables, state variables, or inputs. Me would like to hear more! :-) It would really appreciate if anyone could maybe post a simple SVD example and tell what the vectors from the SVD represents geometrically / visually, because I don't understand it good enough and I'm sure it's very important, when it comes to solving matrix systems... From silideba at gmail.com Wed May 2 02:25:15 2012 From: silideba at gmail.com (Debashish Saha) Date: Wed, 2 May 2012 11:55:15 +0530 Subject: linux Message-ID: can anyone say me how to subscribe linux mailing list like 'python mailing list'. Actually i want to post question there. From russ.paielli at gmail.com Wed May 2 02:36:32 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 1 May 2012 23:36:32 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On May 1, 11:03?pm, someone wrote: > On 05/02/2012 01:38 AM, Russ P. wrote: > > > > > > > > > > > On May 1, 4:05 pm, Paul Rubin ?wrote: > >> someone ?writes: > >>> Actually I know some... I just didn't think so much about, before > >>> writing the question this as I should, I know theres also something > >>> like singular value decomposition that I think can help solve > >>> otherwise illposed problems, > > >> You will probably get better advice if you are able to describe what > >> problem (ill-posed or otherwise) you are actually trying to solve. ?SVD > >> just separates out the orthogonal and scaling parts of the > >> transformation induced by a matrix. ?Whether that is of any use to you > >> is unclear since you don't say what you're trying to do. > > > I agree with the first sentence, but I take slight issue with the word > > "just" in the second. The "orthogonal" part of the transformation is > > non-distorting, but the "scaling" part essentially distorts the space. > > At least that's how I think about it. The larger the ratio between the > > largest and smallest singular value, the more distortion there is. SVD > > may or may not be the best choice for the final algorithm, but it is > > useful for visualizing the transformation you are applying. It can > > provide clues about the quality of the selection of independent > > variables, state variables, or inputs. > > Me would like to hear more! :-) > > It would really appreciate if anyone could maybe post a simple SVD > example and tell what the vectors from the SVD represents geometrically > / visually, because I don't understand it good enough and I'm sure it's > very important, when it comes to solving matrix systems... SVD is perhaps the ultimate matrix decomposition and the ultimate tool for linear analysis. Google it and take a look at the excellent Wikipedia page on it. I would be wasting my time if I tried to compete with that. To really appreciate the SVD, you need some background in linear algebra. In particular, you need to understand orthogonal transformations. Think about a standard 3D Cartesian coordinate frame. A rotation of the coordinate frame is an orthogonal transformation of coordinates. The original frame and the new frame are both orthogonal. A vector in one frame is converted to the other frame by multiplying by an orthogonal matrix. The main feature of an orthogonal matrix is that its transpose is its inverse (hence the inverse is trivial to compute). The SVD can be thought of as factoring any linear transformation into a rotation, then a scaling, followed by another rotation. The scaling is represented by the middle matrix of the transformation, which is a diagonal matrix of the same dimensions as the original matrix. The singular values can be read off of the diagonal. If any of them are zero, then the original matrix is singular. If the ratio of the largest to smallest singular value is large, then the original matrix is said to be poorly conditioned. Standard Cartesian coordinate frames are orthogonal. Imagine an x-y coordinate frame in which the axes are not orthogonal. Such a coordinate frame is possible, but they are rarely used. If the axes are parallel, the coordinate frame will be singular and will basically reduce to one-dimensional. If the x and y axes are nearly parallel, the coordinate frame could still be used in theory, but it will be poorly conditioned. You will need large numbers to represent points fairly close to the origin, and small deviations will translate into large changes in coordinate values. That can lead to problems due to numerical roundoff errors and other kinds of errors. --Russ P. From rustompmody at gmail.com Wed May 2 02:37:07 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 1 May 2012 23:37:07 -0700 (PDT) Subject: Trouble splitting strings with consecutive delimiters References: Message-ID: <137f4c31-dbab-4a0d-b96c-476fdc61a0cd@e9g2000yqm.googlegroups.com> On May 1, 9:50?am, deuteros wrote: > I'm using regular expressions to split a string using multiple delimiters. > But if two or more of my delimiters occur next to each other in the > string, it puts an empty string in the resulting list. For example: > > ? ? ? ? re.split(':|;|px', "width:150px;height:50px;float:right") > > Results in > > ? ? ? ? ['width', '150', '', 'height', '50', '', 'float', 'right'] > > Is there any way to avoid getting '' in my list without adding px; as a > delimiter? Are you parsing css? If so have you tried things like cssutils http://cthedot.de/cssutils/? [There are other such... And I dont know which is best...] From jpiitula at ling.helsinki.fi Wed May 2 02:42:10 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 02 May 2012 09:42:10 +0300 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: "someone" writes: > except it would be nice to learn some things for future use (for > instance understanding SVD more - perhaps someone geometrically can > explain SVD, that'll be really nice, I hope)... The Wikipedia article looks promising to me: Lots in it, with annotated links to more, including a song. From rosuav at gmail.com Wed May 2 03:25:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 May 2012 17:25:09 +1000 Subject: linux In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 4:25 PM, Debashish Saha wrote: > can anyone say me how to subscribe linux mailing list like 'python > mailing list'. Actually i want to post question there. Search the web, you'll find something. ChrisA From lamialily at cleverpun.com Wed May 2 03:39:50 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 02 May 2012 00:39:50 -0700 Subject: linux In-Reply-To: References: Message-ID: >can anyone say me how to subscribe linux mailing list like 'python >mailing list'. Actually i want to post question there. It'd probably be best to visit the mailing list (if any) for the distribution that you're using in particular. Odds are any such mailing list would be available on the distro's site. ~Temia -- When on earth, do as the earthlings do. From no.email at nospam.invalid Wed May 2 03:56:31 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 00:56:31 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <7xpqanc8y8.fsf@ruckus.brouhaha.com> someone writes: >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD > I don't understand what else I should write. I gave the singular > matrix and that's it. Nothing more is to say about this problem, You could write what your application is. What do the numbers in that matrix actually represent? > except it would be nice to learn some things for future use (for > instance understanding SVD more The Wikipedia article about SVD is pretty good. > Still, I dont think I completely understand SVD. SVD (at least in > Matlab) returns 3 matrices, one is a diagonal matrix I think. Yes. Two diagonal matrices and a unitary matrix. The diagonal matrices have the singular values which are the magnitudes of the matrix's eigenvalues. A matrix (for simplicity consider it to have nonzero determinant) represents a linear transformation in space. Think of a bunch of vectors as arrows sticking out of the origin in different directions, and consider what happens to them if you use the matrix to act on all of them at once. You could break the transformation into 3 steps: 1) scale the axes by suitable amounts, so all the vectors stretch or shrink depending on their directions. 2) Rotate all the vectors without changing their lengths, through some combination of angles; 3) undo the scaling transformation so that the vectors get their original lengths back. Each of these 3 steps can be described by a matrix and the 3 matrices are what SVD calculates. I still don't have any idea whether this info is going to do you any good. There are some quite knowledgeable numerics folks here (I'm not one) who can probably be of more help, but frankly your questions don't make a whole lot of sense. You might get the book "Numerical Recipes" which is old but instructive. Maybe someone else here has other recommendations. From no.email at nospam.invalid Wed May 2 03:57:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 00:57:59 -0700 Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: <7xlilbc8vs.fsf@ruckus.brouhaha.com> "Russ P." writes: > The SVD can be thought of as factoring any linear transformation into > a rotation, then a scaling, followed by another rotation. Ah yes, my description was backwards, sorry. From alec.taylor6 at gmail.com Wed May 2 05:19:43 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 2 May 2012 19:19:43 +1000 Subject: How would I go about building an API converter? Message-ID: I have multiple different APIs with different schemas serialised in XML or JSON which I need to output as a standardised schema. Main features needed: - *Serialisation to XML and JSON* - *Authentication* - I.e.: can't get/set data unless you have the correct user+pass - *Role/Scope limitation* - I.e.: you can't access everything in our database, only what your role allows for - *Get/set (conversion) between different schemas* - I.e.: No matter the input API, you can get it formatted in whichever output API you request Is this the sort of problem Slumber with TastyPiewould be best for? Or are there a different libraries you'd recommend? Thanks for all suggestions, Alec Taylor -------------- next part -------------- An HTML attachment was scrubbed... URL: From faulksp at iinet.net.au Wed May 2 05:24:46 2012 From: faulksp at iinet.net.au (Peter Faulks) Date: Wed, 02 May 2012 19:24:46 +1000 Subject: The amazing disappearing stderr Message-ID: <4FA0FD5E.10804@iinet.net.au> G'day All, Following on from my earlier query on overloading print().... I've come up with this: /* < stdcallbk.pyd > */ /*---------------stdcallbk.h---------------------*/ #ifndef STDCALLBK_MODULE_H #include #define STDCALLBK_MODULE_H // Type definition for the callback function. typedef void __stdcall(CALLBK_FUNC_T)(const char* p); #ifdef __cplusplus extern "C" { #endif void register_callback(CALLBK_FUNC_T* callback); void import_stdcallbk(void); #ifdef __cplusplus } #endif #endif /* #define STDCALLBK_MODULE_H */ /*---------------stdcallbk.c---------------------*/ #include "stdcallbk_module.h" static CALLBK_FUNC_T *callback_write_func = NULL; static FILE *fp; /*for debugging*/ static PyObject* g_stdout; typedef struct { PyObject_HEAD CALLBK_FUNC_T *write; } Stdout; static PyObject* write2(PyObject* self, PyObject* args) { const char* p; if (!PyArg_ParseTuple(args, "s", &p)) return NULL; fputs(p, fp); fflush(fp); if(callback_write_func) callback_write_func(p); else printf("----%s----", p); return PyLong_FromLong(strlen(p)); } static PyObject* flush2(PyObject* self, PyObject* args) { // no-op return Py_BuildValue(""); } static PyMethodDef Stdout_methods[] = { {"write", write2, METH_VARARGS, "sys-stdout-write"}, {"flush", flush2, METH_VARARGS, "sys-stdout-write"}, {NULL, NULL, 0, NULL} }; static PyTypeObject StdoutType = { PyVarObject_HEAD_INIT(0, 0) "stdcallbk.StdoutType", /* tp_name */ sizeof(Stdout), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ "stdcallbk.Stdout objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ Stdout_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; static struct PyModuleDef stdcallbkmodule = { PyModuleDef_HEAD_INIT, "stdcallbk", /* name of module */ NULL, /* module documentation, may be NULL */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ NULL, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_stdcallbk(void) { PyObject* m; fp = fopen("debuggered.txt", "wt"); fputs("got to here Vers 12\n", fp); fflush(fp); StdoutType.tp_new = PyType_GenericNew; if (PyType_Ready(&StdoutType) < 0) return 0; m = PyModule_Create(&stdcallbkmodule); if (m) { Py_INCREF(&StdoutType); PyModule_AddObject(m, "Stdout", (PyObject*) &StdoutType); fputs("PyModule_AddObject() Called\n", fp); fflush(fp); } g_stdout = StdoutType.tp_new(&StdoutType, 0, 0); /*PySys_SetObject("stdout", g_stdout)*/ fprintf(fp, "PySys_SetObject(stdout) returned %d\n", PySys_SetObject("stdout", g_stdout)); fflush(fp); /*PySys_SetObject("stderr", g_stdout)*/ fprintf(fp, "PySys_SetObject(stderr) returned %d\n", PySys_SetObject("stderr", g_stdout)); fflush(fp); return m; } /* called by cpp exe _after_ Py_Initialize(); */ void __declspec(dllexport) import_stdcallbk(void) { PyImport_ImportModule("stdcallbk"); } /* called by cpp exe _before_ Py_Initialize(); */ void __declspec(dllexport) register_callback(CALLBK_FUNC_T* callback) { PyImport_AppendInittab("stdcallbk", &PyInit_stdcallbk); callback_write_func = callback; } /* < /stdcallbk.pyd > */ /*------------- Embarcadero C++ Builder exe ---------------------*/ #include "/py_module/stdcallbk_module.h" void __stdcall callback_write_func(const char* p) { ShowMessage(p); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { PyObject *pName, *pModule; register_callback(callback_write_func); Py_Initialize(); import_stdcallbk(); //PyRun_SimpleString("import stdcallbk\n"); pName = PyUnicode_FromString("hello_emb.py"); pModule = PyImport_Import(pName); Py_Finalize(); } //--------------------------------------------------------------------------- -------------- python script - hello_emb.py ---------------- #import stdcallbk print("HELLO FRED !") assert 1==2 ------------------------------------------------------------ When run from the cpp exe, I get a messagebox "HELLO FRED!" followed by an empty message box which I assume is the carriage return. All good so far, but when the exception is raised, I get nothing. Nothing is written to the text file either. But... if I uncomment the "import stdcallbk" from the python script and run it from the command line, I get this: D:\projects\embed_python3\Win32\Debug>hello_emb.py ----HELLO FRED !-------- --------Traceback (most recent call last): -------- File "D:\projects\embed_python3\Win32\Debug\hello_emb.py", line 7, in -------- --------assert 1==2-------- --------AssertionError---------------- ---- and this: D:\projects\embed_python3\Win32\Debug>type debuggered.txt got to here Vers 12 PyModule_AddObject() Called PySys_SetObject(stdout) returned 0 PySys_SetObject(stderr) returned 0 HELLO FRED ! Traceback (most recent call last): File "D:\projects\embed_python3\Win32\Debug\hello_emb.py", line 7, in assert 1==2 AssertionError So it DOES work, just not when it is run from the cpp exe. Anybody have any idea what on earth is going on here? Cheers From etothepowerpi at gmail.com Wed May 2 05:59:55 2012 From: etothepowerpi at gmail.com (ArifulHossain tuhin) Date: Wed, 2 May 2012 02:59:55 -0700 (PDT) Subject: reading data file into a list Message-ID: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> I have this data file which contains raw data in newline terminated for like below: 10.6626 11.2683 11.9244 12.5758 14.1402 15.1636 Now i want to read that file and import this data into a numpy array. how should i go about it? From __peter__ at web.de Wed May 2 06:17:41 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 May 2012 12:17:41 +0200 Subject: reading data file into a list References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for > like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. how > should i go about it? myarray = numpy.loadtxt(filename) From kiuhnm03.4t.yahoo.it Wed May 2 06:52:50 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 12:52:50 +0200 Subject: syntax for code blocks In-Reply-To: References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> On 5/2/2012 4:43, alex23 wrote: > [Apologies in advance if this comes through twice] > > On May 2, 12:18 am, Kiuhnm wrote: >> "Most Pythonic" doesn't mean better, unfortunately. > > Nor does it mean "Kiuhnm prefers it". That goes without saying. >> For instance, assume that you want to write a function that accepts a >> dictionary of callbacks: >> func(some_args, callbacks) >> >> Pythonic way >> ------------ >> >> def when_odd(n): >> pass >> >> def when_prime(n): >> pass >> >> def before_check(): >> pass >> >> def after_check(): >> pass >> >> func(some_args, {'when_odd' : when_odd, >> 'when_prime' : when_prime, >> 'before_check' : before_check, >> 'after_check' : after_check}) > > When would you _ever_ define a function like this? Why are you passing > in _named_ callbacks? Are you calling them by name? Then declare them > in the function signature and rely on scoping. Does func() branch on > existent keys? Then don't write code like that. > > At the very _least_, you could change the function call to: > > func(some_args, locals()) I think that's very bad. It wouldn't be safe either. What about name clashing and how would you pass only some selected functions? A second call would also need some cleaning up leading to some serious bugs. > But as you're _passing them in by name_ why not just make it > func(some_args) and pick them up out of the scope. Because that's not clean and maintainable. It's not different from using global variables. > _No one_ writes Python code like this. Presenting bad code as > "pythonic" is a bit of a straw man. How can I present good code where there's no good way of doing that without my module or something equivalent? That was my point. >> My way >> ------ >> >> with func(some_args)<< ':dict': >> with when_odd as 'n': >> pass >> with when_prime as 'n': >> pass >> with before_check as '': >> pass >> with after_check as '': >> pass > > This is unintuitive, to say the least. You're effectively replacing > the common form of function definition with "with when_odd as 'n'", > then using the surrounding context manager to limit the scope. What's so unintuitive about it? It's just "different". > More importantly, _you're naming your "anonymous" code blocks_, I'm > guessing so that func() can choose which ones to use. But if you're > naming them, why not just use a function? I'm creating a dictionary, not naming my blocks just for the sake of it. If you use a function, you end up with the solution that you called 'bad' and non-pythonic. > I'm not entirely sure what your 'solution' offers over something like: > > class FOO(object): > def __init__(self, fn): > self.fn = fn > > def __enter__(self): > return self.fn > > def __exit__(self, exc_type, exc_value, traceback): > pass > > def func(x, before_check=None, after_check=None, when_odd=None, > when_prime=None): > pass > > with FOO(func) as f: > def before_check(x): > pass > def after_check(x): > pass > def when_odd(x): > pass > def when_prime(x): > pass > > f(1) The problem is always the same. Those functions are defined at the module level so name clashing and many other problems are possible. I remember a post on this ng when one would create a list of commands and then use that list as a switch table. My module let you do that very easily. The syntax is: with func() << ':list': with 'arg': cmd_code with 'arg': cmd_code with '': cmd_code Kiuhnm From miguel.a.guedes at gmail.com Wed May 2 06:55:35 2012 From: miguel.a.guedes at gmail.com (Miguel Guedes) Date: Wed, 02 May 2012 11:55:35 +0100 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: Message-ID: <4fa11386$0$11126$88263eea@blocknews.net> On 27/04/12 03:11, Xah Lee wrote: > John Carmack glorifying functional programing in 3k words > > http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/ > > where was he ten years ago? > > O, and btw, i heard that Common Lispers don't do functional > programing, is that right? > > Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and > Fuck Pythoners. Python fucking idiots.) > > O, don't forget, > > ?Programing: What are OOP's Jargons and Complexities (Object Oriented > Program as Functional Program)? > http://xahlee.org/Periodic_dosage_dir/t2/oop.html > > please you peruse of it. I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or personally affected by your retarded and offensive comment. However, who the fuck do you think you are to post stuff of this nature? (I believe) I'll understand if you've got some sort of psychological issue affecting your behaviour. From kiuhnm03.4t.yahoo.it Wed May 2 07:03:36 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:03:36 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> On 5/2/2012 8:00, someone wrote: > Still, I dont think I completely understand SVD. SVD (at least in > Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I > would better understand it with geometric examples, if one would be so > kind to maybe write something about that... I can plot 3D vectors in > matlab, very easily so maybe I better understand SVD if I hear/read the > geometric explanation (references to textbook/similar is also appreciated). Russ's post is a very good starting point. I hope you read it. Kiuhnm From gdamjan at gmail.com Wed May 2 07:08:04 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Wed, 02 May 2012 13:08:04 +0200 Subject: How can I read streaming output of a subprocess Message-ID: I want to read the stream of an external process that I start with Python. From what I've seen that's not possible with the subprocess module? I want to read the output of "ip monitor neigh" which will show changes in the ARP table on my Linux computer. Each change is a new line printed by "ip" and the process continues to run forever. -- damjan From kiuhnm03.4t.yahoo.it Wed May 2 07:12:08 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:12:08 +0200 Subject: reading data file into a list In-Reply-To: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: <4fa11687$0$1375$4fafbaef@reader2.news.tin.it> On 5/2/2012 11:59, ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. how should i go about it? http://docs.scipy.org/doc/numpy/reference/routines.io.html Kiuhnm From breamoreboy at yahoo.co.uk Wed May 2 07:23:20 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 02 May 2012 12:23:20 +0100 Subject: syntax for code blocks In-Reply-To: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: On 02/05/2012 11:52, Kiuhnm wrote: > I remember a post on this ng when one would create a list of commands > and then use that list as a switch table. My module let you do that very > easily. > > Kiuhnm I'll believe that when I see a reference to your code repository and the working example that others have already asked you to provide. -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Wed May 2 07:33:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 11:33:31 GMT Subject: reading data file into a list References: <10810968.1830.1335952795285.JavaMail.geo-discussion-forums@pbcoq1> Message-ID: <4fa11b8b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 May 2012 02:59:55 -0700, ArifulHossain tuhin wrote: > I have this data file which contains raw data in newline terminated for > like below: > > 10.6626 > 11.2683 > 11.9244 > 12.5758 > 14.1402 > 15.1636 > > Now i want to read that file and import this data into a numpy array. > how should i go about it? That depends. How big is the file? Could it include extraneous whitespace and possibly even comments? How do you expect to deal with bad data? What version of Python are you using? Who will be maintaining this, a Python expert or somebody who doesn't know Python very well? Here's one way (untested but should work): import numpy f = open("my data file.txt", "r") contents = numpy.array([float(line) for line in f]) f.close() -- Steven From kushal.kumaran+python at gmail.com Wed May 2 07:34:39 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 2 May 2012 17:04:39 +0530 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 4:38 PM, Damjan Georgievski wrote: > I want to read the stream of an external process that I start with Python. > From what I've seen that's not possible with the subprocess module? > > I want to read the output of "ip monitor neigh" which will show changes in > the ARP table on my Linux computer. Each change is a new line printed by > "ip" and the process continues to run forever. > You can use subprocess for this. If you don't call wait() or communicate() on the Popen object, the process will happily continue running. You can call readline on the stdout pipe, which will block until the command you are running outputs (and flushes) a line. Something like this should work: p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE) first_line = p.stdout.readline() Buffering done by "ip" can ruin your day. It seems reasonable to expect, though, that something that is printing state changes on stdout will be careful to flush its output when appropriate. -- regards, kushal From kiuhnm03.4t.yahoo.it Wed May 2 07:46:09 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 02 May 2012 13:46:09 +0200 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: <4fa11e80$0$1388$4fafbaef@reader2.news.tin.it> On 5/2/2012 13:08, Damjan Georgievski wrote: > I want to read the stream of an external process that I start with > Python. From what I've seen that's not possible with the subprocess module? Try with cmd = 'your command here' stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout print(stdout.read()) just to see if it works. You can also use for line in stdout: print(line) or similar. Then you should add some error checking, etc... Kiuhnm From steve+comp.lang.python at pearwood.info Wed May 2 07:52:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 May 2012 11:52:27 GMT Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> Message-ID: <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 May 2012 08:00:44 +0200, someone wrote: > On 05/02/2012 01:05 AM, Paul Rubin wrote: >> someone writes: >>> Actually I know some... I just didn't think so much about, before >>> writing the question this as I should, I know theres also something >>> like singular value decomposition that I think can help solve >>> otherwise illposed problems, >> >> You will probably get better advice if you are able to describe what >> problem (ill-posed or otherwise) you are actually trying to solve. SVD > > I don't understand what else I should write. I gave the singular matrix > and that's it. You can't judge what an acceptable condition number is unless you know what your data is. http://mathworld.wolfram.com/ConditionNumber.html http://en.wikipedia.org/wiki/Condition_number If your condition number is ten, then you should expect to lose one digit of accuracy in your solution, over and above whatever loss of accuracy comes from the numeric algorithm. A condition number of 64 will lose six bits, or about 1.8 decimal digits, of accuracy. If your data starts off with only 1 or 2 digits of accuracy, as in your example, then the result is meaningless -- the accuracy will be 2-2 digits, or 0 -- *no* digits in the answer can be trusted to be accurate. -- Steven From shahviral.it at gmail.com Wed May 2 08:30:25 2012 From: shahviral.it at gmail.com (viral shah) Date: Wed, 2 May 2012 18:00:25 +0530 Subject: Code help for understand Message-ID: Hi in every .py file I found this same code line on the below side *def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) run_wsgi_app(application) if __name__ == '__main__': main() * can anyone explain me what's the all this thing suggest? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Wed May 2 08:43:47 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 2 May 2012 14:43:47 +0200 Subject: Code help for understand In-Reply-To: References: Message-ID: if you are referring to the line * * *if __name__ == '__main__':* * * Find a good explanation here * * http://stackoverflow.com/questions/419163/what-does-if-name-main-do On Wed, May 2, 2012 at 2:30 PM, viral shah wrote: > Hi > > in every .py file I found this same code line on the below side > > *def main(): > application = webapp.WSGIApplication([('/', MainHandler)], > debug=True) > run_wsgi_app(application) > > > if __name__ == '__main__': > main() > * > can anyone explain me what's the all this thing suggest? > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From askutt at gmail.com Wed May 2 10:23:27 2012 From: askutt at gmail.com (Adam Skutt) Date: Wed, 2 May 2012 07:23:27 -0700 (PDT) Subject: How can I read streaming output of a subprocess References: <4fa11e80$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: <85021cac-4d0e-474e-ba1f-ddb1371acdb5@w5g2000vbp.googlegroups.com> On May 2, 7:46?am, Kiuhnm wrote: > On 5/2/2012 13:08, Damjan Georgievski wrote: > > > I want to read the stream of an external process that I start with > > Python. From what I've seen that's not possible with the subprocess module? > > Try with > ? ? cmd = 'your command here' > ? ? stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout One should never, ever start a process with shell=True unless it's absolutely necessary. It is a waste of resources and an a security issue waiting to happen. Just say no. Also, stderr shouldn't be combined with stdout unless there is a need to mix the two streams, which usually is not the case. Also, one needs to hold on to the POpen object so the process can be properly reaped later or use a with block. This is where things get tricky for most applications. It gets a little extra tricky for 'ip monitor'. Assuming the intention is to write a command-line application, the right thing to do _most likely_ is: with Popen(['ip', 'monitor', 'neigh'], stdout=PIPE) as proc: try: for line in proc.stdout: # Do your processing here, it need not be line-by-line. finally: process.terminate() Calling process.terminate() explicitly is necessary since "ip monitor" writes output forever. This is not the right thing to do in all situations, and the right thing to do depends on your application and the command being executed as a subprocess. It's not really possible to generalize fully. As such, your error-handling / cleanup code may end up being completely different. Don't use my code if it's not applicable to your situation. In any case, you need to cleanup after yourself, which means waiting until the subprocess terminates. It may also include cleaning up the file objects for the pipes. Using POpen objects in a with block does both, so do that where you can. The official Python documentation for the subprocess module is pretty clear and worth reading. I encourage you to look through it carefully. It does, unfortunately, gloss over which resources need to be cleaned up and when. Adam From jaialai.technology at gmail.com Wed May 2 10:44:36 2012 From: jaialai.technology at gmail.com (jaialai.technology at gmail.com) Date: Wed, 02 May 2012 10:44:36 -0400 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4fa11386$0$11126$88263eea@blocknews.net> References: <4fa11386$0$11126$88263eea@blocknews.net> Message-ID: <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or > personally affected by your retarded and offensive comment. However, who > the fuck do you think you are to post stuff of this nature? (I believe) > I'll understand if you've got some sort of psychological issue affecting > your behaviour. OP lives out of his car and his main source of income seems to be ad revenue from his website. He may be nuts be he is pretty smart and some of the articles he has up there are worth reading. Still, he has to promote it in some way and by constantly posting these sorts of things he brings people to his site. I'm honestly impressed he can survive this way so I am willing to ignore or maybe killfile his postings and leave him be. From slord at mathworks.com Wed May 2 10:47:57 2012 From: slord at mathworks.com (Steven_Lord) Date: Wed, 2 May 2012 10:47:57 -0400 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: "Russ P." wrote in message news:2275231f-405f-4ee3-966a-40c821b7c0a8 at 2g2000yqp.googlegroups.com... > On May 1, 11:52 am, someone wrote: >> On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote: >> >> > On 04/29/2012 07:59 PM, someone wrote: >> > I do not use python much myself, but a quick google showed that pyhton >> > scipy has API for linalg, so use, which is from the documentation, the >> > following code example >> >> > X = scipy.linalg.solve(A, B) >> >> > But you still need to check the cond(). If it is too large, not good. >> > How large and all that, depends on the problem itself. But the rule of >> > thumb, the lower the better. Less than 100 can be good in general, but >> > I >> > really can't give you a fixed number to use, as I am not an expert in >> > this subjects, others who know more about it might have better >> > recommendations. >> >> Ok, that's a number... >> >> Anyone wants to participate and do I hear something better than "less >> than 100 can be good in general" ? >> >> If I don't hear anything better, the limit is now 100... >> >> What's the limit in matlab (on the condition number of the matrices), by >> the way, before it comes up with a warning ??? I'm not going to answer, and the reason why is that saying "the limit is X" may lead you to believe that "as long as my condition number is less than X, I'm safe." That's not the case. The threshold above which MATLAB warns is the fence that separates the tourists from the edge of the cliff of singularity -- just because you haven't crossed the fence doesn't mean you're not in danger of tripping and falling into the ravine. > The threshold of acceptability really depends on the problem you are > trying to solve. I agree with this statement, although you generally don't want it to be too big. The definition of "too big" is somewhat fluid, though. > I haven't solved linear equations for a long time, > but off hand, I would say that a condition number over 10 is > questionable. That seems pretty low as a general bound IMO. > A high condition number suggests that the selection of independent > variables for the linear function you are trying to fit is not quite > right. For a poorly conditioned matrix, your modeling function will be > very sensitive to measurement noise and other sources of error, if > applicable. If the condition number is 100, then any input on one > particular axis gets magnified 100 times more than other inputs. > Unless your inputs are very precise, that is probably not what you > want. > > Or something like that. Russ, you and the OP (and others) may be interested in one of the books that Cleve Moler has written and made freely available on the MathWorks website: http://www.mathworks.com/moler/ The chapter Linear Equations in "Numerical Computing with MATLAB" includes a section (section 2.9, starting on page 14 if I remember correctly) that discusses norm and condition number and gives a more formal statement of what you described. The code included in the book is written in MATLAB, but even if you don't use MATLAB (since I know this has been cross-posted to comp.lang.python) there's plenty of good, crunchy mathematics in that section. -- Steve Lord slord at mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com From varma.nikhil22 at gmail.com Wed May 2 10:49:13 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 2 May 2012 20:19:13 +0530 Subject: DateTime objectFormatting Message-ID: Hi I am using a DateTimeField in my class and want to do some tweaking with its object. class ClinicVisitDateSettings(models.Model): name = models.CharField(max_length=80,blank=True,null=True) date_created = models.DateTimeField(blank=True,null=True) def __unicode__(self): return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) The user fills Gen GI in name and date along with time. What i am able to achieve with this class object to return is :- Gen GI Monday May 7 I want that the this class should return object like this :- Gen GI Monday AM, May 7 Pancreas Tuesday PM, May 8 How can achieve AM and PM also ? with this datetime object Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Wed May 2 10:51:13 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Wed, 02 May 2012 16:51:13 +0200 Subject: How can I read streaming output of a subprocess In-Reply-To: References: Message-ID: <4FA149E1.1070508@gmail.com> >> I want to read the stream of an external process that I start with Python. >> From what I've seen that's not possible with the subprocess module? >> >> I want to read the output of "ip monitor neigh" which will show changes in >> the ARP table on my Linux computer. Each change is a new line printed by >> "ip" and the process continues to run forever. >> > > You can use subprocess for this. If you don't call wait() or > communicate() on the Popen object, the process will happily continue > running. You can call readline on the stdout pipe, which will block > until the command you are running outputs (and flushes) a line. > > Something like this should work: > > p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE) > first_line = p.stdout.readline() > > Buffering done by "ip" can ruin your day. It seems reasonable to > expect, though, that something that is printing state changes on > stdout will be careful to flush its output when appropriate. > thanks, With your confirmation, I've rechecked again and now I see that the problem I experienced before was with some strange ssh interaction. From malaclypse2 at gmail.com Wed May 2 10:57:00 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 2 May 2012 10:57:00 -0400 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 10:49 AM, Nikhil Verma wrote: > What i am able to achieve with this class object to return is :- > > Gen GI Monday? May 7 > > I want that the this class should return object like this :- > > Gen GI Monday AM, May 7 > Pancreas Tuesday PM, May 8 Check the documentation for the strftime method: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior That has a list of the various formatting directives that can be used to lay out your date and time as you wish. In this case, instead of "%A %B %d", you probably want "%A %p, %B %d". That is, Full Weekday Name, followed by the AM/PM marker, then a comma, then the Full Month Name and the day of month. -- Jerry From clp2 at rebertia.com Wed May 2 10:57:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 May 2012 07:57:05 -0700 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma wrote: > ??? def __unicode__(self): > ??????? return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) > > > The user fills Gen GI in name and date along with time. > > What i am able to achieve with this class object to return is :- > > Gen GI Monday? May 7 > > I want that the this class should return object like this :- > > Gen GI Monday AM, May 7 > Pancreas Tuesday PM, May 8 > > How can achieve AM and PM also ? with this datetime object Consult the docs. http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior : "%p -- Locale?s equivalent of either AM or PM." So, strftime("%A %p, %B %d"). Regards, Chris From tfb at tfeb.org Wed May 2 11:30:23 2012 From: tfb at tfeb.org (Tim Bradshaw) Date: Wed, 2 May 2012 16:30:23 +0100 Subject: John Carmack glorifying functional programing in 3k words References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On 2012-05-02 14:44:36 +0000, jaialai.technology at gmail.com said: > He may be nuts But he's right: programmers are pretty much fuckwits[*]: if you think that's not true you are not old enough. [*] including me, especially. From rtomek at ceti.pl Wed May 2 11:31:33 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 17:31:33 +0200 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: > > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or > > personally affected by your retarded and offensive comment. However, who > > the fuck do you think you are to post stuff of this nature? (I believe) > > I'll understand if you've got some sort of psychological issue affecting > > your behaviour. > OP lives out of his car and his main source of income seems to be ad > revenue from his website. > He may be nuts be he is pretty smart and some of the articles he has up > there are worth reading. Still, he has to promote it in some way and by > constantly posting these sorts of things he brings people to his site. > I'm honestly impressed he can survive this way so I am willing to > ignore or maybe killfile his postings and leave him be. He may be smart but obviously hasn't figured out this yet: positive aura drives more people and more permamently towards you. Perhaps he should develop an alter ego that could stand side by side with Dalai Lama and see which one gets more attention. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From varma.nikhil22 at gmail.com Wed May 2 11:35:44 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 2 May 2012 21:05:44 +0530 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: Thanks On Wed, May 2, 2012 at 8:27 PM, Chris Rebert wrote: > On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma > wrote: > > > def __unicode__(self): > > return "%s %s" % (self.name, self.date_created.strftime("%A %B > %d")) > > > > > > The user fills Gen GI in name and date along with time. > > > > What i am able to achieve with this class object to return is :- > > > > Gen GI Monday May 7 > > > > I want that the this class should return object like this :- > > > > Gen GI Monday AM, May 7 > > Pancreas Tuesday PM, May 8 > > > > How can achieve AM and PM also ? with this datetime object > > Consult the docs. > http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior: > "%p -- Locale?s equivalent of either AM or PM." > > So, strftime("%A %p, %B %d"). > > Regards, > Chris > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Wed May 2 11:35:50 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 2 May 2012 08:35:50 -0700 (PDT) Subject: Python SOAP library Message-ID: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> What's the best SOAP library for Python? I am creating an API converter which will be serialising to/from a variety of sources, including REST and SOAP. Relevant parsing is XML [incl. SOAP] and JSON. Would you recommend: http://code.google.com/p/soapbox/ Or suggest another? Thanks for all information, Alec Taylor From tjreedy at udel.edu Wed May 2 12:02:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 May 2012 12:02:03 -0400 Subject: DateTime objectFormatting In-Reply-To: References: Message-ID: On 5/2/2012 10:49 AM, Nikhil Verma wrote: This was posted as html (with text copy). Please send messages to the list and newsgroup as text (only). Html sometimes does strange things, especially if you post code. -- Terry Jan Reedy From tim.wintle at teamrubber.com Wed May 2 12:12:32 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 02 May 2012 17:12:32 +0100 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <1335975152.15772.14.camel@tim-laptop> On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: > positive aura drives more people and more permamently towards you. Perhaps he should > develop an alter ego that could stand side by side with Dalai Lama and see > which one gets more attention. Really? If all you want is attention then "being nice" doesn't seem to be the best option. (of course if you want any respect...) From rosuav at gmail.com Wed May 2 12:23:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:23:29 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola wrote: > He may be smart but obviously hasn't figured out this yet: positive aura > drives more people and more permamently towards you. You catch more flies with honey than with vinegar, but who wants to catch flies? I don't see much value in Xah Lee's posts, myself; if he wants to use LISP and hate Python then he's free to, but why ramble about it on this list? ChrisA From rosuav at gmail.com Wed May 2 12:29:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:29:56 +1000 Subject: [GENERAL] Uppercase to lowercase trigger? In-Reply-To: <1335962003519-5680384.post@n5.nabble.com> References: <1335962003519-5680384.post@n5.nabble.com> Message-ID: On Wed, May 2, 2012 at 10:33 PM, Chrishelring wrote: > Hi, > > I?ve got some tables with column names in lowercase. Before updatering these > tables I want to add a trigger that can convert these lowercase to > uppercase, and when the tables are updates convert them back to lowercase.. Not entirely sure what you're looking for here, but in Postgres, if you don't quote your column names, they are lowercased by default. UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar'; This will work if the table has "columnname" and "columnname2". ChrisA From rosuav at gmail.com Wed May 2 12:31:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 02:31:02 +1000 Subject: [GENERAL] Uppercase to lowercase trigger? In-Reply-To: References: <1335962003519-5680384.post@n5.nabble.com> Message-ID: On Thu, May 3, 2012 at 2:29 AM, Chris Angelico wrote: > On Wed, May 2, 2012 at 10:33 PM, Chrishelring > wrote: >> Hi, >> >> I?ve got some tables with column names in lowercase. Before updatering these >> tables I want to add a trigger that can convert these lowercase to >> uppercase, and when the tables are updates convert them back to lowercase.. > > Not entirely sure what you're looking for here, but in Postgres, if > you don't quote your column names, they are lowercased by default. > > UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar'; > > This will work if the table has "columnname" and "columnname2". > > ChrisA Take no notice of me... 'py'thon and 'pg'-sql are apparently too close on my keyboard and brain... ChrisA From rtomek at ceti.pl Wed May 2 12:57:13 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 18:57:13 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <1335975152.15772.14.camel@tim-laptop> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <1335975152.15772.14.camel@tim-laptop> Message-ID: On Wed, 2 May 2012, Tim Wintle wrote: > On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: > > positive aura drives more people and more permamently towards you. Perhaps he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > Really? > > +lama&ctab=0&geo=all&date=all&sort=0> > > If all you want is attention then "being nice" doesn't seem to be the > best option. > > (of course if you want any respect...) Okay, I should have given the idea a second thought. OTOH, see for yourself: http://www.google.com/trends/?q=xah+lee,dalai+lama&ctab=0&geo=all&date=all&sort=0 Esp. "xah lee does not have enough search volume for ranking"... For me, the conclusion is simple. If he wants to achieve anything, he should mimic Dalai Lama first and only after becoming comparable to the guy, if he's still dissatisfied, only then he should follow OBL. But by all means he should stop being himself. If becoming DL-like is too hard (I believe it is), he might find something even easier, like Miyamoto Musashi, a sword/Zen master. http://www.google.com/trends/?q=miyamoto+musashi,+dalai+lama&ctab=0&geo=all&date=all&sort=0 Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From ramit.prasad at jpmorgan.com Wed May 2 13:20:01 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 17:20:01 +0000 Subject: syntax for code blocks In-Reply-To: <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4f9ffd07$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa0186d$0$1389$4fafbaef@reader2.news.tin.it> <4fa07b22$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303B58@SCACMX008.exchad.jpmchase.net> Steven D'Aprano wrote: > >> Have you actually tried to use these code blocks of yours? I asked you > >> for a *working* example earlier, and you replied with examples that > >> failed with multiple NameErrors and no hint as to how to fix them. And > >> now you give an example that fails with SyntaxError. > > > > The examples I gave you work perfectly. > > Except they don't. > > Look, this isn't difficult. I asked for *working* examples, you gave > examples that give NameError. Some of those errors are easy to fix, e.g. > by importing the random and re modules. Some of them aren't. [snip] > > > It's clear that you don't even > > have the vaguest idea of how my module works or, otherwise, you'd know > > what you're doing wrong. > > Well duh. What module? Where do I find it? [snip part deux] > Whatever man. It's no skin off my nose. I've tried really hard to give > your proposal a fair go, but my care factor is rapidly running out if you > can't even be bothered to ensure your examples use legal Python syntax. I think the crucial link that was provided in another thread (and should have been included in a new thread on the same project) is http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ The only example I see on that page (for running from module) that looks fully complete is: import codeblocks codeblocks.rewrite() def each(iterable, block): for e in iterable: block(e) # step into -> 6: with each(range(0, 10)) << 'x': print('element ' + str(x)) codeblocks.end_of_module() I have not tried this (or any) example. To me it seems like an overly complicated way to avoid creating a function def. Especially since it creates a function anyway (whether anonymous or named). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From lamialily at cleverpun.com Wed May 2 13:21:42 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 02 May 2012 10:21:42 -0700 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4fa11386$0$11126$88263eea@blocknews.net> References: <4fa11386$0$11126$88263eea@blocknews.net> Message-ID: >On 27/04/12 03:11, Xah Lee wrote: >> John Carmack glorifying functional programing in 3k words >> >> http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/ >> >> where was he ten years ago? >> >> O, and btw, i heard that Common Lispers don't do functional >> programing, is that right? >> >> Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and >> Fuck Pythoners. Python fucking idiots.) >> >> O, don't forget, >> >> ?Programing: What are OOP's Jargons and Complexities (Object Oriented >> Program as Functional Program)? >> http://xahlee.org/Periodic_dosage_dir/t2/oop.html >> >> please you peruse of it. > >I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or >personally affected by your retarded and offensive comment. However, who >the fuck do you think you are to post stuff of this nature? (I believe) >I'll understand if you've got some sort of psychological issue affecting >your behaviour. And another one gets trolled. ~Temia -- When on earth, do as the earthlings do. From rtomek at ceti.pl Wed May 2 13:22:27 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 2 May 2012 19:22:27 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, 3 May 2012, Chris Angelico wrote: > On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola wrote: > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. > > You catch more flies with honey than with vinegar, but who wants to > catch flies? Nah. Who invents such distorted examples only to prove himself right :-). I think you can catch more girls with honey and I'm not sure if I'd like to catch those who prefer vinegar. I think we can make it into some kind of law, say Angelico-Rola Law (of girlscatching), ok? "One cannot catch a girl on honey without catching some flies in the process." Or is it a hypothesis? > I don't see much value in Xah Lee's posts, myself; if he wants to use > LISP and hate Python then he's free to, but why ramble about it on > this list? Well, it is strange because about half of his every post are filled up with f and sh words. Even I feel a bit dirty after reading them (and I swear without giving it much of second thought). Myself, I think I shouldn't try too hard to understand his motives - because one can easily become what one understands. Especially that he doesn't seem to be interested in getting feedback, so chances are there is some force of chaos behind all this. Or his feelings have been hurt by Lisp/Python/Emacs/Perl community (but I couldn't care less, really). Either way, I greet Xah for taking my mind off a subject of writing some piece of code that should have been written a while ago :-). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From torriem at gmail.com Wed May 2 13:37:49 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 11:37:49 -0600 Subject: Some posts do not show up in Google Groups In-Reply-To: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> Message-ID: <4FA170ED.6070304@gmail.com> On 05/01/2012 12:12 AM, Frank Millman wrote: > I have had a look at this before, but there is one thing that Google > Groups does that no other reader seems to do, and that is that > messages are sorted according to thread-activity, not original posting > date. This makes it easy to see what has changed since the last time I > checked. Any good threaded e-mail reader will do this. I use Thunderbird, for example, and all incoming python messages to the list come in, sorting the threads by most recent activity. Also coming from google groups I think you would enjoy the capabilities that a true threaded e-mail reader brings. Google's "conversations" view of things just does not preserve the structure of the more complicated and long-running threads. If you want to stick with NNTP, thunderbird works with nntp just fine, and in fact works very well, unlike what Dennis Lee Bieber claims on his post. And as far as nntp goes, I don't see any difference between reading the list in Thunderbird via nntp or a dedicated e-mail feed (which I filter into its own IMAP folder). Avoid using gmail for reading and posting to mailing lists (yes I know I post from gmail). Google helpfully tosses out your own posts to the list so you never see them, which is a real problem for mailing lists. Google certainly knows about this bug but claims its a feature. What a crock. In the gmail web interface, google puts messages from your sent folder into the "conversation" stream, so they toss the duplicate message coming from the list. When using IMAP, this leads to dropped messages as no IMAP client will presume to know enough to put sent messages into a thread. The workwaround, which is what I use, is to send your messages to the list through a non-Gmail SMTP server. From petr.jakes.tpc at gmail.com Wed May 2 13:40:16 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Wed, 2 May 2012 10:40:16 -0700 (PDT) Subject: mmap and bit wise twiddling - Raspberry Pi Message-ID: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Hi, I am trying to work with HW peripherals on Raspberry Pi To achieve this, it is necessary read/write some values from/to the memory directly. I am looking for some wise way how to organize the bit twiddling. To set some specific bit, for example, it is necessary: - read 4 bytes string representation (I am using mmap) - transform it to the corresponding integer (I am using numpy) - do some bit masking over this integer - transport integer to the string representation (numpy again) - write it back to the memory In other words I mean: is there wise way to create an instrument/ machinery to define Class and then simply define all necessary objects and set the bit values over object attributes so the whole bit- twiddling remains under the hood. say: LED01 = GPIO(4) # gpio PIN number 4 is assigned to the LED01 name (attribute) LED01.on() LED01.off() or gpio = GPIO() LED01 = gpio.pin04 LED01 = 1 # led diode is shining (or gpio pin 4 is set) LED01 = 0 # led diode is off General suggestions, how to organise this work are more then welcome. Petr Jakes From laurent.pointal at free.fr Wed May 2 13:57:37 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 02 May 2012 19:57:37 +0200 Subject: Converting a string to list for submission to easygui =?UTF-8?B?bXVsdGVudGVyYuKAi294?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> Message-ID: <4fa17591$0$20186$426a34cc@news.free.fr> ksals wrote: > On May 1, 5:29 pm, John Gordon wrote: >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> >> ksals writes: >> >> > The original choice looks like this when I print it: >> > print(choice) >> > ('ksals', '', 'alsdkfj', '3', '') >> > I need to submit these as defaults to a multenterbox. Each entry above >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. >> > I tried your suggestion so you must be right it is a tuple of 5 >> > strings. But I need them to work in an instruction like >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) >> > fieldNames has 5 fields. >> >> If you just need to convert a tuple to a list, that's easy. Call the >> built-in function list() and pass the tuple as an intializer: >> >> >>> choice = ('ksals', '', 'alsdkfj', '3', '') >> >>> print choice >> >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) >> >>> print choice_list >> >> ['ksals', '', 'alsdkfj', '3', ''] >> >> -- >> John Gordon A is for Amy, who fell down the stairs >> gor... at panix.com B is for Basil, assaulted by bears >> -- Edward Gorey, "The Gashlycrumb Tinies" >> >> > This is a small excert to show you what I get > > for choice in easygui.multchoicebox(msg1, title,qstack): > if choice[0] == None: > print ("No entries made") > break > > > print("CHOICE IS: ",choice) ..... CHOICE IS: > ('', 'ksals', '', '', '') > c=list(choice) > print("C IS: ",c) ..... C IS: ['(', > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", > "'", ',', ' ', "'", "'", ',', ' ', "'", "'", > ')'] Looks like you have your tuple expression ('ksals', '', 'alsdkfj', '3', '') not as a tuple, but as a string. Do you convert it somewhere ? If you have it as a string, you can use eval() (not safe!) on the string to retrieve the tuple, then list() on the tuple to get a list. -- Laurent POINTAL - laurent.pointal at laposte.net 3 all?e des Orangers - 91940 Les Ulis - France T?l. 01 69 29 06 59 From jmwebaze at gmail.com Wed May 2 15:51:22 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 2 May 2012 21:51:22 +0200 Subject: try/except in a loop Message-ID: I have multiple objects, where any of them can serve my purpose.. However some objects might not have some dependencies. I can not tell before hand if the all the dependencies exsit. What i want to is begin processing from the 1st object, if no exception is raised, i am done.. if an exception is raised, the next object is tried, etc Something like objs = [... ] try: obj = objs[0] obj.make() except Exception, e: try: obj = objs[1] obj.make() except Exception, e: try: obj = objs[2] obj.make() except Exception, e: continue The problem is the length of the list of objs is variable... How can i do this? -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Wed May 2 15:58:19 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 2 May 2012 12:58:19 -0700 Subject: try/except in a loop In-Reply-To: References: Message-ID: On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: > I have?multiple?objects, where any of them can serve my purpose.. However > some objects might not have some dependencies. I can not tell before hand if > the all the dependencies exsit. What i want to is begin processing from the > 1st object, if no exception is raised, i am done.. if an exception is > raised, the next object is tried, etc ?Something like > > objs = [... ] > try: > ? obj = objs[0] > ? obj.make() > except Exception, e: > ? try: > ? ? ? obj = objs[1] > ? ? ? obj.make() > ? except Exception, e: > ? ? ?try: > ? ? ? ? obj = objs[2] > ? ? ? ? obj.make() > ? ? ?except Exception, e: > ? ? ? ?continue > > The problem is the length of the list of objs is variable... How can i do > this? for obj in objs: try: obj.make() except Exception: continue else: break else: raise RuntimeError('No object worked') > > > > -- > Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | > skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */ > > > -- > http://mail.python.org/mailman/listinfo/python-list > From theller at ctypes.org Wed May 2 16:05:17 2012 From: theller at ctypes.org (Thomas Heller) Date: Wed, 02 May 2012 22:05:17 +0200 Subject: mmap and bit wise twiddling - Raspberry Pi In-Reply-To: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> References: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Message-ID: Am 02.05.2012 19:40, schrieb Petr Jakes: > Hi, > I am trying to work with HW peripherals on Raspberry Pi > To achieve this, it is necessary read/write some values from/to the > memory directly. > > I am looking for some wise way how to organize the bit twiddling. > > To set some specific bit, for example, it is necessary: > - read 4 bytes string representation (I am using mmap) > - transform it to the corresponding integer (I am using numpy) > - do some bit masking over this integer > - transport integer to the string representation (numpy again) > - write it back to the memory > > In other words I mean: is there wise way to create an instrument/ > machinery to define Class and then simply define all necessary objects > and set the bit values over object attributes so the whole bit- > twiddling remains under the hood. > > say: > LED01 = GPIO(4) # gpio PIN number 4 is assigned to the LED01 name > (attribute) > LED01.on() > LED01.off() > or > > gpio = GPIO() > LED01 = gpio.pin04 > LED01 = 1 # led diode is shining (or gpio pin 4 is set) > LED01 = 0 # led diode is off I have an abstract BitVector base-class that allows to get/set single bits or several bits in a convenient way. You must define concrete subclasses which define a _value get/set property that actually updates the byte or word in the hardware. I use it to access bits or groups of bits of I2C devices. You would basically code like this, assuming an 8-bit GPIO port: class GPIO(BitVector): def __init__(self, address, value=0xFF, nbits=8): self.address = address super(GPIO, self).__init__(value, nbits) def _get_value(self): "read an 8-bit value from the hardware as 8-bit integer" ... def _set_value(self, v): "write the 8-bit value 'v' to the hardware" ... then you can do: gpio = GPIO(0x12345678) led0 = gpio[4] # bit 4 led0.value = 1 # switch led on print led0.value # get led status For multiple bits use this (note that different from standard Python practices, indexing works inclusive and uses [high_bitnum:low_bitnum]: port = GPIO(0x12345678) high_nibble = port[7:4] print high_nibble.value low_nibble = port[3:0] low_nibble.value = 0xF Thomas -------------- next part -------------- class BitVector(object): """BitVector class, represents mutable integers constricted to a certain range. Single bits can be get/set by indexing with integers. Slices can be used to get/set the bits in this range, as an integer constricted to this range also. Slices must use [MSB:LSB], and are inclusive. >>> [x for x in BitVector(0xAA)] [0, 1, 0, 1, 0, 1, 0, 1] >>> [x for x in BitVector(0xFF)] [1, 1, 1, 1, 1, 1, 1, 1] >>> >>> bv = BitVector(0) >>> bv[6:3] = 0xf >>> [x for x in bv] [0, 0, 0, 1, 1, 1, 1, 0] >>> bv[6:3] = -1 Traceback (most recent call last): ... ValueError: value out of allowed range >>> bv[6:3] = 16 Traceback (most recent call last): ... ValueError: value out of allowed range >>> hex(bv) '0x78' >>> bin(bv) '0b1111000' >>> """ def __init__(self, value=0, nbits=8): self._nbits = nbits self._value = value def __index__(self): return self._value def __hex__(self): return hex(self._value) def __getitem__(self, index): if isinstance(index, slice): return self._getslice(index) if not 0 <= index < self._nbits: raise IndexError("invalid index") return int(bool(self._value & (1 << index))) @property def bits(self): """ Return some bits as an object that has a .value property. The .value property represents the current value of the specied bits. b = BitVector().bits[7:0] b.value = ... print b.value """ class Bits(object): def __init__(self, bv): self.bv = bv def __getitem__(self, index): class GetSet(object): def __init__(self, bv): self.bv = bv def _get(self): return self.bv[index] def _set(self, value): self.bv[index] = value value = property(_get, _set) return GetSet(self.bv) return Bits(self) def _getslice(self, index): if index.step is not None: raise ValueError("extended slicing not supported") stop, start = index.stop, index.start if start <= stop or start < 0 or stop >= self._nbits: print "START, STOP", start, stop raise ValueError("invalid slice range") mask = (1 << (start+1)) - 1 return (self._value & mask) >> stop def _setslice(self, index, value): if index.step is not None: raise ValueError("extended slicing not supported") stop, start = index.stop, index.start if start <= stop or start < 0 or stop >= self._nbits: print "START, STOP", start, stop raise ValueError("invalid slice range") mask = (1 << (start+1)) - 1 mask &= ~((1 << stop) - 1) value = value << stop if value & ~mask: raise ValueError("value out of allowed range") v = self._value v &= ~mask v |= mask & value self._value = v def __setitem__(self, index, value): value = int(value) if isinstance(index, slice): self._setslice(index, value) return if not 0 <= index < self._nbits: raise IndexError("invalid index") mask = 1 << index if not 0 <= value <= 1: raise ValueError("value must be 0 or 1") if value: self._value |= mask else: self._value &= ~mask From bahamutzero8825 at gmail.com Wed May 2 16:07:15 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 02 May 2012 15:07:15 -0500 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA193F3.30704@gmail.com> Why wouldn't a for loop work? If something works, you can break out, otherwise continue. working_obj = None for obj in iterable: try: obj.do_something() working_obj = obj break except: continue -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From theller at ctypes.org Wed May 2 16:07:33 2012 From: theller at ctypes.org (Thomas Heller) Date: Wed, 02 May 2012 22:07:33 +0200 Subject: mmap and bit wise twiddling - Raspberry Pi In-Reply-To: References: <88d7d42c-3797-4dc1-a2e4-92f91f8f538e@w5g2000vbp.googlegroups.com> Message-ID: Am 02.05.2012 22:05, schrieb Thomas Heller: > class GPIO(BitVector): > def __init__(self, address, value=0xFF, nbits=8): > self.address = address > super(GPIO, self).__init__(value, nbits) > def _get_value(self): > "read an 8-bit value from the hardware as 8-bit integer" > ... > def _set_value(self, v): > "write the 8-bit value 'v' to the hardware" > ... Sorry, forgot to create the property; so please add this to the class definition: _value = property(_get_value, _set_value) Thomas From bahamutzero8825 at gmail.com Wed May 2 16:10:39 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 02 May 2012 15:10:39 -0500 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA194BF.5010709@gmail.com> Forgot to add that all this is covered in the tutorial in the official docs: http://docs.python.org/tutorial/controlflow.html#for-statements -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From ramit.prasad at jpmorgan.com Wed May 2 16:12:46 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 20:12:46 +0000 Subject: try/except in a loop In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> > > I have multiple objects, where any of them can serve my purpose.. > However > > some objects might not have some dependencies. I can not tell before > hand if > > the all the dependencies exsit. What i want to is begin processing from > the > > 1st object, if no exception is raised, i am done.. if an exception is > > raised, the next object is tried, etc Something like > > > > objs = [... ] > > try: > > obj = objs[0] > > obj.make() > > except Exception, e: > > try: > > obj = objs[1] > > obj.make() > > except Exception, e: > > try: > > obj = objs[2] > > obj.make() > > except Exception, e: > > continue > > > > The problem is the length of the list of objs is variable... How can i > do > > this? > > > for obj in objs: > try: > obj.make() > except Exception: > continue > else: > break > else: > raise RuntimeError('No object worked') I think you misunderstand the else clauses. >>> for obj in [ 1,2,3,4 ]: ... try: ... print obj ... except Exception: ... print 'EXCEPTION' ... else: ... print 'NO EXCEPTION' ... else: ... print 'NO OBJECTS' ... 1 NO EXCEPTION 2 NO EXCEPTION 3 NO EXCEPTION 4 NO EXCEPTION NO OBJECTS Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From newsboost at gmail.com Wed May 2 16:25:11 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:25:11 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <84bb4948-328d-4242-9034-28fad0d20899@r2g2000pbs.googlegroups.com> Message-ID: On 05/02/2012 08:36 AM, Russ P. wrote: > On May 1, 11:03 pm, someone wrote: >> On 05/02/2012 01:38 AM, Russ P. wrote: .. >>> On May 1, 4:05 pm, Paul Rubin wrote: >> It would really appreciate if anyone could maybe post a simple SVD >> example and tell what the vectors from the SVD represents geometrically >> / visually, because I don't understand it good enough and I'm sure it's >> very important, when it comes to solving matrix systems... > > SVD is perhaps the ultimate matrix decomposition and the ultimate tool > for linear analysis. Google it and take a look at the excellent > Wikipedia page on it. I would be wasting my time if I tried to compete > with that. Ok. > To really appreciate the SVD, you need some background in linear > algebra. In particular, you need to understand orthogonal > transformations. Think about a standard 3D Cartesian coordinate frame. > A rotation of the coordinate frame is an orthogonal transformation of > coordinates. The original frame and the new frame are both orthogonal. Yep. > A vector in one frame is converted to the other frame by multiplying > by an orthogonal matrix. The main feature of an orthogonal matrix is > that its transpose is its inverse (hence the inverse is trivial to > compute). As far as i know, you have to replace orthogonal with: orthonormal. That much I at least think I know without even going to wikipedia first... > The SVD can be thought of as factoring any linear transformation into > a rotation, then a scaling, followed by another rotation. The scaling > is represented by the middle matrix of the transformation, which is a > diagonal matrix of the same dimensions as the original matrix. The > singular values can be read off of the diagonal. If any of them are > zero, then the original matrix is singular. If the ratio of the > largest to smallest singular value is large, then the original matrix > is said to be poorly conditioned. Aah, thank you very much. I can easily recognize some of this... > Standard Cartesian coordinate frames are orthogonal. Imagine an x-y > coordinate frame in which the axes are not orthogonal. Such a > coordinate frame is possible, but they are rarely used. If the axes > are parallel, the coordinate frame will be singular and will basically > reduce to one-dimensional. If the x and y axes are nearly parallel, > the coordinate frame could still be used in theory, but it will be > poorly conditioned. You will need large numbers to represent points > fairly close to the origin, and small deviations will translate into > large changes in coordinate values. That can lead to problems due to > numerical roundoff errors and other kinds of errors. Thank you very much for your time. It always helps to get the same explanation from different people with slightly different ways of explaining it. Thanks! From newsboost at gmail.com Wed May 2 16:26:03 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:26:03 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11487$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On 05/02/2012 01:03 PM, Kiuhnm wrote: > On 5/2/2012 8:00, someone wrote: >> Still, I dont think I completely understand SVD. SVD (at least in >> Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I >> would better understand it with geometric examples, if one would be so >> kind to maybe write something about that... I can plot 3D vectors in >> matlab, very easily so maybe I better understand SVD if I hear/read the >> geometric explanation (references to textbook/similar is also >> appreciated). > > Russ's post is a very good starting point. I hope you read it. Ofcourse I do. From ckaynor at zindagigames.com Wed May 2 16:27:26 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 2 May 2012 13:27:26 -0700 Subject: try/except in a loop In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> Message-ID: On Wed, May 2, 2012 at 1:12 PM, Prasad, Ramit wrote: >> > I have multiple objects, where any of them can serve my purpose.. >> However >> > some objects might not have some dependencies. I can not tell before >> hand if >> > the all the dependencies exsit. What i want to is begin processing from >> the >> > 1st object, if no exception is raised, i am done.. if an exception is >> > raised, the next object is tried, etc ?Something like >> > >> > objs = [... ] >> > try: >> > ? obj = objs[0] >> > ? obj.make() >> > except Exception, e: >> > ? try: >> > ? ? ? obj = objs[1] >> > ? ? ? obj.make() >> > ? except Exception, e: >> > ? ? ?try: >> > ? ? ? ? obj = objs[2] >> > ? ? ? ? obj.make() >> > ? ? ?except Exception, e: >> > ? ? ? ?continue >> > >> > The problem is the length of the list of objs is variable... How can i >> do >> > this? >> >> >> for obj in objs: >> ? ? try: >> ? ? ? ? obj.make() >> ? ? except Exception: >> ? ? ? ? continue >> ? ? else: >> ? ? ? ? break >> else: >> ? ? raise RuntimeError('No object worked') > > > I think you misunderstand the else clauses. > >>>> for obj in [ 1,2,3,4 ]: > ... ? ? try: > ... ? ? ? ? print obj > ... ? ? except Exception: > ... ? ? ? ? print 'EXCEPTION' > ... ? ? else: > ... ? ? ? ? print 'NO EXCEPTION' > ... else: > ... ? ? print 'NO OBJECTS' > ... > 1 > NO EXCEPTION > 2 > NO EXCEPTION > 3 > NO EXCEPTION > 4 > NO EXCEPTION > NO OBJECTS You left out the break in the try clause's else that I had. That break statement causes the for loop to exit early if there is no exception, and thus the for loop's else clause does not run: >>> for obj in [ 1,2,3,4 ]: ... try: ... print obj ... except Exception: ... print 'EXCEPTION' ... else: ... print 'NO EXCEPTION' ... break ... else: ... print 'NO OBJECTS' ... 1 NO EXCEPTION > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list From newsboost at gmail.com Wed May 2 16:29:27 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:29:27 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/02/2012 01:52 PM, Steven D'Aprano wrote: > On Wed, 02 May 2012 08:00:44 +0200, someone wrote: > >> On 05/02/2012 01:05 AM, Paul Rubin wrote: >>> someone writes: >>>> Actually I know some... I just didn't think so much about, before >>>> writing the question this as I should, I know theres also something >>>> like singular value decomposition that I think can help solve >>>> otherwise illposed problems, >>> >>> You will probably get better advice if you are able to describe what >>> problem (ill-posed or otherwise) you are actually trying to solve. SVD >> >> I don't understand what else I should write. I gave the singular matrix >> and that's it. > > You can't judge what an acceptable condition number is unless you know > what your data is. > > http://mathworld.wolfram.com/ConditionNumber.html > http://en.wikipedia.org/wiki/Condition_number > > If your condition number is ten, then you should expect to lose one digit > of accuracy in your solution, over and above whatever loss of accuracy > comes from the numeric algorithm. A condition number of 64 will lose six > bits, or about 1.8 decimal digits, of accuracy. > > If your data starts off with only 1 or 2 digits of accuracy, as in your > example, then the result is meaningless -- the accuracy will be 2-2 > digits, or 0 -- *no* digits in the answer can be trusted to be accurate. I just solved a FEM eigenvalue problem where the condition number of the mass and stiffness matrices was something like 1e6... Result looked good to me... So I don't understand what you're saying about 10 = 1 or 2 digits. I think my problem was accurate enough, though I don't know what error with 1e6 in condition number, I should expect. How did you arrive at 1 or 2 digits for cond(A)=10, if I may ask ? From fred.sells at adventistcare.org Wed May 2 16:31:29 2012 From: fred.sells at adventistcare.org (Sells, Fred) Date: Wed, 2 May 2012 16:31:29 -0400 Subject: Overlayong PDF Files In-Reply-To: <1335443124.15347.1.camel@workstation.wmmi.net> References: <1335443124.15347.1.camel@workstation.wmmi.net> Message-ID: Assuming your form has actual PDF data entry fields. I export the form to a .fdf file, run a little script to replace fieldnames with %(fieldname)s and save this as a staic template. At run time I'll merge the template with a python dictionary using the % operator and shell down to pdftk to merge the two files and create a filled in PDF. This way you don't have to worry about exact placement of data. I have been looking for an api that would let me do this without the .fdf step, but to no avail. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of Adam Tauno Williams Sent: Thursday, April 26, 2012 8:25 AM To: python-list at python.org Subject: Re: Overlayong PDF Files On Wed, 2012-04-25 at 13:36 -0500, Greg Lindstrom wrote: > I would like to take an existing pdf file which has the image of a > health care claim and overlay the image with claim data (insured name, > address, procedures, etc.). I'm pretty good with reportlab -- in > fact, I've created a form close to the CMS 1500 (with NPI), but it's > not close enough for scanning. I'd like to read in the "official" > form and add my data. Is this possible? I 'overlay' PDF documents using pypdf. Example -- Adam Tauno Williams System Administrator, OpenGroupware Developer, LPI / CNA Fingerprint 8C08 209A FBE3 C41A DD2F A270 2D17 8FA4 D95E D383 From newsboost at gmail.com Wed May 2 16:32:28 2012 From: newsboost at gmail.com (someone) Date: Wed, 02 May 2012 22:32:28 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <2275231f-405f-4ee3-966a-40c821b7c0a8@2g2000yqp.googlegroups.com> Message-ID: On 05/02/2012 04:47 PM, Steven_Lord wrote: > > Russ, you and the OP (and others) may be interested in one of the books > that Cleve Moler has written and made freely available on the MathWorks > website: > > http://www.mathworks.com/moler/ > > The chapter Linear Equations in "Numerical Computing with MATLAB" > includes a section (section 2.9, starting on page 14 if I remember > correctly) that discusses norm and condition number and gives a more > formal statement of what you described. The code included in the book is > written in MATLAB, but even if you don't use MATLAB (since I know this > has been cross-posted to comp.lang.python) there's plenty of good, > crunchy mathematics in that section. I use matlab more than python. I just want to learn python, which seems extremely powerful and easy but yet, I'm a python beginner. Thank you very much for the reference, Mr. Lord. I'll look closely at that Moler-book, in about 1/2 hour or so.... Looking forward to learning more about this... From kbsals5179 at gmail.com Wed May 2 16:55:59 2012 From: kbsals5179 at gmail.com (ksals) Date: Wed, 2 May 2012 13:55:59 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> <4fa17591$0$20186$426a34cc@news.free.fr> Message-ID: <437857ea-e12b-4088-ae90-c401039d53a9@p21g2000vby.googlegroups.com> On May 2, 1:57?pm, Laurent Pointal wrote: > ksals wrote: > > On May 1, 5:29 pm, John Gordon wrote: > >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1... at d20g2000vbh.googlegroups.com> > >> ksals writes: > > >> > The original choice looks like this when I print it: > >> > print(choice) > >> > ('ksals', '', 'alsdkfj', '3', '') > >> > I need to submit these as defaults to a multenterbox. Each entry above > >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. > >> > I tried your suggestion so you must be right it is a tuple of 5 > >> > strings. ?But I need them to work in an instruction like > >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice) > >> > fieldNames has 5 fields. > > >> If you just need to convert a tuple to a list, that's easy. ?Call the > >> built-in function list() and pass the tuple as an intializer: > > >> >>> choice = ('ksals', '', 'alsdkfj', '3', '') > >> >>> print choice > > >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice) > >> >>> print choice_list > > >> ['ksals', '', 'alsdkfj', '3', ''] > > >> -- > >> John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > >> gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > >> -- Edward Gorey, "The Gashlycrumb Tinies" > > > This is a small excert to show you what I get > > > for choice in easygui.multchoicebox(msg1, title,qstack): > > ? ? ? ? ? ? if choice[0] == None: > > ? ? ? ? ? ? ? ? print ("No entries made") > > ? ? ? ? ? ? ? ? break > > > ? ? ? ? ? ? print("CHOICE IS: ",choice) ? ?..... ? ? ? ? CHOICE IS: > > ('', 'ksals', '', '', '') > > ? ? ? ? ? ? c=list(choice) > > ? ? ? ? ? ? print("C IS: ",c) ? ? ? ? ? ? ?..... ? ? ?C IS: ?['(', > > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'", > > "'", ',', ' ', "'", "'", ',', ' ', "'", "'", > > ')'] > > Looks like you have your tuple expression > ? ? ? ? ('ksals', '', 'alsdkfj', '3', '') > not as a tuple, but as a string. Do you convert it somewhere ? > > If you have it as a string, you can use eval() (not safe!) on the string to > retrieve the tuple, then list() on the tuple to get a list. > > -- > Laurent POINTAL - laurent.poin... at laposte.net > 3 all?e des Orangers - 91940 Les Ulis - France > T?l. 01 69 29 06 59 > > Thank you and everyone that helped me. I did finally figure it out this morning. I am now converting for my use. I just didn't understand what I was looking at From ramit.prasad at jpmorgan.com Wed May 2 17:00:58 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 2 May 2012 21:00:58 +0000 Subject: try/except in a loop In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF47409303DD7@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409303EC8@SCACMX008.exchad.jpmchase.net> > >> for obj in objs: > >> try: > >> obj.make() > >> except Exception: > >> continue > >> else: > >> break > >> else: > >> raise RuntimeError('No object worked') > > > > > > I think you misunderstand the else clauses. > > > >>>> for obj in [ 1,2,3,4 ]: > > ... try: > > ... print obj > > ... except Exception: > > ... print 'EXCEPTION' > > ... else: > > ... print 'NO EXCEPTION' > > ... else: > > ... print 'NO OBJECTS' > > ... > > 1 > > NO EXCEPTION > > 2 > > NO EXCEPTION > > 3 > > NO EXCEPTION > > 4 > > NO EXCEPTION > > NO OBJECTS > > You left out the break in the try clause's else that I had. That break > statement causes the for loop to exit early if there is no exception, > and thus the for loop's else clause does not run: > > >>> for obj in [ 1,2,3,4 ]: > ... try: > ... print obj > ... except Exception: > ... print 'EXCEPTION' > ... else: > ... print 'NO EXCEPTION' > ... break > ... else: > ... print 'NO OBJECTS' > ... > 1 > NO EXCEPTION Whoops, you are right. My apologies Chris! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nagle at animats.com Wed May 2 17:24:53 2012 From: nagle at animats.com (John Nagle) Date: Wed, 02 May 2012 14:24:53 -0700 Subject: Python SOAP library In-Reply-To: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: On 5/2/2012 8:35 AM, Alec Taylor wrote: > What's the best SOAP library for Python? > I am creating an API converter which will be serialising to/from a variety of sources, including REST and SOAP. > Relevant parsing is XML [incl. SOAP] and JSON. > Would you recommend: http://code.google.com/p/soapbox/ > > Or suggest another? > Thanks for all information, Are you implementing the client or the server? Python "Suds" is a good client-side library. It's strict SOAP; you must have a WSDL file, and the XML queries and replies must verify against the WSDL file. https://fedorahosted.org/suds/ John Nagle From russ.paielli at gmail.com Wed May 2 17:45:22 2012 From: russ.paielli at gmail.com (Russ P.) Date: Wed, 2 May 2012 14:45:22 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 2, 1:29?pm, someone wrote: > > If your data starts off with only 1 or 2 digits of accuracy, as in your > > example, then the result is meaningless -- the accuracy will be 2-2 > > digits, or 0 -- *no* digits in the answer can be trusted to be accurate. > > I just solved a FEM eigenvalue problem where the condition number of the > mass and stiffness matrices was something like 1e6... Result looked good > to me... So I don't understand what you're saying about 10 = 1 or 2 > digits. I think my problem was accurate enough, though I don't know what > error with 1e6 in condition number, I should expect. How did you arrive > at 1 or 2 digits for cond(A)=10, if I may ask ? As Steven pointed out earlier, it all depends on the precision you are dealing with. If you are just doing pure mathematical or numerical work with no real-world measurement error, then a condition number of 1e6 may be fine. But you had better be using "double precision" (64- bit) floating point numbers (which are the default in Python, of course). Those have approximately 12 digits of precision, so you are in good shape. Single-precision floats only have 6 or 7 digits of precision, so you'd be in trouble there. For any practical engineering or scientific work, I'd say that a condition number of 1e6 is very likely to be completely unacceptable. From torriem at gmail.com Wed May 2 18:04:35 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 16:04:35 -0600 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <4FA1AF73.5000804@gmail.com> On 05/02/2012 09:31 AM, Tomasz Rola wrote: > On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: >> OP lives out of his car and his main source of income seems to be ad >> revenue from his website. I'm always curious about this sort of thing. Do you know this for a fact, jaialai.technology? >> He may be nuts be he is pretty smart and some of the articles he has up >> there are worth reading. Still, he has to promote it in some way and by >> constantly posting these sorts of things he brings people to his site. >> I'm honestly impressed he can survive this way so I am willing to >> ignore or maybe killfile his postings and leave him be. > > He may be smart but obviously hasn't figured out this yet: positive aura > drives more people and more permamently towards you. Perhaps he should > develop an alter ego that could stand side by side with Dalai Lama and see > which one gets more attention. He appears to have some degree of the Aspergers/autism spectrum disorder. He quite literally cannot understand how people see him and why other people don't recognize his genius (both real and imagined). At least this is one possibility. Others who have crossed this list appear to have aspergers or autism too, such as Ranting Rick. He pops up occasionally, posts quite normally and even helpfully, and then lapses back into periods of ranting about how he can fix python and we all should be doing something. He refuses to write code to put his ideas into practice, and berates the list readers for being lazy and unwilling to code this ideas. Then eventually he disappears for months even years at a time before resurfacing. I've always been curious to know more about Rick. Where does he work? How does he live, and what does he do outside of the python list (he appears to only use his e-mail address on this list). Then other times I just worry about coding something cool in python. From rtomek at ceti.pl Wed May 2 19:01:33 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Thu, 3 May 2012 01:01:33 +0200 (CEST) Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4FA1AF73.5000804@gmail.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <4FA1AF73.5000804@gmail.com> Message-ID: On Wed, 2 May 2012, Michael Torrie wrote: > On 05/02/2012 09:31 AM, Tomasz Rola wrote: > > On Wed, 2 May 2012, jaialai.technology at gmail.com wrote: > >> OP lives out of his car and his main source of income seems to be ad > >> revenue from his website. > > I'm always curious about this sort of thing. Do you know this for a > fact, jaialai.technology? I guess everything we can tell about Xah comes from his own website's "about me" pages :-). > >> He may be nuts be he is pretty smart and some of the articles he has up > >> there are worth reading. Still, he has to promote it in some way and by > >> constantly posting these sorts of things he brings people to his site. > >> I'm honestly impressed he can survive this way so I am willing to > >> ignore or maybe killfile his postings and leave him be. > > > > He may be smart but obviously hasn't figured out this yet: positive aura > > drives more people and more permamently towards you. Perhaps he should > > develop an alter ego that could stand side by side with Dalai Lama and see > > which one gets more attention. > > He appears to have some degree of the Aspergers/autism spectrum > disorder. He quite literally cannot understand how people see him and > why other people don't recognize his genius (both real and imagined). > At least this is one possibility. >From what I have learned, Aspergers know there is a "language" that other people speak that makes them comfortable with each other, but are unable to reproduce it (in a manner similar to, say, Englishman living in France for years, with Frenchmen not very content about his broken accent). OTOH people with autism, even so called Highly Functioning Autism, neither understand there is such a language, nor give a damn (abovementioned Englishman lives in France without realizing guys around him speak differently). About geniuses - I have heard they stand up and deliver, do not rant. Xah has his strong points - they come up on his website, but interaction is probably not one of them. Perhaps Xah (and other guys) have particularly hard time with being attacked by depression and react by ranting? This, or some kind of narcistic delirium. Of course, all of those are just my somewhat-semi-educated guesses. > Others who have crossed this list appear to have aspergers or autism > too, such as Ranting Rick. He pops up occasionally, posts quite > normally and even helpfully, and then lapses back into periods of > ranting about how he can fix python and we all should be doing > something. He refuses to write code to put his ideas into practice, and > berates the list readers for being lazy and unwilling to code this > ideas. Then eventually he disappears for months even years at a time Well? I thought there were some languages similar in form to Python, that could satisfy anybody looking for such form "only with few features different". I don't remember their names - but just staying here and doing like you describe does not look rational. > before resurfacing. I've always been curious to know more about Rick. > Where does he work? How does he live, and what does he do outside of > the python list (he appears to only use his e-mail address on this list). Yep. It is always interesting, in a way. I think if they do not have constant income, they probably live a miserable lifes in some shack, working on hardware in a pre-death state, reanimated and resuscitated and breaking again... Or maybe not. Afterall, ability to resuscitate computer can be sold, too. > Then other times I just worry about coding something cool in python. Or some other language :-) Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From wuwei23 at gmail.com Wed May 2 20:20:16 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 May 2012 17:20:16 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> On May 2, 8:52?pm, Kiuhnm wrote: >> func(some_args, locals()) > > I think that's very bad. It wouldn't be safe either. What about name > clashing locals() is a dict. It's not injecting anything into func's scope other than a dict so there's not going to be any name clashes. If you don't want any of its content in your function's scope, just don't use that content. > and how would you pass only some selected functions? You wouldn't. You would just refer to the required functions in the dict _in the same way you would in both your "bad python" and code block versions. > > But as you're _passing them in by name_ why not just make it > > func(some_args) and pick them up out of the scope. > > Because that's not clean and maintainable. It's not different from using > global variables. ...I'm beginning to suspect we're not engaging in the same conversation. This is very common in Python: from module1 import func1 def func2(args): pass def main(): # do something with func1 and func2 And I've never had problems maintaining code like this. I know _exactly_ the scope that the functions exist within because I added them to it. They're not _global_ because they're restricted to that specific scope. > > _No one_ writes Python code like this. Presenting bad code as > > "pythonic" is a bit of a straw man. > > How can I present good code where there's no good way of doing that > without my module or something equivalent? > That was my point. You haven't presented *any* good code or use cases. > > This is unintuitive, to say the least. You're effectively replacing > > the common form of function definition with "with when_odd as 'n'", > > then using the surrounding context manager to limit the scope. > > What's so unintuitive about it? It's just "different". Because under no circumstance does "with function_name as string_signature" _read_ in an understandable way. It's tortuous grammar that makes no sense as a context manager. You're asking people to be constantly aware that there are two completely separate meanings to 'with x as y'. > > More importantly, _you're naming your "anonymous" code blocks_, I'm > > guessing so that func() can choose which ones to use. But if you're > > naming them, why not just use a function? > > I'm creating a dictionary, not naming my blocks just for the sake of it. > If you use a function, you end up with the solution that you called > 'bad' and non-pythonic. What I considered 'bad' was having a _single_ function that takes _multiple differing collections_ of named functions. Now you've moved the onus onto the caller to ensure that the function is provided what it needs in a specific context to do its thing. Rather than overload one single function and push the complexity out to the caller, why not have multiple functions with obvious names about what they do that only take the data they need to act on? Then again, it's _really difficult_ to tell if something named 'func()' could have a real use like this. > The problem is always the same. Those functions are defined at the > module level so name clashing and many other problems are possible. So define & use a different scope! Thankfully module level isn't the only one to play with. > I remember a post on this ng when one would create a list of commands > and then use that list as a switch table. My module let you do that very > easily. The syntax is: > > ? ? ?with func() << ':list': > ? ? ? ? ?with 'arg': > ? ? ? ? ? ? ?cmd_code > ? ? ? ? ?with 'arg': > ? ? ? ? ? ? ?cmd_code > ? ? ? ? ?with '': > ? ? ? ? ? ? ?cmd_code I'm sorry but it is still clear-as-mud what you're trying to show here. Can you show _one_ practical, real-world, non-toy example that solves a real problem in a way that Python cannot? From pengyu.ut at gmail.com Wed May 2 20:52:25 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 2 May 2012 19:52:25 -0500 Subject: Why variable used in list comprehension available outside? Message-ID: Hi, The following example demonstrates the variable 'v' used in the list comprehension is accessible out site the list comprehension. I think that 'v' should be strictly local. Does anybody know where this behavior is documented and why it is designed this way? ~/linux/test/python/man/library/__buildin__/class/{/iteritems$ cat main1.py #!/usr/bin/env python d = {'one': 10, 'two': 20} for k, v in d.iteritems(): print k, v x=[2*v for v in [1, 2, 3]] print x print k, v ~/linux/test/python/man/library/__buildin__/class/{/iteritems$ ./main1.py two 20 [2, 4, 6] two 3 one 10 [2, 4, 6] one 3 -- Regards, Peng From python.list at tim.thechases.com Wed May 2 21:23:30 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 02 May 2012 20:23:30 -0500 Subject: Why variable used in list comprehension available outside? In-Reply-To: References: Message-ID: <4FA1DE12.90305@tim.thechases.com> On 05/02/12 19:52, Peng Yu wrote: > The following example demonstrates the variable 'v' used in the > list comprehension is accessible out site the list > comprehension. It did in Python 2.x but has been fixed in 3.x: tim at bigbox:~$ python3 Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 42 >>> tim at bigbox:~$ python2.6 Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 9 >>> -tkc From showell30 at yahoo.com Wed May 2 22:14:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 19:14:54 -0700 (PDT) Subject: key/value store optimized for disk storage Message-ID: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> This is slightly off topic, but I'm hoping folks can point me in the right direction. I'm looking for a fairly lightweight key/value store that works for this type of problem: ideally plays nice with the Python ecosystem the data set is static, and written infrequently enough that I definitely want *read* performance to trump all there is too much data to keep it all in memory (so no memcache) users will access keys with fairly uniform, random probability the key/value pairs are fairly homogenous in nature: keys are <= 16 chars values are between 1k and 4k bytes generally approx 3 million key/value pairs total amount of data == 6Gb needs to work on relatively recent versions of FreeBSD and Linux My current solution works like this: keys are file paths directories are 2 levels deep (30 dirs w/100k files each) values are file contents The current solution isn't horrible, but I'm try to squeeze a little performance/robustness out of it. A minor nuisance is that I waste a fair amount of disk space, since the values are generally less than 4k in size. A larger concern is that I'm not convinced that file systems are optimized for dealing with lots of little files in a shallow directory structure. To deal with the latter issue, a minor refinement would be to deepen the directory structure, but I want to do due diligence on other options first. I'm looking for something a little lighter than a full-on database (either SQL or no-SQL), although I'm not completely ruling out any alternatives yet. As I mention up top, I'm mostly hoping folks can point me toward sources they trust, whether it be other mailing lists, good tools, etc. To the extent that this is on topic and folks don't mind discussing this here, I'm happy to follow up on any questions. Thanks, Steve P.S. I've already found some good information via Google, but there's a lot of noise out there. From no.email at nospam.invalid Wed May 2 22:46:20 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 19:46:20 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <7xsjfinfr7.fsf@ruckus.brouhaha.com> Steve Howell writes: > keys are file paths > directories are 2 levels deep (30 dirs w/100k files each) > values are file contents > The current solution isn't horrible, Yes it is ;-) > As I mention up top, I'm mostly hoping folks can point me toward > sources they trust, whether it be other mailing lists, good tools, cdb sounds reasonable for your purposes. I'm sure there are python bindings for it. http://cr.yp.to/cdb.html mentions a 4gb limit (2**32) but I half-remember something about a 64 bit version. From wrw at mac.com Wed May 2 22:50:08 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 02 May 2012 22:50:08 -0400 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: On May 2, 2012, at 10:14 PM, Steve Howell wrote: > This is slightly off topic, but I'm hoping folks can point me in the > right direction. > > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are <= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux > I don't understand that statement, I don't think I agree with it. I'm writing this e-mail on a system with 16 GB of memory. It is just under 3 years old, and if it were purchased today, it would have 32 GB of memory at essentially the same price. I think you might want to re-examine your thinking about the limits of a memory-based system. It could probably be completely written in python and still have acceptable performance. -Bill From tjreedy at udel.edu Wed May 2 23:00:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 May 2012 23:00:28 -0400 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: On 5/2/2012 10:14 PM, Steve Howell wrote: > This is slightly off topic, but I'm hoping folks can point me in the > right direction. > > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are<= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux On my 64bit machine with 64 bit Python, I would consider putting all the values in one data file and creating a key:file-offset dict. Each value would start with length(value) so that is not needed in memory. The dict, once created, could be pickled and unpickled for each run. -- Terry Jan Reedy From python.list at tim.thechases.com Wed May 2 23:03:37 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 02 May 2012 22:03:37 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <4FA1F589.5000201@tim.thechases.com> On 05/02/12 21:14, Steve Howell wrote: > I'm looking for a fairly lightweight key/value store that works for > this type of problem: > > ideally plays nice with the Python ecosystem > the data set is static, and written infrequently enough that I > definitely want *read* performance to trump all > there is too much data to keep it all in memory (so no memcache) > users will access keys with fairly uniform, random probability > the key/value pairs are fairly homogenous in nature: > keys are <= 16 chars > values are between 1k and 4k bytes generally > approx 3 million key/value pairs > total amount of data == 6Gb > needs to work on relatively recent versions of FreeBSD and Linux [snip] > I'm looking for something a little lighter than a full-on database > (either SQL or no-SQL), although I'm not completely ruling out any > alternatives yet. This sounds suspiciously like the standard library's anydbm module[1] which should handle everything you list (though I can't be positive about the 6Gb bit, though I expect it should be fine; I can't find any documentation on the limits). -tkc [1] http://docs.python.org/library/anydbm.html From rosuav at gmail.com Wed May 2 23:08:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 13:08:23 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: On Thu, May 3, 2012 at 3:22 AM, Tomasz Rola wrote: > I think you can catch more girls with honey and I'm not sure if I'd like > to catch those who prefer vinegar. I think we can make it into some kind > of law, say Angelico-Rola Law (of girlscatching), ok? > > "One cannot catch a girl on honey without catching some flies in the > process." > > Or is it a hypothesis? This has the makings of a publication in a respected scientific journal, I think. We should totally pursue that... next time we're bored and have no interesting problems to solve by writing code. Also, I lolled. :) ChrisA From rosuav at gmail.com Wed May 2 23:09:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 13:09:35 +1000 Subject: John Carmack glorifying functional programing in 3k words In-Reply-To: <4FA1AF73.5000804@gmail.com> References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> <4FA1AF73.5000804@gmail.com> Message-ID: On Thu, May 3, 2012 at 8:04 AM, Michael Torrie wrote: > Others who have crossed this list appear to have aspergers or autism > too, such as Ranting Rick. ?He pops up occasionally, posts quite > normally and even helpfully, and then lapses back into periods of > ranting about how he can fix python and we all should be doing > something. ?He refuses to write code to put his ideas into practice, and > berates the list readers for being lazy and unwilling to code this > ideas. ?Then eventually he disappears for months even years at a time > before resurfacing. ?I've always been curious to know more about Rick. > Where does he work? ?How does he live, and what does he do outside of > the python list (he appears to only use his e-mail address on this list). My first thought was that he was the alt of some regular poster - that he's the email account used for trolling, keeping it separate from the regular address. But that theory hasn't really gained credence. ChrisA From showell30 at yahoo.com Wed May 2 23:20:23 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 20:20:23 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> Message-ID: <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> On May 2, 7:46?pm, Paul Rubin wrote: > Steve Howell writes: > > ? keys are file paths > > ? directories are 2 levels deep (30 dirs w/100k files each) > > ? values are file contents > > The current solution isn't horrible, > > Yes it is ;-) > > As I mention up top, I'm mostly hoping folks can point me toward > > sources they trust, whether it be other mailing lists, good tools, > > cdb sounds reasonable for your purposes. ?I'm sure there are python > bindings for it. > > http://cr.yp.to/cdb.htmlmentions a 4gb limit (2**32) but I > half-remember something about a 64 bit version. Thanks. That's definitely in the spirit of what I'm looking for, although the non-64 bit version is obviously geared toward a slightly smaller data set. My reading of cdb is that it has essentially 64k hash buckets, so for 3 million keys, you're still scanning through an average of 45 records per read, which is about 90k of data for my record size. That seems actually inferior to a btree-based file system, unless I'm missing something. I did find this as follow up to your lead: http://thomas.mangin.com/data/source/cdb.py Unfortunately, it looks like you have to first build the whole thing in memory. From no.email at nospam.invalid Wed May 2 23:29:11 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 20:29:11 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> Message-ID: <7x62cehri0.fsf@ruckus.brouhaha.com> Steve Howell writes: > Thanks. That's definitely in the spirit of what I'm looking for, > although the non-64 bit version is obviously geared toward a slightly > smaller data set. My reading of cdb is that it has essentially 64k > hash buckets, so for 3 million keys, you're still scanning through an > average of 45 records per read, which is about 90k of data for my > record size. That seems actually inferior to a btree-based file > system, unless I'm missing something. 1) presumably you can use more buckets in a 64 bit version; 2) scanning 90k probably still takes far less time than a disk seek, even a "seek" (several microseconds in practice) with a solid state disk. > http://thomas.mangin.com/data/source/cdb.py > Unfortunately, it looks like you have to first build the whole thing > in memory. It's probably fixable, but I'd guess you could just use Bernstein's cdbdump program instead. Alternatively maybe you could use one of the *dbm libraries, which burn a little more disk space, but support online update. From showell30 at yahoo.com Thu May 3 00:08:35 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 2 May 2012 21:08:35 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> Message-ID: <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> On May 2, 8:29?pm, Paul Rubin wrote: > Steve Howell writes: > > Thanks. ?That's definitely in the spirit of what I'm looking for, > > although the non-64 bit version is obviously geared toward a slightly > > smaller data set. ?My reading of cdb is that it has essentially 64k > > hash buckets, so for 3 million keys, you're still scanning through an > > average of 45 records per read, which is about 90k of data for my > > record size. ?That seems actually inferior to a btree-based file > > system, unless I'm missing something. > > 1) presumably you can use more buckets in a 64 bit version; 2) scanning > 90k probably still takes far less time than a disk seek, even a "seek" > (several microseconds in practice) with a solid state disk. > Doesn't cdb do at least one disk seek as well? In the diagram on this page, it seems you would need to do a seek based on the value of the initial pointer (from the 256 possible values): http://cr.yp.to/cdb/cdb.txt > >http://thomas.mangin.com/data/source/cdb.py > > Unfortunately, it looks like you have to first build the whole thing > > in memory. > > It's probably fixable, but I'd guess you could just use Bernstein's > cdbdump program instead. > > Alternatively maybe you could use one of the *dbm libraries, > which burn a little more disk space, but support online update. Yup, I don't think I want to incur the extra overhead. Do you have any first hand experience pushing dbm to the scale of 6Gb or so? My take on dbm is that its niche is more in the 10,000-record range. From alec.taylor6 at gmail.com Thu May 3 00:18:20 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 3 May 2012 14:18:20 +1000 Subject: Python SOAP library In-Reply-To: References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: Client and server (unfortunately) I need to support serialisation between formats On Thu, May 3, 2012 at 7:24 AM, John Nagle wrote: > On 5/2/2012 8:35 AM, Alec Taylor wrote: >> >> What's the best SOAP library for Python? >> I am creating an API converter which will be serialising to/from a variety >> of sources, including REST and SOAP. >> Relevant parsing is XML [incl. SOAP] and JSON. >> Would you recommend: http://code.google.com/p/soapbox/ >> >> Or suggest another? >> Thanks for all information, > > > ? Are you implementing the client or the server? > > ? Python "Suds" is a good client-side library. It's strict SOAP; > you must have a WSDL file, and the XML queries and replies must > verify against the WSDL file. > > ? ?https://fedorahosted.org/suds/ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Thu May 3 00:26:35 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 22:26:35 -0600 Subject: syntax for code blocks In-Reply-To: <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4FA208FB.8010006@gmail.com> On 05/02/2012 04:52 AM, Kiuhnm wrote: > The problem is always the same. Those functions are defined at the > module level so name clashing and many other problems are possible. Only functions defined at the module level are in fact in the module's namespace. For example, this works fine, and the definitions for one and two are only within their respective scopes: def other_part(): def one(): pass def two(): pass # do something with one and two def main(): def one(): pass def two(): pass # do something with one and two other_part() If you are experiencing name clashes you need to start dividing your code up logically instead of keeping everything in the global namespace of your module. From rosuav at gmail.com Thu May 3 00:29:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 May 2012 14:29:46 +1000 Subject: =?UTF-8?Q?Re=3A_Converting_a_string_to_list_for_submission_to_ea?= =?UTF-8?Q?sygui_multenterb=E2=80=8Box?= In-Reply-To: <4fa17591$0$20186$426a34cc@news.free.fr> References: <316efebe-7f54-4054-96b1-51c7bb7b7b25@f5g2000vbt.googlegroups.com> <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80@d20g2000vbh.googlegroups.com> <1f25af0e-a7cb-4c15-acc5-0975ccc1ab01@h5g2000vbx.googlegroups.com> <4fa17591$0$20186$426a34cc@news.free.fr> Message-ID: On Thu, May 3, 2012 at 3:57 AM, Laurent Pointal wrote: > If you have it as a string, you can use eval() (not safe!) on the string to > retrieve the tuple, then list() on the tuple to get a list. Are you saying that eval is not safe (which it isn't), or that it has to be eval() and not safe_eval() to do this job? There's also ast.literal_eval which ought to be safe for this situation (I think). ChrisA From torriem at gmail.com Thu May 3 00:31:00 2012 From: torriem at gmail.com (Michael Torrie) Date: Wed, 02 May 2012 22:31:00 -0600 Subject: syntax for code blocks In-Reply-To: <4FA208FB.8010006@gmail.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <4FA208FB.8010006@gmail.com> Message-ID: <4FA20A04.1080203@gmail.com> On 05/02/2012 10:26 PM, Michael Torrie wrote: > If you are experiencing name clashes you need to start dividing your > code up logically instead of keeping everything in the global namespace > of your module. I shouldn't have used the word "global" here as it's not actually global. From no.email at nospam.invalid Thu May 3 02:33:56 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 23:33:56 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> Message-ID: <7xtxzx3h9n.fsf@ruckus.brouhaha.com> Steve Howell writes: > Doesn't cdb do at least one disk seek as well? In the diagram on this > page, it seems you would need to do a seek based on the value of the > initial pointer (from the 256 possible values): Yes, of course it has to seek if there is too much data to fit in memory. All I'm saying is that if you're spending milliseconds on the seek, that may dominate the lookup time even if you scan the 90k. Actually, looking at the spec more closely, there are 256 hash tables in the file, but each table can be of any size. So there can be far more than 2**16 hash slots. Uncharacteristically for Bernstein, the document is pretty unclear, so maybe you have to look at the code to be sure of the layout. Note also that empty hash buckets have just 2 words of overhead. So with 3M keys and 75% load factor, you get 4M buckets and relatively few collisions. The extra 1M buckets in a 64 bit implementation is just 16MB in the file, which isn't much at all even considering that you want it to stay resident in memory to avoid some seeks, assuming you're on a PC and not some smaller device like a phone. (A phone will have a solid state disk eliminating most seek time, so you're ok in that situation too). > Yup, I don't think I want to incur the extra overhead. Do you have > any first hand experience pushing dbm to the scale of 6Gb or so? My > take on dbm is that its niche is more in the 10,000-record range. There are a bunch of different variants. I'm trying to remember what I've personally done with it and I'm sure I've used much more than 10k records, but maybe not millions. Unix dbm was originally designed to handle millions of records back when that was a lot. I'd expect gdbm, bsddb and so forth can handle it easily. The naive Python dbm module might not be able to. The amount of data you're talking about (a few million keys, a few gb of data) is fairly modest by today's standards, so I would think fancy methods aren't really needed. From no.email at nospam.invalid Thu May 3 02:48:30 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 May 2012 23:48:30 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> Message-ID: <7xpqal3gld.fsf@ruckus.brouhaha.com> Paul Rubin writes: >looking at the spec more closely, there are 256 hash tables.. ... You know, there is a much simpler way to do this, if you can afford to use a few hundred MB of memory and you don't mind some load time when the program first starts. Just dump all the data sequentially into a file. Then scan through the file, building up a Python dictionary mapping data keys to byte offsets in the file (this is a few hundred MB if you have 3M keys). Then dump the dictionary as a Python pickle and read it back in when you start the program. You may want to turn off the cyclic garbage collector when building or loading the dictionary, as it badly can slow down the construction of big lists and maybe dicts (I'm not sure of the latter). From kushal.kumaran+python at gmail.com Thu May 3 02:53:10 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 3 May 2012 12:23:10 +0530 Subject: bus errors when the network interface is reset? In-Reply-To: References: Message-ID: On Tue, May 1, 2012 at 7:31 PM, David M Chess wrote: > > We have a system running Python 2.6.6 under RHEL 6.1. ?A bunch of processes > spend most of their time sitting in a BaseHTTPServer.HTTPServer waiting for > requests. > > Last night an update pushed out via xcat whimsically restarted all of the > network interfaces, and at least some of our processes died with bus errors > (i.e. no errors or exceptions reflected up to the Python level, just a > crash). > > This is just my initial looking into this. ?Seeking opinions of the form, > say: > > Yeah, that happens, don't reset the network interfaces. > Yeah, that happens, and you can prevent the crash by doing X in your OS. > Yeah, that happens, and you can prevent the crash by doing X in your Python > code. > That wouldn't happen if you upgraded S to version V. > That sounds like a new bug and/or more information is needed; please provide > copious details including at least X, Y, and Z. > > Any thoughts or advice greatly appreciated. > Never seen this happen. Does it matter if your listening socket is bound to all interfaces v/s bound to a specific interface? From a cursory look at the source, SocketServer.TCPServer (which BaseHTTPServer is derived from) simply does a select, followed by an accept. Do any other server applications crash as well? -- regards, kushal From pjb at informatimago.com Thu May 3 04:06:42 2012 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 03 May 2012 10:06:42 +0200 Subject: John Carmack glorifying functional programing in 3k words References: <4fa11386$0$11126$88263eea@blocknews.net> <7777f$4fa14855$813f0835$20772@news.eurofeeds.com> Message-ID: <874nrxn0x9.fsf@kuiper.lan.informatimago.com> Tim Bradshaw writes: > On 2012-05-02 14:44:36 +0000, jaialai.technology at gmail.com said: > >> He may be nuts > > But he's right: programmers are pretty much fuckwits[*]: if you think > that's not true you are not old enough. > > [*] including me, especially. You need to watch: http://blog.ted.com/2012/02/29/the-only-way-to-learn-to-fly-is-to-fly-regina-dugan-at-ted2012/ -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From showell30 at yahoo.com Thu May 3 04:42:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 01:42:54 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: On May 2, 11:48?pm, Paul Rubin wrote: > Paul Rubin writes: > >looking at the spec more closely, there are 256 hash tables.. ... > > You know, there is a much simpler way to do this, if you can afford to > use a few hundred MB of memory and you don't mind some load time when > the program first starts. ?Just dump all the data sequentially into a > file. ?Then scan through the file, building up a Python dictionary > mapping data keys to byte offsets in the file (this is a few hundred MB > if you have 3M keys). ?Then dump the dictionary as a Python pickle and > read it back in when you start the program. > > You may want to turn off the cyclic garbage collector when building or > loading the dictionary, as it badly can slow down the construction of > big lists and maybe dicts (I'm not sure of the latter). I'm starting to lean toward the file-offset/seek approach. I am writing some benchmarks on it, comparing it to a more file-system based approach like I mentioned in my original post. I'll report back when I get results, but it's already way past my bedtime for tonight. Thanks for all your help and suggestions. From kiuhnm03.4t.yahoo.it Thu May 3 07:46:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 03 May 2012 13:46:31 +0200 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: <4fa27016$0$1378$4fafbaef@reader2.news.tin.it> On 5/3/2012 10:42, Steve Howell wrote: > On May 2, 11:48 pm, Paul Rubin wrote: >> Paul Rubin writes: >>> looking at the spec more closely, there are 256 hash tables.. ... >> >> You know, there is a much simpler way to do this, if you can afford to >> use a few hundred MB of memory and you don't mind some load time when >> the program first starts. Just dump all the data sequentially into a >> file. Then scan through the file, building up a Python dictionary >> mapping data keys to byte offsets in the file (this is a few hundred MB >> if you have 3M keys). Then dump the dictionary as a Python pickle and >> read it back in when you start the program. >> >> You may want to turn off the cyclic garbage collector when building or >> loading the dictionary, as it badly can slow down the construction of >> big lists and maybe dicts (I'm not sure of the latter). > > I'm starting to lean toward the file-offset/seek approach. I am > writing some benchmarks on it, comparing it to a more file-system > based approach like I mentioned in my original post. I'll report back > when I get results, but it's already way past my bedtime for tonight. > > Thanks for all your help and suggestions. You should really cache the accesses to that file hoping that the accesses are not as random as you think. If that's the case you should notice a *huge* improvement. Kiuhnm From wuwei23 at gmail.com Thu May 3 07:52:36 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 04:52:36 -0700 (PDT) Subject: pyjamas / pyjs Message-ID: Anyone else following the apparent hijack of the pyjs project from its lead developer? From ulrich.eckhardt at dominolaser.com Thu May 3 08:51:54 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 03 May 2012 14:51:54 +0200 Subject: docstrings for data fields Message-ID: Hi! My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with functions I would simply add a docstring explaining the meaning of this, but how do I do that for a non-function member? Note also that ideally, this constant wouldn't show up inside instances of the class but only inside the class itself. There are decorators for static functions or class functions, similarly there is one for instance properties but there isn't one for class properties. Would that be a useful addition? Uli From fayaz at dexetra.com Thu May 3 09:13:39 2012 From: fayaz at dexetra.com (Fayaz Yusuf Khan) Date: Thu, 03 May 2012 18:43:39 +0530 Subject: What is the use of python.cache_ubuntu? Message-ID: My Ubuntu 11.04 server ran out of inodes due to too many files in '/tmp/python.cache_ubuntu'. Does anyone know what it does? -- Cloud architect and hacker, Dexetra, India fayaz.yusuf.khan_AT_gmail_DOT_com fayaz_AT_dexetra_DOT_com +91-9746-830-823 From jeanmichel at sequans.com Thu May 3 09:27:40 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 15:27:40 +0200 Subject: try/except in a loop In-Reply-To: References: Message-ID: <4FA287CC.9040000@sequans.com> Chris Kaynor wrote: > On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: > >> I have multiple objects, where any of them can serve my purpose.. However >> some objects might not have some dependencies. I can not tell before hand if >> the all the dependencies exsit. What i want to is begin processing from the >> 1st object, if no exception is raised, i am done.. if an exception is >> raised, the next object is tried, etc Something like >> >> objs = [... ] >> try: >> obj = objs[0] >> obj.make() >> except Exception, e: >> try: >> obj = objs[1] >> obj.make() >> except Exception, e: >> try: >> obj = objs[2] >> obj.make() >> except Exception, e: >> continue >> >> The problem is the length of the list of objs is variable... How can i do >> this? >> > > > for obj in objs: > try: > obj.make() > except Exception: > continue > else: > break > else: > raise RuntimeError('No object worked') > > For the record, an alternative solution without try block: candidates = [obj for obj in objs if hasattr(obj, 'make') and callable(obj.make)] if candidates: candidates[0].make() JM From __peter__ at web.de Thu May 3 09:57:32 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 May 2012 15:57:32 +0200 Subject: try/except in a loop References: <4FA287CC.9040000@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Chris Kaynor wrote: >> On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: >> >>> I have multiple objects, where any of them can serve my purpose.. >>> However some objects might not have some dependencies. I can not tell >>> before hand if the all the dependencies exsit. What i want to is begin >>> processing from the 1st object, if no exception is raised, i am done.. >>> if an exception is >>> raised, the next object is tried, etc Something like >>> >>> objs = [... ] >>> try: >>> obj = objs[0] >>> obj.make() >>> except Exception, e: >>> try: >>> obj = objs[1] >>> obj.make() >>> except Exception, e: >>> try: >>> obj = objs[2] >>> obj.make() >>> except Exception, e: >>> continue >>> >>> The problem is the length of the list of objs is variable... How can i >>> do this? >>> >> >> >> for obj in objs: >> try: >> obj.make() >> except Exception: >> continue >> else: >> break >> else: >> raise RuntimeError('No object worked') >> >> > For the record, an alternative solution without try block: Hmm, it's not sufficient that the method exists, it should succeed, too. class Obj: def make(self): raise Exception("I'm afraid I can't do that") objs = [Obj()] > candidates = [obj for obj in objs if hasattr(obj, 'make') and > callable(obj.make)] > if candidates: > candidates[0].make() It is often a matter of taste, but I tend to prefer EAFP over LBYL. From deltaquattro at gmail.com Thu May 3 10:52:54 2012 From: deltaquattro at gmail.com (deltaquattro at gmail.com) Date: Thu, 3 May 2012 07:52:54 -0700 (PDT) Subject: Create directories and modify files with Python In-Reply-To: <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> <4fa07117$0$6944$e4fe514c@news2.news.xs4all.nl> Message-ID: <31975208.1249.1336056774993.JavaMail.geo-discussion-forums@vbq19> I'm leaving the thread because I cannot read any posts, apart from Irmen's. Anyway, I would like to publicly thank all who contributed, in particular rurpy who solved my problem (and kindly sent me a personal email, so that I could see his/her post :) Best Regards Sergio Rossi From ccurvey at gmail.com Thu May 3 10:53:52 2012 From: ccurvey at gmail.com (Chris Curvey) Date: Thu, 3 May 2012 07:53:52 -0700 (PDT) Subject: c-based version of pyPdf? Message-ID: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot. So performance is starting to become a problem. Does anyone know of an analogue to pyPdf that is faster? (Maybe something based on C with Python bindings?) From jeanmichel at sequans.com Thu May 3 10:54:05 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 16:54:05 +0200 Subject: try/except in a loop In-Reply-To: References: <4FA287CC.9040000@sequans.com> Message-ID: <4FA29C0D.2020107@sequans.com> Peter Otten wrote: > Jean-Michel Pichavant wrote: > > >> Chris Kaynor wrote: >> >>> On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze wrote: >>> >>> >>>> I have multiple objects, where any of them can serve my purpose.. >>>> However some objects might not have some dependencies. I can not tell >>>> before hand if the all the dependencies exsit. What i want to is begin >>>> processing from the 1st object, if no exception is raised, i am done.. >>>> if an exception is >>>> raised, the next object is tried, etc Something like >>>> >>>> objs = [... ] >>>> try: >>>> obj = objs[0] >>>> obj.make() >>>> except Exception, e: >>>> try: >>>> obj = objs[1] >>>> obj.make() >>>> except Exception, e: >>>> try: >>>> obj = objs[2] >>>> obj.make() >>>> except Exception, e: >>>> continue >>>> >>>> The problem is the length of the list of objs is variable... How can i >>>> do this? >>>> >>>> >>> for obj in objs: >>> try: >>> obj.make() >>> except Exception: >>> continue >>> else: >>> break >>> else: >>> raise RuntimeError('No object worked') >>> >>> >>> >> For the record, an alternative solution without try block: >> > > Hmm, it's not sufficient that the method exists, it should succeed, too. > > class Obj: > def make(self): > raise Exception("I'm afraid I can't do that") > objs = [Obj()] > > >> candidates = [obj for obj in objs if hasattr(obj, 'make') and >> callable(obj.make)] >> if candidates: >> candidates[0].make() >> > > It is often a matter of taste, but I tend to prefer EAFP over LBYL. > > Could be that the OP did its job by calling the make method if it exists. If the method raises an exception, letting it through is a viable option if you cannot handle the exception. Additionaly, having a method not raising any exception is not a criteria for success, for instance def make(self): return 42 will surely fail to do what the OP is expecting. By the way on a unrelated topic, using try blocks to make the code "robust" is never a good idea, I hope the OP is not try to do that. JM From jeanmichel at sequans.com Thu May 3 11:00:25 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 May 2012 17:00:25 +0200 Subject: docstrings for data fields In-Reply-To: References: Message-ID: <4FA29D89.4010402@sequans.com> Ulrich Eckhardt wrote: > Hi! > > My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with > functions I would simply add a docstring explaining the meaning of this, > but how do I do that for a non-function member? Note also that ideally, > this constant wouldn't show up inside instances of the class but only > inside the class itself. > > There are decorators for static functions or class functions, similarly > there is one for instance properties but there isn't one for class > properties. Would that be a useful addition? > > Uli > class Foo: MAX_VALUE = 42 """The maximum value""" epydoc support such docstring. If you need a native support for the python help function for instance, document it within the class docstring: class Foo: """Foo support Attributes: MAX_VALUE: the maximum value """ MAX_VALUE = 42 From lamialily at cleverpun.com Thu May 3 11:01:15 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 03 May 2012 08:01:15 -0700 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <9a75q7lj1h82efp9r8mkh0s6r8bu175ke8@4ax.com> >Anyone else following the apparent hijack of the pyjs project from its >lead developer? Not beyond what the lead developer has been posting on the newsgroup, no. Still a damn shame, though. What happens when you have an unresolvable ideological seperation like that is you branch, not take over. ~Temia -- When on earth, do as the earthlings do. From kushal.kumaran+python at gmail.com Thu May 3 11:22:13 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 3 May 2012 20:52:13 +0530 Subject: c-based version of pyPdf? In-Reply-To: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> References: <30405633.1571.1336056832840.JavaMail.geo-discussion-forums@vbvx4> Message-ID: On Thu, May 3, 2012 at 8:23 PM, Chris Curvey wrote: > I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot. ?So performance is starting to become a problem. > > Does anyone know of an analogue to pyPdf that is faster? ?(Maybe something based on C with Python bindings?) I wonder if it is possible to use cython to speed it up. -- regards, kushal From ian.g.kelly at gmail.com Thu May 3 11:33:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 09:33:24 -0600 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 5:52 AM, alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? I've been following it but quietly since I don't use pyjs. It surprises me that nobody is talking much about it outside of the thread on pyjamas-dev. Seems to me that any credibility in the long-term stability of the project has been pretty much shot. From tobias.koeck at gmail.com Thu May 3 11:57:01 2012 From: tobias.koeck at gmail.com (joblack) Date: Thu, 3 May 2012 08:57:01 -0700 (PDT) Subject: Problems to list *all* mountedwindows partitions Message-ID: I do have a script which shows me the mounted partitions: c = wmi.WMI ('localhost') for disk in c.Win32_DiskPartition (DriveType=3): diskspace = int(disk.FreeSpace)/1000000 if diskspace < mfspace: trigger = True ldisks.append(disk.Name +'\\ '+str('{0:,}'.format(diskspace).replace(",", "."))+' MByte\t *LOW_DISK_SPACE*') else: ldisks.append(disk.Name+'\\ '+str('{0:,}'.format(diskspace).replace(",", "."))+' MByte\t *OK*') Unfortunetly it only shows partitions mounted to a character (e.g. c: d:). There is another physical partition mounted in d:\www1 which isn't shown. Any idea how to add those partitions as well? From antti.ylikoski at aalto.fi Thu May 3 12:02:18 2012 From: antti.ylikoski at aalto.fi (Antti J Ylikoski) Date: Thu, 03 May 2012 19:02:18 +0300 Subject: Algorithms in Python, cont'd Message-ID: <8_xor.34865$I33.34584@uutiset.elisa.fi> I wrote here about some straightforward ways to program D. E. Knuth in Python, and John Nagle answered that the value of Knuth's book series to the programmer has been significantly diminished by the fact that many functionalities such as sorting and hashing have either been built in the Python language, or are available in libraries (? propos, as an aside, very many functionalities are available notably in the CPAN, the Comprehensive Perl Language Network. I wonder what were the corresponding repository with the Python language....) Nagle's comment is to my opinion very true. So I carried out a search procedure -- and found two good sources of algorithms for the Python programmer: 1) Cormen-Leiserson-Rivest-Stein: Introduction to Algorithms, 2nd edition, ISBN 0-262-53196-8. The 3rd edition has been published, I don't know which one is the most recent one. 2) Atallah-Blanton: Algorithms and Theory of Computation Handbook, Second Edition, 2 books, ISBNs 978-1-58488-822-2 and 978-1-58488-820-8. This one in particular is really good as a general computer science source. The point of this entry is that my answer to Nagle's criticism is that numerous such more or less sophisticated algorithm reference books can be found. I intended to write some demonstrations in Python -- I chose the RSA cryptosystem from Cormen et al's book and the linear programming ellipsoid algorithm from Atallah-Blanton's book -- but I have not yet done so, it would have been straightforward but too time-consuming. yours, and V/R, Antti J Ylikoski Helsinki, Finland, the EU From foobar at invalid.invalid Thu May 3 12:12:30 2012 From: foobar at invalid.invalid (mblume) Date: Thu, 3 May 2012 16:12:30 +0000 (UTC) Subject: docstrings for data fields References: Message-ID: Am Thu, 03 May 2012 14:51:54 +0200 schrieb Ulrich Eckhardt: > Hi! > > My class Foo exports a constant, accessible as Foo.MAX_VALUE. Now, with > functions I would simply add a docstring explaining the meaning of this, > but how do I do that for a non-function member? Note also that ideally, > this constant wouldn't show up inside instances of the class but only > inside the class itself. > > There are decorators for static functions or class functions, similarly > there is one for instance properties but there isn't one for class > properties. Would that be a useful addition? > > Uli Docstring for Foo? >>> >>> class Foo: ... """ exports a FOO_MAX value """ ... FOO_MAX = 42 ... >>> >>> >>> >>> >>> help(Foo) Help on class Foo in module __main__: class Foo | exports a FOO_MAX value | | Data and other attributes defined here: | | FOO_MAX = 42 >>> Foo.FOO_MAX 42 >>> >>> >>> HTH Martin From kiuhnm03.4t.yahoo.it Thu May 3 12:17:05 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 03 May 2012 18:17:05 +0200 Subject: syntax for code blocks In-Reply-To: <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> Message-ID: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> On 5/3/2012 2:20, alex23 wrote: > On May 2, 8:52 pm, Kiuhnm wrote: >>> func(some_args, locals()) >> >> I think that's very bad. It wouldn't be safe either. What about name >> clashing > > locals() is a dict. It's not injecting anything into func's scope > other than a dict so there's not going to be any name clashes. If you > don't want any of its content in your function's scope, just don't use > that content. The clashing is *inside* the dictionary itself. It contains *all* local functions and variables. >> and how would you pass only some selected functions? > > You wouldn't. You would just refer to the required functions in the > dict _in the same way you would in both your "bad python" and code > block versions. See above. >>> But as you're _passing them in by name_ why not just make it >>> func(some_args) and pick them up out of the scope. >> >> Because that's not clean and maintainable. It's not different from using >> global variables. > > ...I'm beginning to suspect we're not engaging in the same > conversation. > > This is very common in Python: > > from module1 import func1 > > def func2(args): pass > > def main(): > # do something with func1 and func2 > > And I've never had problems maintaining code like this. I know > _exactly_ the scope that the functions exist within because I added > them to it. They're not _global_ because they're restricted to that > specific scope. That's not the same thing. If a function accepts some optional callbacks, and you call that function more than once, you will have problems. You'll need to redefine some callbacks and remove others. That's total lack of encapsulation. >>> _No one_ writes Python code like this. Presenting bad code as >>> "pythonic" is a bit of a straw man. >> >> How can I present good code where there's no good way of doing that >> without my module or something equivalent? >> That was my point. > > You haven't presented *any* good code or use cases. Says who? You and some others? Not enough. >>> This is unintuitive, to say the least. You're effectively replacing >>> the common form of function definition with "with when_odd as 'n'", >>> then using the surrounding context manager to limit the scope. >> >> What's so unintuitive about it? It's just "different". > > Because under no circumstance does "with function_name as > string_signature" _read_ in an understandable way. It's tortuous > grammar that makes no sense as a context manager. You're asking people > to be constantly aware that there are two completely separate meanings > to 'with x as y'. The meaning is clear from the context. I would've come up with something even better if only Python wasn't so rigid. > Rather than overload > one single function and push the complexity out to the caller, why not > have multiple functions with obvious names about what they do that > only take the data they need to act on? Because that would reveal part of the implementation. Suppose you have a complex visitor. The OOP way is to subclass, while the FP way is to accept callbacks. Why the FP way? Because it's more concise. In any case, you don't want to reveal how the visitor walks the data structure or, better, the user doesn't need to know about it. > Then again, it's _really difficult_ to tell if something named > 'func()' could have a real use like this. > >> The problem is always the same. Those functions are defined at the >> module level so name clashing and many other problems are possible. > > So define& use a different scope! Thankfully module level isn't the > only one to play with. We can do OOP even in ASM, you know? >> I remember a post on this ng when one would create a list of commands >> and then use that list as a switch table. My module let you do that very >> easily. The syntax is: >> >> with func()<< ':list': >> with 'arg': >> cmd_code >> with 'arg': >> cmd_code >> with '': >> cmd_code > > I'm sorry but it is still clear-as-mud what you're trying to show > here. Can you show _one_ practical, real-world, non-toy example that > solves a real problem in a way that Python cannot? I just did. It's just that you can't see it. Kiuhnm From lamialily at cleverpun.com Thu May 3 12:31:19 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 03 May 2012 09:31:19 -0700 Subject: syntax for code blocks In-Reply-To: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: > if only Python wasn't so rigid. what. You realize you'd have a little more luck with Python if you weren't wielding it like a cudgel in the examples you've posted here, right? Because it looks like you're treating the language as everything it isn't and nothing it is this whole time. No wonder you're having trouble making your code Pythonic. Go with the flow. ~Temia -- When on earth, do as the earthlings do. From k.sahithi2862 at gmail.com Thu May 3 12:34:39 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 3 May 2012 09:34:39 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: TOP DOT NET INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html Rajsekhar Mahankali Movie Stills http://actressgallery-kalyani.blogspot.in/2012/03/mahankali-movie-stills.html Mamata 100% Prema Movie Hot Stills http://actressgallery-kalyani.blogspot.in/2012/03/mamata-100-prema-movie-stills.html Raviteja Daruvu Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/daruvu-movie-stills.html NUVVA NENA MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/03/nuvva-nena-movie-stills.html Yadartha Prema Katha Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/yadartha-prema-katha-movie-stills.html RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From newsboost at gmail.com Thu May 3 13:30:35 2012 From: newsboost at gmail.com (someone) Date: Thu, 03 May 2012 19:30:35 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/02/2012 11:45 PM, Russ P. wrote: > On May 2, 1:29 pm, someone wrote: > >>> If your data starts off with only 1 or 2 digits of accuracy, as in your >>> example, then the result is meaningless -- the accuracy will be 2-2 >>> digits, or 0 -- *no* digits in the answer can be trusted to be accurate. >> >> I just solved a FEM eigenvalue problem where the condition number of the >> mass and stiffness matrices was something like 1e6... Result looked good >> to me... So I don't understand what you're saying about 10 = 1 or 2 >> digits. I think my problem was accurate enough, though I don't know what >> error with 1e6 in condition number, I should expect. How did you arrive >> at 1 or 2 digits for cond(A)=10, if I may ask ? > > As Steven pointed out earlier, it all depends on the precision you are > dealing with. If you are just doing pure mathematical or numerical > work with no real-world measurement error, then a condition number of > 1e6 may be fine. But you had better be using "double precision" (64- > bit) floating point numbers (which are the default in Python, of > course). Those have approximately 12 digits of precision, so you are > in good shape. Single-precision floats only have 6 or 7 digits of > precision, so you'd be in trouble there. > > For any practical engineering or scientific work, I'd say that a > condition number of 1e6 is very likely to be completely unacceptable. So how do you explain that the natural frequencies from FEM (with condition number ~1e6) generally correlates really good with real measurements (within approx. 5%), at least for the first 3-4 natural frequencies? I would say that the problem lies with the highest natural frequencies, they for sure cannot be verified - there's too little energy in them. But the lowest frequencies (the most important ones) are good, I think - even for high cond number. From russ.paielli at gmail.com Thu May 3 13:55:34 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 10:55:34 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> On May 3, 10:30?am, someone wrote: > On 05/02/2012 11:45 PM, Russ P. wrote: > > > > > On May 2, 1:29 pm, someone ?wrote: > > >>> If your data starts off with only 1 or 2 digits of accuracy, as in your > >>> example, then the result is meaningless -- the accuracy will be 2-2 > >>> digits, or 0 -- *no* digits in the answer can be trusted to be accurate. > > >> I just solved a FEM eigenvalue problem where the condition number of the > >> mass and stiffness matrices was something like 1e6... Result looked good > >> to me... So I don't understand what you're saying about 10 = 1 or 2 > >> digits. I think my problem was accurate enough, though I don't know what > >> error with 1e6 in condition number, I should expect. How did you arrive > >> at 1 or 2 digits for cond(A)=10, if I may ask ? > > > As Steven pointed out earlier, it all depends on the precision you are > > dealing with. If you are just doing pure mathematical or numerical > > work with no real-world measurement error, then a condition number of > > 1e6 may be fine. But you had better be using "double precision" (64- > > bit) floating point numbers (which are the default in Python, of > > course). Those have approximately 12 digits of precision, so you are > > in good shape. Single-precision floats only have 6 or 7 digits of > > precision, so you'd be in trouble there. > > > For any practical engineering or scientific work, I'd say that a > > condition number of 1e6 is very likely to be completely unacceptable. > > So how do you explain that the natural frequencies from FEM (with > condition number ~1e6) generally correlates really good with real > measurements (within approx. 5%), at least for the first 3-4 natural > frequencies? > > I would say that the problem lies with the highest natural frequencies, > they for sure cannot be verified - there's too little energy in them. > But the lowest frequencies (the most important ones) are good, I think - > even for high cond number. Did you mention earlier what "FEM" stands for? If so, I missed it. Is it finite-element modeling? Whatever the case, note that I said, "If you are just doing pure mathematical or numerical work with no real- world measurement error, then a condition number of 1e6 may be fine." I forgot much more than I know about finite-element modeling, but isn't it a purely numerical method of analysis? If that is the case, then my comment above is relevant. By the way, I didn't mean to patronize you with my earlier explanation of orthogonal transformations. They are fundamental to understanding the SVD, and I thought it might be interesting to anyone who is not familiar with the concept. From ian.g.kelly at gmail.com Thu May 3 14:03:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 12:03:43 -0600 Subject: syntax for code blocks In-Reply-To: <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: On Thu, May 3, 2012 at 10:17 AM, Kiuhnm wrote: > On 5/3/2012 2:20, alex23 wrote: >> >> On May 2, 8:52 pm, Kiuhnm ?wrote: >>>> >>>> ? ? ?func(some_args, locals()) >>> >>> >>> I think that's very bad. It wouldn't be safe either. What about name >>> clashing >> >> >> locals() is a dict. It's not injecting anything into func's scope >> other than a dict so there's not going to be any name clashes. If you >> don't want any of its content in your function's scope, just don't use >> that content. > > > The clashing is *inside* the dictionary itself. It contains *all* local > functions and variables. Since all locals within a frame must have different names (or else they would actually be the same local), they cannot clash with one another. >> Because under no circumstance does "with function_name as >> string_signature" _read_ in an understandable way. It's tortuous >> grammar that makes no sense as a context manager. You're asking people >> to be constantly aware that there are two completely separate meanings >> to 'with x as y'. > > > The meaning is clear from the context. I would've come up with something > even better if only Python wasn't so rigid. It's really not very clear. I think the biggest difficulty is that it effectively reverses the roles of the elements in the with statement. The usual meaning of: with func(): do_stuff is that func is called to set up a context, and then the block is executed within that context. The modified meaning is that the block is gathered up as a code object and then passed as an argument into func (despite that func *appears* to be called with no arguments), which may or may not do something with it. In the former, the emphasis is on the code block; func is effectively an adverb. In the latter, func describes the main action, and the code block is the adverb. For that reason, I think that this would really need a brand new syntax in order to gain any real acceptance, not just a complicated overload of an existing statement. For that you'll need to use a preprocessor or a compiler patch (although I'm not denying that the run-time module rewriting is a neat trick). From yanegomi at gmail.com Thu May 3 14:49:29 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Thu, 3 May 2012 11:49:29 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? Message-ID: Hi Python folks! I came across a piece of code kicking around a sourcebase that does something similar to the following: >>> START >>>> #!/usr/bin/env python import sys def foo(): bar = 'abcdefg' foo = [ 'a' ] # Should throw SyntaxError? for foo[0]in bar: sys.stdout.write('%s' % foo[0]) sys.stdout.write('\n') sys.stdout.write('%s\n' % (str(foo))) # Should throw SyntaxError? if foo[0]in bar: return True return False sys.stdout.write('%r\n' % (repr(sys.version_info))) sys.stdout.write('%s\n' % (str(foo()))) >>> END >>>> I ran it against several versions of python to ensure that it wasn't a regression or fixed in a later release: $ /scratch/bin/bin/python ~/test_bad_in.py "(2, 3, 7, 'final', 0)" abcdefg ['g'] True $ python2.7 ~/test_bad_in.py "sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)" abcdefg ['g'] True $ python3.2 ~/test_bad_in.py "sys.version_info(major=3, minor=2, micro=3, releaselevel='final', serial=0)" abcdefg ['g'] True $ uname -rom FreeBSD 9.0-STABLE amd64 $ And even tried a different OS, just to make sure it wasn't a FreeBSD thing... % python test_bad_in.py "(2, 6, 5, 'final', 0)" abcdefg ['g'] True % uname -rom 2.6.32-71.el6.x86_64 x86_64 GNU/Linux I was wondering whether this was a parser bug or feature (seems like a bug, in particular because it implicitly encourages bad syntax, but I could be wrong). The grammar notes (for 2.7 at least [1]) don't seem to explicitly require a space between 'in' and another parser token (reserved work, expression, operand, etc), but I could be misreading the documentation. Thanks! -Garrett 1. http://docs.python.org/reference/grammar.html From ian.g.kelly at gmail.com Thu May 3 15:03:25 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 13:03:25 -0600 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper wrote: > ? ?I was wondering whether this was a parser bug or feature (seems > like a bug, in particular because it implicitly encourages bad syntax, > but I could be wrong). The grammar notes (for 2.7 at least [1]) don't > seem to explicitly require a space between 'in' and another parser > token (reserved work, expression, operand, etc), but I could be > misreading the documentation. The grammar doesn't require whitespace there. It tends to be flexible about whitespace wherever it's not necessary to resolve ambiguity. >>> x = [3, 2, 1] >>> x [0]if x [1]else x [2] 3 >>> 1 . real 1 >>> 1.5.real 1.5 From yanegomi at gmail.com Thu May 3 15:21:05 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Thu, 3 May 2012 12:21:05 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:03 PM, Ian Kelly wrote: > On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper wrote: >> ? ?I was wondering whether this was a parser bug or feature (seems >> like a bug, in particular because it implicitly encourages bad syntax, >> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't >> seem to explicitly require a space between 'in' and another parser >> token (reserved work, expression, operand, etc), but I could be >> misreading the documentation. > > The grammar doesn't require whitespace there. ?It tends to be flexible > about whitespace wherever it's not necessary to resolve ambiguity. > >>>> x = [3, 2, 1] >>>> x [0]if x [1]else x [2] > 3 >>>> 1 . real > 1 >>>> 1.5.real > 1.5 Sure.. it's just somewhat inconsistent with other expectations in other languages, and seems somewhat unpythonic. Not really a big deal (if it was I would have filed a bug instead), but this was definitely a bit confusing when I ran it through the interpreter a couple of times... Thanks! -Garrett From nagle at animats.com Thu May 3 15:59:00 2012 From: nagle at animats.com (John Nagle) Date: Thu, 03 May 2012 12:59:00 -0700 Subject: " An HTML page for a major site (http://www.chase.com) has some incorrect HTML. It contains Hi there, If you have USA work visa and if you reside in USA; please send the resume to Preeti at groupwaremax.com or pnbhattad at gmail.com Title Python Developer for Test Development Location: Waukesha, WI (53188) Duration: 12 months Job Description ? Proficient in Python scripting and Pyunit. ? Proficient in Python related packages knowledge. ? Experience in Unix internals and working knowledge as user. ? Expertise in Unit, Integration and System test methodologies and techniques. ? Excellent written and oral communication along with problem solving skills ? Good analytical and trouble shooting skills. ? Knowledge of C/C++ and RTOS is desired. ? Experience of designing a solution for Testing framework is desired. Regards, Preeti Bhattad | Technical Recruiter |Groupware Solution Inc Work: (732) 543 7000 x 208 |Fax: (831) 603 4007 | Email: Preeti at groupwaremax.com | Gmail: Pnbhattad at gmail.com From pnbhattad at gmail.com Thu May 3 17:23:55 2012 From: pnbhattad at gmail.com (Preeti Bhattad) Date: Thu, 3 May 2012 14:23:55 -0700 (PDT) Subject: Immediate need: Python Developer position in Waukesha, Wisconsin, USA-12 months contract with direct client with very good pay rate! Message-ID: Please send the resume to preeti at groupwaremax dot com or pnbhattad at gmail dot com Title Python Developer for Test Development Location: Waukesha, WI (53188) Duration: 12 months Job Description ? Proficient in Python scripting and Pyunit. ? Proficient in Python related packages knowledge. ? Experience in Unix internals and working knowledge as user. ? Expertise in Unit, Integration and System test methodologies and techniques. ? Excellent written and oral communication along with problem solving skills ? Good analytical and trouble shooting skills. ? Knowledge of C/C++ and RTOS is desired. ? Experience of designing a solution for Testing framework is desired. Regards, Preeti Bhattad | Technical Recruiter |Groupware Solution Inc Work: (732) 543 7000 x 208 |Fax: (831) 603 4007 | Email: Preeti at groupwaremax.com | Gmail: Pnbhattad at gmail.com From newsboost at gmail.com Thu May 3 18:21:15 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 00:21:15 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/03/2012 07:55 PM, Russ P. wrote: > On May 3, 10:30 am, someone wrote: >> On 05/02/2012 11:45 PM, Russ P. wrote: >>> For any practical engineering or scientific work, I'd say that a >>> condition number of 1e6 is very likely to be completely unacceptable. >> >> So how do you explain that the natural frequencies from FEM (with >> condition number ~1e6) generally correlates really good with real >> measurements (within approx. 5%), at least for the first 3-4 natural >> frequencies? >> >> I would say that the problem lies with the highest natural frequencies, >> they for sure cannot be verified - there's too little energy in them. >> But the lowest frequencies (the most important ones) are good, I think - >> even for high cond number. > > Did you mention earlier what "FEM" stands for? If so, I missed it. Is > it finite-element modeling? Whatever the case, note that I said, "If Sorry, yes: Finite Element Model. > you are just doing pure mathematical or numerical work with no real- > world measurement error, then a condition number of > 1e6 may be fine." I forgot much more than I know about finite-element > modeling, but isn't it a purely numerical method of analysis? If that I'm not sure exactly, what is the definition of a purely numerical method of analysis? I would guess that the answer is yes, it's a purely numerical method? But I also thing it's a practical engineering or scientific work... > is the case, then my comment above is relevant. Uh, I just don't understand the difference: 1) "For any practical engineering or scientific work, I'd say that a condition number of 1e6 is very likely to be completely unacceptable." vs. 2) "If you are just doing pure mathematical or numerical work with no real-world measurement error, then a condition number of, 1e6 may be fine." I would think that FEM is a practical engineering work and also pure numerical work... Or something... > By the way, I didn't mean to patronize you with my earlier explanation > of orthogonal transformations. They are fundamental to understanding > the SVD, and I thought it might be interesting to anyone who is not > familiar with the concept. Don't worry, I think it was really good and I don't think anyone patronized me, on the contrary, people was/is very helpful. SVD isn't my strongest side and maybe I should've thought a bit more about this singular matrix and perhaps realized what some people here already explained, a bit earlier (maybe before I asked). Anyway, it's been good to hear/read what you've (and others) have written. Yesterday and earlier today I was at work during the day so answering/replying took a bit longer than I like, considering the huge flow of posts in the matlab group. But now I'm home most of the time, for the next 3 days and will check for followup posts quite frequent, I think... From ramit.prasad at jpmorgan.com Thu May 3 18:24:05 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 3 May 2012 22:24:05 +0000 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409305758@SCACMX008.exchad.jpmchase.net> > > Sure.. it's just somewhat inconsistent with other expectations in > > other languages, and seems somewhat unpythonic. > > Never done FORTRAN, have you... Classic FORTRAN even allows > white-space INSIDE keywords. Java tends to ignore a lot of spaces as well...though not as much as classic FORTRAN it would seem. class test{ public static void main( String []args ){ System.out. println( "test" ); for (String each : args){ System.out. println( each ); } System.out. println( args [0] ); } } Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From russ.paielli at gmail.com Thu May 3 18:58:31 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 15:58:31 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: Yeah, I realized that I should rephrase my previous statement to something like this: For any *empirical* engineering or scientific work, I'd say that a condition number of 1e6 is likely to be unacceptable. I'd put finite elements into the category of theoretical and numerical rather than empirical. Still, a condition number of 1e6 would bother me, but maybe that's just me. --Russ P. On May 3, 3:21?pm, someone wrote: > On 05/03/2012 07:55 PM, Russ P. wrote: > > > > > On May 3, 10:30 am, someone ?wrote: > >> On 05/02/2012 11:45 PM, Russ P. wrote: > >>> For any practical engineering or scientific work, I'd say that a > >>> condition number of 1e6 is very likely to be completely unacceptable. > > >> So how do you explain that the natural frequencies from FEM (with > >> condition number ~1e6) generally correlates really good with real > >> measurements (within approx. 5%), at least for the first 3-4 natural > >> frequencies? > > >> I would say that the problem lies with the highest natural frequencies, > >> they for sure cannot be verified - there's too little energy in them. > >> But the lowest frequencies (the most important ones) are good, I think - > >> even for high cond number. > > > Did you mention earlier what "FEM" stands for? If so, I missed it. Is > > it finite-element modeling? Whatever the case, note that I said, "If > > Sorry, yes: Finite Element Model. > > > you are just doing pure mathematical or numerical work with no real- > > world measurement error, then a condition number of > > 1e6 may be fine." I forgot much more than I know about finite-element > > modeling, but isn't it a purely numerical method of analysis? If that > > I'm not sure exactly, what is the definition of a purely numerical > method of analysis? I would guess that the answer is yes, it's a purely > numerical method? But I also thing it's a practical engineering or > scientific work... > > > is the case, then my comment above is relevant. > > Uh, I just don't understand the difference: > > 1) "For any practical engineering or scientific work, I'd say that a > condition number of 1e6 is very likely to be completely unacceptable." > > vs. > > 2) "If you are just doing pure mathematical or numerical work with no > real-world measurement error, then a condition number of, 1e6 may be fine." > > I would think that FEM is a practical engineering work and also pure > numerical work... Or something... > > > By the way, I didn't mean to patronize you with my earlier explanation > > of orthogonal transformations. They are fundamental to understanding > > the SVD, and I thought it might be interesting to anyone who is not > > familiar with the concept. > > Don't worry, I think it was really good and I don't think anyone > patronized me, on the contrary, people was/is very helpful. SVD isn't my > strongest side and maybe I should've thought a bit more about this > singular matrix and perhaps realized what some people here already > explained, a bit earlier (maybe before I asked). Anyway, it's been good > to hear/read what you've (and others) have written. > > Yesterday and earlier today I was at work during the day so > answering/replying took a bit longer than I like, considering the huge > flow of posts in the matlab group. But now I'm home most of the time, > for the next 3 days and will check for followup posts quite frequent, I > think... From drsalists at gmail.com Thu May 3 19:00:29 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 16:00:29 -0700 Subject: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 12:21 PM, Garrett Cooper wrote: > On Thu, May 3, 2012 at 12:03 PM, Ian Kelly wrote: > > On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper > wrote: > >> I was wondering whether this was a parser bug or feature (seems > >> like a bug, in particular because it implicitly encourages bad syntax, > >> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't > >> seem to explicitly require a space between 'in' and another parser > >> token (reserved work, expression, operand, etc), but I could be > >> misreading the documentation. > > > > The grammar doesn't require whitespace there. It tends to be flexible > > about whitespace wherever it's not necessary to resolve ambiguity. > > > >>>> x = [3, 2, 1] > >>>> x [0]if x [1]else x [2] > > 3 > >>>> 1 . real > > 1 > >>>> 1.5.real > > 1.5 > > Sure.. it's just somewhat inconsistent with other expectations in > other languages, and seems somewhat unpythonic. > Not really a big deal (if it was I would have filed a bug > instead), but this was definitely a bit confusing when I ran it > through the interpreter a couple of times... > Thanks! > -Garrett > -- > http://mail.python.org/mailman/listinfo/python-list > For the code prettiness police, check out pep8 and/or pylint. I highly value pylint for projects more than a couple hundred lines. For the whitespace matter that's been beaten to death: http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html I'll include one issue about whitespace here. In FORTRAN 77, the following two statements look very similar, but have completely different meanings, because FORTRAN had too little significant whitespace: DO10I=1,10 DO10I=1.10 The first is the start of a loop, the second is an assignment statement. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu May 3 19:02:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 May 2012 17:02:02 -0600 Subject: " References: Message-ID: On Thu, May 3, 2012 at 1:59 PM, John Nagle wrote: > ?An HTML page for a major site (http://www.chase.com) has > some incorrect HTML. ?It contains > > ? ? ? ? > which is not valid HTML, XML, or SMGL. ?However, most browsers > ignore it. ?BeautifulSoup treats it as the start of a CDATA section, > and consumes the rest of the document in CDATA format. > > ?Bug? Seems like a bug to me. BeautifulSoup is supposed to parse like a browser would, so if most browsers just ignore an unterminated CDATA section, then BeautifulSoup probably should too. From newsboost at gmail.com Thu May 3 19:59:50 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 01:59:50 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/04/2012 12:58 AM, Russ P. wrote: > Yeah, I realized that I should rephrase my previous statement to > something like this: > > For any *empirical* engineering or scientific work, I'd say that a > condition number of 1e6 is likely to be unacceptable. Still, I don't understand it. Do you have an example of this kind of work, if it's not FEM? > I'd put finite elements into the category of theoretical and numerical > rather than empirical. Still, a condition number of 1e6 would bother > me, but maybe that's just me. Ok, but I just don't understand what's in the "empirical" category, sorry... Maybe the conclusion is just that if cond(A) > 1e15 or 1e16, then that problem shouldn't be solved and maybe this is also approx. where matlab has it's warning-threshold (maybe, I'm just guessing here)... So, maybe I could perhaps use that limit in my future python program (when I find out how to get the condition number etc, but I assume this can be googled for with no problems)... From pengyu.ut at gmail.com Thu May 3 20:36:38 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 3 May 2012 19:36:38 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? Message-ID: Hi, list(a_set) When convert two sets with the same elements to two lists, are the lists always going to be the same (i.e., the elements in each list are ordered the same)? Is it documented anywhere? -- Regards, Peng From drsalists at gmail.com Thu May 3 20:56:40 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 17:56:40 -0700 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: If you need the same ordering in two lists, you really should sort the lists - though your comparison function need not be that traditional. You might be able to get away with not sorting sometimes, but on CPython upgrades or using different Python interpreters (Pypy, Jython), it's almost certain the ordering will be allowed to change. But sorting in a loop is not generally a good thing - there's almost always a better alternative. On Thu, May 3, 2012 at 5:36 PM, Peng Yu wrote: > Hi, > > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? > > -- > Regards, > Peng > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu May 3 21:00:50 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 May 2012 20:00:50 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <4FA32A42.7090009@tim.thechases.com> On 05/03/12 19:36, Peng Yu wrote: > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? Sets are defined as unordered which the documentation[1] confirms. A simple test seems to show that on cPython2.6 on this box, sets with 1000000 elements converted to lists without sorting seem to compare as equal (i.e., cPython is sorting), but I don't see any guarantee that this should hold for other implementations, so I'd sort first to ensure the intended behavior. -tkc [1] http://docs.python.org/library/stdtypes.html#set-types-set-frozenset """ Being an unordered collection, sets do not record element position or order of insertion. """ From miki.tebeka at gmail.com Thu May 3 21:10:46 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 3 May 2012 18:10:46 -0700 (PDT) Subject: key/value store optimized for disk storage In-Reply-To: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> Message-ID: <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> > I'm looking for a fairly lightweight key/value store that works for > this type of problem: I'd start with a benchmark and try some of the things that are already in the standard library: - bsddb - sqlite3 (table of key, value, index key) - shelve (though I doubt this one) You might find that for a little effort you get enough out of one of these. Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. HTH, -- Miki From bahamutzero8825 at gmail.com Thu May 3 22:06:48 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 03 May 2012 21:06:48 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <4FA339B8.3070306@gmail.com> On 5/3/2012 7:36 PM, Peng Yu wrote: > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? Sets are by definition unordered, so depending on their order would not be a good idea. If the order stays the same, it's at most an implementation detail which may or may not be consistent across versions, and will likely not be consistent across implementations. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From astan.chee at rhubarbfizz.com Thu May 3 22:07:51 2012 From: astan.chee at rhubarbfizz.com (astan.chee Astan) Date: Thu, 3 May 2012 19:07:51 -0700 (PDT) Subject: most efficient way of populating a combobox (in maya) Message-ID: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> Hi, I'm making a GUI in maya using python only and I'm trying to see which is more efficient. I'm trying to populate an optionMenuGrp / combo box whose contents come from os.listdir(folder). Now this is fine if the folder isn't that full but the folder has a few hundred items (almost in the thousands), it is also on the (work) network and people are constantly reading from it as well. Now I'm trying to write the GUI so that it makes the interface, and using threading - Thread, populate the box. Is this a good idea? Has anyone done this before and have experience with any limitations on it? Is the performance not significant? Thanks for any advice From wuwei23 at gmail.com Thu May 3 22:44:57 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 19:44:57 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> On May 4, 2:17?am, Kiuhnm wrote: > On 5/3/2012 2:20, alex23 wrote: > > locals() is a dict. It's not injecting anything into func's scope > > other than a dict so there's not going to be any name clashes. If you > > don't want any of its content in your function's scope, just don't use > > that content. > > The clashing is *inside* the dictionary itself. It contains *all* local > functions and variables. This is nonsense. locals() produces a dict of the local scope. I'm passing it into a function. Nothing in the local scope clashes, so the locals() dict has no "internal clashing". Nothing is injecting it into the function's local scope, so _there is no "internal clashing"_. To revise, your original "pythonic" example was, effectively: def a(): pass def b(): pass func_packet = {'a': a, 'b': b} func(arg, func_packet) My version was: def a(): pass def b(): pass func_packet = locals() func(arg, func_packet) Now, please explain how that produces name-clashes that your version does not. > >> and how would you pass only some selected functions? > > > You wouldn't. You would just refer to the required functions in the > > dict _in the same way you would in both your "bad python" and code > > block versions. > > See above. This is more nonsense. So calling 'a' in your dict is fine, but calling a in the locals() returned dict isn't? > That's not the same thing. If a function accepts some optional > callbacks, and you call that function more than once, you will have > problems. You'll need to redefine some callbacks and remove others. > That's total lack of encapsulation. Hand-wavy, no real example, doesn't make sense. > > You haven't presented *any* good code or use cases. > > Says who? You and some others? Not enough. So far, pretty much everyone who has tried to engage you on this subject on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the commenters on your project page. > The meaning is clear from the context. Which is why pretty much every post in this thread mentioned finding it confusing? > I would've come up with something even better if only Python wasn't so rigid. The inability for people to add 6 billion mini-DSLs to solve any stupid problem _is a good thing_. It makes Python consistent and predictable, and means I don't need to parse _the same syntax_ utterly different ways depending on the context. > Because that would reveal part of the implementation. > Suppose you have a complex visitor. The OOP way is to subclass, while > the FP way is to accept callbacks. Why the FP way? Because it's more > concise. > In any case, you don't want to reveal how the visitor walks the data > structure or, better, the user doesn't need to know about it. Again, nothing concrete, just vague intimations of your way being better. > > So define& ?use a different scope! Thankfully module level isn't the > > only one to play with. > > We can do OOP even in ASM, you know? ??? > > I'm sorry but it is still clear-as-mud what you're trying to show > > here. Can you show _one_ practical, real-world, non-toy example that > > solves a real problem in a way that Python cannot? > > I just did. It's just that you can't see it. "I don't understand this example, can you provide one." "I just did, you didn't understand it." Okay, done with this now. Your tautologies and arrogance are not clarifying your position at all, and I really don't give a damn, so *plonk* From showell30 at yahoo.com Thu May 3 23:12:02 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 20:12:02 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> Message-ID: <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> On May 3, 1:42?am, Steve Howell wrote: > On May 2, 11:48?pm, Paul Rubin wrote: > > > Paul Rubin writes: > > >looking at the spec more closely, there are 256 hash tables.. ... > > > You know, there is a much simpler way to do this, if you can afford to > > use a few hundred MB of memory and you don't mind some load time when > > the program first starts. ?Just dump all the data sequentially into a > > file. ?Then scan through the file, building up a Python dictionary > > mapping data keys to byte offsets in the file (this is a few hundred MB > > if you have 3M keys). ?Then dump the dictionary as a Python pickle and > > read it back in when you start the program. > > > You may want to turn off the cyclic garbage collector when building or > > loading the dictionary, as it badly can slow down the construction of > > big lists and maybe dicts (I'm not sure of the latter). > > I'm starting to lean toward the file-offset/seek approach. ?I am > writing some benchmarks on it, comparing it to a more file-system > based approach like I mentioned in my original post. ?I'll report back > when I get results, but it's already way past my bedtime for tonight. > > Thanks for all your help and suggestions. I ended up going with the approach that Paul suggested (except I used JSON instead of pickle for persisting the hash). I like it for its simplicity and ease of troubleshooting. My test was to write roughly 4GB of data, with 2 million keys of 2k bytes each. The nicest thing was how quickly I was able to write the file. Writing tons of small files bogs down the file system, whereas the one- big-file approach finishes in under three minutes. Here's the code I used for testing: https://github.com/showell/KeyValue/blob/master/test_key_value.py Here are the results: ~/WORKSPACE/KeyValue > ls -l values.txt hash.txt -rw-r--r-- 1 steve staff 44334161 May 3 18:53 hash.txt -rw-r--r-- 1 steve staff 4006000000 May 3 18:53 values.txt 2000000 out of 2000000 records yielded (2k each) Begin READING test num trials 100000 time spent 39.8048191071 avg delay 0.000398048191071 real 2m46.887s user 1m35.232s sys 0m19.723s From steve+comp.lang.python at pearwood.info Thu May 3 23:19:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:19:32 GMT Subject: most efficient way of populating a combobox (in maya) References: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> Message-ID: <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:07:51 -0700, astan.chee Astan wrote: > Hi, > I'm making a GUI in maya using python only and I'm trying to see which > is more efficient. I'm trying to populate an optionMenuGrp / combo box > whose contents come from os.listdir(folder). Now this is fine if the > folder isn't that full but the folder has a few hundred items (almost in > the thousands), it is also on the (work) network and people are > constantly reading from it as well. Now I'm trying to write the GUI so > that it makes the interface, and using threading - Thread, populate the > box. Is this a good idea? Has anyone done this before and have > experience with any limitations on it? Is the performance not > significant? > Thanks for any advice Why don't you try it and see? It's not like populating a combobox in Tkinter with the contents of os.listdir requires a large amount of effort. Just try it and see whether it performs well enough. -- Steven From Joshua.R.English at gmail.com Thu May 3 23:39:47 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Thu, 3 May 2012 20:39:47 -0700 (PDT) Subject: PyTextile Question Message-ID: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> I am working with an XML database and have large chunks of text in certain child and grandchildren nodes. Because I consider well-formed XML to wrap at 70 characters and indent children, I end up with a lot of extra white space in the node.text string. (I parse with ElementTree.) I thought about using pytextile to convert this text to HTML for a nicer display option, using a wx.HTMLWindow (I don't need much in the way of fancy HTML for this application.) However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved. Example (may be munged, formatting-wise):

   This is a long multi-line description
        with several paragraphs and hopefully, eventually,
        proper HTML P-tags.

        This is a new paragraph. It should be surrounded
        by its own P-tag.

        Hopefully (again), I won't have a bunch of unwanted
        BR tags thrown in.
    

I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks. Any suggestions? Is there a good tutorial for PyTextile that I haven't found? Thanks. Josh From steve+comp.lang.python at pearwood.info Thu May 3 23:47:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:47:36 GMT Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:44:57 -0700, alex23 wrote: [snip] > My version was: > > def a(): pass > def b(): pass > > func_packet = locals() > func(arg, func_packet) > > Now, please explain how that produces name-clashes that your version > does not. I too am uncomfortable about passing locals() to a function, but not because of imaginary "name clashes". The problem as I see it is that this will give the function access to things the function has no need for. While CPython doesn't allow the called function to rebind names in the local scope (except in the case where the local scope is also the global scope), that may not apply to all Python implementations. So code which works safely in CPython may break badly in some other implementation. Another problem is that even in implementations where you can't rebind locals, the called function might mutate them instead. If any of the content of locals() are mutable, you're giving the function the potential to mutate them, whether it needs that power or not. Let me put it this way... suppose you had a function with a signature like this: def spam(a, b, c, **kwargs): ... and you knew that spam() ignores keyword arguments that it doesn't need. Or at least is supposed to. Suppose you needed to make this call: spam(23, 42, ham=None, cheese="something") Would you do this instead? foo = ['some', 'list', 'of', 'things'] spam(23, 42, ham=None, cheese="something", aardvark=foo) on the basis that since aardvark will be ignored, it is perfectly safe to do so? No, of course not, that would be stupid. Perhaps spam() has a bug that will mutate the list even though it shouldn't touch it. More importantly, you cause difficulty to the reader, who wonders why you are passing this unused and unnecessary aardvark argument to the function. My argument is that this is equivalent to passing locals() as argument. Your local scope contains some arbitrary number of name bindings. Only some of them are actually used. Why pass all (say) 25 of them if the function only needs access to (say) three? To me, passing locals() as an argument in this fashion is a code-smell: not necessary wrong or bad, but a hint that something unusual and slightly worrying is going on, and you should take a close look at it because there *may* be a problem. > So far, pretty much everyone who has tried to engage you on this subject > on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the > commenters on your project page. Goddamit, did I miss a post somewhere? What the hell is this project people keep talking about? -- Steven From steve+comp.lang.python at pearwood.info Thu May 3 23:52:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 May 2012 03:52:55 GMT Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 May 2012 19:30:35 +0200, someone wrote: > On 05/02/2012 11:45 PM, Russ P. wrote: >> On May 2, 1:29 pm, someone wrote: >> >>>> If your data starts off with only 1 or 2 digits of accuracy, as in >>>> your example, then the result is meaningless -- the accuracy will be >>>> 2-2 digits, or 0 -- *no* digits in the answer can be trusted to be >>>> accurate. >>> >>> I just solved a FEM eigenvalue problem where the condition number of >>> the mass and stiffness matrices was something like 1e6... Result >>> looked good to me... So I don't understand what you're saying about 10 >>> = 1 or 2 digits. I think my problem was accurate enough, though I >>> don't know what error with 1e6 in condition number, I should expect. >>> How did you arrive at 1 or 2 digits for cond(A)=10, if I may ask ? >> >> As Steven pointed out earlier, it all depends on the precision you are >> dealing with. If you are just doing pure mathematical or numerical work >> with no real-world measurement error, then a condition number of 1e6 >> may be fine. But you had better be using "double precision" (64- bit) >> floating point numbers (which are the default in Python, of course). >> Those have approximately 12 digits of precision, so you are in good >> shape. Single-precision floats only have 6 or 7 digits of precision, so >> you'd be in trouble there. >> >> For any practical engineering or scientific work, I'd say that a >> condition number of 1e6 is very likely to be completely unacceptable. > > So how do you explain that the natural frequencies from FEM (with > condition number ~1e6) generally correlates really good with real > measurements (within approx. 5%), at least for the first 3-4 natural > frequencies? I would counter your hand-waving ("correlates really good", "within approx 5%" of *what*?) with hand-waving of my own: "Sure, that's exactly what I would expect!" *wink* By the way, if I didn't say so earlier, I'll say so now: the interpretation of "how bad the condition number is" will depend on the underlying physics and/or mathematics of the situation. The interpretation of loss of digits of precision is a general rule of thumb that holds in many diverse situations, not a rule of physics that cannot be broken in this universe. If you have found a scenario where another interpretation of condition number applies, good for you. That doesn't change the fact that, under normal circumstances when trying to solve systems of linear equations, a condition number of 1e6 is likely to blow away *all* the accuracy in your measured data. (Very few physical measurements are accurate to more than six digits.) -- Steven From rosuav at gmail.com Fri May 4 00:05:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 14:05:53 +1000 Subject: syntax for code blocks In-Reply-To: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: On Fri, May 4, 2012 at 12:44 PM, alex23 wrote: > On May 4, 2:17?am, Kiuhnm wrote: >> I would've come up with something even better if only Python wasn't so rigid. > > The inability for people to add 6 billion mini-DSLs to solve any > stupid problem _is a good thing_. It makes Python consistent and > predictable, and means I don't need to parse _the same syntax_ utterly > different ways depending on the context. Agreed. If a language can be everything, it is nothing. Python has value BECAUSE it is rigid. A while ago I played around with the idea of a language that let you define your own operators... did up a spec for how it could work. It is NOT an improvement over modern languages. http://rosuav.com/1/?id=683 ChrisA From russ.paielli at gmail.com Fri May 4 00:15:20 2012 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 3 May 2012 21:15:20 -0700 (PDT) Subject: numpy (matrix solver) - python vs. matlab References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On May 3, 4:59?pm, someone wrote: > On 05/04/2012 12:58 AM, Russ P. wrote: > > > Yeah, I realized that I should rephrase my previous statement to > > something like this: > > > For any *empirical* engineering or scientific work, I'd say that a > > condition number of 1e6 is likely to be unacceptable. > > Still, I don't understand it. Do you have an example of this kind of > work, if it's not FEM? > > > I'd put finite elements into the category of theoretical and numerical > > rather than empirical. Still, a condition number of 1e6 would bother > > me, but maybe that's just me. > > Ok, but I just don't understand what's in the "empirical" category, sorry... I didn't look it up, but as far as I know, empirical just means based on experiment, which means based on measured data. Unless I am mistaken , a finite element analysis is not based on measured data. Yes, the results can be *compared* with measured data and perhaps calibrated with measured data, but those are not the same thing. I agree with Steven D's comment above, and I will reiterate that a condition number of 1e6 would not inspire confidence in me. If I had a condition number like that, I would look for a better model. But that's just a gut reaction, not a hard scientific rule. From tjreedy at udel.edu Fri May 4 00:16:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 00:16:07 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On 5/3/2012 8:36 PM, Peng Yu wrote: > Hi, > > list(a_set) > > When convert two sets with the same elements to two lists, are the > lists always going to be the same (i.e., the elements in each list are > ordered the same)? Is it documented anywhere? "A set object is an unordered collection of distinct hashable objects". If you create a set from unequal objects with equal hashes, the iteration order may (should, will) depend on the insertion order as the first object added with a colliding hash will be at its 'natural position in the hash table while succeeding objects will be elsewhere. Python 3.3.0a3 (default, May 1 2012, 16:46:00) >>> hash('a') -292766495615408879 >>> hash(-292766495615408879) -292766495615408879 >>> a = {'a', -292766495615408879} >>> b = {-292766495615408879, 'a'} >>> list(a) [-292766495615408879, 'a'] >>> list(b) ['a', -292766495615408879] -- Terry Jan Reedy From wuwei23 at gmail.com Fri May 4 00:26:29 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 21:26:29 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 4, 1:47?pm, Steven D'Aprano wrote: > I too am uncomfortable about passing locals() to a function, but not > because of imaginary "name clashes". The problem as I see it is that this > will give the function access to things the function has no need for. And I would never use it in the real world. If anything, I'd rebind via the function parameters: def f(arg,fn1=None,fn2=None): pass f('arg', **locals()) This way, only the aspects of the local scope that the function explicitly asks for are provided. But: I would _only_ do this in a context I controlled. However, that would be the _same_ context in which the code blocks example would also be used. I think. I'm still waiting to see an example that is clear. I've never _ever_ found myself thinking "this code would be a LOT clearer if I didn't have to give it a name..." > Another problem is that even in implementations where you can't rebind > locals, the called function might mutate them instead. If any of the > content of locals() are mutable, you're giving the function the potential > to mutate them, whether it needs that power or not. This is true. But that would be the case with a provided dict too. I wasn't suggesting someone blindly throw locals into every function and hope for the best. I was merely stating that if you know that your function is only going to use certain values, it doesn't matter how many values you pass it, if it chooses to ignore them. > My argument is that this is equivalent to passing locals() as argument. > Your local scope contains some arbitrary number of name bindings. Only > some of them are actually used. Why pass all (say) 25 of them if the > function only needs access to (say) three? Flip it: I've set up a local scope that _only_ contains the functions I need. Why manually create a dict, repeating the name of each function as a key, when I can just use locals()? > To me, passing locals() as an > argument in this fashion is a code-smell: not necessary wrong or bad, but > a hint that something unusual and slightly worrying is going on, and you > should take a close look at it because there *may* be a problem. Or, conversely, I _know_ what I'm doing in the context of my own code and it's the most elegant way to write it. Frankly, I don't really care; I'm sick of this whole thread. We're all taking bullshit abstractions & toy examples and none of it is indicative of how anyone would really write code. > > So far, pretty much everyone who has tried to engage you on this subject > > on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 like the > > commenters on your project page. > > Goddamit, did I miss a post somewhere? What the hell is this project > people keep talking about? https://bitbucket.org/mtomassoli/codeblocks/ The examples here are a wonder to behold as well: http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ From no.email at nospam.invalid Fri May 4 00:38:03 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 21:38:03 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> Message-ID: <7xhavw4l3o.fsf@ruckus.brouhaha.com> Steve Howell writes: > My test was to write roughly 4GB of data, with 2 million keys of 2k > bytes each. If the records are something like english text, you can compress them with zlib and get some compression gain by pre-initializing a zlib dictionary from a fixed english corpus, then cloning it. That is, if your messages are a couple paragraphs, you might say something like: iv = (some fixed 20k or so of records concatenated together) compressor = zlib(iv).clone() # I forget what this # operation is actually called # I forget what this is called too, but the idea is you throw # away the output of compressing the fixed text, and sync # to a byte boundary compressor.sync() zout = compressor.compress(your_record).sync() ... i.e. the part you save in the file is just the difference between compress(corpus) and compress(corpus_record). To decompress, you initialize a compressor the same way, etc. It's been a while since I used that trick but for json records of a few hundred bytes, I remember getting around 2:1 compression, while starting with an unprepared compressor gave almost no compression. From research at johnohagan.com Fri May 4 00:52:14 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 4 May 2012 14:52:14 +1000 Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> On Thu, 3 May 2012 04:52:36 -0700 (PDT) alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? > -- Just read the thread on pyjamas-dev. Even without knowing anything about the lead-up to the coup, its leader's linguistic contortions trying to justify it ("i have retired Luke of the management duties"), and his eagerness to change the subject ("let's move into more productive areas of discussion", and "this is the path forward; make good of the newfound power") are indicative of a guilty conscience or an underdeveloped sense of ethics. He's convinced himself that his actions were technically legal; get this: "i would recommend you terminate thought paths regarding criminal activity", and "please don't make me further intervene or forcibly terminate additional threats or remarks. there is no case to be had"! But I am having trouble imagining a scenario where sneakily acquiring the domain name and copying all the source and mailinglist data to your own server would be preferable to just forking, which is what everyone knows you're supposed to do in cases where the boss is too FOSS for your taste, or whatever the problem was. Seems like a great deal of hurt has occurred, both to people and to the project, just to save the administrative hassle of forking. In the words of the hijacker, he was going to fork but "an opportunity presented itself, and i ran with it". Nice. -- John From showell30 at yahoo.com Fri May 4 01:09:04 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 22:09:04 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> Message-ID: <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> On May 3, 9:38?pm, Paul Rubin wrote: > Steve Howell writes: > > My test was to write roughly 4GB of data, with 2 million keys of 2k > > bytes each. > > If the records are something like english text, you can compress > them with zlib and get some compression gain by pre-initializing > a zlib dictionary from a fixed english corpus, then cloning it. > That is, if your messages are a couple paragraphs, you might > say something like: > > ? iv = (some fixed 20k or so of records concatenated together) > ? compressor = zlib(iv).clone() ?# I forget what this > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# operation is actually called > > ? # I forget what this is called too, but the idea is you throw > ? # away the output of compressing the fixed text, and sync > ? # to a byte boundary > ? compressor.sync() > > ? zout = compressor.compress(your_record).sync() > ? ... > > i.e. the part you save in the file is just the difference > between compress(corpus) and compress(corpus_record). ?To > decompress, you initialize a compressor the same way, etc. > > It's been a while since I used that trick but for json records of a few > hundred bytes, I remember getting around 2:1 compression, while starting > with an unprepared compressor gave almost no compression. Sounds like a useful technique. The text snippets that I'm compressing are indeed mostly English words, and 7-bit ascii, so it would be practical to use a compression library that just uses the same good-enough encodings every time, so that you don't have to write the encoding dictionary as part of every small payload. Sort of as you suggest, you could build a Huffman encoding for a representative run of data, save that tree off somewhere, and then use it for all your future encoding/decoding. Is there a name to describe this technique? From no.email at nospam.invalid Fri May 4 02:03:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 23:03:02 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> Message-ID: <7xhavwiiuh.fsf@ruckus.brouhaha.com> Steve Howell writes: > Sounds like a useful technique. The text snippets that I'm > compressing are indeed mostly English words, and 7-bit ascii, so it > would be practical to use a compression library that just uses the > same good-enough encodings every time, so that you don't have to write > the encoding dictionary as part of every small payload. Zlib stays adaptive, the idea is just to start with some ready-made compression state that reflects the statistics of your data. > Sort of as you suggest, you could build a Huffman encoding for a > representative run of data, save that tree off somewhere, and then use > it for all your future encoding/decoding. Zlib is better than Huffman in my experience, and Python's zlib module already has the right entry points. Looking at the docs, Compress.flush(Z_SYNC_FLUSH) is the important one. I did something like this before and it was around 20 lines of code. I don't have it around any more but maybe I can write something else like it sometime. > Is there a name to describe this technique? Incremental compression maybe? From ben+python at benfinney.id.au Fri May 4 02:04:57 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 04 May 2012 16:04:57 +1000 Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wr4s7a7q.fsf@benfinney.id.au> alex23 writes: > The examples here are a wonder to behold as well: > http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ Wow. ?What really happens is that rewrite rewrites the code, executes it and quits.? Please keep this far away from anything resembling Python. -- \ ?If you go flying back through time and you see somebody else | `\ flying forward into the future, it's probably best to avoid eye | _o__) contact.? ?Jack Handey | Ben Finney From showell30 at yahoo.com Fri May 4 02:29:28 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 3 May 2012 23:29:28 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> Message-ID: <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> On May 3, 11:03?pm, Paul Rubin wrote: > Steve Howell writes: > > Sounds like a useful technique. ?The text snippets that I'm > > compressing are indeed mostly English words, and 7-bit ascii, so it > > would be practical to use a compression library that just uses the > > same good-enough encodings every time, so that you don't have to write > > the encoding dictionary as part of every small payload. > > Zlib stays adaptive, the idea is just to start with some ready-made > compression state that reflects the statistics of your data. > > > Sort of as you suggest, you could build a Huffman encoding for a > > representative run of data, save that tree off somewhere, and then use > > it for all your future encoding/decoding. > > Zlib is better than Huffman in my experience, and Python's zlib module > already has the right entry points. ?Looking at the docs, > Compress.flush(Z_SYNC_FLUSH) is the important one. ?I did something like > this before and it was around 20 lines of code. ?I don't have it around > any more but maybe I can write something else like it sometime. > > > Is there a name to describe this technique? > > Incremental compression maybe? Many thanks, this is getting me on the right path: compressor = zlib.compressobj() s = compressor.compress("foobar") s += compressor.flush(zlib.Z_SYNC_FLUSH) s_start = s compressor2 = compressor.copy() s += compressor.compress("baz") s += compressor.flush(zlib.Z_FINISH) print zlib.decompress(s) s = s_start s += compressor2.compress("spam") s += compressor2.flush(zlib.Z_FINISH) print zlib.decompress(s) From wuwei23 at gmail.com Fri May 4 02:30:51 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 3 May 2012 23:30:51 -0700 (PDT) Subject: syntax for code blocks References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa35157$0$29965$c3e8da3$5496439d@news.astraweb.com> <87wr4s7a7q.fsf@benfinney.id.au> Message-ID: On May 4, 4:04?pm, Ben Finney wrote: > Wow. ?What really happens is that rewrite rewrites the code, executes it > and quits.? But that's the best bit! It's the one aspect of the module for which a context manager would actually be applicable and there's not even a suggestion of it :) From neruyume at hotmail.com Fri May 4 02:39:36 2012 From: neruyume at hotmail.com (Neru Yumekui) Date: Fri, 4 May 2012 06:39:36 +0000 Subject: [image-SIG] img.show() does not seem to work. Message-ID: I am trying to get Image.show() to work, but seem to struggle with it. Thus far I have been using PIL on Windows, and it has worked fine and all - But I recently installed it on a Linux-machine, where img.show does not seem to work (All other features apart from screengrab seems to work well). When I run the following as a normal user (id est, not root) Image.new("RGBA", (100, 100), (255, 255, 255, 0)).show() it results in these error messages in popupboxes: Failed to open "/tmp/tmpsVfqf4". Error stating file '/tmp/tmpsVfqf4': No such file or directory. Failed to execute default File Manager. Input/output error. The interpreter has the following printout Thunar: Failed to open "/tmp/tmpFs5EZr": Error stating file '/tmp/tmpFs5EZr': No such file or directory Running the same as root, nothing (visible) seems to happen, either via popups or in the interpreter, but no image shows up either. At first I did not have xv installed (it tried to open the image in gimp, but that did not work as it resulted in the errors above when gimp opened) - So I installed xv, and it still tried to open gimp - So I removed gimp, and that is more or less how I ended up where I am now. I guess show() is not that important to me as I could just save the image and open it manually, but it would be helpful to have show() at times. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shahviral.it at gmail.com Fri May 4 02:47:57 2012 From: shahviral.it at gmail.com (viral shah) Date: Fri, 4 May 2012 12:17:57 +0530 Subject: python sandbox question Message-ID: Hi Can anyone answer these two questions : I have two questions regarding Pysandbox: 1.) How do I achieve the functionality of eval? I understand sandbox.execute() is equivalent to exec, but I can't find anything such that if the code entered were 2 + 2, then it would return 4, or something to that effect. 2.) By default, sandbox.execute() makes a passed-in environment read-only -- i.e. if I do sandbox.execute('data.append(4)', locals={'data': [1, 2, 3]}), an error will occur. How do I make passed-in environments read-write? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri May 4 02:57:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 04 May 2012 08:57:06 +0200 Subject: " References: Message-ID: Ian Kelly, 04.05.2012 01:02: > BeautifulSoup is supposed to parse like a browser would Not at all, that would be html5lib. Stefan From drsalists at gmail.com Fri May 4 02:58:09 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 3 May 2012 23:58:09 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <7xhavwiiuh.fsf@ruckus.brouhaha.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> Message-ID: On Thu, May 3, 2012 at 11:03 PM, Paul Rubin wrote: > > Sort of as you suggest, you could build a Huffman encoding for a > > representative run of data, save that tree off somewhere, and then use > > it for all your future encoding/decoding. > > Zlib is better than Huffman in my experience, and Python's zlib module > already has the right entry points. > > Isn't zlib kind of dated? Granted, it's newer than Huffman, but there's been bzip2 and xz since then, among numerous others. Here's something for xz: http://stromberg.dnsalias.org/svn/xz_mod/trunk/ An xz module is in the CPython 3.3 alphas - the above module wraps it if available, otherwise it uses ctypes or a pipe to an xz binary.. And I believe bzip2 is in the standard library for most versions of CPython. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Fri May 4 02:59:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 May 2012 23:59:59 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> Message-ID: <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Steve Howell writes: > compressor = zlib.compressobj() > s = compressor.compress("foobar") > s += compressor.flush(zlib.Z_SYNC_FLUSH) > > s_start = s > compressor2 = compressor.copy() I think you also want to make a decompressor here, and initialize it with s and then clone it. Then you don't have to reinitialize every time you want to decompress something. I also seem to remember that the first few bytes of compressed output are always some fixed string or checksum, that you can strip out after compression and put back before decompression, giving further savings in output size when you have millions of records. From showell30 at yahoo.com Fri May 4 03:14:06 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 00:14:06 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: On May 3, 11:59?pm, Paul Rubin wrote: > Steve Howell writes: > > ? ? compressor = zlib.compressobj() > > ? ? s = compressor.compress("foobar") > > ? ? s += compressor.flush(zlib.Z_SYNC_FLUSH) > > > ? ? s_start = s > > ? ? compressor2 = compressor.copy() > > I think you also want to make a decompressor here, and initialize it > with s and then clone it. ?Then you don't have to reinitialize every > time you want to decompress something. Makes sense. I believe I got that part correct: https://github.com/showell/KeyValue/blob/master/salted_compressor.py > I also seem to remember that the first few bytes of compressed output > are always some fixed string or checksum, that you can strip out after > compression and put back before decompression, giving further savings in > output size when you have millions of records. I'm pretty sure this happens for free as long as the salt is large enough, but maybe I'm misunderstanding. From no.email at nospam.invalid Fri May 4 04:01:29 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 May 2012 01:01:29 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <7xzk9oidd2.fsf@ruckus.brouhaha.com> Steve Howell writes: > Makes sense. I believe I got that part correct: > > https://github.com/showell/KeyValue/blob/master/salted_compressor.py The API looks nice, but your compress method makes no sense. Why do you include s.prefix in s and then strip it off? Why do you save the prefix and salt in the instance, and have self.salt2 and s[len(self.salt):] in the decompress? You should be able to just get the incremental bit. > I'm pretty sure this happens for free as long as the salt is large > enough, but maybe I'm misunderstanding. No I mean there is some fixed overhead (a few bytes) in the compressor output, to identify it as such. That's fine when the input and output are both large, but when there's a huge number of small compressed strings, it adds up. From showell30 at yahoo.com Fri May 4 04:09:50 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 01:09:50 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> <7xzk9oidd2.fsf@ruckus.brouhaha.com> Message-ID: <0b07d733-1920-4b58-bc3a-1a0881cb02b9@kw17g2000pbb.googlegroups.com> On May 4, 1:01?am, Paul Rubin wrote: > Steve Howell writes: > > Makes sense. ?I believe I got that part correct: > > > ?https://github.com/showell/KeyValue/blob/master/salted_compressor.py > > The API looks nice, but your compress method makes no sense. ?Why do you > include s.prefix in s and then strip it off? ?Why do you save the prefix > and salt in the instance, and have self.salt2 and s[len(self.salt):] > in the decompress? ?You should be able to just get the incremental bit. This is fixed now. https://github.com/showell/KeyValue/commit/1eb316d6e9e44a37ab4f3ca73fcaf4ec0e7f22b4#salted_compressor.py > > I'm pretty sure this happens for free as long as the salt is large > > enough, but maybe I'm misunderstanding. > > No I mean there is some fixed overhead (a few bytes) in the compressor > output, to identify it as such. ?That's fine when the input and output > are both large, but when there's a huge number of small compressed > strings, it adds up. It it's in the header, wouldn't it be part of the output that comes before Z_SYNC_FLUSH? From hansmu at xs4all.nl Fri May 4 04:11:53 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 04 May 2012 10:11:53 +0200 Subject: Create directories and modify files with Python In-Reply-To: References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: <4fa38f4a$0$6924$e4fe514c@news2.news.xs4all.nl> On 1/05/12 17:34:57, rurpy at yahoo.com wrote: > from __future__ import print_function #1 > > ------------------------------------------------------------ > > #1: Not sure whether you're using Python 2 or 3. I ran > this on Python 2.7 and think it will run on Python 3 if > you remove this line. You don't have to remove that line: Python3 will accept it. It doesn't do anything in python3, since 'print' is a function whether or not you include that line, but for backward compatibility, you're still allowed to say it. Incidentally, the same is true for all __future__ features. For example, Python3 still accepts: from __future__ import nested_scopes , even though it's only really needed if you're using python 2.1, since from 2.2 onwards scopes have nested with or without that command. HTH, -- HansM From tjreedy at udel.edu Fri May 4 04:16:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 04:16:35 -0400 Subject: pyjamas / pyjs In-Reply-To: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> References: <20120504145214.2c4601e9a283c529caa90eec@johnohagan.com> Message-ID: On 5/4/2012 12:52 AM, John O'Hagan wrote: > Just read the thread on pyjamas-dev. Even without knowing anything about the > lead-up to the coup, its leader's linguistic contortions trying to justify it And what is the name of the miscreant, so we know who to have nothing to with? -- Terry Jan Reedy From no.email at nospam.invalid Fri May 4 04:58:25 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 May 2012 01:58:25 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> <7xzk9oidd2.fsf@ruckus.brouhaha.com> <0b07d733-1920-4b58-bc3a-1a0881cb02b9@kw17g2000pbb.googlegroups.com> Message-ID: <7xpqak5nm6.fsf@ruckus.brouhaha.com> Steve Howell writes: >> You should be able to just get the incremental bit. > This is fixed now. Nice. > It it's in the header, wouldn't it be part of the output that comes > before Z_SYNC_FLUSH? Hmm, maybe you are right. My version was several years ago and I don't remember it well, but I half-remember spending some time diddling around with this issue. From jameskhedley at gmail.com Fri May 4 05:56:24 2012 From: jameskhedley at gmail.com (james hedley) Date: Fri, 4 May 2012 02:56:24 -0700 (PDT) Subject: pyjamas / pyjs In-Reply-To: References: Message-ID: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> On Thursday, 3 May 2012 12:52:36 UTC+1, alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? Yes, me. The guy now in control got the owner of the domain name to turn it over to him, which is probably ok legally, but he had no public mandate or support. As far as I can see from the mailing list, only 3 or 4 out of the 650 subscribers actively support his actions. He's a long time contributor and genuinely seems quite talented. However there's no getting away from the fact that he's done this undemocratically, when he could have forked the project. To my mind he hasn't made a good enough reasoned justification of his arguments and he's coming across as being very defensive at the moment. The former leader, Luke Leighton, seemed to have vanished from the face of the earth but I mailed him yesterday and he's on holiday so trying not to pay too much attention to it at the moment. There's also an allegation, which I am not making myself at this point - only describing its nature, that a person may have lifted data from the original mail server without authorisation and used it to recreate the mailing list on a different machine. *If* that were to be true, then the law has been broken in at least one country. I'm arguing that there should be a public consultation over who gets to run this project and I'm also thinking of making a suggestion to the python software foundation or maybe other bodies such as the FSF (I'm not a FOSS expert but they were suggested by others) that they host a fork of this project so that we can have a legitimate and stable route forward. The problem for me with all this is that I use pyjamas in a commercial capacity and (sorry if this sounds vague but I have to be a bit careful) there are probably going to be issues with our clients - corporate people distrust FOSS at the best of times and this kind of thing will make them run for the bloody hills. In fact, there appear to be a lot of "sleeper" users who make a living out of this stuff and the actions of the new de-facto leader has jeopardised this, pretty needlessly in our opinion. James From jameskhedley at gmail.com Fri May 4 06:02:11 2012 From: jameskhedley at gmail.com (james hedley) Date: Fri, 4 May 2012 03:02:11 -0700 (PDT) Subject: pyjamas / pyjs In-Reply-To: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: <32250799.682.1336125731492.JavaMail.geo-discussion-forums@vbbfr18> By the way, there's a lot more to say on this, which I'll cover another time. There are arguments for and against what's happened; at this stage I'm just trying to flag up that there is *not* unanimity and we are not just carrying on as normal. From pengyu.ut at gmail.com Fri May 4 06:14:06 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 05:14:06 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Thu, May 3, 2012 at 11:16 PM, Terry Reedy wrote: > On 5/3/2012 8:36 PM, Peng Yu wrote: >> >> Hi, >> >> list(a_set) >> >> When convert two sets with the same elements to two lists, are the >> lists always going to be the same (i.e., the elements in each list are >> ordered the same)? Is it documented anywhere? > > > "A set object is an unordered collection of distinct hashable objects". > If you create a set from unequal objects with equal hashes, the iteration > order may (should, will) depend on the insertion order as the first object > added with a colliding hash will be at its 'natural position in the hash > table while succeeding objects will be elsewhere. > > Python 3.3.0a3 (default, May ?1 2012, 16:46:00) >>>> hash('a') > -292766495615408879 >>>> hash(-292766495615408879) > -292766495615408879 >>>> a = {'a', -292766495615408879} >>>> b = {-292766495615408879, 'a'} >>>> list(a) > [-292766495615408879, 'a'] >>>> list(b) > ['a', -292766495615408879] Thanks. This is what I'm looking for. I think that this should be added to the python document as a manifestation (but nonnormalized) of what "A set object is an unordered collection of distinct hashable objects" means. -- Regards, Peng From kiuhnm03.4t.yahoo.it Fri May 4 07:12:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 04 May 2012 13:12:59 +0200 Subject: syntax for code blocks In-Reply-To: <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> Message-ID: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> On 5/4/2012 4:44, alex23 wrote: > On May 4, 2:17 am, Kiuhnm wrote: >> On 5/3/2012 2:20, alex23 wrote: >>> locals() is a dict. It's not injecting anything into func's scope >>> other than a dict so there's not going to be any name clashes. If you >>> don't want any of its content in your function's scope, just don't use >>> that content. >> >> The clashing is *inside* the dictionary itself. It contains *all* local >> functions and variables. > > This is nonsense. > > locals() produces a dict of the local scope. I'm passing it into a > function. Nothing in the local scope clashes, so the locals() dict has > no "internal clashing". Nothing is injecting it into the function's > local scope, so _there is no "internal clashing"_. > > To revise, your original "pythonic" example was, effectively: > > def a(): pass > def b(): pass > > func_packet = {'a': a, 'b': b} > func(arg, func_packet) > > My version was: > > def a(): pass > def b(): pass > > func_packet = locals() > func(arg, func_packet) > > Now, please explain how that produces name-clashes that your version > does not. It doesn't always produce name-clashes but it may do so. Suppose that func takes some functions named fn1, fn2 and fn3. If you only define fn2 but you forget that you already defined somewhere before fn1, you inadvertently pass to func both fn1 and fn2. Even worse, if you write def a(): pass def b(): pass func(arg, locals()) and then you want to call func again with c() alone, you must write this: def c(): pass a = b = None func(arg, locals()) Moreover, think what happens if you add a function whose name is equal to that of a function accepted by func. That's what I call name-clashing. My solution avoids all these problems, promote encapsulation and let you program in a more functional way which is more concise that the OOP way, sometimes. >> That's not the same thing. If a function accepts some optional >> callbacks, and you call that function more than once, you will have >> problems. You'll need to redefine some callbacks and remove others. >> That's total lack of encapsulation. > > Hand-wavy, no real example, doesn't make sense. Really? Then I don't know what would make sense to you. >>> You haven't presented *any* good code or use cases. >> >> Says who? You and some others? Not enough. > > So far, pretty much everyone who has tried to engage you on this > subject on the list. I'm sorry we're not all ZOMGRUBYBLOCKS!!!!111 > like the commenters on your project page. It's impossible to have a constructive discussion while you and others feel that way. You're so biased that you don't even see how biased you are. >> The meaning is clear from the context. > > Which is why pretty much every post in this thread mentioned finding > it confusing? > >> I would've come up with something even better if only Python wasn't so rigid. > > The inability for people to add 6 billion mini-DSLs to solve any > stupid problem _is a good thing_. It makes Python consistent and > predictable, and means I don't need to parse _the same syntax_ utterly > different ways depending on the context. If I and my group of programmers devised a good and concise syntax and semantics to describe some applicative domain, then we would want to translate that into the language we use. Unfortunately, Python doesn't let you do that. I also think that uniformity is the death of creativity. What's worse, uniformity in language is also uniformity in thinking. As I said in some other posts, I think that Python is a good language, but as soon as you need to do something a little different or just differently, it's a pain to work with. >> Because that would reveal part of the implementation. >> Suppose you have a complex visitor. The OOP way is to subclass, while >> the FP way is to accept callbacks. Why the FP way? Because it's more >> concise. >> In any case, you don't want to reveal how the visitor walks the data >> structure or, better, the user doesn't need to know about it. > > Again, nothing concrete, just vague intimations of your way being > better. Sigh. >>> So define& use a different scope! Thankfully module level isn't the >>> only one to play with. >> >> We can do OOP even in ASM, you know? > > ??? You can do whatever you want by hand: you can certainly define your functions inside another function or a class, but that's just more noise added to the mix. >>> I'm sorry but it is still clear-as-mud what you're trying to show >>> here. Can you show _one_ practical, real-world, non-toy example that >>> solves a real problem in a way that Python cannot? >> >> I just did. It's just that you can't see it. > > "I don't understand this example, can you provide one." "I just did, > you didn't understand it." Your rephrasing is quite wrong. You asked for a practical example and I said that I already showed you one. It's just that you can't see it (as practical). > Okay, done with this now. Your tautologies and arrogance are not > clarifying your position at all, and I really don't give a damn, so > *plonk* I don't care if you don't read this post. Now that I've written it I'll post it anyway. Unfortunately, communication is a two-people thing. It's been clear from the first post that your intention wasn't to understand what I'm proposing. There are some things, like what I say about name-clashing, that you should understand no matter how biased you are. If you don't, you're just pretending or maybe you weren't listening at all. Kiuhnm From rosuav at gmail.com Fri May 4 07:21:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 21:21:30 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: > Thanks. This is what I'm looking for. I think that this should be > added to the python document as a manifestation (but nonnormalized) of > what "A set object is an unordered collection of distinct hashable > objects" means. There are other things that can prove it to be unordered, too; the exact pattern and order of additions and deletions can affect the iteration order. The only thing you can be sure of is that you can't be sure of it. ChrisA From rosuav at gmail.com Fri May 4 07:29:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 May 2012 21:29:29 +1000 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, May 4, 2012 at 9:12 PM, Kiuhnm wrote: > If I and my group of programmers devised a good and concise syntax and > semantics to describe some applicative domain, then we would want to > translate that into the language we use. > Unfortunately, Python doesn't let you do that. No, this is not unfortunate. Python does certain things and does them competently. If Python doesn't let you write what you want the way you want, then you do not want Python. This is not an insult to Python, nor is it a cop-out whereby the Python Cabal tells you to shut up and go away, you aren't doing things the Proper Way, you need to change your thinking to be more in line with Correct Syntax. It is simply a reflection of the nature of languages. If I want to write a massively-parallel program that can be divided across any number of computers around the world, Python isn't the best thing to use. If I want to write a MUD with efficient reloading of code on command, Python isn't the best thing to use. If I want to write a device driver, Python isn't the best thing to use. If I want to write a simple script that does exactly what it should and didn't take me long to write, then Python quite likely IS the best thing to use. But whatever you do, play to the strengths of the language you use, don't play to its weaknesses. Don't complain when C leaks the memory that you forgot to free(), don't bemoan LISP's extreme parenthesizing, don't fight the Python object model. You'll only hurt yourself. In any case, you know where to find Ruby any time you want it. ChrisA From pengyu.ut at gmail.com Fri May 4 08:00:32 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 07:00:32 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 6:21 AM, Chris Angelico wrote: > On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: >> Thanks. This is what I'm looking for. I think that this should be >> added to the python document as a manifestation (but nonnormalized) of >> what "A set object is an unordered collection of distinct hashable >> objects" means. > > There are other things that can prove it to be unordered, too; the > exact pattern and order of additions and deletions can affect the > iteration order. The only thing you can be sure of is that you can't > be sure of it. I agree. My point was just to suggest adding more explanations on the details in the manual. -- Regards, Peng From krishnandhevika at gmail.com Fri May 4 08:14:54 2012 From: krishnandhevika at gmail.com (dhevika k) Date: Fri, 4 May 2012 05:14:54 -0700 (PDT) Subject: Download hot and tempting love application this link click here Message-ID: <005409ef-55aa-4c92-82dd-6efd2bb82751@t2g2000pbl.googlegroups.com> http://123maza.com/48/share007/ From ndbecker2 at gmail.com Fri May 4 08:21:57 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 04 May 2012 08:21:57 -0400 Subject: set PYTHONPATH for a directory? Message-ID: I'm testing some software I'm building against an alternative version of a library. So I have an alternative library in directory L. Then I have in an unrelated directory, the test software, which I need to use the library version from directory L. One approach is to set PYTHONPATH whenever I run this test software. Any suggestion on a more foolproof approach? From newsboost at gmail.com Fri May 4 09:30:12 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 15:30:12 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <4fa35296$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/04/2012 05:52 AM, Steven D'Aprano wrote: > On Thu, 03 May 2012 19:30:35 +0200, someone wrote: >> So how do you explain that the natural frequencies from FEM (with >> condition number ~1e6) generally correlates really good with real >> measurements (within approx. 5%), at least for the first 3-4 natural >> frequencies? > > I would counter your hand-waving ("correlates really good", "within > approx 5%" of *what*?) with hand-waving of my own: Within 5% of experiments of course. There is not much else to compare with. > "Sure, that's exactly what I would expect!" > > *wink* > > By the way, if I didn't say so earlier, I'll say so now: the > interpretation of "how bad the condition number is" will depend on the > underlying physics and/or mathematics of the situation. The > interpretation of loss of digits of precision is a general rule of thumb > that holds in many diverse situations, not a rule of physics that cannot > be broken in this universe. > > If you have found a scenario where another interpretation of condition > number applies, good for you. That doesn't change the fact that, under > normal circumstances when trying to solve systems of linear equations, a > condition number of 1e6 is likely to blow away *all* the accuracy in your > measured data. (Very few physical measurements are accurate to more than > six digits.) Not true, IMHO. Eigenfrequencies (I think that is a very typical physical measurement and I cannot think of something that is more typical) don't need to be accurate with 6 digits. I'm happy with below 5% error. So if an eigenfrequency is measured to 100 Hz, I'm happy if the numerical model gives a result in the 5%-range of 95-105 Hz. This I got with a condition number of approx. 1e6 and it's good enough for me. I don't think anyone expects 6-digit accuracy with eigenfrequncies. From newsboost at gmail.com Fri May 4 09:36:09 2012 From: newsboost at gmail.com (someone) Date: Fri, 04 May 2012 15:36:09 +0200 Subject: numpy (matrix solver) - python vs. matlab In-Reply-To: References: <4f9dc320$0$1388$4fafbaef@reader2.news.tin.it> <7xd36qdojc.fsf@ruckus.brouhaha.com> <7x62cfv6x9.fsf@ruckus.brouhaha.com> <4fa11ffb$0$29965$c3e8da3$5496439d@news.astraweb.com> <02188ab6-6fc5-4b5c-adab-7738a2ed9ab5@9g2000yqp.googlegroups.com> Message-ID: On 05/04/2012 06:15 AM, Russ P. wrote: > On May 3, 4:59 pm, someone wrote: >> On 05/04/2012 12:58 AM, Russ P. wrote: >> Ok, but I just don't understand what's in the "empirical" category, sorry... > > I didn't look it up, but as far as I know, empirical just means based > on experiment, which means based on measured data. Unless I am FEM based on measurement data? Still, I don't understand it, sorry. > mistaken , a finite element analysis is not based on measured data. I'm probably a bit narrow-thinking because I just worked with this small FEM-program (in Matlab), but can you please give an example of a matrix-problem that is based on measurement data? > Yes, the results can be *compared* with measured data and perhaps > calibrated with measured data, but those are not the same thing. Exactly. That's why I don't understand what solving a matrix system using measurement/empirical data, could typically be an example of...? > I agree with Steven D's comment above, and I will reiterate that a > condition number of 1e6 would not inspire confidence in me. If I had a > condition number like that, I would look for a better model. But > that's just a gut reaction, not a hard scientific rule. I don't have any better model and don't know anything better. I still think that 5% accuracy is good enough and that nobody needs 6-digits precision for practical/engineering/empirical work... Maybe quantum physicists needs more than 6 digits of accuracy, but most practical/engineering problems are ok with an accuracy of 5%, I think, IMHO... Please tell me if I'm wrong. From duncan.booth at invalid.invalid Fri May 4 09:43:03 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 May 2012 13:43:03 GMT Subject: pyjamas / pyjs References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: james hedley wrote: > There's also an allegation, which I am not making myself at this point > - only describing its nature, that a person may have lifted data from > the original mail server without authorisation and used it to recreate > the mailing list on a different machine. *If* that were to be true, > then the law has been broken in at least one country. > I don't know whether they moved it to another machine or not, but what they definitely did do was start sending emails to all the people on the list who had sending of emails disabled (including myself) which resulted in a flood of emails and from the sound of it a lot of annoyed people. If he wanted to community support for the takeover that probably wasn't a good start. In case it isn't obvious why I might be subscribed but emails turned off, I read mailing lists like that through gmane in which case I still need to sign up to the list to post but definitely don't want to receive emails. -- Duncan Booth http://kupuguy.blogspot.com From d at davea.name Fri May 4 09:46:36 2012 From: d at davea.name (Dave Angel) Date: Fri, 04 May 2012 09:46:36 -0400 Subject: set PYTHONPATH for a directory? In-Reply-To: References: Message-ID: <4FA3DDBC.9050405@davea.name> On 05/04/2012 08:21 AM, Neal Becker wrote: > I'm testing some software I'm building against an alternative version of a > library. So I have an alternative library in directory L. Then I have in an > unrelated directory, the test software, which I need to use the library version > from directory L. > > One approach is to set PYTHONPATH whenever I run this test software. Any > suggestion on a more foolproof approach? > Simply modify sys.path at the beginning of your test software. That's where import searches. -- DaveA From pedro.larroy.lists at gmail.com Fri May 4 10:04:58 2012 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Fri, 4 May 2012 16:04:58 +0200 Subject: set PYTHONPATH for a directory? In-Reply-To: <4FA3DDBC.9050405@davea.name> References: <4FA3DDBC.9050405@davea.name> Message-ID: Isn't virtualenv for this kind of scenario? Pedro. On Fri, May 4, 2012 at 3:46 PM, Dave Angel wrote: > On 05/04/2012 08:21 AM, Neal Becker wrote: >> I'm testing some software I'm building against an alternative version of a >> library. ?So I have an alternative library in directory L. ?Then I have in an >> unrelated directory, the test software, which I need to use the library version >> from directory L. >> >> One approach is to set PYTHONPATH whenever I run this test software. ?Any >> suggestion on a more foolproof approach? >> > Simply modify ?sys.path ?at the beginning of your test software. ?That's > where import searches. > > > > -- > > DaveA > > -- > http://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Fri May 4 10:41:04 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 May 2012 08:41:04 -0600 Subject: " References: Message-ID: On Fri, May 4, 2012 at 12:57 AM, Stefan Behnel wrote: > Ian Kelly, 04.05.2012 01:02: >> BeautifulSoup is supposed to parse like a browser would > > Not at all, that would be html5lib. Well, I guess that depends on whether we're talking about BeautifulSoup 3 (a regex-based screen scraper with methods for navigating and searching the resulting tree) or 4 (purely a parse tree navigation library that relies on external libraries to do the actual parsing). According to the BS3 documentation, "The BeautifulSoup class is full of web-browser-like heuristics for divining the intent of HTML authors." If we're talking about BS4, though, then the problem in this instance would have nothing to do with BS4 and instead would be an issue of whatever underlying parser the OP is using. From torriem at gmail.com Fri May 4 11:18:27 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 04 May 2012 09:18:27 -0600 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <4f9a81f2$0$1374$4fafbaef@reader1.news.tin.it> <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4FA3F343.9050207@gmail.com> On 05/04/2012 05:12 AM, Kiuhnm wrote: >> Hand-wavy, no real example, doesn't make sense. > > Really? Then I don't know what would make sense to you. Speaking as as an observer here, I've read your blog post, and looked at your examples. They don't make sense to me either. They aren't real examples. They are abstract examples. They do not answer the questions, "what actual, real world python problems does this solve?" and "how is this better than a plain python solution?" For example, I've seen ruby code where blocks are used in a real-world way. Could you not put in something similar in your examples? Since you've written this code you must use it in everyday python coding. Show us what you've been doing with it. Also while some of your blog snippets are snippets, other code examples you provide purport to be complete examples, when in fact they are not. For example, about 45% of the way down your blog page you have a block of code that looks to be self-contained. It has "import logging" and "import random" at the top of it. Yet it cannot run as it's missing an import of your module. >>>> You haven't presented *any* good code or use cases. >>> >>> Says who? You and some others? Not enough. How many people do you need to tell you this before it's good enough? Doesn't matter how genius your code is if no one knows when or how to use it. > It's impossible to have a constructive discussion while you and others > feel that way. You're so biased that you don't even see how biased you are. Having followed the conversation somewhat, I can say that you have been given a fair hearing. People aren't just dissing on it because it's ruby. You are failing to listen to them just as much as you claim they are failing to listen to them. >>> The meaning is clear from the context. Not really. For one we're not Ruby programmers here, and like has been said, where is a real example of real code that's not just some abstract "hello this is block1, this is block 2" sort of thing? Providing non-block code to compare is important too. > Unfortunately, communication is a two-people thing. It's been clear from > the first post that your intention wasn't to understand what I'm proposing. > There are some things, like what I say about name-clashing, that you > should understand no matter how biased you are. > If you don't, you're just pretending or maybe you weren't listening at all. well there's my attempt. From showell30 at yahoo.com Fri May 4 11:27:54 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 4 May 2012 08:27:54 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> Message-ID: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> On May 3, 6:10?pm, Miki Tebeka wrote: > > I'm looking for a fairly lightweight key/value store that works for > > this type of problem: > > I'd start with a benchmark and try some of the things that are already in the standard library: > - bsddb > - sqlite3 (table of key, value, index key) > - shelve (though I doubt this one) > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: http://www.gossamer-threads.com/lists/python/python/106494 I'll give sqlite3 a spin. Has anybody out there wrapped sqlite3 behind a hash interface already? I know it's simple to do conceptually, but there are some minor details to work out for large amounts of data (like creating the index after all the inserts), so if somebody's already tackled this, it would be useful to see their code. > You might find that for a little effort you get enough out of one of these. > > Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. Thanks. From lamialily at cleverpun.com Fri May 4 12:53:08 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 04 May 2012 09:53:08 -0700 Subject: syntax for code blocks In-Reply-To: <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> References: <34a048fc-344c-46fd-8de8-64227ab140f7@sm5g2000pbc.googlegroups.com> <4f9ff09b$0$1375$4fafbaef@reader2.news.tin.it> <4fa11201$0$1385$4fafbaef@reader2.news.tin.it> <0ef8dcd9-c88f-4784-8599-6fa0fd6498fc@r2g2000pbs.googlegroups.com> <4fa2af80$0$1383$4fafbaef@reader1.news.tin.it> <0e75a278-1bf8-445b-b71d-2fedbb396558@ns1g2000pbc.googlegroups.com> <4fa3b9ba$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <5528q7pvga8sl9dao3psl4n7mlnk77dql6@4ax.com> You know what I find rich about all of this? >>>[ ... ]> I'd like to change the syntax of my module 'codeblocks' to make it more >>>[ ... ]> pythonic. Kiuhnm posted a thread to the group asking us to help him make it more Pythonic, but he has steadfastly refused every single piece of help he was offered because he feels his code is good enough after all. So why are we perpetuating it? ~Temia -- When on earth, do as the earthlings do. From python.list at tim.thechases.com Fri May 4 13:14:36 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 12:14:36 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> Message-ID: <4FA40E7C.3040504@tim.thechases.com> On 05/04/12 10:27, Steve Howell wrote: > On May 3, 6:10 pm, Miki Tebeka wrote: >>> I'm looking for a fairly lightweight key/value store that works for >>> this type of problem: >> >> I'd start with a benchmark and try some of the things that are already in the standard library: >> - bsddb >> - sqlite3 (table of key, value, index key) > > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: Have you tested the standard library's anydbm module (certainly not deprecated)? In a test I threw together, after populating one gig worth of data, lookups were pretty snappy (compared to the lengthy time it took to populate the 1gb of junk data). -tkc From chris at python.org Fri May 4 13:20:29 2012 From: chris at python.org (Chris Withers) Date: Fri, 04 May 2012 18:20:29 +0100 Subject: recruiter spam In-Reply-To: References: Message-ID: <4FA40FDD.1080306@python.org> Please don't spam the list with job adverts, post to the job board instead: http://www.python.org/community/jobs/howto/ cheers, Chris On 03/05/2012 22:13, Preeti Bhattad wrote: > Hi there, > If you have USA work visa and if you reside in USA; > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Fri May 4 13:43:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 13:43:12 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On 5/4/2012 8:00 AM, Peng Yu wrote: > On Fri, May 4, 2012 at 6:21 AM, Chris Angelico wrote: >> On Fri, May 4, 2012 at 8:14 PM, Peng Yu wrote: >>> Thanks. This is what I'm looking for. I think that this should be >>> added to the python document as a manifestation (but nonnormalized) of >>> what "A set object is an unordered collection of distinct hashable >>> objects" means. >> >> There are other things that can prove it to be unordered, too; the >> exact pattern and order of additions and deletions can affect the >> iteration order. The only thing you can be sure of is that you can't >> be sure of it. > > I agree. My point was just to suggest adding more explanations on the > details in the manual. I am not sure how much clearer we can be in the language manual. The word 'unordered' means just that. If one imposes an arbitrary linear order on an unordered collection, it is arbitrary. It is frustrating that people do not want to believe that, and even write tests depending on today's arbitrary serialization order being deterministic indefinitely. There is a section about this in the doctest doc, but people do it anyway. I will think about a sentence to add. -- Terry Jan Reedy From python.list at tim.thechases.com Fri May 4 13:46:43 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 12:46:43 -0500 Subject: key/value store optimized for disk storage In-Reply-To: <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> Message-ID: <4FA41603.5000804@tim.thechases.com> On 05/04/12 12:22, Steve Howell wrote: > Which variant do you recommend? > > """ anydbm is a generic interface to variants of the DBM database > ? dbhash (requires bsddb), gdbm, or dbm. If none of these modules > is installed, the slow-but-simple implementation in module > dumbdbm will be used. > > """ If you use the stock anydbm module, it automatically chooses the best it knows from the ones available: import os import hashlib import random from string import letters import anydbm KB = 1024 MB = KB * KB GB = MB * KB DESIRED_SIZE = 1 * GB KEYS_TO_SAMPLE = 20 FNAME = "mydata.db" i = 0 md5 = hashlib.md5() db = anydbm.open(FNAME, 'c') try: print("Generating junk data...") while os.path.getsize(FNAME) < 6*GB: key = md5.update(str(i))[:16] size = random.randrange(1*KB, 4*KB) value = ''.join(random.choice(letters) for _ in range(size)) db[key] = value i += 1 print("Gathering %i sample keys" % KEYS_TO_SAMPLE) keys_of_interest = random.sample(db.keys(), KEYS_TO_SAMPLE) finally: db.close() print("Reopening for a cold sample set in case it matters") db = anydbm.open(FNAME) try: print("Performing %i lookups") for key in keys_of_interest: v = db[key] print("Done") finally: db.close() (your specs said ~6gb of data, keys up to 16 characters, values of 1k-4k, so this should generate such data) -tkc From ramit.prasad at jpmorgan.com Fri May 4 14:19:39 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 4 May 2012 18:19:39 +0000 Subject: most efficient way of populating a combobox (in maya) In-Reply-To: <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <24166e22-bf6c-47b4-ac22-0a886d68b0ec@e15g2000vba.googlegroups.com> <4fa34ac4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409306248@SCACMX008.exchad.jpmchase.net> > > I'm making a GUI in maya using python only and I'm trying to see which > > is more efficient. I'm trying to populate an optionMenuGrp / combo box > > whose contents come from os.listdir(folder). Now this is fine if the > > folder isn't that full but the folder has a few hundred items (almost in > > the thousands), it is also on the (work) network and people are > > constantly reading from it as well. Now I'm trying to write the GUI so > > that it makes the interface, and using threading - Thread, populate the > > box. Is this a good idea? Has anyone done this before and have > > experience with any limitations on it? Is the performance not > > significant? > > Thanks for any advice > > > Why don't you try it and see? > > > It's not like populating a combobox in Tkinter with the contents of > os.listdir requires a large amount of effort. Just try it and see whether > it performs well enough. In my experience, a generic combobox with hundreds or thousands of elements is difficult and annoying to use. Not sure if the Tkinter version has scroll bars or auto-completion, but if not you may want to subclass and add those features. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From emile at fenx.com Fri May 4 15:14:18 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 May 2012 12:14:18 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <4FA41603.5000804@tim.thechases.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> Message-ID: On 5/4/2012 10:46 AM Tim Chase said... I hit a few snags testing this on my winxp w/python2.6.1 in that getsize wasn't finding the file as it was created in two parts with .dat and .dir extension. Also, setting key failed as update returns None. The changes I needed to make are marked below. Emile > import os > import hashlib > import random > from string import letters > > import anydbm > > KB = 1024 > MB = KB * KB > GB = MB * KB > DESIRED_SIZE = 1 * GB > KEYS_TO_SAMPLE = 20 > FNAME = "mydata.db" FDATNAME = r"mydata.db.dat" > > i = 0 > md5 = hashlib.md5() > db = anydbm.open(FNAME, 'c') > try: > print("Generating junk data...") > while os.path.getsize(FNAME)< 6*GB: while os.path.getsize(FDATNAME) < 6*GB: > key = md5.update(str(i))[:16] md5.update(str(i)) key = md5.hexdigest()[:16] > size = random.randrange(1*KB, 4*KB) > value = ''.join(random.choice(letters) > for _ in range(size)) > db[key] = value > i += 1 > print("Gathering %i sample keys" % KEYS_TO_SAMPLE) > keys_of_interest = random.sample(db.keys(), KEYS_TO_SAMPLE) > finally: > db.close() > > print("Reopening for a cold sample set in case it matters") > db = anydbm.open(FNAME) > try: > print("Performing %i lookups") > for key in keys_of_interest: > v = db[key] > print("Done") > finally: > db.close() > From python.list at tim.thechases.com Fri May 4 15:49:25 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 May 2012 14:49:25 -0500 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> Message-ID: <4FA432C5.3040809@tim.thechases.com> On 05/04/12 14:14, Emile van Sebille wrote: > On 5/4/2012 10:46 AM Tim Chase said... > > I hit a few snags testing this on my winxp w/python2.6.1 in that getsize > wasn't finding the file as it was created in two parts with .dat and > .dir extension. Hrm...must be a Win32 vs Linux thing. > Also, setting key failed as update returns None. Doh, that's what I get for not testing my hand-recreation of the test program I cobbled together and then deleted. Thanks for tweaking that. -tkc From rowen at uw.edu Fri May 4 15:54:27 2012 From: rowen at uw.edu (Russell E. Owen) Date: Fri, 04 May 2012 12:54:27 -0700 Subject: pickle question: sequencing of operations Message-ID: What is the sequence of calls when unpickling a class with __setstate__? >From experimentation I see that __setstate__ is called and __init__ is not, but I think I need more info. I'm trying to pickle an instance of a class that is a subclass of another class that contains unpickleable objects. What I'd like to do is basically just pickle the constructor parameters and then use those to reconstruct the object on unpickle, but I'm not sure how to go about this. Or an example if anyone has one. -- Russell From pengyu.ut at gmail.com Fri May 4 16:08:23 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 15:08:23 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > On 5/4/2012 8:00 AM, Peng Yu wrote: >> >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: >>> >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: >>>> >>>> Thanks. This is what I'm looking for. I think that this should be >>>> added to the python document as a manifestation (but nonnormalized) of >>>> what "A set object is an unordered collection of distinct hashable >>>> objects" means. >>> >>> >>> There are other things that can prove it to be unordered, too; the >>> exact pattern and order of additions and deletions can affect the >>> iteration order. The only thing you can be sure of is that you can't >>> be sure of it. >> >> >> I agree. My point was just to suggest adding more explanations on the >> details in the manual. > > > I am not sure how much clearer we can be in the language manual. The word > 'unordered' means just that. If one imposes an arbitrary linear order on an > unordered collection, it is arbitrary. It is frustrating that people do not > want to believe that, and even write tests depending on today's arbitrary > serialization order being deterministic indefinitely. There is a section > about this in the doctest doc, but people do it anyway. I will think about a > sentence to add. You can just add the example that you posted to demonstrate what the unordered means. A curious user might want to know under what condition the "unorderness" can affect the results, because for trivial examples (like the following), it does seem that there is some orderness in a set. set(['a', 'b', 'c']) set(['c', 'b', 'a']) -- Regards, Peng From emile at fenx.com Fri May 4 16:15:05 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 May 2012 13:15:05 -0700 Subject: key/value store optimized for disk storage In-Reply-To: <4FA432C5.3040809@tim.thechases.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> <4FA40E7C.3040504@tim.thechases.com> <1336152145.33191.YahooMailNeo@web160702.mail.bf1.yahoo.com> <4FA41603.5000804@tim.thechases.com> <4FA432C5.3040809@tim.thechases.com> Message-ID: On 5/4/2012 12:49 PM Tim Chase said... > On 05/04/12 14:14, Emile van Sebille wrote: >> On 5/4/2012 10:46 AM Tim Chase said... >> >> I hit a few snags testing this on my winxp w/python2.6.1 in that getsize >> wasn't finding the file as it was created in two parts with .dat and >> .dir extension. > > Hrm...must be a Win32 vs Linux thing. Or an anydbm thing -- you may get different results depending... Emile From ferreirafm at lim12.fm.usp.br Fri May 4 16:33:39 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Fri, 4 May 2012 13:33:39 -0700 (PDT) Subject: for loop: weird behavior Message-ID: <1336163619790-4953214.post@n6.nabble.com> Hi there, I simply can't print anything in the second for-loop bellow: ######################################### #!/usr/bin/env python import sys filename = sys.argv[1] outname = filename.split('.')[0] + '_pdr.dat' begin = 'Distance distribution' end = 'Reciprocal' first = 0 last = 0 with open(filename) as inf: for num, line in enumerate(inf, 1): #print num, line if begin in line: first = num if end in line: last = num for num, line in enumerate(inf, 1): print 'Ok!' print num, line if num in range(first + 5, last - 1): print line print first, last print range(first + 5, last - 1) #################################### The output goes here: http://pastebin.com/egnahct2 Expected: at least the string 'Ok!' from the second for-loop. What I'm doing wrong? thanks in advance. Fred -- View this message in context: http://python.6.n6.nabble.com/for-loop-weird-behavior-tp4953214.html Sent from the Python - python-list mailing list archive at Nabble.com. From tjreedy at udel.edu Fri May 4 16:47:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 May 2012 16:47:07 -0400 Subject: for loop: weird behavior In-Reply-To: <1336163619790-4953214.post@n6.nabble.com> References: <1336163619790-4953214.post@n6.nabble.com> Message-ID: On 5/4/2012 4:33 PM, ferreirafm wrote: > Hi there, > I simply can't print anything in the second for-loop bellow: > > ######################################### > #!/usr/bin/env python > > import sys > > filename = sys.argv[1] > outname = filename.split('.')[0] + '_pdr.dat' > begin = 'Distance distribution' > end = 'Reciprocal' > first = 0 > last = 0 > with open(filename) as inf: > for num, line in enumerate(inf, 1): > #print num, line > if begin in line: > first = num > if end in line: > last = num The file pointer is now at the end of the file. As an iterator, the file is exhausted. To reiterate, return the file pointer to the beginning with inf.seek(0). > for num, line in enumerate(inf, 1): > print 'Ok!' > print num, line > if num in range(first + 5, last - 1): > print line > print first, last > print range(first + 5, last - 1) -- Terry Jan Reedy From cs at zip.com.au Fri May 4 19:12:25 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 5 May 2012 09:12:25 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: Message-ID: <20120504231225.GA29167@cskk.homeip.net> On 04May2012 15:08, Peng Yu wrote: | On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: | > On 5/4/2012 8:00 AM, Peng Yu wrote: | >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: | >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: | >>>> Thanks. This is what I'm looking for. I think that this should be | >>>> added to the python document as a manifestation (but nonnormalized) of | >>>> what "A set object is an unordered collection of distinct hashable | >>>> objects" means. | >>> | >>> There are other things that can prove it to be unordered, too; the | >>> exact pattern and order of additions and deletions can affect the | >>> iteration order. The only thing you can be sure of is that you can't | >>> be sure of it. | >> | >> I agree. My point was just to suggest adding more explanations on the | >> details in the manual. | > | > I am not sure how much clearer we can be in the language manual. The word | > 'unordered' means just that. [...] | | You can just add the example that you posted to demonstrate what the | unordered means. A curious user might want to know under what | condition the "unorderness" can affect the results, because for | trivial examples (like the following), it does seem that there is some | orderness in a set. I'm with Terry here: anything else in the line you suggest would complicate things for the reader, and potentially mislead. Future implementation changes (and, indeed, _other_ implementations like Jython) can change any of this. So there _are_ no ``condition the "unorderness" can affect the results'': a set is unordered, and you could even _legitimately_ get different orders from the same set if you iterate over it twice. It is unlikely, but permissable. Any attempt to describe such conditions beyond "it might happen at any time" would be misleading. | set(['a', 'b', 'c']) | set(['c', 'b', 'a']) The language does not say these will get the same iteration order. It happens that the Python you're using, today, does that. You can't learn the language specification from watching behaviour; you learn the guarrenteed behaviour -- what you may rely on happening -- from the specification, and you can test that an implementation obeys (or at any rate, does not disobey) the specification by watching behaviour. You seem to be trying to learn the spec from behaviour. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Loud pipes make noise. Skill and experience save lives. - EdBob Morandi From pengyu.ut at gmail.com Fri May 4 19:37:02 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 4 May 2012 18:37:02 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: <20120504231225.GA29167@cskk.homeip.net> References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On Fri, May 4, 2012 at 6:12 PM, Cameron Simpson wrote: > On 04May2012 15:08, Peng Yu wrote: > | On Fri, May 4, 2012 at 12:43 PM, Terry Reedy wrote: > | > On 5/4/2012 8:00 AM, Peng Yu wrote: > | >> On Fri, May 4, 2012 at 6:21 AM, Chris Angelico ?wrote: > | >>> On Fri, May 4, 2012 at 8:14 PM, Peng Yu ?wrote: > | >>>> Thanks. This is what I'm looking for. I think that this should be > | >>>> added to the python document as a manifestation (but nonnormalized) of > | >>>> what "A set object is an unordered collection of distinct hashable > | >>>> objects" means. > | >>> > | >>> There are other things that can prove it to be unordered, too; the > | >>> exact pattern and order of additions and deletions can affect the > | >>> iteration order. The only thing you can be sure of is that you can't > | >>> be sure of it. > | >> > | >> I agree. My point was just to suggest adding more explanations on the > | >> details in the manual. > | > > | > I am not sure how much clearer we can be in the language manual. The word > | > 'unordered' means just that. [...] > | > | You can just add the example that you posted to demonstrate what the > | unordered means. A curious user might want to know under what > | condition the "unorderness" can affect the results, because for > | trivial examples (like the following), it does seem that there is some > | orderness in a set. > > I'm with Terry here: anything else in the line you suggest would > complicate things for the reader, and potentially mislead. > > Future implementation changes (and, indeed, _other_ implementations like > Jython) can change any of this. So there _are_ no ``condition the > "unorderness" can affect the results'': a set is unordered, and you > could even _legitimately_ get different orders from the same set > if you iterate over it twice. It is unlikely, but permissable. > > Any attempt to describe such conditions beyond "it might happen at any > time" would be misleading. > > | set(['a', 'b', 'c']) > | set(['c', 'b', 'a']) > > The language does not say these will get the same iteration order. It > happens that the Python you're using, today, does that. > > You can't learn the language specification from watching behaviour; > you learn the guarrenteed behaviour -- what you may rely on happening -- > from the specification, and you can test that an implementation obeys (or > at any rate, does not disobey) the specification by watching behaviour. > > You seem to be trying to learn the spec from behaviour. My point is if something is said in the document, it is better to be substantiated by an example. I don't think that this has anything with "learn the spec from behaviour." -- Regards, Peng From breamoreboy at yahoo.co.uk Fri May 4 20:31:28 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 05 May 2012 01:31:28 +0100 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On 05/05/2012 00:37, Peng Yu wrote: > > My point is if something is said in the document, it is better to be > substantiated by an example. I don't think that this has anything with > "learn the spec from behaviour." > I side with the comments made by Terry Reedy and Cameron Simpson so please give it a rest, you're flogging a dead horse. -- Cheers. Mark Lawrence. From tjreedy at udel.edu Sat May 5 00:28:40 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 May 2012 00:28:40 -0400 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: Peng, I actually am thinking about it. Underlying problem: while unordered means conceptually unordered as far as the collection goes, the items in the collection, if homogenous enough, may have a natural order, which users find hard to ignore. Even if not comparable, an implementation such as CPython that uses linear sequential memory will impose some order. Even if the implementation uses unordered (holographic?) memory, order will be imposed to iterate, as when creating a serialized representation of the collection. Abstract objects, concrete objects, and serialized representations are three different things, but people tend to conflate them. Order consistency issues: if the unordered collection is iterated, when can one expect the order to be the same? Theoretically, essentially never, except that iterating dicts by keys, values, or key-value pairs is guaranteed to be consistent, which means that re-iterating has to be consistent. I actually think the same might as well be true for sets, although there is no doc that says so. If two collections are equal, should the iteration order be the same? It has always been true that if hash values collide, insertion order matters. However, a good hash function avoids hash collisions as much as possible in practical use cases. Without doing something artificial, as I did with the example, collisions should be especially rare on 64-bit builds. If one collection has a series of additions and deletions so that the underlying hash table has a different size than an equal collection build just from insertions, then order will also be different. If the same collection is built by insertion in the same order, but in different runs, bugfix versions, or language versions, will iteration order by the same? Historically, it has been for CPython for about a decade, and people has come to depend on that constancy, in spite of warning not to. Even core developers have not been immune, as the CPython test suite has a few set or dict iteration order dependencies until it was recently randomized. Late last year, it became obvious that this constancy is a practical denial-of-service security hole. The option to randomize hashing for each run was added to 2.6, 2.7, 3.1, and 3.2. Randomized hashing by run is part of 3.3. So some of the discussion above is obsolete. The example I gave only works for that one run, as hash('a') changes each run. So iteration order now changes with each run in fact as well as in theory. For the doc, the problem is what to say and where without being repetitous (and to get multiple people to agree ;-). -- Terry Jan Reedy From joncle at googlemail.com Sat May 5 06:03:58 2012 From: joncle at googlemail.com (Jon Clements) Date: Sat, 5 May 2012 03:03:58 -0700 (PDT) Subject: key/value store optimized for disk storage In-Reply-To: <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <25878701.181.1336093846733.JavaMail.geo-discussion-forums@ynei5> <34048f10-2074-4589-b04f-6332da7c4e3b@vd1g2000pbc.googlegroups.com> Message-ID: <15930137.526.1336212238754.JavaMail.geo-discussion-forums@ynep10> On Friday, 4 May 2012 16:27:54 UTC+1, Steve Howell wrote: > On May 3, 6:10?pm, Miki Tebeka wrote: > > > I'm looking for a fairly lightweight key/value store that works for > > > this type of problem: > > > > I'd start with a benchmark and try some of the things that are already in the standard library: > > - bsddb > > - sqlite3 (table of key, value, index key) > > - shelve (though I doubt this one) > > > > Thanks. I think I'm ruling out bsddb, since it's recently deprecated: > > http://www.gossamer-threads.com/lists/python/python/106494 > > I'll give sqlite3 a spin. Has anybody out there wrapped sqlite3 > behind a hash interface already? I know it's simple to do > conceptually, but there are some minor details to work out for large > amounts of data (like creating the index after all the inserts), so if > somebody's already tackled this, it would be useful to see their > code. > > > You might find that for a little effort you get enough out of one of these. > > > > Another module which is not in the standard library is hdf5/PyTables and in my experience very fast. > > Thanks. Could also look at Tokyo cabinet or Kyoto cabinet (but I believe that has slightly different licensing conditions for commercial use). From pengyu.ut at gmail.com Sat May 5 07:04:35 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 5 May 2012 06:04:35 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: Hi Terry, Thank you for you detailed email. > If two collections are equal, should the iteration order be the same? It has > always been true that if hash values collide, insertion order matters. > However, a good hash function avoids hash collisions as much as possible in > practical use cases. Without doing something artificial, as I did with the > example, collisions should be especially rare on 64-bit builds. If one > collection has a series of additions and deletions so that the underlying > hash table has a different size than an equal collection build just from > insertions, then order will also be different. The reason that I asked to add the artificial example in the doc is because I never completely understand the unorderness until I see your artificial example. You will surely use more words for explaining what "unorderness" means than just showing your example. And the example (since formatted as code) is more eye catching than just plain text. For my case, since I didn't understand the unorderness, I made some subtle bug in my program, which works fine in my testing code. However, it produce a small amount of corrupted results for the real production use, which is harder to debug. It did wasted quite some of my time. > For the doc, the problem is what to say and where without being repetitous > (and to get multiple people to agree ;-). I agree that people have different opinions on issues like this. But I think that "The Customer Is God". Readers of the doc is the customers, the writers of the doc is the producers. The opinion of customers should carry more weight than producers. -- Regards, Peng From rosuav at gmail.com Sat May 5 07:53:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 May 2012 21:53:31 +1000 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On Sat, May 5, 2012 at 9:04 PM, Peng Yu wrote: > I agree that people have different opinions on issues like this. But I > think that "The Customer Is God". Readers of the doc is the customers, > the writers of the doc is the producers. The opinion of customers > should carry more weight than producers. Nah, the customer's not God, and I have proof. http://notalwaysright.com/ Oops, now everyone's off reading funny stories about stupid/abusive customers. Well, when you're all back... The reason you're reading documentation is to learn. You're not handing over wads of cash and saying "Do stuff for me"; you're reading the Player's Handbook and learning which dice to roll when. Perhaps there's some jargon that you don't understand; in that case, either a FAQ/glossary or a forum post will set you straight. But if the doc says that something can't be relied upon, then there's nothing more to write there. Documentation that takes ten pages to say something is just as bad as documentation that leaves stuff out, because it's almost guaranteed that it won't be read. ChrisA From jmwebaze at gmail.com Sat May 5 08:12:56 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sat, 5 May 2012 14:12:56 +0200 Subject: How to compute a delta: the difference between lists of strings Message-ID: This is out of curiosity, i know this can be done with python diffllib module, but been figuring out how to compute the delta, Consider two lists below. s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] This is the result should be [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ z'] ideas on how to approach this.. ? -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat May 5 08:39:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 May 2012 22:39:59 +1000 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: On Sat, May 5, 2012 at 10:12 PM, J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' ?e', '+ A', '+ B', ' ?f', ' ?g', '- A', '- B', ' ?C', ' ?D', '- C', '+ > z'] > > ideas on how to approach this.. ? Here's a simple algorithm that produces sorta-mostly-reasonable results most of the time: Set your current-position-index to the beginning of each lists. (Call them 'pos1' and 'pos2'.) If s1[pos1] and s2[pos2] are identical, match - increment and iterate. Otherwise, increment pos2 until either it matches pos1 or you reach the end of s2. If you find a match, report the insertion into s2, increment both pointers past the match, and carry on. If you hit the end of s2, increment pos1 once and report an insertion into s1, then go back to looking for a match. It helps to append a sentinel to each list; that way, you don't need to separately check for additional content at the end of either list (as the sentinel won't match any of the strings). This is the algorithm I used for writing a simple file diff tool ages ago. It's not as good as diff(1), but it was fun to do the exercise. It's quite inefficient at handling large insertions into s1, and needs to be modified for most file handling (for instance, requiring a 2-line or 3-line rematch after a difference, to avoid matching on blank lines), but it's a basis. Producing beautiful or minimal diffs is a more complex task. :) ChrisA From jmwebaze at gmail.com Sat May 5 09:13:23 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sat, 5 May 2012 15:13:23 +0200 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: thank Chris.. On Sat, May 5, 2012 at 2:39 PM, Chris Angelico wrote:k > On Sat, May 5, 2012 at 10:12 PM, J. Mwebaze wrote: > > This is out of curiosity, i know this can be done with python diffllib > > module, but been figuring out how to compute the delta, Consider two > lists > > below. > > > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > > > This is the result should be > > > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ > > z'] > > > > ideas on how to approach this.. ? > > Here's a simple algorithm that produces sorta-mostly-reasonable > results most of the time: > > Set your current-position-index to the beginning of each lists. (Call > them 'pos1' and 'pos2'.) > If s1[pos1] and s2[pos2] are identical, match - increment and iterate. > Otherwise, increment pos2 until either it matches pos1 or you reach > the end of s2. > If you find a match, report the insertion into s2, increment both > pointers past the match, and carry on. > If you hit the end of s2, increment pos1 once and report an insertion > into s1, then go back to looking for a match. > > It helps to append a sentinel to each list; that way, you don't need > to separately check for additional content at the end of either list > (as the sentinel won't match any of the strings). > > This is the algorithm I used for writing a simple file diff tool ages > ago. It's not as good as diff(1), but it was fun to do the exercise. > It's quite inefficient at handling large insertions into s1, and needs > to be modified for most file handling (for instance, requiring a > 2-line or 3-line rematch after a difference, to avoid matching on > blank lines), but it's a basis. > > Producing beautiful or minimal diffs is a more complex task. :) > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Sat May 5 11:50:23 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 05 May 2012 08:50:23 -0700 Subject: How to compute a delta: the difference between lists of strings In-Reply-To: References: Message-ID: On 5/5/2012 5:12 AM J. Mwebaze said... > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two > lists below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', > '+ z'] > > ideas on how to approach this.. ? > use difflib: from difflib import unified_diff as ud s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] s2 = ['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] [ r for r in ud(s1,s2,lineterm="|") if not r.endswith("|") ] HTH, Emile From emile at fenx.com Sat May 5 12:04:32 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 05 May 2012 09:04:32 -0700 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: On 5/5/2012 4:04 AM Peng Yu said... > I agree that people have different opinions on issues like this. But I > think that "The Customer Is God". Readers of the doc is the customers, > the writers of the doc is the producers. The opinion of customers > should carry more weight than producers. Only to a point. The experience of the producers should carry more weight than the opinion of the customers. Emile From vito.detullio at gmail.com Sat May 5 12:16:40 2012 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 05 May 2012 18:16:40 +0200 Subject: How to compute a delta: the difference between lists of strings References: Message-ID: J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ > z'] > > ideas on how to approach this.. ? http://en.wikipedia.org/wiki/Longest_common_subsequence_problem -- ZeD From pengyu.ut at gmail.com Sat May 5 12:17:31 2012 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 5 May 2012 11:17:31 -0500 Subject: When convert two sets with the same elements to lists, are the lists always going to be the same? In-Reply-To: References: <20120504231225.GA29167@cskk.homeip.net> Message-ID: > Documentation that takes ten pages to say something is just as bad as > documentation that leaves stuff out, because it's almost guaranteed > that it won't be read. That's the point. If a simple example (6 lines) can demonstrate the concept, why spending "ten pages" to explain it. My experience is that for certain things, it is better describe by a spec once you know it, but it is certainly not true for people to learn it. A reasonable strategy is to interleave spec with demonstrating examples. There is no excuse to not to make the manual easier to read. -- Regards, Peng From bob at bobcowdery.plus.com Sat May 5 15:33:44 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sat, 05 May 2012 20:33:44 +0100 Subject: Problem with time.time() standing still Message-ID: <4FA58098.60009@bobcowdery.plus.com> Hi all, I've been a long time user of Python and written many extensions but this problem has me stumped. I've written a straight forward extension that wraps a vendors SDK for a video capture card. All works well except that in the Python thread on which I call the extension, after certain calls that I believe are using DirectShow, time stands still. The thread returns fine as the extension does its stuff in its own threads. In all other respects the Python thread seems unaffected but calls to time.time() always return the same time which is usually several seconds in the past or future and always has no fractional part. If I leave it long enough time will suddently jump forward after a few minutes, then again after a few minutes more. I've never encountered this behaviour before and can't understand what on earth is going on. If I call the 'C' time() function just the other side of my call to the extension the time is ticking along fine. It's just the one Python thread that is affected. If I call from the main thread then the main thread is affected. The calling program I've used to test this is just a few lines long. I believe the time function is a thin wrapper over the 'C' runtime so its very odd that time only stands still on the Python side but not on the 'C' side. As time is built in I've not looked at the code as its not in the distribution. Don't know if it would help to do that. This also can affect the time.sleep() function making it return immediately but that only seems to happen in my full application. Any ideas would be very greatly received. Bob From danyellawson at gmail.com Sat May 5 16:17:52 2012 From: danyellawson at gmail.com (Danyel Lawson) Date: Sat, 5 May 2012 16:17:52 -0400 Subject: Problem with time.time() standing still In-Reply-To: <4FA58098.60009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: Add a time.sleep(0) call to all your loops. Multithreading in Python is a cooperative cross platform threading simulation if you have tight loops Python won't task switch until you make a system call. Potentially preventing internal library variables from being updated. Your five minute interval may be almost exactly how long it takes to process a flooded queue in a tight loop in your program and it may be why it continues to happen as the queue waits to fill again while processing happens. You can simulate the progression of time by overriding the time.time function by simply setting it to a function that just increments a module level or function property variable. You can also override the time.time function to return the posix time function's value to maybe get around whatever optimization is happening in the time.time function to pass back the same value. If you post your sample code that exhibits the same behavior it may be obvious to someone on the list as to what is the problem. On Sat, May 5, 2012 at 3:33 PM, Bob Cowdery wrote: > Hi all, > > I've been a long time user of Python and written many extensions but > this problem has me stumped. > > I've written a straight forward extension that wraps a vendors SDK for a > video capture card. All works well except that in the Python thread on > which I call the extension, after certain calls that I believe are using > DirectShow, ?time stands still. The thread returns fine as the extension > does its stuff in its own threads. In all other respects the Python > thread seems unaffected but calls to time.time() always return the same > time which is usually several seconds in the past or future and always > has no fractional part. If I leave it long enough time will suddently > jump forward after a few minutes, then again after a few minutes more. > > I've never encountered this behaviour before and can't understand what > on earth is going on. If I call the 'C' time() function just the other > side of my call to the extension the time is ticking along fine. It's > just the one Python thread that is affected. If I call from the main > thread then the main thread is affected. The calling program I've used > to test this is just a few lines long. > > I believe the time function is a thin wrapper over the 'C' runtime so > its very odd that time only stands still on the Python side but not on > the 'C' side. As time is built in I've not looked at the code as its not > in the distribution. Don't know if it would help to do that. > > This also can affect the time.sleep() function making it return > immediately but that only seems to happen in my full application. > > Any ideas would be very greatly received. > > Bob > -- > http://mail.python.org/mailman/listinfo/python-list From bob at bobcowdery.plus.com Sat May 5 16:51:59 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sat, 05 May 2012 21:51:59 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: <4FA592EF.7030807@bobcowdery.plus.com> Thanks Daniel, that's interesting. Unfortunately there is no sensible code I can post because this only happens when I make a specific call into the vendors SDK. I can exercise my own code in the extension without a problem. The python test calling code is doing practically nothing. I make 3 calls to the extension to set things going and then loop every 5 seconds and print the time. I know Pythons own threading model is cooperative because of the GIL and therefore one thread can hog the show but I've never had issues with threads running in a C extension messing up a Python thread. I really need to understand what mechanism is at play here rather than work around it. Bob The time.clock() function does increment correctly. CPU is around 30% On 05/05/2012 21:17, Danyel Lawson wrote: > Add a time.sleep(0) call to all your loops. Multithreading in Python > is a cooperative cross platform threading simulation if you have tight > loops Python won't task switch until you make a system call. > Potentially preventing internal library variables from being updated. > > Your five minute interval may be almost exactly how long it takes to > process a flooded queue in a tight loop in your program and it may be > why it continues to happen as the queue waits to fill again while > processing happens. > > You can simulate the progression of time by overriding the time.time > function by simply setting it to a function that just increments a > module level or function property variable. You can also override the > time.time function to return the posix time function's value to maybe > get around whatever optimization is happening in the time.time > function to pass back the same value. > > If you post your sample code that exhibits the same behavior it may be > obvious to someone on the list as to what is the problem. > > > > On Sat, May 5, 2012 at 3:33 PM, Bob Cowdery wrote: >> Hi all, >> >> I've been a long time user of Python and written many extensions but >> this problem has me stumped. >> >> I've written a straight forward extension that wraps a vendors SDK for a >> video capture card. All works well except that in the Python thread on >> which I call the extension, after certain calls that I believe are using >> DirectShow, time stands still. The thread returns fine as the extension >> does its stuff in its own threads. In all other respects the Python >> thread seems unaffected but calls to time.time() always return the same >> time which is usually several seconds in the past or future and always >> has no fractional part. If I leave it long enough time will suddently >> jump forward after a few minutes, then again after a few minutes more. >> >> I've never encountered this behaviour before and can't understand what >> on earth is going on. If I call the 'C' time() function just the other >> side of my call to the extension the time is ticking along fine. It's >> just the one Python thread that is affected. If I call from the main >> thread then the main thread is affected. The calling program I've used >> to test this is just a few lines long. >> >> I believe the time function is a thin wrapper over the 'C' runtime so >> its very odd that time only stands still on the Python side but not on >> the 'C' side. As time is built in I've not looked at the code as its not >> in the distribution. Don't know if it would help to do that. >> >> This also can affect the time.sleep() function making it return >> immediately but that only seems to happen in my full application. >> >> Any ideas would be very greatly received. >> >> Bob >> -- >> http://mail.python.org/mailman/listinfo/python-list From cs at zip.com.au Sat May 5 18:05:42 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 6 May 2012 08:05:42 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA58098.60009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> Message-ID: <20120505220542.GA15014@cskk.homeip.net> On 05May2012 20:33, Bob Cowdery wrote: | I've written a straight forward extension that wraps a vendors SDK for a | video capture card. All works well except that in the Python thread on | which I call the extension, after certain calls that I believe are using | DirectShow, time stands still. The thread returns fine as the extension | does its stuff in its own threads. In all other respects the Python | thread seems unaffected but calls to time.time() always return the same | time which is usually several seconds in the past or future and always | has no fractional part. Thought #1: you are calling time.time() and haven't unfortunately renamed it? (I doubt this scenario, though the lack of fractional part is interesting.) | If I leave it long enough time will suddently | jump forward after a few minutes, then again after a few minutes more. | | I've never encountered this behaviour before and can't understand what | on earth is going on. If I call the 'C' time() function just the other | side of my call to the extension the time is ticking along fine. It's | just the one Python thread that is affected. [...] Thought #2: On a UNIX system I'd be running the process under strace (or dtrace or ktrace depending on flavour) to see what actual OS system calls are being made during this behaviour. Is this feasible for you? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A slipping sear could let your M203 grenade launcher fire when you least expect it. That would make you quite unpopular in what's left of your unit. - page 9 of the August 1993 issue of PS magazine, the US Army's preventive maintenance magazine From rosuav at gmail.com Sat May 5 19:11:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 May 2012 09:11:26 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA592EF.7030807@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> <4FA592EF.7030807@bobcowdery.plus.com> Message-ID: On Sun, May 6, 2012 at 6:51 AM, Bob Cowdery wrote: > The time.clock() function does increment correctly. CPU is around 30% 30% of how many cores? If that's a quad-core processor, that could indicate one core completely pegged plus a little usage elsewhere. ChrisA From wuwei23 at gmail.com Sat May 5 23:19:51 2012 From: wuwei23 at gmail.com (alex23) Date: Sat, 5 May 2012 20:19:51 -0700 (PDT) Subject: pyjamas / pyjs References: <8263790.806.1336125384240.JavaMail.geo-discussion-forums@vbvx4> Message-ID: On May 4, 11:43?pm, Duncan Booth wrote: > In case it isn't obvious why I might be subscribed but emails turned off, I > read mailing lists like that through gmane in which case I still need to > sign up to the list to post but definitely don't want to receive emails. This. I was surprised to suddenly start receiving emails, as I thought I'd left the pyjamas list _years_ ago. I've asked them to stop spamming me and even now and getting snide, shitty emails claiming that what they were doing wasn't spam as I "could have chosen to ignore it or delete it". I've had to email the abuse address at Rackspace. I'm pretty sure it's illegal to add people to a mailing list without their consent, to not include instructions on how to unsubscribe from the mailing list, and to continue to email them when they've asked to be removed. As for the project itself, having a bunch of arrogant assholes decide that the lead developer has "hijacked" the project with his explicit- from-the-start libre software "philosophies", because such belief runs counter to the desires - sorry, the "philosophies" - held by that core group of assholes, is just the must astounding hypocrisy I've ever seen. The correct approach in such an instance is to *fork* the project; but that way you don't get to steal the community, I guess. The unwanted email was bad enough. The overwhelming sense of entitlement those emails expressed was even worse. From emekamicro at gmail.com Sun May 6 00:19:01 2012 From: emekamicro at gmail.com (Emeka) Date: Sun, 6 May 2012 06:19:01 +0200 Subject: Is Python Lazy? Message-ID: Hello All, Could one say that generator expressions and functions are Python way of introducing Lazy concept? Regards, \Emeka -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sun May 6 01:40:59 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 5 May 2012 22:40:59 -0700 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: Generators and iterators are laziness where you tend to need laziness the most. Generator expressions are tiny generators - more full fledged generators are supported. Python probably won't have laziness at its core ever, but it's nice having a dose of it. IOW, you probably won't be able to write a sort routine, and use it as a "first 100 lowest values" routine for free. But you could construct something that does almost the same thing lazily using a generator - not for free. On Sat, May 5, 2012 at 9:19 PM, Emeka wrote: > > Hello All, > > Could one say that generator expressions and functions are Python way of > introducing Lazy concept? > > Regards, \Emeka > -- > *Satajanus Nig. Ltd > > > * > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun May 6 02:10:27 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 06 May 2012 08:10:27 +0200 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: Dan Stromberg, 06.05.2012 07:40: > you probably won't be able to write a sort routine, and > use it as a "first 100 lowest values" routine for free. But you could > construct something that does almost the same thing lazily using a > generator - not for free. OTOH, if you really wanted to do this particular thing, I'd just use heapq. Stefan From bob at bobcowdery.plus.com Sun May 6 04:18:23 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 09:18:23 +0100 Subject: Problem with time.time() standing still In-Reply-To: <20120505220542.GA15014@cskk.homeip.net> References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> Message-ID: <4FA633CF.7060009@bobcowdery.plus.com> On 05/05/2012 23:05, Cameron Simpson wrote: > On 05May2012 20:33, Bob Cowdery wrote: > | I've written a straight forward extension that wraps a vendors SDK for a > | video capture card. All works well except that in the Python thread on > | which I call the extension, after certain calls that I believe are using > | DirectShow, time stands still. The thread returns fine as the extension > | does its stuff in its own threads. In all other respects the Python > | thread seems unaffected but calls to time.time() always return the same > | time which is usually several seconds in the past or future and always > | has no fractional part. > > Thought #1: you are calling time.time() and haven't unfortunately > renamed it? (I doubt this scenario, though the lack of fractional part > is interesting.) Not sure what you mean by renamed it. I also tried datetime and that had the same behaviour. > > | If I leave it long enough time will suddently > | jump forward after a few minutes, then again after a few minutes more. > | > | I've never encountered this behaviour before and can't understand what > | on earth is going on. If I call the 'C' time() function just the other > | side of my call to the extension the time is ticking along fine. It's > | just the one Python thread that is affected. > [...] > > Thought #2: On a UNIX system I'd be running the process under strace (or > dtrace or ktrace depending on flavour) to see what actual OS system calls are > being made during this behaviour. Is this feasible for you? I'm on Windows for this particular part of the application. The video SDK is Windows only. But debugging into this is probably the only way. I looked at the built-in time module. As far as I can tell it just calls the underlying C time() function as an extension. This is more mystifying as that is pretty much what I'm doing by checking the time in my own extension module where it ticks along fine. I have another scenario using a different part of their SDK where the time does still tick but the fractional part is frozen, not 0 but frozen. I'd dearly love to know what's going on here. I thought about extracting the time module, building it, calling it something else and seeing if it behaves the same. All time consuming unfortunately when I have a deadline. > > Cheers, From bob at bobcowdery.plus.com Sun May 6 04:20:23 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 09:20:23 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> <4FA592EF.7030807@bobcowdery.plus.com> Message-ID: <4FA63447.3040800@bobcowdery.plus.com> On 06/05/2012 00:11, Chris Angelico wrote: > On Sun, May 6, 2012 at 6:51 AM, Bob Cowdery wrote: >> The time.clock() function does increment correctly. CPU is around 30% > 30% of how many cores? If that's a quad-core processor, that could > indicate one core completely pegged plus a little usage elsewhere. It is a quad core but no CPU is pegged as there are a number of threads running in C. It's reasonably well spread. > > ChrisA From rosuav at gmail.com Sun May 6 04:24:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 May 2012 18:24:41 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA633CF.7060009@bobcowdery.plus.com> References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: On Sun, May 6, 2012 at 6:18 PM, Bob Cowdery wrote: > On 05/05/2012 23:05, Cameron Simpson wrote: >> Thought #1: you are calling time.time() and haven't unfortunately >> renamed it? (I doubt this scenario, though the lack of fractional part >> is interesting.) > Not sure what you mean by renamed it. I also tried datetime and that had > the same behaviour. In Python, names are nothing special, so you could do something like: time.time = lambda: 142857 which means that time.time() will forever return that constant. Take a snapshot of time.time early in your code somewhere, and try using that instead, just in case. It's a long shot but might save you some insanity! ChrisA From cs at zip.com.au Sun May 6 04:49:15 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 6 May 2012 18:49:15 +1000 Subject: Problem with time.time() standing still In-Reply-To: <4FA633CF.7060009@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: <20120506084915.GA19916@cskk.homeip.net> On 06May2012 09:18, Bob Cowdery wrote: | On 05/05/2012 23:05, Cameron Simpson wrote: | > On 05May2012 20:33, Bob Cowdery wrote: | > | [...] calls to time.time() always return the same | > | time which is usually several seconds in the past or future and always | > | has no fractional part. | > | > Thought #1: you are calling time.time() and haven't unfortunately | > renamed it? (I doubt this scenario, though the lack of fractional part | > is interesting.) | | Not sure what you mean by renamed it. Like this: from time import time [...] time = some_unfortunate_other_function [...] now = time() # calls wrong function It seems unlikely, but possible. | I also tried datetime and that had | the same behaviour. Makes my suggestion even less likely unless the time module itself gets monkeypatched (i.e. "time.time = bad_function" somewhere). | > | If I leave it long enough time will suddently | > | jump forward after a few minutes, then again after a few minutes more. | > | | > | I've never encountered this behaviour before and can't understand what | > | on earth is going on. If I call the 'C' time() function just the other | > | side of my call to the extension the time is ticking along fine. It's | > | just the one Python thread that is affected. | > [...] | > | > Thought #2: On a UNIX system I'd be running the process under strace (or | > dtrace or ktrace depending on flavour) to see what actual OS system calls are | > being made during this behaviour. Is this feasible for you? | | I'm on Windows for this particular part of the application. I'd guessed so. I've no Windows programming background; I was wondering if there was something like this you had to hand on windows. | [...] But debugging into this is probably the only way. I | looked at the built-in time module. As far as I can tell it just calls | the underlying C time() function as an extension. This is more | mystifying as that is pretty much what I'm doing by checking the time in | my own extension module where it ticks along fine. Hmm. A C extension I presume? How about writing a little pure Python thread to call time.time(), and spin it off parallel to the rest of the app; does it also get bad time.time() behaviour? | I have another | scenario using a different part of their SDK where the time does still | tick but the fractional part is frozen, not 0 but frozen. Curiouser and curiouser. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ As you can see, unraveling even a small part of 'sendmail' can introduce more complexity than answers. - Brian Costales, _sendmail_ From bob at bobcowdery.plus.com Sun May 6 05:09:01 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 10:09:01 +0100 Subject: Problem with time.time() standing still In-Reply-To: References: <4FA58098.60009@bobcowdery.plus.com> <20120505220542.GA15014@cskk.homeip.net> <4FA633CF.7060009@bobcowdery.plus.com> Message-ID: <4FA63FAD.8030504@bobcowdery.plus.com> On 06/05/2012 09:24, Chris Angelico wrote: > On Sun, May 6, 2012 at 6:18 PM, Bob Cowdery wrote: >> On 05/05/2012 23:05, Cameron Simpson wrote: >>> Thought #1: you are calling time.time() and haven't unfortunately >>> renamed it? (I doubt this scenario, though the lack of fractional part >>> is interesting.) >> Not sure what you mean by renamed it. I also tried datetime and that had >> the same behaviour. > In Python, names are nothing special, so you could do something like: > > time.time = lambda: 142857 > > which means that time.time() will forever return that constant. > > Take a snapshot of time.time early in your code somewhere, and try > using that instead, just in case. It's a long shot but might save you > some insanity! Thanks. I will try that. Away now until Monday when the battle will resume. Bob > ChrisA From bob at bobcowdery.plus.com Sun May 6 05:19:27 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Sun, 06 May 2012 10:19:27 +0100 Subject: Problem with time.time() standing still In-Reply-To: <20120506084915.GA19916@cskk.homeip.net> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> Message-ID: <4FA6421F.40002@bobcowdery.plus.com> On 06/05/2012 09:49, Cameron Simpson wrote: > On 06May2012 09:18, Bob Cowdery wrote: > | On 05/05/2012 23:05, Cameron Simpson wrote: > | > On 05May2012 20:33, Bob Cowdery wrote: > | > | [...] calls to time.time() always return the same > | > | time which is usually several seconds in the past or future and always > | > | has no fractional part. > | > > | > Thought #1: you are calling time.time() and haven't unfortunately > | > renamed it? (I doubt this scenario, though the lack of fractional part > | > is interesting.) > | > | Not sure what you mean by renamed it. > > Like this: > > from time import time > [...] > time = some_unfortunate_other_function > [...] > now = time() # calls wrong function > > It seems unlikely, but possible. > > | I also tried datetime and that had > | the same behaviour. > > Makes my suggestion even less likely unless the time module itself gets > monkeypatched (i.e. "time.time = bad_function" somewhere). I don't think the function is subverted unless there is some way inside the vendor SDK or even DirectShow (the SDK uses this as a COM object) which can somehow hijack it. It does catch up every few minutes so there has to be a clue there. > | > | If I leave it long enough time will suddently > | > | jump forward after a few minutes, then again after a few minutes more. > | > | > | > | I've never encountered this behaviour before and can't understand what > | > | on earth is going on. If I call the 'C' time() function just the other > | > | side of my call to the extension the time is ticking along fine. It's > | > | just the one Python thread that is affected. > | > [...] > | > > | > Thought #2: On a UNIX system I'd be running the process under strace (or > | > dtrace or ktrace depending on flavour) to see what actual OS system calls are > | > being made during this behaviour. Is this feasible for you? > | > | I'm on Windows for this particular part of the application. > > I'd guessed so. I've no Windows programming background; I was wondering > if there was something like this you had to hand on windows. Maybe, but not that I know of. > | [...] But debugging into this is probably the only way. I > | looked at the built-in time module. As far as I can tell it just calls > | the underlying C time() function as an extension. This is more > | mystifying as that is pretty much what I'm doing by checking the time in > | my own extension module where it ticks along fine. > > Hmm. A C extension I presume? How about writing a little pure Python > thread to call time.time(), and spin it off parallel to the rest of the > app; does it also get bad time.time() behaviour? I've tried that. It's only the Python thread (or Python main thread) that calls the extension that behaves like this. Other Python threads tick along fine with the correct time including a fractional part. > | I have another > | scenario using a different part of their SDK where the time does still > | tick but the fractional part is frozen, not 0 but frozen. > > Curiouser and curiouser. Indeed. Away now but battle will resume on Tuesday. Bob From jmwebaze at gmail.com Sun May 6 11:57:39 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 17:57:39 +0200 Subject: sorting 1172026 entries Message-ID: I have several lists with approx 1172026 entries. I have been trying to sort the records, but have failed.. I tried lists.sort() i also trired sorted python's inbuilt method. This has been running for weeks. Any one knows of method that can handle such lists. cheers -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin at schollnick.net Sun May 6 12:07:24 2012 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Sun, 6 May 2012 12:07:24 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On May 6, 2012, at 11:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to sort the records, but have failed.. I tried lists.sort() i also trired sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. The issue there is the sheer size of the list. I can't think of an algorithium that wouldn't have a problem with a list of that size. Two suggestions.... 1) Is there no other way to organize this data, other than having it in a single list? You can't organize it by, for example, zip code, area code, year, or something, and make multiple lists? Reducing the size would speed the sort up. 2) Maybe consider a different storage method, for example, adding the data into a database? And then connecting to the database via python? - Benjamin -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Sun May 6 12:09:22 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 May 2012 12:09:22 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 11:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to sort > the records, but have failed.. I tried lists.sort() i also trired sorted > python's?inbuilt?method. This has been running for?weeks. Sorting 1172026 random floats takes about 1.5 seconds to do on my machine. More complicated objects take more time, but usually not that much more time. What exactly are you sorting? -- Devin From jmwebaze at gmail.com Sun May 6 12:10:08 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:10:08 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 6:07 PM, Benjamin Schollnick wrote: > > On May 6, 2012, at 11:57 AM, J. Mwebaze wrote: > > I have several lists with approx 1172026 entries. I have been trying to > sort the records, but have failed.. I tried lists.sort() i also trired > sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. > > > The issue there is the sheer size of the list. I can't think of an > algorithium that wouldn't have a problem with a list of that size. > > Two suggestions.... > > 1) Is there no other way to organize this data, other than having it in a > single list? You can't organize it by, for example, zip code, area code, > year, or something, and make multiple lists? Reducing the size would speed > the sort up. > > 2) Maybe consider a different storage method, for example, adding the data > into a database? And then connecting to the database via python? > > - Benjamin > > I could try the database option.. -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:11:44 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:11:44 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 6:09 PM, Devin Jeanpierre wrote: > On Sun, May 6, 2012 at 11:57 AM, J. Mwebaze wrote: > > I have several lists with approx 1172026 entries. I have been trying to > sort > > the records, but have failed.. I tried lists.sort() i also trired sorted > > python's inbuilt method. This has been running for weeks. > > Sorting 1172026 random floats takes about 1.5 seconds to do on my > machine. More complicated objects take more time, but usually not that > much more time. What exactly are you sorting? > > -- Devin > [ (datatime, int) ] * 1172026 -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Sun May 6 12:21:45 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 6 May 2012 12:21:45 -0400 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: > [ (datatime, int) ] *?1172026 I can't duplicate slowness. It finishes fairly quickly here. Maybe you could try posting specific code? It might be something else that is making your program take forever. >>> x = [(datetime.datetime.now() + datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ in xrange(1172026)] >>> random.shuffle(x) >>> x.sort() >>> -- Devin From jmwebaze at gmail.com Sun May 6 12:26:31 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:26:31 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: I have attached one of the files, try to sort and let me know the results. Kindly sort by date. ooops - am told the file exceed 25M. below is the code import glob txtfiles =glob.glob('*.txt') import dateutil.parser as parser for filename in txtfiles: temp=[] f=open(filename) for line in f.readlines(): line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) temp=sorted(temp) with open(filename.strip('.txt')+ '.sorted', 'wb') as p: for i, j in temp: p.write('%s %s\n' %(str(i),j)) On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: > On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: > > [ (datatime, int) ] * 1172026 > > I can't duplicate slowness. It finishes fairly quickly here. Maybe you > could try posting specific code? It might be something else that is > making your program take forever. > > >>> x = [(datetime.datetime.now() + > datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ > in xrange(1172026)] > >>> random.shuffle(x) > >>> x.sort() > >>> > > -- Devin > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:29:10 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:29:10 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: sorry see, corrected code for filename in txtfiles: temp=[] f=open(filename) for line in f.readlines(): line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) temp=sorted(temp) with open(filename.strip('.txt')+ '.sorted', 'wb') as p: for i, j in temp: p.write('%s %s\n' %(str(i),j)) On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze wrote: > I have attached one of the files, try to sort and let me know the results. > Kindly sort by date. ooops - am told the file exceed 25M. > > below is the code > > import glob > txtfiles =glob.glob('*.txt') > import dateutil.parser as parser > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: > >> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: >> > [ (datatime, int) ] * 1172026 >> >> I can't duplicate slowness. It finishes fairly quickly here. Maybe you >> could try posting specific code? It might be something else that is >> making your program take forever. >> >> >>> x = [(datetime.datetime.now() + >> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ >> in xrange(1172026)] >> >>> random.shuffle(x) >> >>> x.sort() >> >>> >> >> -- Devin >> > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Sun May 6 12:36:37 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Sun, 6 May 2012 18:36:37 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: I noticed the error in code please ignore this post.. On Sun, May 6, 2012 at 6:29 PM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze wrote: > >> I have attached one of the files, try to sort and let me know the >> results. Kindly sort by date. ooops - am told the file exceed 25M. >> >> below is the code >> >> import glob >> txtfiles =glob.glob('*.txt') >> import dateutil.parser as parser >> >> >> for filename in txtfiles: >> temp=[] >> f=open(filename) >> for line in f.readlines(): >> line = line.strip() >> line=line.split() >> temp.append((parser.parse(line[0]), float(line[1]))) >> temp=sorted(temp) >> with open(filename.strip('.txt')+ '.sorted', 'wb') as p: >> for i, j in temp: >> p.write('%s %s\n' %(str(i),j)) >> >> >> On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote: >> >>> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze wrote: >>> > [ (datatime, int) ] * 1172026 >>> >>> I can't duplicate slowness. It finishes fairly quickly here. Maybe you >>> could try posting specific code? It might be something else that is >>> making your program take forever. >>> >>> >>> x = [(datetime.datetime.now() + >>> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _ >>> in xrange(1172026)] >>> >>> random.shuffle(x) >>> >>> x.sort() >>> >>> >>> >>> -- Devin >>> >> >> >> >> -- >> *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze >> | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze >> >> /* Life runs on code */* >> >> > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary.herron at islandtraining.com Sun May 6 12:37:53 2012 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 06 May 2012 09:37:53 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <4FA6A8E1.3040001@islandtraining.com> On 05/06/2012 09:29 AM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) Don't do temp = sorted(temp) That will create a *new* copy of the list to sort, and the assignment will free up the original list for deletion and garbage collection. Instead do the in-place sort: temp.sort() Same result, less thrashing. This will make your program slightly more efficient, HOWEVER, it is not the solution of your week-long sort problem. Gary Herron > > > On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze > wrote: > > I have attached one of the files, try to sort and let me know the > results. Kindly sort by date. ooops - am told the file exceed 25M. > > below is the code > > import glob > txtfiles =glob.glob('*.txt') > import dateutil.parser as parser > > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > > > On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre > > wrote: > > On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze > > wrote: > > [ (datatime, int) ] * 1172026 > > I can't duplicate slowness. It finishes fairly quickly here. > Maybe you > could try posting specific code? It might be something else > that is > making your program take forever. > > >>> x = [(datetime.datetime.now() + > datetime.timedelta(random.getrandbits(10)), > random.getrandbits(32)) for _ in xrange(1172026)] > >>> random.shuffle(x) > >>> x.sort() > >>> > > -- Devin > > > > > -- > *Mob UG: +256 (0) 70 1735800 > | NL +31 (0) 6 852 841 38 > | Gtalk: jmwebaze | > skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > > /* Life runs on code */* > > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: > jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > > /* Life runs on code */* > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at gmail.com Sun May 6 12:49:41 2012 From: thudfoo at gmail.com (xDog Walker) Date: Sun, 6 May 2012 09:49:41 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <201205060949.42169.thudfoo@gmail.com> On Sunday 2012 May 06 09:29, J. Mwebaze wrote: > ?temp=sorted(temp) Change to: temp.sort() RTFM on sorted() and .sort(). -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From clp2 at rebertia.com Sun May 6 13:03:36 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 6 May 2012 10:03:36 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On Sun, May 6, 2012 at 9:29 AM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: > ? ?temp=[] > ? ?f=open(filename) Why not use `with` here too? > ? ?for line in f.readlines(): readlines() reads *the entire file contents* into memory all at once! Use `for line in f:` instead, which will read from the file one line at a time. > ? ? ?line = line.strip() > ? ? ?line=line.split() > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) > ? ?temp=sorted(temp) As already pointed out, use temp.sort() instead. > ? ?with open(filename.strip('.txt')+ '.sorted', 'wb') as p: strip() doesn't do quite what you think it does: $ python Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) >>> '.xtx.foo'.strip('.txt') 'foo' >>> Consult the docs. Also, please avoid top-posting in the future. Cheers, Chris From stefan_ml at behnel.de Sun May 6 13:15:07 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 06 May 2012 19:15:07 +0200 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: J. Mwebaze, 06.05.2012 18:29: > sorry see, corrected code > > for filename in txtfiles: > temp=[] > f=open(filename) > for line in f.readlines(): > line = line.strip() > line=line.split() > temp.append((parser.parse(line[0]), float(line[1]))) > temp=sorted(temp) > with open(filename.strip('.txt')+ '.sorted', 'wb') as p: > for i, j in temp: > p.write('%s %s\n' %(str(i),j)) > >> I have attached one of the files, try to sort and let me know the results. >> Kindly sort by date. ooops - am told the file exceed 25M. >> >> below is the code >> >> import glob >> txtfiles =glob.glob('*.txt') >> import dateutil.parser as parser >> >> >> for filename in txtfiles: >> temp=[] >> f=open(filename) >> for line in f.readlines(): >> line = line.strip() >> line=line.split() >> temp.append((parser.parse(line[0]), float(line[1]))) >> temp=sorted(temp) >> with open(filename.strip('.txt')+ '.sorted', 'wb') as p: >> for i, j in temp: >> p.write('%s %s\n' %(str(i),j)) How much memory do you have on your system? Does the list fit into memory easily or is it swapping to disk while you are running the sort? Stefan From alec.taylor6 at gmail.com Sun May 6 15:11:58 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 7 May 2012 05:11:58 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: Also, is there a reason you are sorting the data-set after insert rather than using a self-sorting data-structure? A well chosen self-sorting data-structure is always more efficient when full data flow is controlled. I.e.: first insert can be modified to use the self-sorting data-structure I cannot think of a situation requiring permanently sorted data-sets which would be better served with a non-self-sorting data-structure except those where you do not have full data-flow control. From breamoreboy at yahoo.co.uk Sun May 6 15:52:56 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 06 May 2012 20:52:56 +0100 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: On 06/05/2012 20:11, Alec Taylor wrote: > Also, is there a reason you are sorting the data-set after insert > rather than using a self-sorting data-structure? > > A well chosen self-sorting data-structure is always more efficient > when full data flow is controlled. > > I.e.: first insert can be modified to use the self-sorting data-structure > > I cannot think of a situation requiring permanently sorted data-sets > which would be better served with a non-self-sorting data-structure > except those where you do not have full data-flow control. Possibly blist from http://pypi.python.org/pypi/blist/1.3.4 ? -- Cheers. Mark Lawrence. From drsalists at gmail.com Sun May 6 18:30:25 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 6 May 2012 15:30:25 -0700 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: How much physical RAM (not the virtual memory, but the physical memory) does your machine have available? We know the number of elements in your dataset, but how big are the individual elements? If a sort is never completing, you're probably swapping. list.sort() is preferrable to sorted(list), if you need to conserve memory. A self-sorting datastructure like a B Tree or whatever is rarely faster than using a good sorting algorithm, assuming that you only need to sort the data once per program invocation. If you're sorting the data in a loop, then yes, a self-sorting datastructure is most likely a much better idea. I've started a page about python trees and heaps at http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ - but again, unless you're sorting in a loop, you're probably better off with a good sorting algorithm, and Python's built-in Timsort is excellent for all-in-RAM sorting. If you have too much data to sort in RAM all at once, it's best to sort sublists that -do- fit in memory, using something like list_.sort() (that's Timsort by another name in CPython), and then write the sorted sublists to disk for subsequent merging using the merge step of a mergesort. If you just need something quick-to-code, GNU sort(1) is very highly optimized (for a text-based sort), and will sort datasets that are larger than your physical memory efficiently using an algorithm similar to (not identical) what I described in the previous paragraph. It's /usr/bin/sort on most Linux systems, and is available for a large number of other operating systems including windows via http://cygwin.com/ or https://github.com/bmatzelle/gow/wiki/ On Sun, May 6, 2012 at 8:57 AM, J. Mwebaze wrote: > I have several lists with approx 1172026 entries. I have been trying to > sort the records, but have failed.. I tried lists.sort() i also trired > sorted python's inbuilt method. This has been running for weeks. > > Any one knows of method that can handle such lists. > > cheers > > > > -- > *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze > | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze > > /* Life runs on code */* > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sun May 6 19:54:16 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 09:54:16 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120506235416.GA13895@cskk.homeip.net> On 06May2012 18:36, J. Mwebaze wrote: | > for filename in txtfiles: | > temp=[] | > f=open(filename) | > for line in f.readlines(): | > line = line.strip() | > line=line.split() | > temp.append((parser.parse(line[0]), float(line[1]))) Have you timed the different parts of your code instead of the whole thing? Specificly, do you know the sort time is the large cost? I would point out that the loop above builds the list by append(), one item at a time. That should have runtime cost of the square of the list length, 1172026 * 1172026. Though I've just done this: [Documents/python]oscar1*> python Python 2.7.3 (default, May 4 2012, 16:19:02) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> L1 = [] >>> for i in range(1000000): L1.append(0) ... and it only took a few seconds. As pointed out by others, the readlines() is also a little expensive, conceivably similarly so (it also needs to build a huge list). Anyway, put some: print time.time() at various points. Not in the inner bits of the loops, but around larger chunks, example: from time import time temp=[] f=open(filename) print "after open", time() lines = f.readlines() print "after readlines", time() for line in lines: line = line.strip() line=line.split() temp.append((parser.parse(line[0]), float(line[1]))) print "after read loop", time() and so on. AT least then you will have more feel for what part of your code is taking so long. Ceers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The shortest path between any two truths in the real domain passes through the complex domain. - J. Hadamand From clp2 at rebertia.com Sun May 6 20:10:22 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 6 May 2012 17:10:22 -0700 Subject: sorting 1172026 entries In-Reply-To: <20120506235416.GA13895@cskk.homeip.net> References: <20120506235416.GA13895@cskk.homeip.net> Message-ID: On Sun, May 6, 2012 at 4:54 PM, Cameron Simpson wrote: > On 06May2012 18:36, J. Mwebaze wrote: > | > for filename in txtfiles: > | > ? ?temp=[] > | > ? ?f=open(filename) > | > ? ?for line in f.readlines(): > | > ? ? ?line = line.strip() > | > ? ? ?line=line.split() > | > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) > > Have you timed the different parts of your code instead of the whole > thing? > > Specificly, do you know the sort time is the large cost? > > I would point out that the loop above builds the list by append(), one > item at a time. That should have runtime cost of the square of the list > length, 1172026 * 1172026. Though I've just done this: Er, what? list.append() is O(1) amortized. Perhaps you're confusing list.append() with list.insert(), which is indeed O(n)? Cheers, Chris From cs at zip.com.au Sun May 6 20:31:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 10:31:14 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120507003113.GA16860@cskk.homeip.net> On 06May2012 17:10, Chris Rebert wrote: | On Sun, May 6, 2012 at 4:54 PM, Cameron Simpson wrote: | > On 06May2012 18:36, J. Mwebaze wrote: | > | > for filename in txtfiles: | > | > ? ?temp=[] | > | > ? ?f=open(filename) | > | > ? ?for line in f.readlines(): | > | > ? ? ?line = line.strip() | > | > ? ? ?line=line.split() | > | > ? ? ?temp.append((parser.parse(line[0]), float(line[1]))) | > | > Have you timed the different parts of your code instead of the whole | > thing? | > | > Specificly, do you know the sort time is the large cost? | > | > I would point out that the loop above builds the list by append(), one | > item at a time. That should have runtime cost of the square of the list | > length, 1172026 * 1172026. Though I've just done this: | | Er, what? list.append() is O(1) amortized. I didn't mean per .append() call (which I'd expect to be O(n) for large n), I meant overall for the completed list. Don't the realloc()s make it O(n^2) overall for large n? The list must get copied when the underlying space fills. I confess to being surprised at how quick it went for me though. I suppose reallocing in chunks (eg to double the available size) might conceal this for a while. It should still be well over O(n) overall (not amortised per .append() call). | Perhaps you're confusing list.append() with list.insert(), which is indeed O(n)? I wasn't, though .insert() is surely way more expensive. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The Borg assimilated my race and all I got was this lousy tagline. - Cath Lawrence From rosuav at gmail.com Sun May 6 21:02:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 May 2012 11:02:57 +1000 Subject: sorting 1172026 entries In-Reply-To: <20120507003113.GA16860@cskk.homeip.net> References: <20120507003113.GA16860@cskk.homeip.net> Message-ID: On Mon, May 7, 2012 at 10:31 AM, Cameron Simpson wrote: > I didn't mean per .append() call (which I'd expect to be O(n) for large > n), I meant overall for the completed list. > > Don't the realloc()s make it O(n^2) overall for large n? The list > must get copied when the underlying space fills. I confess to being > surprised at how quick it went for me though. I suppose reallocing in > chunks (eg to double the available size) might conceal this for a while. > It should still be well over O(n) overall (not amortised per .append() > call). I haven't checked the CPython code, but the usual way to do reallocations is to double the size (or add 50% or something) each time, meaning that as n increases, the frequency of reallocations decreases - hence the O(1) amortized time. In any case, it's the recommended way to build large strings: s = "" while condition: s += "some_value" versus: s = [] while condition: s.append("some_value") s = "".join(s) so I would be very much surprised if this common wisdom is merely replacing one O(n*n) operation with another O(n*n) operation. ChrisA From scubacuda at gmail.com Sun May 6 22:12:42 2012 From: scubacuda at gmail.com (Rogelio) Date: Sun, 6 May 2012 19:12:42 -0700 Subject: new to Python - modules to leverage Perl scripts? Message-ID: I've got quite a few Perl scripts that I would like to leverage, and I'd like to make some Python wrapper scripts for them. The Perl scripts shell into various network appliances, run certain commands, and then output those commands into a file. I recently found out about the subprocess modules (including "call") and am wondering what other Python libraries and modules I should check out. Specifically, I need functions that will do the following... 1) Take a big IP file and break it up into smaller chunks (e.g. 20 IP addresses per file) 2) Run the Perl script on those smaller IP files 3) Run the Perl commands in parallel (to take less time) 4) Take the little logs and concatenate the files 5) Look for existence of certain strings in the logs I'm still playing with the subprocess.call command to make sure that it calls everything okay. But I'm hoping someone can point me where to look for functions that will make this an effective wrapper script. From nospam at nospam.com Sun May 6 23:08:06 2012 From: nospam at nospam.com (Javier) Date: Mon, 7 May 2012 03:08:06 +0000 (UTC) Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: > Learn how to use a database. Creating and managing a > big collection of directories to handle small data items is the > wrong approach to data storage. > > John Nagle Or not... Using directories may be a way to do rapid prototyping, and check quickly how things are going internally, without needing to resort to complex database interfaces. Just a quote from the history of usenet: I wrote the very first version of netnews as a 150-line shellscript. It had multiple newsgroups and cross-posting; newsgroups were directories and cross-posting was implemented as multiple links to the article. It was far too slow to use for production, but the flexibility permitted endless experimentation with the protocol design. -- Steven M. Bellovin http://www.linuxtopia.org/online_books/programming_books/art_of_unix_programming/ch14s04_2.html for the question of the OP: import string import os namefile="..." for line in open("foobar").readlines() dirname,number=string.split(line) os.system("mkdir "+dirname) f=open(dirname+"/"+namefile,"w") f.write("TEXT..."+number) f.close() Portability can be improved by using os.path or something like that. John Nagle wrote: > On 4/30/2012 8:19 AM, deltaquattro at gmail.com wrote: >> Hi, >> >> I would like to automate the following task under Linux. I need to create a set of directories such as >> >> 075 >> 095 >> 100 >> 125 >> >> The directory names may be read from a text file foobar, which also contains a number corresponding to each dir, like this: >> >> 075 1.818 >> 095 2.181 >> 100 2.579 >> 125 3.019 >> >> >> In each directory I must copy a text file input.in. This file contains two lines which need to be edited: > From no.email at nospam.invalid Mon May 7 00:59:59 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 06 May 2012 21:59:59 -0700 Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> Message-ID: <7x62c8bn74.fsf@ruckus.brouhaha.com> Javier writes: > Or not... Using directories may be a way to do rapid prototyping, and > check quickly how things are going internally, without needing to resort > to complex database interfaces. dbm and shelve are extremely simple to use. Using the file system for a million item db is ridiculous even for prototyping. From nagle at animats.com Mon May 7 01:21:46 2012 From: nagle at animats.com (John Nagle) Date: Sun, 06 May 2012 22:21:46 -0700 Subject: key/value store optimized for disk storage In-Reply-To: References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: On 5/4/2012 12:14 AM, Steve Howell wrote: > On May 3, 11:59 pm, Paul Rubin wrote: >> Steve Howell writes: >>> compressor = zlib.compressobj() >>> s = compressor.compress("foobar") >>> s += compressor.flush(zlib.Z_SYNC_FLUSH) >> >>> s_start = s >>> compressor2 = compressor.copy() That's awful. There's no point in compressing six characters with zlib. Zlib has a minimum overhead of 11 bytes. You just made the data bigger. John Nagle From no.email at nospam.invalid Mon May 7 01:34:52 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 06 May 2012 22:34:52 -0700 Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <7xlil44kqr.fsf@ruckus.brouhaha.com> John Nagle writes: > That's awful. There's no point in compressing six characters > with zlib. Zlib has a minimum overhead of 11 bytes. You just > made the data bigger. This hack is about avoiding the initialization overhead--do you really get 11 bytes after every SYNC_FLUSH? I do remember with that SYNC_FLUSH trick, that I got good compression with a few hundred bytes of input (the records I was dealing with at the time). From yegorslists at googlemail.com Mon May 7 02:54:50 2012 From: yegorslists at googlemail.com (Yegor Yefremov) Date: Sun, 6 May 2012 23:54:50 -0700 (PDT) Subject: Override path to python during installation (setuptools) Message-ID: <14367991.255.1336373690973.JavaMail.geo-discussion-forums@ynmk20> I'm trying to add lava-test package to Buildroot. After "cross-compilation" I get following path in the /usr/bin/lava: #!/home/user/MyProjects/versioned/buildroot/output/host/usr/bin/python instead of #!/usr/bin/python I use following command to install lava_test package: +define LAVA_TEST_INSTALL_TARGET_CMDS + (cd $(@D); PYTHONPATH="$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages"\ + $(HOST_DIR)/usr/bin/python setup.py install --prefix=$(TARGET_DIR)/usr) +endef How can I override this auto-generated path? The whole patch can be seen here: http://patchwork.ozlabs.org/patch/155498/ Regards, Yegor From __peter__ at web.de Mon May 7 03:16:20 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 May 2012 09:16:20 +0200 Subject: new to Python - modules to leverage Perl scripts? References: Message-ID: Rogelio wrote: > I've got quite a few Perl scripts that I would like to leverage, and > I'd like to make some Python wrapper scripts for them. > > The Perl scripts shell into various network appliances, run certain > commands, and then output those commands into a file. > > I recently found out about the subprocess modules (including "call") > and am wondering what other Python libraries and modules I should > check out. Specifically, I need functions that will do the > following... > > 1) Take a big IP file and break it up into smaller chunks (e.g. 20 IP > addresses per file) itertools.islice() > 2) Run the Perl script on those smaller IP files subprocess. If the script can read from stdin you may not need the intermediate file; use subprocess.Popen(..., stdin=PIPE).communicate(inputdata_as_a_string) instead. > 3) Run the Perl commands in parallel (to take less time) multiprocessing? Though your problem may be I/O-bound. > 4) Take the little logs and concatenate the files itertools.chain.from_iterable() > 5) Look for existence of certain strings in the logs with open(logfile) as f: for line in f: if some_string in line: # whatever If you know Perl you will not be completely puzzled when you have to switch to a regex. You'll rather make that switch to early ;) > I'm still playing with the subprocess.call command to make sure that > it calls everything okay. But I'm hoping someone can point me where > to look for functions that will make this an effective wrapper script. You sound like you are not completely satisfied with subprocess. What are you missing? From cs at zip.com.au Mon May 7 03:37:21 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 May 2012 17:37:21 +1000 Subject: new to Python - modules to leverage Perl scripts? In-Reply-To: References: Message-ID: <20120507073721.GA10158@cskk.homeip.net> On 07May2012 09:16, Peter Otten <__peter__ at web.de> wrote: | Rogelio wrote: | > I've got quite a few Perl scripts that I would like to leverage, and | > I'd like to make some Python wrapper scripts for them. | > | > The Perl scripts shell into various network appliances, run certain | > commands, and then output those commands into a file. | > | > I recently found out about the subprocess modules (including "call") | > and am wondering what other Python libraries and modules I should | > check out. Specifically, I need functions that will do the | > following... [...] | > 2) Run the Perl script on those smaller IP files | | subprocess. If the script can read from stdin you may not need the | intermediate file; use | | subprocess.Popen(..., stdin=PIPE).communicate(inputdata_as_a_string) | | instead. | | > 3) Run the Perl commands in parallel (to take less time) | | multiprocessing? Though your problem may be I/O-bound. If he stuffs the inputs into TemporaryFiles he can attach them to subprocess.Popen() stdin and just not wait. Dispatch them all and collect afterwards. Only tempfile and subprocess needed; no need for communicate. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ One of the most important things you learn from the internet is that there is no 'them' out there. It's just an awful lot of 'us'. - Douglas Adams From bwalker at itree.com.au Mon May 7 03:57:22 2012 From: bwalker at itree.com.au (nbw) Date: Mon, 7 May 2012 00:57:22 -0700 (PDT) Subject: Scrapy - importing files from local, rather than www Message-ID: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> Hi everyone, I'm new to Python (loving it!) and Scrapy. I have a question I just can't seem to get my head around. I can get a simple Scrapy spider to pick up URLs and download them fine, but the HTML files I have are stored locally. The reason for this, is for some reason when I "Save As" the pages I get everything, whereas if Scrapy runs over them it seems to miss certain areas where there's Javascript. So, I have them sitting in a directory (C:/scrapy_test) but can't for the life of me get Scrapy to find them. Is there anyone who's had this problem and solved it, or can help? Any help is much appreciated. Kind regards, nbw From Nadhiya.A at lnties.com Mon May 7 04:42:39 2012 From: Nadhiya.A at lnties.com (Nadhiya A) Date: Mon, 7 May 2012 08:42:39 +0000 Subject: problem in event handling on change of variable value. Message-ID: Hi, I want know how can I control Canoe tool from Python. I want to use Python as the mediator for linking CANoe and Matlab. Please give me some inputs regarding this. Thanks & Regards Nadhiya.A Larsen & Toubro Limited www.larsentoubro.com This Email may contain confidential or privileged information for the intended recipient (s). If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system. Earth Day. Every Day. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramapraba2653 at gmail.com Mon May 7 06:10:01 2012 From: ramapraba2653 at gmail.com (SUPREME) Date: Mon, 7 May 2012 03:10:01 -0700 (PDT) Subject: LATEST HOT PHOTOS & VIDEOS Message-ID: <9a6a80ce-1fa3-4dab-938c-931e1e87a992@to5g2000pbc.googlegroups.com> TOP DOT NET INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html Rajsekhar Mahankali Movie Stills http://actressgallery-kalyani.blogspot.in/2012/03/mahankali-movie-stills.html Mamata 100% Prema Movie Hot Stills http://actressgallery-kalyani.blogspot.in/2012/03/mamata-100-prema-movie-stills.html Raviteja Daruvu Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/daruvu-movie-stills.html NUVVA NENA MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/03/nuvva-nena-movie-stills.html Yadartha Prema Katha Movie Latest stills http://actressgallery-kalyani.blogspot.in/2012/03/yadartha-prema-katha-movie-stills.html RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From aya.exam at gmail.com Mon May 7 06:23:09 2012 From: aya.exam at gmail.com (Exam Aya) Date: Mon, 7 May 2012 03:23:09 -0700 (PDT) Subject: Workshop on Design Patterns and Advanced OOPS, Bangalore Message-ID: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> Workshop on Design Patterns and Advanced OOPS Date: Sunday , 13th May, 2012 At Bangalore Hurry Register Online Now https://docs.google.com/spreadsheet/viewform?formkey=dGlMMnEtYmJVY2M3bEhNZG5WY3BHTkE6MA#gid=0 About the workshop: For anyone working on object oriented programing languages like C++, Java, C#, Python, PHP, etc. this workshop is a must. It goes through the set of design patterns that started it all - Go4 - (Gang of 4) patterns. The workshop will very interactive and each design pattern will be explored rather than taught or lectured on. A problem statement will be provided and the group will move towards why the design pattern is required. This will not only drill into you why use a pattern in the first place but also which pattern to use in what scenario. Course Contents (Day 1) 1. The Pit Falls of OOPS - Refresher on OOPS - When does OOPS get confusing 2. Design Pattern Intro - What are Design Patterns - What are its uses and applications 3. Design Patterns - Strategy Pattern - Observer Pattern Course Contents (Day 1) - Decorator Pattern - Factory Pattern - Singleton Pattern - Command Pattern - Adapter Pattern - Facade Pattern - Template Pattern - Iterator Pattern - Composite Pattern - State Pattern Time : 09:30 am to 05:30 pm Venue: 1910, 8th A Cross (road connects 4th Main and 6th Main), HAL 3rd Stage (New Thippasandira), Bangalore - 75 Email events at examaya.com Website: www.examaya.com Course Fees: Rs. 750 Cost of Course Materials, Refreshments and Lunch Hurry Register Online Now! https://docs.google.com/spreadsheet/viewform?formkey=dGlMMnEtYmJVY2M3bEhNZG5WY3BHTkE6MA#gid=0 About the Speaker: Sethuraman is a passionate Java programmer who is currently working in Thoughtworks. He has a total of 8 years of experience in the industry and is a very "hands on guy". He is known in the professional circle for his excellent communication From varma.nikhil22 at gmail.com Mon May 7 07:31:20 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 7 May 2012 17:01:20 +0530 Subject: return respective values when mutiple keys are passed in dictionary Message-ID: HI All I was clearing my concepts on dictionary and stuck in this problem. I have a dictionary which i have formed by using zip function on two list so that one list (which i have hardcoded) becomes the keys and the other list becomes its values. Now i want to know how can i get the values of keys at once if i pass the keys in a dictionary. Let say I have a dictionary mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} Now if i do :- mydict.get('a') 'apple' What i want is some i pass keys in get and in return i should have all the values of those keys which i pass. ################## mydict.get('a','b','c') ###demo for what i want 'apple','boy','cat' ### Output i want ################# -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hash.3g at gmail.com Mon May 7 07:36:57 2012 From: hash.3g at gmail.com (=?KOI8-R?B?98nUwczJyiD3z8zLz9c=?=) Date: Mon, 7 May 2012 14:36:57 +0300 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: You can try to use map(mydict.get, ('a', 'b', 'c')) and then make join On May 7, 2012 2:33 PM, "Nikhil Verma" wrote: > HI All > > I was clearing my concepts on dictionary and stuck in this problem. > I have a dictionary which i have formed by using zip function on two list > so that one list (which i have hardcoded) becomes the keys and the other > list > becomes its values. > > Now i want to know how can i get the values of keys at once if i pass the > keys in a dictionary. > > Let say I have a dictionary > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' > > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c') ###demo for what i want > 'apple','boy','cat' ### Output i want > ################# > > -- > Regards > Nikhil Verma > +91-958-273-3156 > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ferreirafm at lim12.fm.usp.br Mon May 7 07:48:16 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Mon, 7 May 2012 04:48:16 -0700 (PDT) Subject: [SOLVED] for-loop: weird behavior In-Reply-To: <1336163619790-4953214.post@n6.nabble.com> References: <1336163619790-4953214.post@n6.nabble.com> Message-ID: <1336391296054-4957597.post@n6.nabble.com> The problem has been solved opening the file for iteration in the second loop. I didn't realized such Python behavior. Any comments are appreciated. Fred -- View this message in context: http://python.6.n6.nabble.com/SOLVED-for-loop-weird-behavior-tp4953214p4957597.html Sent from the Python - python-list mailing list archive at Nabble.com. From dinkypumpkin at gmail.com Mon May 7 09:13:28 2012 From: dinkypumpkin at gmail.com (dinkypumpkin at gmail.com) Date: Mon, 7 May 2012 06:13:28 -0700 (PDT) Subject: PyTextile Question In-Reply-To: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> References: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> Message-ID: <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> On Friday, 4 May 2012 04:39:47 UTC+1, Josh English wrote: > However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved. I think any Textile implementation will preserve line breaks within a paragraph by converting them to BR tags. Both RedCloth and PyTextile do, anyway. > I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks. Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV. import re, textile print "INPUT1:" s1 = """This is a long multi-line description with several paragraphs and hopefully, eventually, proper HTML P-tags. This is a new paragraph. It should be surrounded by its own P-tag. Hopefully (again), I won't have a bunch of unwanted BR tags thrown in.""" print(s1) print "OUTPUT1:" html1 = textile.textile(s1) print(html1) print "INPUT2:" s2 = re.sub(r'[ \t]*\n[ \t]*(\n?)[ \t]*', r' \1\1', s1, flags=re.MULTILINE) print(s2) print "OUTPUT2:" html2 = textile.textile(s2) print(html2) From arnodel at gmail.com Mon May 7 09:40:02 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 7 May 2012 14:40:02 +0100 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: On 7 May 2012 12:31, Nikhil Verma wrote: > HI All > > I was clearing my concepts on dictionary and stuck in this problem. > I have a dictionary which i have formed by using zip function on two list so > that one list (which i have hardcoded) becomes the keys and the other list > becomes its values. > > Now i want to know how can i get the values of keys at once if i pass the > keys in a dictionary. > > Let say I have a dictionary > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' mydict['a'] is the usual way to get the value associated with a key. The difference is that it will throw an exception if the key doesn't exist, which is most of the time the sanest thing to do. > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c')??? ###demo for what i want > 'apple','boy','cat'??????? ### Output i want > ################# 1. You can use a list comprehension >>> [mydict[k] for k in 'a', 'b', 'c'] ['apple', 'boy', 'cat'] 2. You can use map (for python 3.X, you need to wrap this in list(...)) >>> map(mydict.__getitem__, ['a', 'b', 'c']) ['apple', 'boy', 'cat'] 3. You can use operator.itemgetter >>> from operator import itemgetter >>> itemgetter('a', 'b', 'c')(mydict) ('apple', 'boy', 'cat') -- Arnaud From rosuav at gmail.com Mon May 7 09:45:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 May 2012 23:45:46 +1000 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: On Mon, May 7, 2012 at 9:31 PM, Nikhil Verma wrote: > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > Now if i do :- > > mydict.get('a') > 'apple' > > What i want is some i pass keys in get and in return i should have all the > values of those keys which i pass. > > ################## > mydict.get('a','b','c')??? ###demo for what i want > 'apple','boy','cat'??????? ### Output i want > ################# Presumably you want to get back a list or tuple, so a list comprehension is your best bet. [mydict.get(i) for i in ('a','b','c')] Incidentally, are you aware that dictionaries can be subscripted? The get() method is good when you want a default value for anything that doesn't exist, otherwise you can simply use: mydict['a'] ChrisA From showell30 at yahoo.com Mon May 7 12:39:05 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 7 May 2012 09:39:05 -0700 (PDT) Subject: key/value store optimized for disk storage References: <55a42726-ea50-4d80-b89e-d168eab34d4c@is10g2000pbc.googlegroups.com> <7xsjfinfr7.fsf@ruckus.brouhaha.com> <9eecdd75-fda3-40d0-b9ec-3249296e39f7@t2g2000pbg.googlegroups.com> <7x62cehri0.fsf@ruckus.brouhaha.com> <0d89db6a-b701-4640-9ab9-3d03152fd8ba@k10g2000pbk.googlegroups.com> <7xtxzx3h9n.fsf@ruckus.brouhaha.com> <7xpqal3gld.fsf@ruckus.brouhaha.com> <3d747912-8e10-480d-acad-939f067e49a8@jx17g2000pbb.googlegroups.com> <7xhavw4l3o.fsf@ruckus.brouhaha.com> <52964842-9842-46ef-bca9-ee6e84b53482@vy9g2000pbc.googlegroups.com> <7xhavwiiuh.fsf@ruckus.brouhaha.com> <985784e4-251c-4841-8022-cb3e85121a68@iu9g2000pbc.googlegroups.com> <7xy5p8h1n4.fsf@ruckus.brouhaha.com> Message-ID: <2322bfb1-217e-40af-ac43-bc3f2ec3db91@qg3g2000pbc.googlegroups.com> On May 6, 10:21?pm, John Nagle wrote: > On 5/4/2012 12:14 AM, Steve Howell wrote: > > > On May 3, 11:59 pm, Paul Rubin ?wrote: > >> Steve Howell ?writes: > >>> ? ? ?compressor = zlib.compressobj() > >>> ? ? ?s = compressor.compress("foobar") > >>> ? ? ?s += compressor.flush(zlib.Z_SYNC_FLUSH) > > >>> ? ? ?s_start = s > >>> ? ? ?compressor2 = compressor.copy() > > ? ? That's awful. There's no point in compressing six characters > with zlib. ?Zlib has a minimum overhead of 11 bytes. ?You just > made the data bigger. > The actual strings that I'm compressing are much longer than six characters. Obviously, "foobar" was just for example purposes. From tjreedy at udel.edu Mon May 7 12:49:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 07 May 2012 12:49:28 -0400 Subject: Workshop on Design Patterns and Advanced OOPS, Bangalore In-Reply-To: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> References: <3da19a50-0112-416f-b138-e04e9eb762c0@ns1g2000pbc.googlegroups.com> Message-ID: On 5/7/2012 6:23 AM, Exam Aya wrote: > For anyone working on object oriented programing languages like C++, > Java, C#, Python, PHP, etc. this workshop is a must. It goes through > the set of design patterns that started it all - Go4 - (Gang of 4) > patterns. The workshop will very interactive and each design pattern > will be explored rather than taught or lectured on. A problem > statement will be provided and the group will move towards why the > design pattern is required. I hope someone who really knows Python attends, so people can discover how easy some of the patterns are in Python, which does not have the straightjacket of statically typed names. For instance, heterogeneous sets and lists, used for instance for composites consisting of items and sub-composites, are part of Python rather than a tricky add-on. > Course Contents (Day 1) > > 1. The Pit Falls of OOPS > - Refresher on OOPS > - When does OOPS get confusing > > 2. Design Pattern Intro > - What are Design Patterns > - What are its uses and applications > > 3. Design Patterns > - Strategy Pattern > - Observer Pattern > > > Course Contents (Day 1) > - Decorator Pattern > - Factory Pattern > - Singleton Pattern > - Command Pattern > - Adapter Pattern > - Facade Pattern > - Template Pattern > - Iterator Pattern > - Composite Pattern > - State Pattern > > > Time : 09:30 am to 05:30 pm > > Venue: > > 1910, 8th A Cross (road connects 4th Main and 6th Main), HAL 3rd Stage > (New Thippasandira), Bangalore - 75 If I lived in Bangalore, I might attend. This announcement is, however, a bit OT for this list. On the other hand, it is encouraging that Python is now routinely listed as a major language in such things. Not so when I learned it 16 years ago ;-). -- Terry Jan Reedy From cs at zip.com.au Mon May 7 17:52:24 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 8 May 2012 07:52:24 +1000 Subject: sorting 1172026 entries In-Reply-To: References: Message-ID: <20120507215224.GA10765@cskk.homeip.net> On 07May2012 11:02, Chris Angelico wrote: | On Mon, May 7, 2012 at 10:31 AM, Cameron Simpson wrote: | > I didn't mean per .append() call (which I'd expect to be O(n) for large | > n), I meant overall for the completed list. | > | > Don't the realloc()s make it O(n^2) overall for large n? The list | > must get copied when the underlying space fills. I confess to being | > surprised at how quick it went for me though. I suppose reallocing in | > chunks (eg to double the available size) might conceal this for a while. | > It should still be well over O(n) overall (not amortised per .append() | > call). | | I haven't checked the CPython code, but the usual way to do | reallocations is to double the size My example above:-) | (or add 50% or something) each | time, meaning that as n increases, the frequency of reallocations | decreases - hence the O(1) amortized time. Hmm, yes. But it is only O(1) for doubling. If one went with a smaller increment (to waste less space in the end case where one stops growing the array) then there are more copies and less .append efficiency, trading potential memory bloat for compute time in .append(). If you went all the way to adding only one item the cost goes to O(n) for .append() and O(n^2) overall, with varying costs in between. | In any case, it's the | recommended way to build large strings: | | s = "" | while condition: | s += "some_value" | | versus: | | s = [] | while condition: | s.append("some_value") | s = "".join(s) | | so I would be very much surprised if this common wisdom is merely | replacing one O(n*n) operation with another O(n*n) operation. It sort of is (except that list.append may be specially tuned to realloc in big chunks). The join-lots-of-strings standard example is based on the length of the strings in characters/bytes being far more than the number of strings. So you do a lot of tiny listappends instead, copying nothing, then a big allocate-the-correct-size-and-copy-once with s.join. Also, this: s += "some_value" is not a list extension. Because strings are immutable (and anyway in general for "+" in python) you're making a new string and copying two other string contents into it. Inherently a copy of the whole of "s" on every "+" operation. Compared with list.append() or list.extend(), which are in-place modifications to the original list. So these are really apples and oranges here. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ We are in great haste to construct a magnetic telegraph from Maine to Texas; but Maine and Texas, it may be, have nothing important to communicate. - H. D. Thoreau From rafadurancastaneda at gmail.com Mon May 7 17:59:30 2012 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Mon, 07 May 2012 23:59:30 +0200 Subject: try/except KeyboardInterrupt vs signal handler for SIGINT Message-ID: <4FA845C2.4010206@gmail.com> Hi, I was wondering which approach is better to stop several servers from just on python application when 'ctrl-c' is pressed, a try/except KeyboardInterrupt or just registering a SIGINT handler and exit when the signal is triggered. Any advantage/disadvantage from one approach over the other? P.S.: Since several servers are started just one 'ctrl-c' doesn't work without any extra change and I have some concerns about the signal handler. Thank you for your answers. From pinard at iro.umontreal.ca Mon May 7 19:00:32 2012 From: pinard at iro.umontreal.ca (=?utf-8?Q?Fran=C3=A7ois_Pinard?=) Date: Mon, 07 May 2012 19:00:32 -0400 Subject: RELEASED: Pymacs 0.25 Message-ID: <86obpzsijz.fsf@mercure.progiciels-bpi.ca> Hello to everybody, and Emacs users in the Python community. Pymacs 0.25 is now available. There has been a while, so I advise current Pymacs users to switch with caution. - Python 3 is now supported. This required new installation mechanics, and a Python pre-processor written for the circumstance (named *pppp*). - Pymacs now installs a single Python file instead of a Python module. Nice thanks to Pymacs contributors. It surely has been fun working with you all! -------------------------------------- Pymacs is a powerful tool which, once started from Emacs, allows both-way communication between Emacs Lisp and Python. Pymacs aims Python as an extension language for Emacs rather than the other way around, and this asymmetry is reflected in some design choices. Within Emacs Lisp code, one may load and use Python modules. Python functions may themselves use Emacs services, and handle Emacs Lisp objects kept in Emacs Lisp space. For more information, see http://pymacs.progiciels-bpi.ca/ . You may fetch the distribution as one of: - https://github.com/pinard/Pymacs/tarball/v0.25 - https://github.com/pinard/Pymacs/zipball/v0.25 -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From albertsun05 at gmail.com Mon May 7 19:20:35 2012 From: albertsun05 at gmail.com (Albert) Date: Mon, 7 May 2012 16:20:35 -0700 (PDT) Subject: How do I run a python program from an internet address? Message-ID: I have a small text based python program that I want to make available to people who might be behind a firewall or can't install python on their office computers, but can access the internet. It is just an algorithm that makes a handful of straightforward calculations on some input that the user provides and spits out some text as output that they might want to print out on a printer. I can program python on my local machine, but don't know how to make the code accessible from a browser. What would be the best way to figure out how to do this? I looked at Google app engine tutorial, but can't figure out how that will help we get the code into the cloud so I can access it from any browser. From rosuav at gmail.com Mon May 7 19:51:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 09:51:54 +1000 Subject: How do I run a python program from an internet address? In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 9:20 AM, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. ?It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that > they might want to print out on a printer. ?I can program python on my > local machine, but don't know how to make the code accessible from a > browser. Probably the easiest way is to make your program into a web server itself: http://docs.python.org/py3k/library/http.server.html Put it on a high port (eg 8000) and then direct people to http://your.machine.ip.address:8000/ to access it. There are other ways, too, such as CGI scripting, but the http.server module is pretty convenient. ChrisA From steve+comp.lang.python at pearwood.info Mon May 7 20:11:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2012 00:11:33 GMT Subject: How do I run a python program from an internet address? References: Message-ID: <4fa864b5$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 07 May 2012 16:20:35 -0700, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that they > might want to print out on a printer. I can program python on my local > machine, but don't know how to make the code accessible from a browser. > > What would be the best way to figure out how to do this? Try googling "python web app how to". For example, the very first link found here: https://duckduckgo.com/html/?q=python%20web%20app%20how%20to is an introduction to making Python applications available to run over the Internet. -- Steven From charleshixsn at earthlink.net Mon May 7 23:15:36 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 20:15:36 -0700 Subject: indexed property? Can it be done? Message-ID: <4FA88FD8.4000905@earthlink.net> class Node: def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, [key], [value], [downRight], parent, dirty, dlu] Note that node[3] is a list of keys (initially 1) and node[3] is a list of values, etc. What I'd like to do is to be able to address them thusly: k = node.key[2] v = node.value[2] but if there's a way to do this, I haven't been able to figure it out. Any suggestions? -- Charles Hixson From clp2 at rebertia.com Mon May 7 23:33:49 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 7 May 2012 20:33:49 -0700 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: On Mon, May 7, 2012 at 8:15 PM, Charles Hixson wrote: > class Node: > > ? ?def ? ?__init__(self, nodeId, key, value, downRight, downLeft, parent): > ? ? ? ?dirty ? ?= ? ?True > ? ? ? ?dlu ? ?= ? ?utcnow() > ? ? ? ?self.node ? ?= ? ?[nodeId, downLeft, [key], [value], [downRight], > parent, dirty, dlu] Why are you using a single opaque list instead of separate, meaningful attributes for each datum? Cheers, Chris From dan at tombstonezero.net Mon May 7 23:44:05 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 7 May 2012 20:44:05 -0700 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: <20120507204405.2840e422@particle> On Mon, 07 May 2012 20:15:36 -0700 Charles Hixson wrote: > class Node: > > def __init__(self, nodeId, key, value, downRight, downLeft, > parent): dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a > list of values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it > out. Any suggestions? Untested: def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, dict(key=value), [downRight], parent, dirty, dlu] Now you can use self.node[2][key] to get/set value. But why not make the elements of node their own attributes? Untested: def __init__(self, nodeId, key, value, downRight, downLeft, parent): self.dirty = True self.dlu = utcnow() self.nodeId = nodeId self.downLeft = downLeft self.downRight = downRight self.values = dict(key=value) self.parent = parent And then you don't have to remember that node[2] is the key/value pairs (note the typo (the two "3"s) in your original post). With each attribute in its own, well, attribute, you can always use node.values[key] to access the value associated with a particular key. HTH, Dan From nagle at animats.com Mon May 7 23:46:57 2012 From: nagle at animats.com (John Nagle) Date: Mon, 07 May 2012 20:46:57 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: <7x62c8bn74.fsf@ruckus.brouhaha.com> References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On 5/6/2012 9:59 PM, Paul Rubin wrote: > Javier writes: >> Or not... Using directories may be a way to do rapid prototyping, and >> check quickly how things are going internally, without needing to resort >> to complex database interfaces. > > dbm and shelve are extremely simple to use. Using the file system for a > million item db is ridiculous even for prototyping. Right. Steve Bellovin wrote that back when UNIX didn't have any database programs, let alone free ones. John Nagle From steve+comp.lang.python at pearwood.info Mon May 7 23:54:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 May 2012 03:54:11 GMT Subject: Open Source: you're doing it wrong - the Pyjamas hijack Message-ID: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> A.k.a. "we had to destroy the project in order to save it". http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html Seriously, this was a remarkably ham-fisted and foolish way to "resolve" a dispute over the direction of an open source project. That's the sort of thing that gives open source a bad reputation. (The sad thing is, when closed source software developers do this sort of thing, it gets blamed on "bad apples"; when open source developers do it, it gets used as an indictment on the entire FOSS community.) -- Steven From charleshixsn at earthlink.net Tue May 8 00:07:27 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 21:07:27 -0700 Subject: indexed property? Can it be done? In-Reply-To: References: <4FA88FD8.4000905@earthlink.net> Message-ID: <4FA89BFF.1080203@earthlink.net> On 05/07/2012 08:33 PM, Chris Rebert wrote: > On Mon, May 7, 2012 at 8:15 PM, Charles Hixson > wrote: > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], [downRight], >> parent, dirty, dlu] >> > Why are you using a single opaque list instead of separate, meaningful > attributes for each datum? > > Cheers, > Chris > > Because that's the most reasonable implementation. The various list items would not be the same from instance to instance. I could pull the top-level list items off as separate variables, but this would leave the problem exactly where it is, and ordinary properties allow me to address the entries like id, and dlu without problem. But the list variables are a separate problem, and not so readily soluble. FWIW, if I must I can operate with only a list, and define functions to do the access and manipulation. I'd rather not, which is why I'm exploring whether an indexed property is feasible. Note that I *could* return, e.g., the entire keys list, but I'd rather use a bit more data protection than that. Which is what an indexed setter property would allow. And node.key[3] is as fully informative a name as I can construct for that entry. But the number of items in the keys list varies from node to node, so defining a key3 property is not reasonable. (Besides, that's so ugly that I'd rather use a function, even though indexing in Python really should be done with brackets rather than parens.) -- Charles Hixson From showell30 at yahoo.com Tue May 8 00:09:33 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 7 May 2012 21:09:33 -0700 (PDT) Subject: Creating a directory structure and modifying files automatically in Python References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On May 7, 8:46?pm, John Nagle wrote: > On 5/6/2012 9:59 PM, Paul Rubin wrote: > > > Javier ?writes: > >> Or not... Using directories may be a way to do rapid prototyping, and > >> check quickly how things are going internally, without needing to resort > >> to complex database interfaces. > > > dbm and shelve are extremely simple to use. ?Using the file system for a > > million item db is ridiculous even for prototyping. > > ? ? Right. ?Steve Bellovin wrote that back when UNIX didn't have any > database programs, let alone free ones. > It's kind of sad that the Unix file system doesn't serve as an effective key-value store at any kind of nontrivial scale. It would simplify a lot of programming if filenames were keys and file contents were values. From charleshixsn at earthlink.net Tue May 8 00:18:37 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 07 May 2012 21:18:37 -0700 Subject: indexed property? Can it be done? In-Reply-To: <20120507204405.2840e422@particle> References: <4FA88FD8.4000905@earthlink.net> <20120507204405.2840e422@particle> Message-ID: <4FA89E9D.4070406@earthlink.net> On 05/07/2012 08:44 PM, Dan Sommers wrote: > On Mon, 07 May 2012 20:15:36 -0700 > Charles Hixson wrote: > > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, >> parent): dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> >> Note that node[3] is a list of keys (initially 1) and node[3] is a >> list of values, etc. >> >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it >> out. Any suggestions? >> > Untested: > > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, dict(key=value), > [downRight], parent, dirty, dlu] > > Now you can use self.node[2][key] to get/set value. > > But why not make the elements of node their own attributes? > > Untested: > > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > self.dirty = True > self.dlu = utcnow() > self.nodeId = nodeId > self.downLeft = downLeft > self.downRight = downRight > self.values = dict(key=value) > self.parent = parent > > And then you don't have to remember that node[2] is the key/value pairs > (note the typo (the two "3"s) in your original post). With each > attribute in its own, well, attribute, you can always use > node.values[key] to access the value associated with a particular key. > > HTH, > Dan > Did you notice that the node list contained sublists? I can access the top level node items through ordinary properties, and that is my intent. So I don't need to remember what top level index represents what item. But the second level items are variable in length, so I really want to do an indexed access to them. Yes, I admit that in the snipped defined by the __init__ method those secondary lists only received one entry. Other method would extend their length, to a variable amount for different class instances. A part of the reason that the class retains that top level list is so that if I can't create an indexed property to get and set them, I can revert to an alternative that is a bit uglier than this, but might be more efficient. (It would have methods that operated directly on the list rather than using properties for ANY of the approach...and avoid creating a class that they handle. Not as clean as what I'm hoping for, but so far I haven't come up with any way except functions that doesn't directly expose the data...and if I must use that approach, then the class doesn't buy me anything for the overhead.) -- Charles Hixson From nagle at animats.com Tue May 8 00:50:33 2012 From: nagle at animats.com (John Nagle) Date: Mon, 07 May 2012 21:50:33 -0700 Subject: Creating a directory structure and modifying files automatically in Python In-Reply-To: References: <31322317.820.1335799155661.JavaMail.geo-discussion-forums@vbmi19> <7x62c8bn74.fsf@ruckus.brouhaha.com> Message-ID: On 5/7/2012 9:09 PM, Steve Howell wrote: > On May 7, 8:46 pm, John Nagle wrote: >> On 5/6/2012 9:59 PM, Paul Rubin wrote: >> >>> Javier writes: >>>> Or not... Using directories may be a way to do rapid prototyping, and >>>> check quickly how things are going internally, without needing to resort >>>> to complex database interfaces. >> >>> dbm and shelve are extremely simple to use. Using the file system for a >>> million item db is ridiculous even for prototyping. >> >> Right. Steve Bellovin wrote that back when UNIX didn't have any >> database programs, let alone free ones. >> > > It's kind of sad that the Unix file system doesn't serve as an > effective key-value store at any kind of nontrivial scale. It would > simplify a lot of programming if filenames were keys and file contents > were values. You don't want to go there in a file system. Some people I know tried that around 1970. "A bit is a file. An ordered collection of files is a file". Didn't work out. There are file models other than the UNIX one. Many older systems had file versioning. Tandem built their file system on top of their distributed, redundant database system. There are backup systems where the name of the file is its hash, allowing elimination of duplicates. Most of the "free online storage" sites do that. John Nagle From rosuav at gmail.com Tue May 8 01:20:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 15:20:39 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 1:54 PM, Steven D'Aprano wrote: > A.k.a. "we had to destroy the project in order to save it". > > http://technogems.blogspot.com.au/2012/05/pyjamas-hijacked.html Great summary, very handily peppered with links to appropriate posts. > Seriously, this was a remarkably ham-fisted and foolish way to "resolve" > a dispute over the direction of an open source project. That's the sort > of thing that gives open source a bad reputation. I'd probably be on the side of the dissidents in terms of philosophy - freedom is there to be used, but if it costs you too much (effort, quality, etc) to use all-free-software, the cart's involved in equine artistry. You want a wiki? Throw down MySQL and MediaWiki. Want hosting? GitHub is fine. I don't restrict my hardware purchases to "free BIOS or no sale". But a backstabbing takeover is not doing anyone any good. Especially not the reputation of the project. Here at work we have some familiarity with Python, and my boss is just starting to learn Javascript (after our main JS developer left); but there's no way that I'm going to consider introducing pyjamas / pyjs until this is resolved. > (The sad thing is, when closed source software developers do this sort of > thing, it gets blamed on "bad apples"; when open source developers do it, > it gets used as an indictment on the entire FOSS community.) It's not quite as mixed-standards as that. If you see Microsoft or Apple charging a fortune for trivial upgrades and/or bug fixes, you blame it on corporate development. And some low-quality software in the FOSS market is acknowledged as "you get what you pay for", although that one can backfire too. But yes, it's a harsh reality that one open-source community's actions reflect badly on another. (Which is why I want to be really REALLY careful of using the term "open source" here at work. Just because we let people have the source code to certain scripts etc does not mean we should use that term. Just sayin'.) I hope that pyjamas can be restored at some point to a single live project. Whether that's headed by Luke Leighton or C Anthony Risinger (neither of whom I know at all and thus I can't speak to either's merits) or someone else, I don't particularly care, but frankly, I don't think there's need in the world for a fork of such a project. Aside from philosophical disagreements, what would be the differences between the Luke fork and the Anthony fork? Could anyone explain, to a prospective user, why s/he should pick one or the other? If not, the projects need to merge, or else one will die a sad death of stagnation. ChrisA From wuwei23 at gmail.com Tue May 8 01:37:38 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 7 May 2012 22:37:38 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> On May 8, 1:54?pm, Steven D'Aprano wrote: > Seriously, this was a remarkably ham-fisted and foolish way to "resolve" > a dispute over the direction of an open source project. That's the sort > of thing that gives open source a bad reputation. The arrogance and sense of entitlement was so thick you could choke on it. Here's a sampling from the circle jerk of self-justification that flooded my inbox over the weekend: "i did not need to consult Luke, nor would that have be productive" No, it's generally _not_ productive to ask someone if you can steal their project from them. "i have retired Luke of the management duties, particularly, *above* the source" Who is this C Anthony Risinger asshole and in what way did he _hire_ the lead developer? "What I have wondered is, what are effects of having the project hostage to the whims of an individuals often illogically radical software libre beliefs which are absolutely not up for discussion at all with anyone." What I'm wondering is: how is the new set up any different? Why were Luke Leighton's philosophies/"whims" any more right or wrong than those held by the new Gang of Dicks? "Further more, the reason I think it's a bad idea to have this drawn out discussion is that pretty much the main reason for this fork is because of Luke leadership and project management decisions and actions. To have discussions of why the fork was done would invariably lead to quite a bit of personal attacks and petty arguments." Apparently it's nicer to steal someone's work than be mean to them. "I agree, Lex - this is all about moving on. This is a software project, not a cult of personality." Because recognising the effort of the lead developer is cult-like. "My only quibble is with the term "fork." A fork is created when you disagree with the technical direction of a project. That's not the issue here. This is a reassignment of the project administration only - a shuffling of responsibility among *current leaders* of the community. There is no "divine right of kings" here." My quibble is over the term "fork" too, as this is outright theft. I don't remember the community acknowledging _any other leadership_ over Luke Leighton's. "I suspect Luke will be busy with other projects and not do much more for Pyjamas/pyjs, Luke correct me if you see this and I am wrong." How about letting the man make his own fucking decisions? "All of you spamming the list with your unsubscribe attempts: Anthony mentioned in a previous email that he's using mailman now" Apparently it's the responsibility of the person who was subscribed without their permission to find out the correct mechanism for unsubscribing from that list. "apparantly a bunch of people were marked as "POSTING" in the DB, but not receiving mail (?)" Oh I see, the sudden rush of email I received was due to an error in the data they stole... "Nobody wins if we spend any amount of time debating the details of this transition, what's done is done." Truly the justification of assholes. From ian.g.kelly at gmail.com Tue May 8 01:42:49 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 7 May 2012 23:42:49 -0600 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: On Mon, May 7, 2012 at 9:15 PM, Charles Hixson wrote: > class Node: > > ? ?def ? ?__init__(self, nodeId, key, value, downRight, downLeft, parent): > ? ? ? ?dirty ? ?= ? ?True > ? ? ? ?dlu ? ?= ? ?utcnow() > ? ? ? ?self.node ? ?= ? ?[nodeId, downLeft, [key], [value], [downRight], > parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a list of > values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. ?Any > suggestions? http://code.activestate.com/recipes/577703-item-properties/ From wuwei23 at gmail.com Tue May 8 01:46:34 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 7 May 2012 22:46:34 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> Message-ID: <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> Even worse, here's what Risinger had to say when Leighton asked them to stop sending him email: "probably best not to feed the troll, Pascal -- especially one overwrought and lost in high dudgeon -- they tend to brickwall common reason and simple social advices." "Luke has made his decision -- and burned all ties -- by pitching a snit of hollow threats" "i full-heartily recommend that everyone do exactly as Luke requests, i.e. "cease and desist from all communications" with him, regarding this project's past or future ..." There's being an asshole, and then there's being an absolute fucking asshole. It seems pretty clear which category this behaviour falls in. From rosuav at gmail.com Tue May 8 02:01:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 16:01:00 +1000 Subject: indexed property? Can it be done? In-Reply-To: <4FA89E9D.4070406@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> <20120507204405.2840e422@particle> <4FA89E9D.4070406@earthlink.net> Message-ID: On Tue, May 8, 2012 at 2:18 PM, Charles Hixson wrote: > Not as clean as what I'm hoping for, but so far I haven't come up with any > way except functions that doesn't directly expose the data...and if I must > use that approach, then the class doesn't buy me anything for the overhead.) C++ and Java teach us to hide everything and use trivial getters and setters to make things available: class Foo { private: int value; public: int getValue() {return value;} int setValue(int newval) {return value=newval;} }; Python lets us happily access members directly, but change to getter/setter if we need to: (example lifted from http://docs.python.org/library/functions.html#property ) class C(object): def __init__(self): self._x = None def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") Not fundamentally different, except that with Python, you can skip all this in the simple case: class C(object): def __init__(self,val): self.value = val In short, data hiding isn't such a great thing after all. Just use the members directly until such time as you find you need to change that (and be honest, how often have you had thin getter/setter methods and then changed their functionality?). ChrisA From ian.g.kelly at gmail.com Tue May 8 02:15:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 00:15:19 -0600 Subject: sorting 1172026 entries In-Reply-To: <20120507215224.GA10765@cskk.homeip.net> References: <20120507215224.GA10765@cskk.homeip.net> Message-ID: On Mon, May 7, 2012 at 3:52 PM, Cameron Simpson wrote: > | (or add 50% or something) each > | time, meaning that as n increases, the frequency of reallocations > | decreases - hence the O(1) amortized time. > > Hmm, yes. But it is only O(1) for doubling. If one went with a smaller > increment (to waste less space in the end case where one stops growing the > array) then there are more copies and less .append efficiency, trading > potential memory bloat for compute time in .append(). If you went all > the way to adding only one item the cost goes to O(n) for .append() > and O(n^2) overall, with varying costs in between. It's O(1) amortized as long as the increment is exponential. IIRC Python actually grows the list by a factor of 1/8 in the limit, which is still exponential and still O(1) amortized. Cheers, Ian From __peter__ at web.de Tue May 8 03:50:13 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 May 2012 09:50:13 +0200 Subject: indexed property? Can it be done? References: <4FA88FD8.4000905@earthlink.net> Message-ID: Charles Hixson wrote: > class Node: > > def __init__(self, nodeId, key, value, downRight, downLeft, > parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > > Note that node[3] is a list of keys (initially 1) and node[3] is a list > of values, etc. > > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. > Any suggestions? I don't see the problem: >>> class Node(object): ... def __init__(self, key): ... self.node = ["foo", "bar", [key], "baz"] ... @property ... def key(self): ... return self.node[2] ... >>> node = Node(42) >>> node.key [42] >>> node.key[0] 42 >>> node.key.append(7) >>> node.key [42, 7] >>> del node.key[0] >>> node.key[:] = [3, 2, 1] >>> node.key [3, 2, 1] >>> node.key = "foo" Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute But the design proposed by Dan Sommers really is the way to go... From jameskhedley at gmail.com Tue May 8 05:10:13 2012 From: jameskhedley at gmail.com (james hedley) Date: Tue, 8 May 2012 02:10:13 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> Message-ID: <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> Agreed with pretty much all of that. It's third-world politics, lurching from one dictator to another. Risinger seems to have banned all discussion of the subject from the list too, I'm not posting anymore because I don't want to give him an excuse to wield his newly found banhammer. But yeah, a lot of the commentary from the pro-rebel side ( not that any of them admit they had anything to do with it ) really does come across as being ill-informed and childish. This story is on reddit, if anyone is that way inclined: http://www.reddit.com/r/opensource/comments/t5acr/project_hijacked_advice_from_experience_foss/ From davidgshi at yahoo.co.uk Tue May 8 05:38:29 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 8 May 2012 10:38:29 +0100 (BST) Subject: Looking for proven Python code for Line Simplication such as Douglas-Peucker Message-ID: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> Dear All, I am looking for? proven Python code for Line Simplication such as Douglas-Peucker. Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Tue May 8 07:04:13 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 08 May 2012 12:04:13 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1336475053.24832.18.camel@tim-laptop> On Tue, 2012-05-08 at 15:20 +1000, Chris Angelico wrote: > I hope that pyjamas can be restored at some point to a single live > project. Whether that's headed by Luke Leighton or C Anthony Risinger > (neither of whom I know at all and thus I can't speak to either's > merits) or someone else, I don't particularly care I have met Luke (At Europython), and honestly it was his enthusiasm that got me to look at pyjamas in the first place. To be fair I still haven't used it in anger, but I've poked around a lot, it's been under consideration for several bits of work. Although I don't think I've met C Anthony Risinger, his behaviour has seriously put me off the project - and if I consider using it in the future I'm going to be "pricing in" the cost of maintaining a complete local fork as part of the decision. Tim From bob at bobcowdery.plus.com Tue May 8 07:17:33 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Tue, 08 May 2012 12:17:33 +0100 Subject: Problem with time.time() standing still In-Reply-To: <4FA6421F.40002@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> Message-ID: <4FA900CD.7070604@bobcowdery.plus.com> Can anyone make sense of this. I've looked over the Python timemodule.c again and it uses one of gettimeofday(), ftime() or time(). The gettimeofday() is not available on Windows so its going to use ftime() or time(). As time() only has a resolution of 1 second and returns a long and I know Python time.time() has a ms resolution it must be using ftime(). After going round the houses - a lot. I've made a trivially simple extension that goes wrong. I can only think I must be doing something incredibly stupid. Perhaps someone can put me out of my misery. In the full app what happens is that it reports the correct time as given by time() by gets the ms from somewhere also. When it goes wrong it reports the same time as ftime(). Bob >>> import mytime >>> mytime.doTime() TIME : 1336474857 FTIME secs 1336474880.000000 FTIME ms 0.601000 FTIME secs+ms 1336474880.601000 0 >>> mytime.doTime() TIME : 1336474871 FTIME secs 1336474880.000000 FTIME ms 0.548000 FTIME secs+ms 1336474880.548000 0 >>> mytime.doTime() TIME : 1336474897 FTIME secs 1336474880.000000 FTIME ms 0.007000 FTIME secs+ms 1336474880.007000 0 The extension just prints out the time as got from time() and ftime(). For a start the two do not agree on what the time is. Secondly ftime() stops incrementing while the python session is running. If I start a new session it will have incremented. >>> import mytime >>> mytime.doTime() TIME : 1336475029 FTIME secs 1336475008.000000 FTIME ms 0.265000 FTIME secs+ms 1336475008.265000 0 Code and build file ================ #include "Python.h" #include #include #include #include static struct timeb t; static float secs = 0.0; static float ms = 0.0; static float both = 0.0; static PyObject *doTime( PyObject *self, PyObject *args) { time_t seconds; seconds = time (NULL); printf ("TIME : %ld\n", seconds); ftime(&t); secs = (float)t.time; ms = (float)((float)t.millitm * 0.001); printf("FTIME secs+ms %f\n", secs + ms); return PyInt_FromLong((long)0); } static PyMethodDef pyInst_Methods[] = { {"doTime", doTime, METH_VARARGS}, {NULL, NULL, 0, NULL} }; #ifndef PyMODINIT_FUNC #define PyMODINIT_FUNC void #endif /* PyMODINIT_FUNC */ PyMODINIT_FUNC initmytime(void) { PyObject *module; module = Py_InitModule3("mytime", pyInst_Methods,"Time module"); if (!module) return; } Build file ======== import os from distutils.core import setup from distutils.extension import Extension if os.path.exists('C:\\Program Files (x86)'): # 64 bit ProgramFiles = 'Program Files (x86)' else: # 32 bit ProgramFiles = 'Program Files' setup( name='Time Test', author='Bob Cowdery', ext_modules = [ Extension('mytime', ['pytime.cpp'], include_dirs = ['C:\\' + ProgramFiles + '\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'], #define_macros = [("_AFXDLL", None)], library_dirs = ['C:\\' + ProgramFiles + '\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'], libraries = ['User32', 'Gdi32', 'python26', 'odbc32', 'odbccp32'] ) ] ) On 06/05/2012 10:19, Bob Cowdery wrote: > On 06/05/2012 09:49, Cameron Simpson wrote: >> On 06May2012 09:18, Bob Cowdery wrote: >> | On 05/05/2012 23:05, Cameron Simpson wrote: >> |> On 05May2012 20:33, Bob Cowdery wrote: >> |> | [...] calls to time.time() always return the same >> |> | time which is usually several seconds in the past or future and always >> |> | has no fractional part. >> |> >> |> Thought #1: you are calling time.time() and haven't unfortunately >> |> renamed it? (I doubt this scenario, though the lack of fractional part >> |> is interesting.) >> | >> | Not sure what you mean by renamed it. >> >> Like this: >> >> from time import time >> [...] >> time = some_unfortunate_other_function >> [...] >> now = time() # calls wrong function >> >> It seems unlikely, but possible. >> >> | I also tried datetime and that had >> | the same behaviour. >> >> Makes my suggestion even less likely unless the time module itself gets >> monkeypatched (i.e. "time.time = bad_function" somewhere). > I don't think the function is subverted unless there is some way inside > the vendor SDK or even DirectShow (the SDK uses this as a COM object) > which can somehow hijack it. It does catch up every few minutes so there > has to be a clue there. >> |> | If I leave it long enough time will suddently >> |> | jump forward after a few minutes, then again after a few minutes more. >> |> | >> |> | I've never encountered this behaviour before and can't understand what >> |> | on earth is going on. If I call the 'C' time() function just the other >> |> | side of my call to the extension the time is ticking along fine. It's >> |> | just the one Python thread that is affected. >> |> [...] >> |> >> |> Thought #2: On a UNIX system I'd be running the process under strace (or >> |> dtrace or ktrace depending on flavour) to see what actual OS system calls are >> |> being made during this behaviour. Is this feasible for you? >> | >> | I'm on Windows for this particular part of the application. >> >> I'd guessed so. I've no Windows programming background; I was wondering >> if there was something like this you had to hand on windows. > Maybe, but not that I know of. >> | [...] But debugging into this is probably the only way. I >> | looked at the built-in time module. As far as I can tell it just calls >> | the underlying C time() function as an extension. This is more >> | mystifying as that is pretty much what I'm doing by checking the time in >> | my own extension module where it ticks along fine. >> >> Hmm. A C extension I presume? How about writing a little pure Python >> thread to call time.time(), and spin it off parallel to the rest of the >> app; does it also get bad time.time() behaviour? > I've tried that. It's only the Python thread (or Python main thread) > that calls the extension that behaves like this. Other Python threads > tick along fine with the correct time including a fractional part. >> | I have another >> | scenario using a different part of their SDK where the time does still >> | tick but the fractional part is frozen, not 0 but frozen. >> >> Curiouser and curiouser. > Indeed. Away now but battle will resume on Tuesday. > > Bob > > > From roy at panix.com Tue May 8 09:02:12 2012 From: roy at panix.com (Roy Smith) Date: Tue, 08 May 2012 09:02:12 -0400 Subject: Expand RFC-2445 (iCalendar) recurrence rule? Message-ID: Does there exist a stand-alone module to expand RFC-2445 recurrence rule? The idea is to start with a string like: "RRULE:FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR" and derive a list of dates on which that event occurs. I'm aware of http://codespeak.net/icalendar/, but that solves a much larger problem (parsing ics files) and I can't see how to tease out just this one function from that module. From robert.kern at gmail.com Tue May 8 09:08:35 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 08 May 2012 14:08:35 +0100 Subject: Looking for proven Python code for Line Simplication such as Douglas-Peucker In-Reply-To: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> References: <1336469909.65534.YahooMailNeo@web171604.mail.ir2.yahoo.com> Message-ID: On 5/8/12 10:38 AM, David Shi wrote: > Dear All, > > I am looking for proven Python code for Line Simplication such as Douglas-Peucker. https://svn.enthought.com/svn/enthought/EnthoughtBase/trunk/enthought/util/dp.py -- 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 jameskhedley at gmail.com Tue May 8 09:12:18 2012 From: jameskhedley at gmail.com (james hedley) Date: Tue, 8 May 2012 06:12:18 -0700 (PDT) Subject: How do I run a python program from an internet address? In-Reply-To: References: Message-ID: <9136960.456.1336482739269.JavaMail.geo-discussion-forums@vbvx4> > What would be the best way to figure out how to do this? I looked at > Google app engine tutorial, but can't figure out how that will help we > get the code into the cloud so I can access it from any browser. GAE is quite a good option, since it includes free hosting. You should be able to get started just by downloading the SDK and making your app work locally. It includes a little development server so you can see what your users will see in your own browser. In this way, you don't have to do anything with the web until everything is ready, then you just press a button (windows) or run a script (nix) and yor app appears on the web. The datastore is quite complicated though! If you rig up your own host though, you have a lot more freedom with what software you get to use. A very simple way is to plug mod_wsgi into apache (a common web server) and then write your app as a wsgi script; this usually just entails adding a couple of necessary methods to your script. In my case, I have a buddy with a web host set up so I can get things up on there very easily and for free. From jeanpierreda at gmail.com Tue May 8 09:43:19 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 8 May 2012 09:43:19 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 1:20 AM, Chris Angelico wrote: > I hope that pyjamas can be restored at some point to a single live > project. Whether that's headed by Luke Leighton or C Anthony Risinger > (neither of whom I know at all and thus I can't speak to either's > merits) or someone else, I don't particularly care, but frankly, I > don't think there's need in the world for a fork of such a project. > Aside from philosophical disagreements, what would be the differences > between the Luke fork and the Anthony fork? Could anyone explain, to a > prospective user, why s/he should pick one or the other? If not, the > projects need to merge, or else one will die a sad death of > stagnation. There is no "both projects". there was Luke's project, and then Risinger stole it and it's Risinger's project. There is only that one thing -- Luke has no """fork""" of his own codebase. I guess it won't die of stagnation, eh? It'll be a perfectly usable, stable project, led by a thief. -- Devin From rosuav at gmail.com Tue May 8 09:47:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 May 2012 23:47:56 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre wrote: > There is no "both projects". there was Luke's project, and then > Risinger stole it and it's Risinger's project. There is only that one > thing -- Luke has no """fork""" of his own codebase. Presumably Luke could fork his own project, though. I haven't checked, but presumably the source is properly managed, so it can be forked as of any point in time. But it's pretty nasty to have to fork your own project. ChrisA From roy at panix.com Tue May 8 10:12:04 2012 From: roy at panix.com (Roy Smith) Date: Tue, 8 May 2012 07:12:04 -0700 (PDT) Subject: Expand RFC-2445 (iCalendar) recurrence rule? In-Reply-To: References: Message-ID: <23988809.256.1336486324508.JavaMail.geo-discussion-forums@ynei13> O.B. Murithi suggested I look at http://labix.org/python-dateutil, which turns out to have exactly what I'm looking for. Thanks! from dateutil.rrule import rrulestr from dateutil.parser import parse rule = rrulestr("FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR", dtstart=parse("2012-06-15")) for date in rule: print date ./rrule.py 2012-06-15 00:00:00 2012-06-29 00:00:00 2012-07-13 00:00:00 2012-07-27 00:00:00 2012-08-10 00:00:00 2012-08-24 00:00:00 From bob at bobcowdery.plus.com Tue May 8 11:42:29 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Tue, 08 May 2012 16:42:29 +0100 Subject: Problem with time.time() standing still In-Reply-To: <4FA900CD.7070604@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> <4FA900CD.7070604@bobcowdery.plus.com> Message-ID: <4FA93EE5.4040200@bobcowdery.plus.com> Hopefully somebody can add the last piece of this puzzle. My code didn't work because I did make a silly mistake. The number of seconds since EPOC is a large number but it also needs a high precision. Attempting to put this value into a 32 bit float corrupts the least significant part because 24 bits cannot hold that precision. Now Python floats are C doubles and the calculation in timemodule.c is in doubles right back to Python. Normally this retains the precision. For some inexplicable reason when I make certain calls into this vendors SDK, ftime() is getting precision problems and appears to be frozen as a result. C, only supporting early binding cannot change the function referenced at runtime so how the devil is it managing to do this. On 08/05/2012 12:17, Bob Cowdery wrote: > Can anyone make sense of this. > > I've looked over the Python timemodule.c again and it uses one of > gettimeofday(), ftime() or time(). The gettimeofday() is not available > on Windows so its going to use ftime() or time(). As time() only has a > resolution of 1 second and returns a long and I know Python > time.time() has a ms resolution it must be using ftime(). > > After going round the houses - a lot. I've made a trivially simple > extension that goes wrong. I can only think I must be doing something > incredibly stupid. Perhaps someone can put me out of my misery. > > In the full app what happens is that it reports the correct time as > given by time() by gets the ms from somewhere also. When it goes wrong > it reports the same time as ftime(). > > Bob > > >>> import mytime > >>> mytime.doTime() > TIME : 1336474857 > FTIME secs 1336474880.000000 > FTIME ms 0.601000 > FTIME secs+ms 1336474880.601000 > 0 > >>> mytime.doTime() > TIME : 1336474871 > FTIME secs 1336474880.000000 > FTIME ms 0.548000 > FTIME secs+ms 1336474880.548000 > 0 > >>> mytime.doTime() > TIME : 1336474897 > FTIME secs 1336474880.000000 > FTIME ms 0.007000 > FTIME secs+ms 1336474880.007000 > 0 > > The extension just prints out the time as got from time() and ftime(). > For a start the two do not agree on what the time is. Secondly ftime() > stops incrementing while the python session is running. If I start a > new session it will have incremented. > > >>> import mytime > >>> mytime.doTime() > TIME : 1336475029 > FTIME secs 1336475008.000000 > FTIME ms 0.265000 > FTIME secs+ms 1336475008.265000 > 0 > > Code and build file > ================ > > #include "Python.h" > #include > #include > #include > #include > > static struct timeb t; > static float secs = 0.0; > static float ms = 0.0; > static float both = 0.0; > > static PyObject *doTime( > PyObject *self, > PyObject *args) { > time_t seconds; > seconds = time (NULL); > printf ("TIME : %ld\n", seconds); > ftime(&t); > secs = (float)t.time; > ms = (float)((float)t.millitm * 0.001); > printf("FTIME secs+ms %f\n", secs + ms); > > return PyInt_FromLong((long)0); > } > > static PyMethodDef pyInst_Methods[] = { > > {"doTime", > doTime, > METH_VARARGS}, > {NULL, NULL, 0, NULL} > }; > > #ifndef PyMODINIT_FUNC > #define PyMODINIT_FUNC void > #endif /* PyMODINIT_FUNC */ > > PyMODINIT_FUNC initmytime(void) > { > PyObject *module; > module = Py_InitModule3("mytime", pyInst_Methods,"Time module"); > if (!module) return; > } > > Build file > ======== > import os > from distutils.core import setup > from distutils.extension import Extension > > if os.path.exists('C:\\Program Files (x86)'): > # 64 bit > ProgramFiles = 'Program Files (x86)' > else: > # 32 bit > ProgramFiles = 'Program Files' > > setup( > name='Time Test', > author='Bob Cowdery', > ext_modules = [ > Extension('mytime', > ['pytime.cpp'], > include_dirs = ['C:\\' + ProgramFiles + > '\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'], > #define_macros = [("_AFXDLL", None)], > library_dirs = ['C:\\' + ProgramFiles + > '\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'], > libraries = ['User32', 'Gdi32', 'python26', > 'odbc32', 'odbccp32'] > ) > ] > ) > > On 06/05/2012 10:19, Bob Cowdery wrote: >> On 06/05/2012 09:49, Cameron Simpson wrote: >>> On 06May2012 09:18, Bob Cowdery wrote: >>> | On 05/05/2012 23:05, Cameron Simpson wrote: >>> |> On 05May2012 20:33, Bob Cowdery wrote: >>> |> | [...] calls to time.time() always return the same >>> |> | time which is usually several seconds in the past or future >>> and always >>> |> | has no fractional part. >>> |> >>> |> Thought #1: you are calling time.time() and haven't unfortunately >>> |> renamed it? (I doubt this scenario, though the lack of >>> fractional part >>> |> is interesting.) >>> | >>> | Not sure what you mean by renamed it. >>> >>> Like this: >>> >>> from time import time >>> [...] >>> time = some_unfortunate_other_function >>> [...] >>> now = time() # calls wrong function >>> >>> It seems unlikely, but possible. >>> >>> | I also tried datetime and that had >>> | the same behaviour. >>> >>> Makes my suggestion even less likely unless the time module itself gets >>> monkeypatched (i.e. "time.time = bad_function" somewhere). >> I don't think the function is subverted unless there is some way inside >> the vendor SDK or even DirectShow (the SDK uses this as a COM object) >> which can somehow hijack it. It does catch up every few minutes so there >> has to be a clue there. >>> |> | If I leave it long enough time will suddently >>> |> | jump forward after a few minutes, then again after a few >>> minutes more. >>> |> | >>> |> | I've never encountered this behaviour before and can't >>> understand what >>> |> | on earth is going on. If I call the 'C' time() function just >>> the other >>> |> | side of my call to the extension the time is ticking along >>> fine. It's >>> |> | just the one Python thread that is affected. >>> |> [...] >>> |> >>> |> Thought #2: On a UNIX system I'd be running the process under >>> strace (or >>> |> dtrace or ktrace depending on flavour) to see what actual OS >>> system calls are >>> |> being made during this behaviour. Is this feasible for you? >>> | >>> | I'm on Windows for this particular part of the application. >>> >>> I'd guessed so. I've no Windows programming background; I was wondering >>> if there was something like this you had to hand on windows. >> Maybe, but not that I know of. >>> | [...] But debugging into this is probably the only way. I >>> | looked at the built-in time module. As far as I can tell it just >>> calls >>> | the underlying C time() function as an extension. This is more >>> | mystifying as that is pretty much what I'm doing by checking the >>> time in >>> | my own extension module where it ticks along fine. >>> >>> Hmm. A C extension I presume? How about writing a little pure Python >>> thread to call time.time(), and spin it off parallel to the rest of the >>> app; does it also get bad time.time() behaviour? >> I've tried that. It's only the Python thread (or Python main thread) >> that calls the extension that behaves like this. Other Python threads >> tick along fine with the correct time including a fractional part. >>> | I have another >>> | scenario using a different part of their SDK where the time does >>> still >>> | tick but the fractional part is frozen, not 0 but frozen. >>> >>> Curiouser and curiouser. >> Indeed. Away now but battle will resume on Tuesday. >> >> Bob >> >> >> > From tjreedy at udel.edu Tue May 8 12:12:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 12:12:04 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 9:47 AM, Chris Angelico wrote: > On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre > wrote: >> There is no "both projects". there was Luke's project, and then >> Risinger stole it and it's Risinger's project. There is only that one >> thing -- Luke has no """fork""" of his own codebase. > > Presumably Luke could fork his own project, though. I haven't checked, > but presumably the source is properly managed, so it can be forked as > of any point in time. > > But it's pretty nasty to have to fork your own project. You still have it backwards. Risinger forked the project with a new code host and mailing list, but stole the name and and some data in the process and made the false claim that his fork was the original. It is not clear if he damaged anything in the process. If Luke continues his original project, it would still be the true pyjamas project, not a fork. -- Terry Jan Reedy From charleshixsn at earthlink.net Tue May 8 12:30:11 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 08 May 2012 09:30:11 -0700 Subject: indexed property? Can it be done? In-Reply-To: References: <4FA88FD8.4000905@earthlink.net> Message-ID: <4FA94A13.5080703@earthlink.net> On 05/08/2012 12:50 AM, Peter Otten wrote: > Charles Hixson wrote: > > >> class Node: >> >> def __init__(self, nodeId, key, value, downRight, downLeft, >> parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> >> Note that node[3] is a list of keys (initially 1) and node[3] is a list >> of values, etc. >> >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it out. >> Any suggestions? >> > I don't see the problem: > > >>>> class Node(object): >>>> > ... def __init__(self, key): > ... self.node = ["foo", "bar", [key], "baz"] > ... @property > ... def key(self): > ... return self.node[2] > ... > >>>> node = Node(42) >>>> node.key >>>> > [42] > >>>> node.key[0] >>>> > 42 > >>>> node.key.append(7) >>>> node.key >>>> > [42, 7] > >>>> del node.key[0] >>>> node.key[:] = [3, 2, 1] >>>> node.key >>>> > [3, 2, 1] > >>>> node.key = "foo" >>>> > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute > > But the design proposed by Dan Sommers really is the way to go... > > That depends on what you're doing. For many, perhaps most, purposes I would agree. Not for this one. And I couldn't use an internal dict, as the order in which the items of the sub-lists occur is significant. The sub-lists need to be lists, though they could be separated out as named variables (which would be lists). The approach of returning the entire list would, indeed, work, but it exposes things that I would prefer to keep internal to the class (i.e., all the, e.g., keys that aren't currently being addressed). I suppose it isn't too inefficient, as IIUC, all you're really passing back and forth are pointers, but it doesn't *feel* like the right answer. So I can handle it by using getter and setter functions that recognize indicies, but it's less elegant than using indexing to access them. So I thought I'd ask. The ActiveState recipe *might* do what I want. I honestly can't tell after a brief study. But it's much too complex to be a worthwhile choice. I was hoping that I'd just overlooked one of the standard features of Python. To be truthful, the main benefit I see from using a class rather than a naked list structure is that I can readily test the type of the data. A secondary benefit would be the nicer syntax, as with the list all manipulation would be done via specialized functions, and for some of the terms indexed access would be syntactically nicer. But it looks like that isn't one of the possibilities. Using a native list structure and manipulatory functions is nicer except in two ways: 1) There's no data hiding, so discipline must substitute for language structure. 2) There's excess names apparent at an upper level. I wouldn't exactly call it namespace pollution, but it's certainly an increase in the higher-level namespace background noise level, even though it's all functional. -- Charles Hixson From rosuav at gmail.com Tue May 8 12:42:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 May 2012 02:42:10 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: > On 5/8/2012 9:47 AM, Chris Angelico wrote: >> >> On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre >> ?wrote: >>> >>> There is no "both projects". there was Luke's project, and then >>> Risinger stole it and it's Risinger's project. There is only that one >>> thing -- Luke has no """fork""" of his own codebase. >> >> >> Presumably Luke could fork his own project, though. I haven't checked, >> but presumably the source is properly managed, so it can be forked as >> of any point in time. >> >> But it's pretty nasty to have to fork your own project. > > > You still have it backwards. Risinger forked the project with a new code > host and mailing list, but stole the name and and some data in the process > and made the false claim that his fork was the original. It is not clear if > he damaged anything in the process. Yes, but now that it's happened, the most obvious way forward is to fork the hijacked project back to the original, given that the hijacked one is being posted as the original. > If Luke continues his original project, it would still be the true pyjamas > project, not a fork. Yeah, but if he doesn't have command of the domain any more, then he'll likely be spawning it under a new name somewhere. ChrisA From ian.g.kelly at gmail.com Tue May 8 12:49:33 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 10:49:33 -0600 Subject: indexed property? Can it be done? In-Reply-To: <4FA94A13.5080703@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> <4FA94A13.5080703@earthlink.net> Message-ID: On Tue, May 8, 2012 at 10:30 AM, Charles Hixson wrote: > That depends on what you're doing. ?For many, perhaps most, purposes I would > agree. ?Not for this one. ?And I couldn't use an internal dict, as the order > in which the items of the sub-lists occur is significant. ?The sub-lists > need to be lists, though they could be separated out as named variables > (which would be lists). It sounds like a collections.OrderedDict should do what you need. In the cases where you really need to have a list of keys or values, you can just use the .keys() and .values() methods. > The ActiveState recipe *might* do what I want. ?I honestly can't tell after > a brief study. ?But it's much too complex to be a worthwhile choice. ?I was > hoping that I'd just overlooked one of the standard features of Python. What do you find complex about it? The two class definitions are something you would put in a library module to be imported. The rest is just example / test code. The actual usage is no more complex than a regular property: class Node(object): def __init__(self, nodeId, key, value, downRight, downLeft, parent): dirty = True dlu = utcnow() self.node = [nodeId, downLeft, [key], [value], [downRight], parent, dirty, dlu] @itemproperty def key(self, index): return self.node[2][index] @itemproperty def value(self, index): return self.node[3][index] And of course you could also add setters and/or deleters if desired. From d.poreh at gmail.com Tue May 8 14:16:01 2012 From: d.poreh at gmail.com (d.poreh at gmail.com) Date: Tue, 8 May 2012 11:16:01 -0700 (PDT) Subject: which book? Message-ID: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> folks hi, I am going to learn python for some plot issues. which book or sources, do you recommend please? Cheers, Dave From alec.taylor6 at gmail.com Tue May 8 14:31:34 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 9 May 2012 04:31:34 +1000 Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: plot issues? On Wed, May 9, 2012 at 4:16 AM, wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave > -- > http://mail.python.org/mailman/listinfo/python-list From mephisto_9000 at hotmail.com Tue May 8 15:07:49 2012 From: mephisto_9000 at hotmail.com (F L) Date: Tue, 8 May 2012 15:07:49 -0400 Subject: Retrieving result from embedded execution Message-ID: Hello everyone, We are trying to implement our own interactive interpreter in our applicationusing an embedded Python interpreter. I was wondering what would be the best way to retreive as text the result of executing Python code. The text must be exactly the same as it would be in thestandalone interpreter. We used to do this by changing the embedded interpreter's sys.stdout and sys.stderrwith a FILE created in C++. We could then execute code using the PyRun_InteractiveOnefunction and easily retrieve the result from the FILE. The problem is, our applicationshouldn't create any files if possible. We also tried replacing sys.stdout and sys.stderr with a custom made Python objectwhich could be more easily read from C++. We then used the function PyRun_Stringto execute the code. The problem here is that using the Py_file_input start tokendoesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not write 4).It also doesn't print a traceback to sys.stderr when there is an exception. Using theother two start tokens is impossible since we need to be able to execute more than one instruction at once. We also tried using the function PyRun_SimpleString but weencounter the same problems. We are using python 2.7. Any suggestions? Thank you for your time. Also, I'm new to mailling lists, what is the proper way to reply to someone? Should Ireply directly to someone's email adress or is there a way to answer trough the server. F. Lab -------------- next part -------------- An HTML attachment was scrubbed... URL: From edcjones at comcast.net Tue May 8 15:13:03 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 08 May 2012 15:13:03 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 Message-ID: <4FA9703F.50207@comcast.net> I use up-to-date Debian testing (wheezy), amd64 architecture. I downloaded, compiled and installed Python 3.3.0 alpha 3 (from python.org) using "altinstall". Debian wheezy comes with python3.2 (and 2.6 and 2.7). I installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3). Note: Debian uses eggs. Python3.3a3 cannot find module bs4. Python3.2 can find the module. Here is a session with Python 3.3: > python3.3 Python 3.3.0a3 (default, May 5 2012, 11:30:48) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import bs4 Traceback (most recent call last): File "", line 1, in File "", line 1012, in _find_and_load ImportError: No module named 'bs4' >>> Here is what I have tried: 1. Put bs4.pth in /usr/local/lib/python3.3/site-packages. This file should contain the line: /usr/lib/python3/dist-packages This works. 2. At the start of each Python program using bs4: import sys sys.path.append('/usr/lib/python3/dist-packages') import bs4 This works. 3. In the Python 3.3 source code, do ".configure" then edit Modules/Setup to contain SITEPATH=:/usr/lib/python3/dist-packages Finish compiling and altinstalling python. "import bs4" works. The last is the best because I only have to do it once. Next I tried numpy. It is installed from Debian package "python3-numpy". If I compile Python 3.3 _without_ the change in (3) above, I get: > python3.3 Python 3.3.0a3 (default, May 8 2012, 14:30:18) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1012, in _find_and_load ImportError: No module named 'numpy' >>> which is not a surprise. If I compile and install Python 3.3 _with_ the change in (3) above, I get: > python3.3 Python 3.3.0a3 (default, May 8 2012, 14:43:28) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1015, in _find_and_load File "", line 634, in load_module File "", line 294, in module_for_loader_wrapper File "", line 522, in _load_module File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in from . import add_newdocs ImportError: cannot import name add_newdocs >>> "add_newdocs.py" is present in the numpy directory. The "import numpy" works for the Debian python 3.2. What is the problem? From rowen at uw.edu Tue May 8 15:19:35 2012 From: rowen at uw.edu (Russell E. Owen) Date: Tue, 08 May 2012 12:19:35 -0700 Subject: pickle question: sequencing of operations References: Message-ID: In article , "Russell E. Owen" wrote: > What is the sequence of calls when unpickling a class with __setstate__? > > >From experimentation I see that __setstate__ is called and __init__ is > not, but I think I need more info. > > I'm trying to pickle an instance of a class that is a subclass of > another class that contains unpickleable objects. > > What I'd like to do is basically just pickle the constructor parameters > and then use those to reconstruct the object on unpickle, but I'm not > sure how to go about this. Or an example if anyone has one. The following seems to work, but I don't know why: def __getstate__(self): ...return the argument dict needed for __init__ def __setstate__(self, argdict): self.__init__(**argdict) -- Russell From wrw at mac.com Tue May 8 15:44:01 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Tue, 08 May 2012 15:44:01 -0400 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: <1051143A-3EDC-4612-8FA2-E91636122EC6@mac.com> On May 8, 2012, at 3:07 PM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in the > standalone interpreter. > > We used to do this by changing the embedded interpreter's sys.stdout and sys.stderr > with a FILE created in C++. We could then execute code using the PyRun_InteractiveOne > function and easily retrieve the result from the FILE. The problem is, our application > shouldn't create any files if possible. > > We also tried replacing sys.stdout and sys.stderr with a custom made Python object > which could be more easily read from C++. We then used the function PyRun_String > to execute the code. The problem here is that using the Py_file_input start token > doesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not write 4). > It also doesn't print a traceback to sys.stderr when there is an exception. Using the > other two start tokens is impossible since we need to be able to execute more than > one instruction at once. We also tried using the function PyRun_SimpleString but we > encounter the same problems. > > We are using python 2.7. > > Any suggestions? > > Thank you for your time. [byte] I'm pretty new to Python myself, and I may not understand what you are trying to do, but have you looked at the subprocess module? Documented here: http://docs.python.org/library/subprocess.html Using subprocess.Popen would let you hook stdin and staout directly to pipes that will pass data back to the calling program with no intermediate steps. -Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue May 8 15:55:05 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 May 2012 13:55:05 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > In article , > ?"Russell E. Owen" wrote: > >> What is the sequence of calls when unpickling a class with __setstate__? I believe it just calls object.__new__ followed by yourclass.__setstate__. So at the point __setstate__ is called, you have a pristine instance of whatever class you're unpickling. > The following seems to work, but I don't know why: > def __getstate__(self): > ? ...return the argument dict needed for __init__ > > def __setstate__(self, argdict): > ? self.__init__(**argdict) That seems like it should be fine as long as all your initialization code is in __init__ and not in __new__. Cheers, Ian From gordon at panix.com Tue May 8 16:05:20 2012 From: gordon at panix.com (John Gordon) Date: Tue, 8 May 2012 20:05:20 +0000 (UTC) Subject: How to get outer class name from an inner class? Message-ID: I'm trying to come up with a scheme for organizing exceptions in my application. Currently, I'm using a base class which knows how to look up the text of a specific error in a database table, keyed on the error class name. The base class looks like this: class ApplicationException(Exception): """Base class for application-specific errors.""" def get_message(self): """Return the error message associated with this class name.""" class_name = self.__class__.__name__ return UserMessage.objects.get(key=class_name).text And then I define a bunch of subclasses which all have different names: class QuestionTooShortError(NetIDAppsError): """User entered a security question which is too short.""" pass class QuestionTooLongError(NetIDAppsError): """User entered a security question which is too long.""" pass This scheme works, but I'd like to make it more streamlined. Specifically, I'd like to group the classes underneath a parent class, like so: class Question(ApplicationException): class TooShort(ApplicationException): pass class TooLong(ApplicationException): pass This will make it easier in the future for organizing lots of sub-errors. My problem is this: the get_message() method in the base class only knows the current class name, i.e. "TooShort" or "TooLong". But that's not enough; I also need to know the outer class name, i.e. "Question.TooShort" or "Question.TooLong". How do I get the outer class name? Thanks, -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gordon at panix.com Tue May 8 16:08:24 2012 From: gordon at panix.com (John Gordon) Date: Tue, 8 May 2012 20:08:24 +0000 (UTC) Subject: How to get outer class name from an inner class? References: Message-ID: In John Gordon writes: > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass Oops! These classes inherit from ApplicationException, not NetIDAppsError. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From awilliam at whitemice.org Tue May 8 16:19:41 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 08 May 2012 16:19:41 -0400 Subject: indexed property? Can it be done? In-Reply-To: <4FA88FD8.4000905@earthlink.net> References: <4FA88FD8.4000905@earthlink.net> Message-ID: <1336508381.9435.15.camel@linux-nysu.site> On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote: > class Node: > def __init__(self, nodeId, key, value, downRight, downLeft, parent): > dirty = True > dlu = utcnow() > self.node = [nodeId, downLeft, [key], [value], > [downRight], parent, dirty, dlu] > Note that node[3] is a list of keys (initially 1) and node[3] is a list > of values, etc. > What I'd like to do is to be able to address them thusly: > k = node.key[2] > v = node.value[2] > but if there's a way to do this, I haven't been able to figure it out. > Any suggestions? Do not do this; this is bad code in any language. -------------- 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 clp2 at rebertia.com Tue May 8 16:21:13 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 8 May 2012 13:21:13 -0700 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: On Tue, May 8, 2012 at 1:05 PM, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ?"""Base class for application-specific errors.""" > > ? ?def get_message(self): > ? ? ? ?"""Return the error message associated with this class name.""" > > ? ? ? ?class_name = self.__class__.__name__ > ? ? ? ?return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ?"""User entered a security question which is too short.""" > ? ?pass > > class QuestionTooLongError(NetIDAppsError): > ? ?"""User entered a security question which is too long.""" > ? ?pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ?class TooShort(ApplicationException): > ? ? ? ?pass > > ? ?class TooLong(ApplicationException): > ? ? ? ?pass > > This will make it easier in the future for organizing lots of sub-errors. You could use modules instead? Nested classes are stylistically questionable. > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? Use __qualname__ and chop off the last dotted part (i.e. the innermost class' name, thus yielding its parent's name). PEP 3155 -- Qualified name for classes and functions: http://www.python.org/dev/peps/pep-3155/ Cheers, Chris From tjreedy at udel.edu Tue May 8 17:47:36 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 17:47:36 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 12:42 PM, Chris Angelico wrote: > On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: >> You still have it backwards. Risinger forked the project with a new code >> host and mailing list, but stole the name and and some data in the process >> and made the false claim that his fork was the original. It is not clear if >> he damaged anything in the process. > > Yes, but now that it's happened, the most obvious way forward is to > fork the hijacked project back to the original, given that the > hijacked one is being posted as the original. Risinger's fork is NOT the original, no matter what his claim. People should not give credit to his false claim or regard it as an accomplished fact. From what others have posted, it has a new code repository (that being the ostensible reason for the fork), project site, and mailing list -- the latter two incompetently. Apparently, the only thing he has kept are the domain and project names (the latter for sure not legitimately). Luke has not abandoned pyjamas and has not, as of now, ceded ownership of the name to anyone. I am pretty sure Luke he has no plans to adandon his current codebase and and re-fork off of the Risinger et al revised codebase. >> If Luke continues his original project, it would still be the true pyjamas >> project, not a fork. > > Yeah, but if he doesn't have command of the domain any more, then > he'll likely be spawning it under a new name somewhere. Yes, but so what? The domain name is not the project. Open source projects change domain names all the time (though hopefully rarely for any particular project). -- Terry Jan Reedy From tjreedy at udel.edu Tue May 8 18:11:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 18:11:51 -0400 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: On 5/8/2012 4:05 PM, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > """Base class for application-specific errors.""" > > def get_message(self): > """Return the error message associated with this class name.""" > > class_name = self.__class__.__name__ > return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. I think maybe you are being much too fine-grained in your exception hierarchy. Python has, for instance, just one ValueError, with details in the error. The details can include specific values only known at the point of the error. You are putting some specifics in the exception name and then (apparently) given them somewhat redundant canned messages lacking situation-specific details. For instance errfmt = "Security question length {:d} not in legal range {:d} - {:d}" if not (secquemin <= len(secque) <= secquemax): raise ValueError(errfmt.format(len(secque), secquemin, secquemax)) # or ApplicationError or AppValueError if you want. The messages in Python are not this good, but they slowly improve as people raises an issue on the tracker and others implement and apply fixex. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 8 18:46:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 18:46:43 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 In-Reply-To: <4FA9703F.50207@comcast.net> References: <4FA9703F.50207@comcast.net> Message-ID: On 5/8/2012 3:13 PM, Edward C. Jones wrote: > I use up-to-date Debian testing (wheezy), amd64 architecture. I downloaded, > compiled and installed Python 3.3.0 alpha 3 (from python.org) using > "altinstall". Debian wheezy comes with python3.2 (and 2.6 and 2.7). I > installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3). Your problem with bs4 seems to be that it got installed in a way that 3.2 could find it and 3.3 could not. > 1. Put bs4.pth in /usr/local/lib/python3.3/site-packages. This file should > contain the line: > /usr/lib/python3/dist-packages > This works. As it should, being the standard alternative to putting the module in site-packages. > 2. At the start of each Python program using bs4: > import sys > sys.path.append('/usr/lib/python3/dist-packages') > import bs4 > This works. Another standard methods. > 3. In the Python 3.3 source code, do ".configure" then edit > Modules/Setup to > contain > SITEPATH=:/usr/lib/python3/dist-packages > Finish compiling and altinstalling python. "import bs4" works. An option only for those who compile. The two above work on windows for those who do not. > The last is the best because I only have to do it once. The .pth entry is also once only. > Next I tried numpy. It is installed from Debian package "python3-numpy". I bet the Debian packager has not tested the python packages with 3.3ax yet. On Windows, compiled packages don't work with new Python versions. On *nix, things are better but not necessarily perfect. > If I compile and install Python 3.3 _with_ the > change in (3) above, I get: > > > python3.3 > Python 3.3.0a3 (default, May 8 2012, 14:43:28) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > Traceback (most recent call last): > File "", line 1, in > File "", line 1015, in _find_and_load > File "", line 634, in load_module > File "", line 294, in > module_for_loader_wrapper > File "", line 522, in _load_module > File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in > > from . import add_newdocs > ImportError: cannot import name add_newdocs In this case, the problem in Python rather than C code. > "add_newdocs.py" is present in the numpy directory. > The "import numpy" works for the Debian python 3.2. > What is the problem? Question 1: if you use the .pth method, do you get the same result? (I expect you will, but good to check.) Question 2: has anyone successfully run numpy with 3.3 on Debian or anything else? If no one here answers, try Debian or numpy lists. Comment: the import machinery is heavily revised for 3.3. I believe is new. I believe relative imports may have been changed to fix bugs. One could have been introduced (though there are no reports on the tracker). If so, we need to fix it. Or perhaps there is something special about __init__ I am not aware of. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue May 8 18:55:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 08 May 2012 23:55:38 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/05/2012 22:47, Terry Reedy wrote: > On 5/8/2012 12:42 PM, Chris Angelico wrote: >> On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote: > >>> You still have it backwards. Risinger forked the project with a new code >>> host and mailing list, but stole the name and and some data in the >>> process >>> and made the false claim that his fork was the original. It is not >>> clear if >>> he damaged anything in the process. >> >> Yes, but now that it's happened, the most obvious way forward is to >> fork the hijacked project back to the original, given that the >> hijacked one is being posted as the original. > > Risinger's fork is NOT the original, no matter what his claim. People > should not give credit to his false claim or regard it as an > accomplished fact. > > From what others have posted, it has a new code repository (that being > the ostensible reason for the fork), project site, and mailing list -- > the latter two incompetently. Apparently, the only thing he has kept are > the domain and project names (the latter for sure not legitimately). > > Luke has not abandoned pyjamas and has not, as of now, ceded ownership > of the name to anyone. I am pretty sure Luke he has no plans to adandon > his current codebase and and re-fork off of the Risinger et al revised > codebase. > >>> If Luke continues his original project, it would still be the true >>> pyjamas >>> project, not a fork. >> >> Yeah, but if he doesn't have command of the domain any more, then >> he'll likely be spawning it under a new name somewhere. > > Yes, but so what? The domain name is not the project. Open source > projects change domain names all the time (though hopefully rarely for > any particular project). > {Not replying To Terry Reedy or anybody else specifically, but didn't know where to jump in] Who cares, in the sense that zero people (apart from five(ish) morons) will follow the hijacked project, while the vast majority will support Luke as a matter of principal. I suggest the thieves be subjected to this http://en.wikipedia.org/wiki/Send_to_Coventry -- Cheers. Mark Lawrence. From charleshixsn at earthlink.net Tue May 8 18:59:23 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 08 May 2012 15:59:23 -0700 Subject: indexed property? Can it be done? In-Reply-To: <1336508381.9435.15.camel@linux-nysu.site> References: <4FA88FD8.4000905@earthlink.net> <1336508381.9435.15.camel@linux-nysu.site> Message-ID: <4FA9A54B.6090707@earthlink.net> On 05/08/2012 01:19 PM, Adam Tauno Williams wrote: > On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote: > >> class Node: >> def __init__(self, nodeId, key, value, downRight, downLeft, parent): >> dirty = True >> dlu = utcnow() >> self.node = [nodeId, downLeft, [key], [value], >> [downRight], parent, dirty, dlu] >> Note that node[3] is a list of keys (initially 1) and node[3] is a list >> of values, etc. >> What I'd like to do is to be able to address them thusly: >> k = node.key[2] >> v = node.value[2] >> but if there's a way to do this, I haven't been able to figure it out. >> Any suggestions? >> > Do not do this; this is bad code in any language. > I'm sorry, but why do you say that? In D or Eiffel it is a standard approach, with compiler support. I will admit that one shouldn't do it in C++, or, it appears, in Python. This is far from justifying saying one should never do it. -- Charles Hixson From breamoreboy at yahoo.co.uk Tue May 8 18:59:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 08 May 2012 23:59:40 +0100 Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: On 08/05/2012 19:16, d.poreh at gmail.com wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave matplotlib - google and yee shall find. -- Cheers. Mark Lawrence. From k.sharagovind at gmail.com Tue May 8 19:04:05 2012 From: k.sharagovind at gmail.com (sharadha devi) Date: Tue, 8 May 2012 16:04:05 -0700 (PDT) Subject: $1000.00 Daily - See PROOF ! Message-ID: <69009982-6127-45f6-ab32-657dddbd311a@k7g2000pbo.googlegroups.com> REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX +++ Jesus Loves You +++ http://jesuslovesyou-youlovejesus.blogspot.in/ CHECK ALL THESE AMAZING HUGE DISCOUNTED PRODUCTS & BUY THEM WHAT YOU LIKE !!! http://alloffersblog.blogspot.in/ http://myblog-mycash.blogspot.in/ http://stephenanand.blogspot.in/ http://clickforgreatoffers.blogspot.in/ http://buyallamazonproducts.blogspot.in/ CHECK OUT THIS AMAZING ONLINE BUSSINESS STORES : http://linkshareoffers.blogspot.in/ http://buythemwhatyoulike.blogspot.com/ http://paydotoffers.blogspot.com/ SEARCH & BUY FROM OVER 10,000 INFO-PRODUCTS INSTANTLY : http://cbglobe.com/x.cgi?id=stephen1 WORLD BEST DIAMOND RINGS & JEWELRY WEBSITE : CHOOSE FROM A WIDE RANGE ALL @ WHOLESALE PRICES http://www.shireeodiz.com/diamond-engagement-rings/4d6a526826ecd/08898bec.html REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX @@@@@ AMAZING HUGE DISCOUNTED PRODUCTS @@@@@@ >>>> BUY THEM WHAT YOU LIKE !!! <<<<<<<<< Resell Products Monthly (Lifetime Member) - Get Instant Access To 1,132 Private Label Rights And Master Resale Rights Products http://payspree.com/4644/stephen1 Prosperity Party ($608 of Inspiring Vid/Aud/etc) http://payspree.com/2084/stephen1 Hot Marketing Videos - Lifetime Membership http://payspree.com/3242/stephen1 The Art Of Making Money Online Get rid of fear once and for all. Make money on your PC from home with your own stuff. http://payspree.com/4304/stephen1 Nikon D3100 14.2 Megapixel Digital SLR Camera - Overview of Nikon D3100 14.2 Megapixel Digital SLR Camera (Body with Lens Kit) - 18 mm-55 mm - Black http://payspree.com/5242/stephen1 Take Control | Health | Life | MP3 and ebook - "Who Else Is Ready To Be Healthy NOW?" | Take Control ...it's your health ... it's your life | by Donald M. Alanen http://payspree.com/3996/stephen1 Fireball Internet Marketing Course - 2-Month Internet Marketing Course with Ian del Carmen http://payspree.com/858/stephen1 eCover Crusher - High Quality Photoshop Action Scripts with photoshop how to videos, sales page writing template and how to start a ecover design business http://payspree.com/2733/stephen1 Squeeze Synergy One-Time Offer For Fast Track Cash http://payspree.com/3885/stephen1 10 Strategy Sessions With Experts (+transcripts) - Converts like crazy! http://payspree.com/4311/stephen1 Answer Marketing Traffic No Hard Selling, No Product Of Your Own An NO Risk! http://payspree.com/1169/stephen1 Niche Hunting For Newbies, which converts like crazy. http://payspree.com/1391/stephen1 Ezine Articles Quick Niche Secrets - Uncover Complete Gold Mine Niches From Ezine Articles In 10 Minutes Or Less... http://payspree.com/1517/stephen1 Social Marketing Tips http://payspree.com/1398/stephen1 OTO Firesale http://payspree.com/5667/stephen1 Sniper List Building - List building Crushing it online http://payspree.com/3559/stephen1 One Time Offer Blueprint http://payspree.com/1173/stephen1 Easy Offline SEO - How to make money as an offline SEO consultant without doing ANY of the work yourself and with zero expert knowledge! http://payspree.com/4922/stephen1 List Building Conquest - Build Quick In Demand Products And Create A 10,000+ Subscriber Traffic Machine. http://payspree.com/3262/stephen1 Online Paycheck Blueprint - Learn everything you need to start your Internet business. http://payspree.com/5209/stephen1 EASY MONEY - 100% COMMISSIONS INSTANT PAYMENTS NICE PRODUCTS http://payspree.com/5308/stephen1 $20 Dollar Bill Blaster - Get $20 Instantly Blasted into your PayPal Account Every Time Someone Joins through your $20 Bill Blaster Referral Link! http://payspree.com/4406/stephen1 WordPress Product Automator - WP product delivery plugin, includes great bonuses 5 WP themes, making money with PLR/MRR http://payspree.com/1504/stephen1 Quick and Easy CB Riches http://payspree.com/3883/stephen1 20 Newbie Videos - Firesale OTO ($10 Off) - 20 Newbie Videos http://payspree.com/5823/stephen1 From edcjones at comcast.net Tue May 8 20:19:45 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 08 May 2012 20:19:45 -0400 Subject: Using modules from Debian "python3-..." packages with locally compiled Python 3.3 Message-ID: <4FA9B821.8000202@comcast.net> Terry Reedy said: > Question 1: if you use the .pth method, do you get the same result? (I expect you will, but good to > check.) Recompiled Pyhton 3.3 without the SITEPATH change. Same result: > python3.3 Python 3.3.0a3 (default, May 8 2012, 19:57:45) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "", line 1, in File "", line 1015, in _find_and_load File "", line 634, in load_module File "", line 294, in module_for_loader_wrapper File "", line 522, in _load_module File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in from . import add_newdocs ImportError: cannot import name add_newdocs >>> > Question2: has anyone successfully run numpy with 3.3 on Debian or anything else? If no one here > answers, try Debian or numpy lists. I don't know. But Python 3.3.0a3 has been in Debian experimental for only a few days. I have a bunch of code that I want to port to Python 3. I delayed for years because numpy and PIL had not been ported to Python 3. Numpy has now been converted and there are alternatives to PIL. Since I want to deal with unicode only once, I would prefer to use 3.3 but 3.2 would be OK. From wuwei23 at gmail.com Tue May 8 20:42:40 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 8 May 2012 17:42:40 -0700 (PDT) Subject: How do I run a python program from an internet address? References: Message-ID: <1fb7ca0d-854c-4976-8a2a-d362f187b897@s9g2000pbq.googlegroups.com> On May 8, 9:20?am, Albert wrote: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. ?It is just an > algorithm that makes a handful of straightforward calculations on some > input that the user provides and spits out some text as output that > they might want to print out on a printer. ?I can program python on my > local machine, but don't know how to make the code accessible from a > browser. You could do this quite easily with CherryPy: import cherrypy class WebApp(object): def calc(self, a, b): c = int(a) + int(b) return str(c) calc.exposed = True cherrypy.quickstart(WebApp()) This can be called via '/calc/1/2' or 'calc?a=1&b=2'. You can add a method to provide a form and another to produce a pretty output and it's good to go. http://www.cherrypy.org/ From showell30 at yahoo.com Tue May 8 20:52:10 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 8 May 2012 17:52:10 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: On May 8, 1:05?pm, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ? """Base class for application-specific errors.""" > > ? ? def get_message(self): > ? ? ? ? """Return the error message associated with this class name.""" > > ? ? ? ? class_name = self.__class__.__name__ > ? ? ? ? return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ? """User entered a security question which is too short.""" > ? ? pass > > class QuestionTooLongError(NetIDAppsError): > ? ? """User entered a security question which is too long.""" > ? ? pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? This may be somewhat relevant to you, although it doesn't specifically answer your question for pre-3.3: http://www.python.org/dev/peps/pep-3155/ (Qualified name for classes and functions) From tjreedy at udel.edu Tue May 8 21:35:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 May 2012 21:35:22 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/8/2012 5:47 PM, Terry Reedy wrote: > From what others have posted, it has a new code repository (that being > the ostensible reason for the fork), project site, and mailing list -- > the latter two incompetently. Apparently, the only thing he has kept are > the domain and project names (the latter for sure not legitimately). Update: the pyjs.org group (or member thereof) has registered pyjs as a new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they seem not to be claiming the name 'pyjames', at least not on pypi. -- Terry Jan Reedy From sdiwcconferences at gmail.com Tue May 8 23:20:26 2012 From: sdiwcconferences at gmail.com (sdiwc conferences) Date: Tue, 8 May 2012 20:20:26 -0700 (PDT) Subject: Last CFP- CyberSecurity - Malaysia - IEEE Message-ID: <23d473f8-e3a4-401d-9192-e11578af85cf@l5g2000pbo.googlegroups.com> The International Conference on Cyber Security, Cyber Warfare and Digital Forensic (CyberSec2012) University Putra Malaysia, Kuala Lumpur, Malaysia June 26-28, 2012 http://www.sdiwc.net/CyberSec2012/ The CyberSec2012 is technically co-sponsored by IEEE Malaysia Chapter and All papers will be submitted to IEEE for potential inclusion to IEEE Xplore and Ei Compendex. ======================================================================== The proposed conference on the above theme will be held at University Putra Malaysia, Kuala Lumpur, Malaysia, From June 26-28, 2012 which aims to enable researchers to build connections between different digital applications. The conference welcomes papers on the following (but not limited to) research topics: *Cyber Security -Privacy issues -Formal Methods Application in Security -Incident Handling and Penetration Testing -Operating Systems and Database Security -Security in Cloud Computing -Security in Social Networks -Multimedia and Document Security -Hardware-Based security -VOIP, Wireless and Telecommunications Network Security -Security of Web-based Applications and Services -Enterprise Systems Security -SCADA and Embedded systems security -Distributed and Pervasive Systems Security -Secure Software Development, Architecture and Outsourcing -Security for Future Networks -Security protocols -Legal Issues *Digital Forensic -Data leakage, Data protection and Database forensics -Forensics of Virtual and Cloud Environments -Network Forensics and Traffic Analysis Hardware Vulnerabilities and Device Forensics -Information Hiding -File System and Memory Analysis Multimedia Forensic -Executable Content and Content Filtering -Anti-Forensics and Anti-Anti-Forensics Techniques -Malware forensics and Anti-Malware techniques -Evidentiary Aspects of Digital Forensics -Investigation of Insider Attacks -Cyber-Crimes -Large-Scale Investigations -New threats and Non-Traditional approaches *Information Assurance and Security Management -Corporate Governance -Laws and Regulations -Threats, Vulnerabilities, and Risk Management -Business Continuity & Disaster Recovery Planning -Critical Infrastructure Protection -Digital Rights Management and Intellectual Property Protection -Security Policies and Trust Management -Identity Management -Decidability and Complexity -Economics of Security -Fraud Management *Cyber warfare and Physical Security -Surveillance Systems -Cyber Warfare Trends and Approaches -Social engineering -Authentication and Access Control Systems -Biometrics Applications -Electronic Passports, National ID and Smart Card Security -Template Protection and Liveliness detection -Biometrics standards and standardization -New theories and algorithms in biometrics Researchers are encouraged to submit their work electronically. All papers will be fully refereed by a minimum of two specialized referees. Before final acceptance, all referees comments must be considered. Important Dates ============== Submission Date : May 12, 2012 Notification of acceptance: May 22, 2012 Camera Ready submission : May 25, 2012 Registration : May 30, 2012 Conference dates : June 26-28, 2012 From wuwei23 at gmail.com Wed May 9 02:31:04 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 8 May 2012 23:31:04 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: <725e554b-914a-48c6-b4f3-10e6adcfc8f2@r2g2000pbs.googlegroups.com> On May 9, 6:05?am, John Gordon wrote: > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". ?But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". ?How do I get the outer class name? This might do the trick: import inspect def exception_members(scope): classes = (m[1] for m in inspect.getmembers(scope, inspect.isclass)) return set( c for c in classes if Exception in c.__mro__ ) class ApplicationException(Exception): @property def outer_scope(self): for _class in exception_members(inspect.getmodule(self.__class__)): if self.__class__ in exception_members(_class): return _class def get_message(self): scope = self.outer_scope class_name = scope.__name__ + '.' if scope else '' class_name += self.__class__.__name__ return class_name When get_message is run, it looks in the module where the exception was defined for any new classes derived from Exception, then looks at the members of each of those to see if it matches the current object's class. Not really well tested, so beware :) From varma.nikhil22 at gmail.com Wed May 9 02:56:37 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 12:26:37 +0530 Subject: return respective values when mutiple keys are passed in dictionary In-Reply-To: References: Message-ID: Thanks Arnaud List comprehension method really works nicely.sorry for late reply. On Mon, May 7, 2012 at 7:10 PM, Arnaud Delobelle wrote: > On 7 May 2012 12:31, Nikhil Verma wrote: > > HI All > > > > I was clearing my concepts on dictionary and stuck in this problem. > > I have a dictionary which i have formed by using zip function on two > list so > > that one list (which i have hardcoded) becomes the keys and the other > list > > becomes its values. > > > > Now i want to know how can i get the values of keys at once if i pass the > > keys in a dictionary. > > > > Let say I have a dictionary > > > > mydict = {'a':'apple' , 'b':'boy' ,'c' : 'cat', 'd':'duck','e':'egg'} > > > > Now if i do :- > > > > mydict.get('a') > > 'apple' > > mydict['a'] is the usual way to get the value associated with a key. > The difference is that it will throw an exception if the key doesn't > exist, which is most of the time the sanest thing to do. > > > What i want is some i pass keys in get and in return i should have all > the > > values of those keys which i pass. > > > > ################## > > mydict.get('a','b','c') ###demo for what i want > > 'apple','boy','cat' ### Output i want > > ################# > > 1. You can use a list comprehension > > >>> [mydict[k] for k in 'a', 'b', 'c'] > ['apple', 'boy', 'cat'] > > 2. You can use map (for python 3.X, you need to wrap this in list(...)) > > >>> map(mydict.__getitem__, ['a', 'b', 'c']) > ['apple', 'boy', 'cat'] > > 3. You can use operator.itemgetter > > >>> from operator import itemgetter > >>> itemgetter('a', 'b', 'c')(mydict) > ('apple', 'boy', 'cat') > > -- > Arnaud > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From varma.nikhil22 at gmail.com Wed May 9 03:01:49 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 12:31:49 +0530 Subject: tweaking random number Message-ID: Hi All I want to generate a random number of 8 digits which involve 3 number and 5 digits. Like this :- def random_number(): # do something random_number() "123abcde" # first 3 numbers and 5 letters after the numbers. I am able to generate the random number 8 digit like this:- def random_number(): characters = list(string.ascii_lowercase + string.ascii_uppercase\ + string.digits) coll_rand = [] for i in range(8): random.shuffle(characters) coll_rand.append(characters[0]) return ''.join(coll_rand) This generates like this "Kkrgt56r" Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed May 9 03:38:34 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 08:38:34 +0100 Subject: tweaking random number In-Reply-To: References: Message-ID: <4FAA1EFA.5020708@mrabarnett.plus.com> On 09/05/2012 08:01, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number > and 5 digits. > Like this :- > > def random_number(): > # do something > > random_number() > "123abcde" # first 3 numbers and 5 letters after the numbers. > > I am able to generate the random number 8 digit like this:- > > def random_number(): > characters = list(string.ascii_lowercase + string.ascii_uppercase\ > + string.digits) > coll_rand = [] > for i in range(8): > random.shuffle(characters) > coll_rand.append(characters[0]) > return ''.join(coll_rand) > > This generates like this "Kkrgt56r" > Use random.choice to pick a random digit or a random letter. From rosuav at gmail.com Wed May 9 03:44:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 May 2012 17:44:00 +1000 Subject: tweaking random number In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your current random_number function (btw, I wouldn't call it "number" as it isn't one) is most of one possible solution. Divide it into two parts, one part that generates the digits and another part that generates the letters. Your 'characters' template would thus be different for the two parts. There are other solutions, which involve the generation of less random numbers, but your way will work. ChrisA From ulrich.eckhardt at dominolaser.com Wed May 9 03:56:25 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 09 May 2012 09:56:25 +0200 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: Am 08.05.2012 22:05, schrieb John Gordon: [...] > class QuestionTooShortError(ApplicationException): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(ApplicationException): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. What is it that this "parent class" represents? What is the relation between class Question and class TooShort? In general terms, it isn't even a parent class but just an outer class, a parent class implies that child classes inherit from it. I think that you're going about this the wrong way, and that a module represents much better what you are trying to express here. Your code actually looks a bit like it was written with a strong Java or C++ background, could that be the case? > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". How do I get the outer class name? # in module "Question" class _Exception(ApplicationException): def get_message(self): return self._lookup_message("Question." + self.__class__.__name__) class TooLong(_Exception): pass You might even be able to look up the module name instead of hard-coding it in one place. Uli From __peter__ at web.de Wed May 9 04:30:10 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 May 2012 10:30:10 +0200 Subject: tweaking random number References: Message-ID: Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and > 5 digits. > Like this :- > > def random_number(): > # do something > > random_number() > "123abcde" # first 3 numbers and 5 letters after the numbers. > > I am able to generate the random number 8 digit like this:- > > def random_number(): > characters = list(string.ascii_lowercase + string.ascii_uppercase\ > + string.digits) > coll_rand = [] > for i in range(8): > random.shuffle(characters) > coll_rand.append(characters[0]) > return ''.join(coll_rand) > > This generates like this "Kkrgt56r" > > Thanks in advance If you generalize your random_number() function >>> import random, string >>> def random_code(n=8, chars=string.ascii_lowercase+string.ascii_uppercase+string.digits): ... return "".join(random.choice(chars) for _ in range(n)) ... >>> random_code() 'NgcLhYdR' >>> random_code() 'j9gafcHh' >>> random_code(chars="123ABC") 'C311BA31' >>> random_code(n=4) 'MAsV' you can use it as a building block quite easily: >>> def three_five(): ... return random_code(3, string.digits) + random_code(5, string.ascii_lowercase + string.ascii_uppercase) ... >>> three_five() '656xEWmd' >>> three_five() '589XqZcI' >>> three_five() '168iOOIM' From esabel711 at googlemail.com Wed May 9 04:36:30 2012 From: esabel711 at googlemail.com (lilin Yi) Date: Wed, 9 May 2012 01:36:30 -0700 (PDT) Subject: Question of Python second loop break and indexes Message-ID: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> //final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the next time I want to start from next index in x,which will save time. That is to say , when the if command satisfied ,it can automatically jump out out the second while loop and come to the next identifier of final_1 ,meanwhile the j should start not from the beginning but the position previous. //when I run the code it takes too much time more than one hour and give the wrong result....so could you help me make some improvement of the code? i=0 offset_1=0 while i Message-ID: <7xfwb9682w.fsf@ruckus.brouhaha.com> Albert writes: > I have a small text based python program that I want to make available > to people who might be behind a firewall or can't install python on > their office computers, but can access the internet. What kind of people? I.e. is it something you're doing for work, where the users are (say) your co-workers? If you're just asking the simplest way to put a python script on a web page, I'd say it's to write a cgi and put it behind a normal web server. I'd avoid stuff like Google app server if possible, especially if there are any privacy concerns about the data going into the program. I much prefer to use cheap virtual servers even though I have to pay for them. They are amazingly affordable: you can get a 128MB server with enough resources for typical personal websites for a couple USD a month. That approach does require you to know a little bit about server administration but it's not that big a deal. From python at mrabarnett.plus.com Wed May 9 05:13:00 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 10:13:00 +0100 Subject: Question of Python second loop break and indexes In-Reply-To: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> References: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> Message-ID: <4FAA351C.1070606@mrabarnett.plus.com> On 09/05/2012 09:36, lilin Yi wrote: > //final_1 is a list of Identifier which I need to find corresponding > files(four lines) in x(x is the file) and write following four lines > in a new file. > > //because the order of the identifier is the same, so after I find the > same identifier in x , the next time I want to start from next index > in x,which will save time. That is to say , when the if command > satisfied ,it can automatically jump out out the second while loop and > come to the next identifier of final_1 ,meanwhile the j should start > not from the beginning but the position previous. > > //when I run the code it takes too much time more than one hour and > give the wrong result....so could you help me make some improvement of > the code? > > i=0 > > offset_1=0 > > > while i j = offset_1 > while j if final_1[i] == x1[j]: > new_file.write(x1[j]) > new_file.write(x1[j+1]) > new_file.write(x1[j+2]) > new_file.write(x1[j+3]) > offset_1 = j+4 > quit_loop="True" > if quit_loop == "True":break > else: j=j +1 > i=i+1 This is roughly equivalent: j = 0 for f in final_1: try: # Look for the identifier starting at index 'j'. j = x1.index(f, j) except ValueError: # Failed to find the identifier. pass else: # Found the identifier at index 'j'. new_file.write(x1[j]) new_file.write(x1[j + 1]) new_file.write(x1[j + 2]) new_file.write(x1[j + 3]) # Skip over the 4 lines. j += 4 From jameskhedley at gmail.com Wed May 9 05:32:28 2012 From: jameskhedley at gmail.com (james hedley) Date: Wed, 9 May 2012 02:32:28 -0700 (PDT) Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: <5524911.6.1336555948102.JavaMail.geo-discussion-forums@vbez18> On Tuesday, 8 May 2012 19:16:01 UTC+1, d.p... at gmail.com wrote: > folks > hi, > I am going to learn python for some plot issues. which book or sources, do you recommend please? > Cheers, > Dave I started with Dive Into Python. It's getting old now but for me it really catches the spirit of Python programming; clean, readable, and idiomatic. Plus it's fairly concise itself and emphasises the standard libraries. If you get stuck, obviously just search, but there is a lot of good info on Stack Overflow particularly. James From jeanmichel at sequans.com Wed May 9 05:37:33 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 11:37:33 +0200 Subject: Is Python Lazy? In-Reply-To: References: Message-ID: <4FAA3ADD.7030409@sequans.com> Emeka wrote: > > Hello All, > > Could one say that generator expressions and functions are Python way > of introducing Lazy concept? > > Regards, \Emeka > -- > /Satajanus Nig. Ltd > > > / No. From ulrich.eckhardt at dominolaser.com Wed May 9 05:52:33 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 09 May 2012 11:52:33 +0200 Subject: Question of Python second loop break and indexes In-Reply-To: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> References: <8bce0b27-1895-41d8-b3eb-930d41bc8a92@v2g2000vbx.googlegroups.com> Message-ID: <2crp79-rdi.ln1@satorlaser.homedns.org> Am 09.05.2012 10:36, schrieb lilin Yi: > //final_1 is a list of Identifier which I need to find corresponding > files(four lines) in x(x is the file) and write following four lines > in a new file. > > //because the order of the identifier is the same, so after I find the > same identifier in x , the next time I want to start from next index > in x,which will save time. That is to say , when the if command > satisfied ,it can automatically jump out out the second while loop and > come to the next identifier of final_1 ,meanwhile the j should start > not from the beginning but the position previous. > > //when I run the code it takes too much time more than one hour and > give the wrong result....so could you help me make some improvement of > the code? If the code takes too much time and gives the wrong results, you must fix and improve it. In order to do that, the first thing you should do is get familiar with "test-driven development" and Python's unittest library. You can start by fixing the code, but chances are that you will break it again trying to make it fast then. Having tests that tell you after each step that the code still works correctly is invaluable. Some more comments below... > i=0 > > offset_1=0 > > > while i j = offset_1 > while j if final_1[i] == x1[j]: > new_file.write(x1[j]) > new_file.write(x1[j+1]) > new_file.write(x1[j+2]) > new_file.write(x1[j+3]) > offset_1 = j+4 > quit_loop="True" > if quit_loop == "True":break > else: j=j +1 > i=i+1 Just looking at the code, there are a few things to note: 1. You are iterating "i" from zero to len(final_1)-1. The pythonic way to code this is using "for i in range(len(final_1)):...". However, since you only use the index "i" to look up an element inside the "final_1" sequence, the proper way is "for f in final_1:..." 2. Instead of writing four lines separately, you could write them in a loop: "for x in x1[j:j+4]: new_file.write(x)". 3. "x1" is a list, right? In that case, there is a member function "index()" that searches for an element and accepts an optional start position. 4. The "quit_loop" is useless, and you probably are getting wrong results because you don't reset this value. If you use "break" at the place where you assign "True" to it, you will probably get what you want. Also, Python has real boolean variables with the two values "True" and "False", you don't have to use strings. Concerning the speed, you can probably improve it by not storing the lines of the input file in "x1", but rather creating a dictionary mapping between the input value and the according four lines: content = open(...).readlines() d = {} for i in range(0, len(content), 4): d[content[i]] = tuple(content[i, i+4]) Then, drop the "offset_1" (at least do that until you have the code working correctly), as it doesn't work with a dictionary and the dictionary will probably be faster anyway. The whole loop above then becomes: for idf in final_1: for l in d.get(idf): new_file.write(l) ;) I hope I gave you a few ideas, good luck! Uli From varma.nikhil22 at gmail.com Wed May 9 06:17:34 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Wed, 9 May 2012 15:47:34 +0530 Subject: rndom number tweaks Message-ID: Hi Chris (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? No i really don't care for that. I just want first three should be numbers and rest 5 are characters. "123aAbBc" Can you give examples ? ---------- Forwarded message ---------- From: Chris Angelico To: python-list at python.org Cc: Date: Wed, 9 May 2012 17:44:00 +1000 Subject: Re: tweaking random number On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma wrote: > Hi All > > I want to generate a random number of 8 digits which involve 3 number and 5 > digits. (That's 3 digits and 5 letters) Pretty easy. Do you want to distinguish between uppercase and lowercase letters? Your current random_number function (btw, I wouldn't call it "number" as it isn't one) is most of one possible solution. Divide it into two parts, one part that generates the digits and another part that generates the letters. Your 'characters' template would thus be different for the two parts. There are other solutions, which involve the generation of less random numbers, but your way will work. ChrisA -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed May 9 06:23:37 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 12:23:37 +0200 Subject: Help with how to combine two csv files In-Reply-To: <1335710457.64665.YahooMailClassic@web161203.mail.bf1.yahoo.com> References: <1335710457.64665.YahooMailClassic@web161203.mail.bf1.yahoo.com> Message-ID: <4FAA45A9.1030400@sequans.com> Sammy Danso wrote: > Hello Experts, > I am new to python and I have been trying to merge two csv files, and > upon several hours of unsuccessful attempts, I have decided to seek > for help. > > the format of the file is as follows. file A has columns a, b, c and > values 1,2,3 for several rows. File B also has columns d,e and values > 4,5 for same number of rows as A. the files however do not have any > unique column between the two. > I want an output file C to have columns a,b,c,d,e with values 1,2,3,4,5 > > I would be very grateful for your help with some code. > > Thanks very much, > Sammy > Post some code so we may point at your problem. The solution is easy, the code very small. Something like (pseudo code): import csv writer = csv.writer(file3) for index, row in enumerate(csv.reader(file1)): writer.writerow(row + csv.reader(file2)[index]) JM From askutt at gmail.com Wed May 9 06:30:51 2012 From: askutt at gmail.com (Adam Skutt) Date: Wed, 9 May 2012 03:30:51 -0700 (PDT) Subject: How to get outer class name from an inner class? References: Message-ID: <2acada35-eb30-4ac8-bb27-8bd6f35b0c50@m13g2000yqc.googlegroups.com> On May 8, 4:05?pm, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > ? ? """Base class for application-specific errors.""" > > ? ? def get_message(self): > ? ? ? ? """Return the error message associated with this class name.""" > > ? ? ? ? class_name = self.__class__.__name__ > ? ? ? ? return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > ? ? """User entered a security question which is too short.""" > ? ? pass > > class QuestionTooLongError(NetIDAppsError): > ? ? """User entered a security question which is too long.""" > ? ? pass > > This scheme works, but I'd like to make it more streamlined. ?Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > ? ? class TooShort(ApplicationException): > ? ? ? ? pass > > ? ? class TooLong(ApplicationException): > ? ? ? ? pass > > This will make it easier in the future for organizing lots of sub-errors. It's no more or less organized than using a module, so use a module. This is why they exist, after all. That being said, this seems like a bad idea to me: this is a lot of code and types just for a message lookup! Exception types should usually be created based on what you expect users to catch, not based on what you could throw. If all of these exceptions will be handled in the same way, then they shouldn't be distinct types. Adam From cyborgv2 at hotmail.com Wed May 9 07:01:47 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Wed, 9 May 2012 12:01:47 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , , , , , , Message-ID: Hi, I'm not big Python user but like to keep a eye on this mailing list as there are a few subjects that can be applied to other languages and just for general interest (Yes, I'm a geek!!! lol) This message thread has really shocked me: I've been a programmer for some thirty years and yes in the past I've had code/intellectual property stolen mainly by corporate bodies (well more like little upstart twats that cannot come up with ideas for themselves, acting in the name of a company.) I've never been able to do anything about it, proving that code and/or an idea has been stolen is not a simple thing to do... But surely in this case, as the project is so visibly the intellectual property of Luke that Risinger and his sheep are standing on the edge of a very large and loose cliff! > To: python-list at python.org > From: tjreedy at udel.edu > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Tue, 8 May 2012 21:35:22 -0400 > > On 5/8/2012 5:47 PM, Terry Reedy wrote: > > > From what others have posted, it has a new code repository (that being > > the ostensible reason for the fork), project site, and mailing list -- > > the latter two incompetently. Apparently, the only thing he has kept are > > the domain and project names (the latter for sure not legitimately). > > Update: the pyjs.org group (or member thereof) has registered pyjs as a > new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they > seem not to be claiming the name 'pyjames', at least not on pypi. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmwebaze at gmail.com Wed May 9 07:02:02 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Wed, 9 May 2012 13:02:02 +0200 Subject: dynamically selecting a class to instantiate based on the object attributes. Message-ID: I have a bunch of objects of the same type. Each object has a version attribute and this refers to source code that was used to make the object. SouceCode is maintained in separate files. eg. myclass_01.py, myclass_02.py, myclass_03.py, myclass_04.py .. During object instantiaton, i would like to use the specific class, that corresponds to the version of the class that was used to create the object. However i cant know the specific "myclass_??.py" before i read the version attribute of the object. Seems like a situation where i have to partially instantiate the object to read the version attribute, and after that continue with instantiaton with the specific version of the version.. Is this doeable? - -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony at xtfx.me Wed May 9 07:02:03 2012 From: anthony at xtfx.me (anthony at xtfx.me) Date: Wed, 9 May 2012 04:02:03 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> Message-ID: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote: > Agreed with pretty much all of that. It's third-world politics, lurching from one dictator to another. Risinger seems to have banned all discussion of the subject from the list too, I'm not posting anymore because I don't want to give him an excuse to wield his newly found banhammer. hello James, i'm not really sure what you're referring too ... you appear to be making these things up. i have not banned anything, or even alluded to it, whatsoever. i asked that one specific mail not be commented upon, as a request; perhaps this is the dreaded bannhammer you speak of? reading your accounts strewn about is interesting, what exactly are *your* motives? a simple curiosity, nothing more. your comparison to gov'ts is pretty skewed i would say, you know this as well as i. regardless of what you think or know of me, i have a permanent track record of being pretty fair and receptive to virtually anything, and am involved in a wide range of projects. Luke is a talented developer, there is no doubt of this, but he is one of the most socially inept persons i have ever encountered. leading your users to statements such as this: https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ ... dozens of times on several occasions, is truly incredible. other such behavior, eg. being the only person in the history of the webkit project to ever be *ejected* from contributing or communicating *at all*, is further testament to the deficiencies provoking this maneuver. however, i have no interest in comparing or being compared. go read my notes again; i have a high level of respect for Luke in many capacities, and this has not changed. lets make one thing perfectly clear; you are not the only one who cares of this project or wishes it to succeed. mistakes were made. problems were had. the decisions however, stands. > But yeah, a lot of the commentary from the pro-rebel side ( not that any of them admit they had anything to do with it ) really does come across as being ill-informed and childish. indeed, you have witnessed little chatter. however, barring your belief of such, i had received dozens of notes thanking me and attesting to a renewed impetus for action. the original goal was to purchase a domain and fork -- i made this very clear in my notes -- `uxpy.net`. however, the most respectable member of the commit IMO convinced me otherwise. names names, yes you want names? sorry :-(. alas, he, myself, and numerous others are still active and moving forward. the list is actually approaching 100 ... not the "4-5" you so graciously quoted. i am simply the point man willing to stand the flurry. likewise, i did not "convince" the domain holder to give me the domain. not only was he already aware prior to me approaching him -- list member, passive -- he was more that willing to assist in reinstating the projects foundations and direction. he *was* the person who "left Luke in charge" ... why do you think he was the owner? as far as im concerned, the domain was already "hijacked"; this was, in good faith, intended as remedy. this was not a easy or light decision, the dissonance exists to this day. the idea was to retain Luke, but he decided to play legal threats as the first card (which i'm afraid can only backfire), before he even knew of the domain changes. hge is not a victim here, nor is anyone else. so please, show some cognitive capacity by realizing this is not as black-and-white as you's like it to be. when you decide to include yourself -- sooner, or later -- you are more than welcome. @alex23 ... try reading a bit further. as a human i am subject to annoyance and frustration. i probably shouldn't have started the message in that manner, but the absurdity and absolute inaccurate statements being made were rather upsetting. you will note that i make it perfectly clear that Luke is a fantastic developer, and a great part of the team. this of course has neither waned nor faltered. i encourage anyone willing to take the time to consult the archives, pyjamas' and elsewhere, as they are the only path to proper answers. this will impact the project in both known and untold ways, but we have a great number of minds willing to push beyond. -- C Anthony From john at hamilton.org.uk Wed May 9 07:16:21 2012 From: john at hamilton.org.uk (hamiljf) Date: Wed, 9 May 2012 04:16:21 -0700 (PDT) Subject: Pydev configuration In-Reply-To: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> Message-ID: <1336562181117-4962800.post@n6.nabble.com> I suppose this is the nearest thread... editor configuration and all. I'm using PyDev in a MyEclipse environment and it works fine, except for one tiny but horrible niggle. The editor function I can't find is block indent/exdent... like you can block comment/uncomment it would be really handy to be able to do the same with indentation. I cannot believe the function isn't there, but I cannot find it. PyDev works fine now I'm running in the latest JRE, btw: used to bomb the 1.6 JRE on a regular basis. -- View this message in context: http://python.6.n6.nabble.com/Pydev-configuration-tp1102326p4962800.html Sent from the Python - python-list mailing list archive at Nabble.com. From fetchinson at googlemail.com Wed May 9 07:34:05 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 9 May 2012 13:34:05 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: > the original goal was to purchase a domain and fork -- > i made this very clear in my notes -- `uxpy.net`. however, the most > respectable member of the commit IMO convinced me otherwise. (I'm a total outsider, never used pyjs.) Anthony, you never explained what the reasoning behind the advice of the "most respectable member of the commit" was. Why didn't you finally buy the new domain name, pick a new name, and fork the project? As it stands now the obvious answer for most people is "because it looked easier to just take over than to build a new community, new infrastructure, new fame, etc, and I sure as hell like to take the easy road as opposed to the hard road". Until you clearly explain your reasoning for taking over as opposed to forking, the default answer is the above one. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed May 9 07:44:38 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 9 May 2012 13:44:38 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: It's also quite ironic that the initial complaining started from how the domain name www.pyjs.org is not available only pyjs.org is. At the same time the Rebel Chief's listed domain name on github, see https://github.com/xtfxme, gives you a server not found: http://the.xtfx.me/ :) On 5/9/12, anthony at xtfx.me wrote: > On Tuesday, May 8, 2012 4:10:13 AM UTC-5, james hedley wrote: >> Agreed with pretty much all of that. It's third-world politics, lurching >> from one dictator to another. Risinger seems to have banned all discussion >> of the subject from the list too, I'm not posting anymore because I don't >> want to give him an excuse to wield his newly found banhammer. > > hello James, > > i'm not really sure what you're referring too ... you appear to be making > these things up. i have not banned anything, or even alluded to it, > whatsoever. i asked that one specific mail not be commented upon, as a > request; perhaps this is the dreaded bannhammer you speak of? > > reading your accounts strewn about is interesting, what exactly are *your* > motives? a simple curiosity, nothing more. > > your comparison to gov'ts is pretty skewed i would say, you know this as > well as i. regardless of what you think or know of me, i have a permanent > track record of being pretty fair and receptive to virtually anything, and > am involved in a wide range of projects. Luke is a talented developer, > there is no doubt of this, but he is one of the most socially inept persons > i have ever encountered. leading your users to statements such as this: > > https://groups.google.com/forum/?fromgroups#!searchin/pyjamas-dev/credo/pyjamas-dev/xzp4CCWhJN4/nQ3-emtYFVgJ > > ... dozens of times on several occasions, is truly incredible. other such > behavior, eg. being the only person in the history of the webkit project to > ever be *ejected* from contributing or communicating *at all*, is further > testament to the deficiencies provoking this maneuver. > > however, i have no interest in comparing or being compared. go read my > notes again; i have a high level of respect for Luke in many capacities, and > this has not changed. > > lets make one thing perfectly clear; you are not the only one who cares of > this project or wishes it to succeed. mistakes were made. problems were > had. the decisions however, stands. > >> But yeah, a lot of the commentary from the pro-rebel side ( not that any >> of them admit they had anything to do with it ) really does come across as >> being ill-informed and childish. > > indeed, you have witnessed little chatter. however, barring your belief of > such, i had received dozens of notes thanking me and attesting to a renewed > impetus for action. the original goal was to purchase a domain and fork -- > i made this very clear in my notes -- `uxpy.net`. however, the most > respectable member of the commit IMO convinced me otherwise. names names, > yes you want names? sorry :-(. alas, he, myself, and numerous others are > still active and moving forward. the list is actually approaching 100 ... > not the "4-5" you so graciously quoted. i am simply the point man willing > to stand the flurry. > > likewise, i did not "convince" the domain holder to give me the domain. not > only was he already aware prior to me approaching him -- list member, > passive -- he was more that willing to assist in reinstating the projects > foundations and direction. he *was* the person who "left Luke in charge" > ... why do you think he was the owner? as far as im concerned, the domain > was already "hijacked"; this was, in good faith, intended as remedy. > > this was not a easy or light decision, the dissonance exists to this day. > the idea was to retain Luke, but he decided to play legal threats as the > first card (which i'm afraid can only backfire), before he even knew of the > domain changes. hge is not a victim here, nor is anyone else. so please, > show some cognitive capacity by realizing this is not as black-and-white as > you's like it to be. > > when you decide to include yourself -- sooner, or later -- you are more than > welcome. > > @alex23 ... try reading a bit further. as a human i am subject to annoyance > and frustration. i probably shouldn't have started the message in that > manner, but the absurdity and absolute inaccurate statements being made were > rather upsetting. you will note that i make it perfectly clear that Luke is > a fantastic developer, and a great part of the team. this of course has > neither waned nor faltered. > > i encourage anyone willing to take the time to consult the archives, > pyjamas' and elsewhere, as they are the only path to proper answers. this > will impact the project in both known and untold ways, but we have a great > number of minds willing to push beyond. > > -- > > C Anthony > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jeanmichel at sequans.com Wed May 9 08:21:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 14:21:26 +0200 Subject: How to get outer class name from an inner class? In-Reply-To: References: Message-ID: <4FAA6146.1030601@sequans.com> John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks like this: > > class ApplicationException(Exception): > """Base class for application-specific errors.""" > > def get_message(self): > """Return the error message associated with this class name.""" > > class_name = self.__class__.__name__ > return UserMessage.objects.get(key=class_name).text > > And then I define a bunch of subclasses which all have different names: > > class QuestionTooShortError(NetIDAppsError): > """User entered a security question which is too short.""" > pass > > class QuestionTooLongError(NetIDAppsError): > """User entered a security question which is too long.""" > pass > > This scheme works, but I'd like to make it more streamlined. Specifically, > I'd like to group the classes underneath a parent class, like so: > > class Question(ApplicationException): > > class TooShort(ApplicationException): > pass > > class TooLong(ApplicationException): > pass > > This will make it easier in the future for organizing lots of sub-errors. > > My problem is this: the get_message() method in the base class only knows > the current class name, i.e. "TooShort" or "TooLong". But that's not > enough; I also need to know the outer class name, i.e. "Question.TooShort" > or "Question.TooLong". How do I get the outer class name? > > Thanks, > > You're going way too much into details regarding your exceptions. Basically, you need to create an exception class is at some point you need different handlers. For instance, try: whatever() except Question.TooShort: dosomething() except Question.TooLong: dosomethingelse() But I'm not sure you really need this. Try to keep it simple. You fetch you exception message from a database, is that really required ? Why can't you just write it in your code ? Another problem is getting the database key from the class name, this makes difficult changing any class name, I'm not sure this is a good idea. Anyway I'm not sure I'm helping here, providing more questions than answer. What you could do : class AppException(Exception): pass class Question(AppException): pass class TooShort(Question): pass class TooLong(Question): pass def getName(cls): if not hasattr(cls, '__base__'): raise ValueError('Not a new class style') if cls is AppException: return cls.__name__ return getName(cls.__base__)+'.' + cls.__name__ > getName(TooShort) < 'AppException.Question.TooShort' This implies you're using only inheritance, not using class as ccontainer/namespace. JM From jeanmichel at sequans.com Wed May 9 08:47:57 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 May 2012 14:47:57 +0200 Subject: Communication between C++ server and Python app In-Reply-To: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> References: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> Message-ID: <4FAA677D.8070308@sequans.com> kenk wrote: > Hi, > > I've got a server process written in C++ running on Unix machine. > On the same box I'd like to run multiple Python scripts that will > communicate with this server. > > Can you please suggest what would be best was to achieve this ? > > Kind regards and thanks in advance! > M. > xmlrpc shoudl do it. http://en.wikipedia.org/wiki/XML-RPC There's is a client/server python module fort that, same for C++. Your python client will be able to call C++ server procedures. It could be slighlty overkill but that get rid of the tedious socket programming. JM From miki.tebeka at gmail.com Wed May 9 10:13:54 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 9 May 2012 07:13:54 -0700 (PDT) Subject: which book? In-Reply-To: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> Message-ID: <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> > I am going to learn python for some plot issues. which book or sources, do you recommend please? The tutorial is pretty good if you already know how to program. I also heard a lot of good things on "Python Essential Reference". From mailinglists at xgm.de Wed May 9 11:35:36 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 9 May 2012 17:35:36 +0200 Subject: tee-like behavior in Python Message-ID: Hello, how can I achieve a behavior like tee in Python? * execute an application * leave the output to stdout and stderr untouched * but capture both and save it to a file (resp. file-like object) I have this code proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, stderr=subprocess.STDOUT) while True: out = proc.stdout.readline() if out == '' and proc.poll() != None: break sys.stdout.write(out) logfile.write(out) This works so far but always buffers a couple of lines and outputs them en bloc. The final output is like it is desired but with a significant delay. Is there a way around that? Thanks, Florian From toby at tobiah.org Wed May 9 11:52:59 2012 From: toby at tobiah.org (Tobiah) Date: Wed, 09 May 2012 08:52:59 -0700 Subject: Real time event accuracy Message-ID: I'd like to send MIDI events from python to another program. I'd like advice as to how to accurately time the events. I'll have a list of floating point start times in seconds for the events, and I'd like to send them off as close to the correct time as possible. I'd also appreciate suggestions and pointers to a suitable python MIDI library, and maybe an outline of what must be done to get the MIDI events to the other program's MIDI in. Thanks, Tobiah From d at davea.name Wed May 9 12:13:19 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 12:13:19 -0400 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <4FAA979F.3040604@davea.name> On 05/09/2012 11:52 AM, Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. > > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to > the other program's MIDI in. > > Thanks, > > Tobiah You really need to specify the OS environment you're targeting, as well as telling what program you're intending to feed MIDI into, if you've already picked one. Also, the midi file format has timing information, and that timing should be much better than trying to do it in python before sending commands to some external program. In other words, instead of sleeping in your code and then issuing one midi event, use the midi file format to send a stream of commands that will be played according to the timing information included. -- DaveA From d at davea.name Wed May 9 12:14:58 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 12:14:58 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: <4FAA9802.6030107@davea.name> On 05/09/2012 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian Chances are that other program is buffering its output. Many programs check if they're running on a tty, and turn off buffering for interactive use. But redirect them into a pipe, and they'll run as efficiently as possible, which includes buffering the output. -- DaveA From dreadpiratejeff at gmail.com Wed May 9 12:22:48 2012 From: dreadpiratejeff at gmail.com (J) Date: Wed, 9 May 2012 12:22:48 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > ? ?out = proc.stdout.readline() > ? ?if out == '' and proc.poll() != None: > ? ? ? break > ? ?sys.stdout.write(out) > ? ?logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? Perhaps this would help: http://docs.python.org/library/subprocess.html#popen-constructor specifically, the bits about setting bufsize to 0 indicating unbuffered behaviour. From toby at tobiah.org Wed May 9 12:33:39 2012 From: toby at tobiah.org (Toby) Date: Wed, 09 May 2012 09:33:39 -0700 Subject: Real time event accuracy In-Reply-To: <4FAA979F.3040604@davea.name> References: <4FAA979F.3040604@davea.name> Message-ID: <4FAA9C63.7000905@tobiah.org> On 05/09/2012 09:13 AM, Dave Angel wrote: > On 05/09/2012 11:52 AM, Tobiah wrote: >> I'd like to send MIDI events from python to another >> program. I'd like advice as to how to accurately >> time the events. I'll have a list of floating point >> start times in seconds for the events, and I'd like to send them >> off as close to the correct time as possible. >> >> I'd also appreciate suggestions and pointers to a >> suitable python MIDI library, and maybe an outline >> of what must be done to get the MIDI events to >> the other program's MIDI in. >> >> Thanks, >> >> Tobiah > > You really need to specify the OS environment you're targeting, as well > as telling what program you're intending to feed MIDI into, if you've > already picked one. I'm using Kontakt on Windows 7. The MIDI file think would be good, but (not having that computer in front of me) I don't think that Kontakt had the ability to open a MIDI file. Now, I know that I could load the file into Reaper, and use Kontakt as a plugin. My problem is that I can't afford to mess with GUI menus during my composition process. I need to edit a python program in Vi, then slap it out to python, hearing the music, then edit again. The cycle has to be very quick in order to get anything done. Loading Kontakt with a bunch of samples is very time consuming, so it needs to keep running. Now, if I could find a program that would interpret the MIDI file and send events off to Kontakt either as a plugin or standalone, then the MIDI file generation idea would be perfect. > Also, the midi file format has timing information, and that timing > should be much better than trying to do it in python before sending > commands to some external program. In other words, instead of sleeping > in your code and then issuing one midi event, use the midi file format > to send a stream of commands that will be played according to the timing > information included. > > > > From oliver at obeattie.com Wed May 9 13:11:34 2012 From: oliver at obeattie.com (Oliver Beattie) Date: Wed, 9 May 2012 10:11:34 -0700 (PDT) Subject: Re-raised exceptions in 2.7.3 -- stack trace missing Message-ID: <6286778.1710.1336583494655.JavaMail.geo-discussion-forums@vbbgl4> Hi there I'm tying to investigate a bit of a weird problem here. Basically, I've just upgraded Python (from 2.7.2 -> 2.7.3) by way of an OS upgrade (Ubuntu), and now all the tracebacks I'm getting sent from my web app are looking like this: http://dpaste.org/EgKJp/ As you can see, Django is correctly re-raising the exception, but the original stack trace is not there by way of sys.exc_info(). I've dug into the code a little and it seems fairly simple, exc_info is passed through logging.error from sys.exc_info() so I see no reason why this shouldn't work. Bit perplexing, any idea what could cause this? ?Oliver From kroger at pedrokroger.net Wed May 9 13:14:22 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Wed, 9 May 2012 14:14:22 -0300 Subject: Real time event accuracy In-Reply-To: <4FAA9C63.7000905@tobiah.org> References: <4FAA979F.3040604@davea.name> <4FAA9C63.7000905@tobiah.org> Message-ID: <008AFB2C-FB5F-49CF-8C3C-7BB31B5A0667@pedrokroger.net> I don't know the details of how Kontakt works, but you can try pygame.midi: pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. Also pygame.music can play midi files. Can get input from midi devices and can output to midi devices. For osx, linux and windows. New with pygame 1.9.0. python -m pygame.examples.midi --output (http://wiki.python.org/moin/PythonInMusic) Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ On May 9, 2012, at 1:33 PM, Toby wrote: > On 05/09/2012 09:13 AM, Dave Angel wrote: >> On 05/09/2012 11:52 AM, Tobiah wrote: >>> I'd like to send MIDI events from python to another >>> program. I'd like advice as to how to accurately >>> time the events. I'll have a list of floating point >>> start times in seconds for the events, and I'd like to send them >>> off as close to the correct time as possible. >>> >>> I'd also appreciate suggestions and pointers to a >>> suitable python MIDI library, and maybe an outline >>> of what must be done to get the MIDI events to >>> the other program's MIDI in. >>> >>> Thanks, >>> >>> Tobiah >> >> You really need to specify the OS environment you're targeting, as well >> as telling what program you're intending to feed MIDI into, if you've >> already picked one. > > I'm using Kontakt on Windows 7. The MIDI file think would be good, but > (not having that computer in front of me) I don't think that Kontakt > had the ability to open a MIDI file. > > Now, I know that I could load the file into Reaper, and use Kontakt > as a plugin. My problem is that I can't afford to mess with GUI menus > during my composition process. I need to edit a python program in > Vi, then slap it out to python, hearing the music, then edit again. > The cycle has to be very quick in order to get anything done. > > Loading Kontakt with a bunch of samples is very time consuming, so > it needs to keep running. Now, if I could find a program that would > interpret the MIDI file and send events off to Kontakt either as a plugin > or standalone, then the MIDI file generation idea would be perfect. > > > >> Also, the midi file format has timing information, and that timing >> should be much better than trying to do it in python before sending >> commands to some external program. In other words, instead of sleeping >> in your code and then issuing one midi event, use the midi file format >> to send a stream of commands that will be played according to the timing >> information included. >> >> >> >> > > -- > http://mail.python.org/mailman/listinfo/python-list From kroger at pedrokroger.net Wed May 9 13:15:04 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Wed, 9 May 2012 14:15:04 -0300 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <107FC3CF-737A-4C76-948A-4E157C981862@pedrokroger.net> > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to the other program's MIDI in. Mark Wirt's MidiUtil is a nice library for MIDI. It doesn't do exactly what you want (it generates MIDI files) but it's a nice library and it may be a good starting point: http://code.google.com/p/midiutil/ Pedro -- http://pedrokroger.net http://musicforgeeksandnerds.com/ From RDRichardson at rad-con.com Wed May 9 13:52:45 2012 From: RDRichardson at rad-con.com (Rob Richardson) Date: Wed, 9 May 2012 17:52:45 +0000 Subject: How do I find out what file an import is using? Message-ID: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> I am trying to work with a Python script someone else wrote. The script includes the line from Level3Utils import * I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! How do I find out where the class definition actually is? (There is no PYTHONPATH environmental variable defined on my machine.) Thanks very much! RobR From darcy at druid.net Wed May 9 14:09:42 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 09 May 2012 14:09:42 -0400 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: <4FAAB2E6.7000200@druid.net> On 12-05-09 01:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! >>> import Level3Utils >>> Level3Utils.__file__ -- 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. IM: darcy at Vex.Net From robert.kern at gmail.com Wed May 9 14:10:54 2012 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 09 May 2012 19:10:54 +0100 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: On 5/9/12 6:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! > > How do I find out where the class definition actually is? > > (There is no PYTHONPATH environmental variable defined on my machine.) import Level3Utils print Level3Utils.__file__ -- 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 d at davea.name Wed May 9 14:15:17 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 14:15:17 -0400 Subject: How do I find out what file an import is using? In-Reply-To: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> References: <67D108EDFAD3C148A593E6ED7DCB4BBD1FDA9269@RADCONWIN2K8PDC.radcon.local> Message-ID: <4FAAB435.1030603@davea.name> On 05/09/2012 01:52 PM, Rob Richardson wrote: > I am trying to work with a Python script someone else wrote. The script includes the line > from Level3Utils import * > > I need to look at the functions that are included in that import. In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on. The import command in PythonWin executed without error. I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case). None were there. I then commented out the import line and stepped through the code. It ran without error! The class that should have come from Level3Utils executed successfully without being imported! > > How do I find out where the class definition actually is? > > (There is no PYTHONPATH environmental variable defined on my machine.) > > Thanks very much! > > RobR First, if you want to see the import path, just display sys.path import sys print sys.path Next, it's bad practice to use the form: from nnnn import * because it's then hard to see what (if anything) you actually imported from there. And you can easily hide your own globals, or conversely hide some imports with a new global you might define. If removing the import doesn't stop the code from running, you probably aren't using anything from it, and should leave the line out. However, it is frequently useful to find where a module is coming from, and what symbols it defines. I'm using wxversion module for an example, because it's not very big. And I'm doing it interactively, while you probably want to print these values from your code. >>> dir(wxversion) ['AlreadyImportedError', 'UPDATE_URL', 'VersionError', '_EM_DEBUG', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_find_default', '_find_installed', '_get_best_match', '_pattern', '_selected', '_wxPackageInfo', 'checkInstalled', 'ensureMinimal', 'fnmatch', 'getInstalled', 'glob', 'os', 're', 'select', 'sys'] >>> wxversion.__file__ '/usr/lib/python2.7/dist-packages/wxversion.pyc' In other words, try print Level3Utils.__file__ -- DaveA From wrw at mac.com Wed May 9 14:19:00 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 09 May 2012 14:19:00 -0400 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: <4026A618-D662-4792-8E7D-720EC4B3B245@mac.com> On May 9, 2012, at 11:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list Have you tried explicitly calling file.flush() on the log file? (The docs note that you may have to follow this with os.fsync() on some systems.) -Bill From no.email at nospam.invalid Wed May 9 14:30:04 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 09 May 2012 11:30:04 -0700 Subject: Real time event accuracy References: Message-ID: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Tobiah writes: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. I don't think you can really do this accurately enough to get good sound, but the basic mechanism is time.sleep(t) which takes a floating point argument. That turns into the appropriate microsleep, I think. I'm not even sure how to do it from C code with the Linux realtime scheduler. Traditionally for this sort of thing you'd use dedicated hardware, or else generate waveforms with a little bit of buffering in the sound card. From lamialily at cleverpun.com Wed May 9 14:45:34 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 09 May 2012 11:45:34 -0700 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: If the support you have from the other contributors is anywhere near what you claim it is, I may as well be kissing Pyjamas goodbye. Doubt it, though - this whole post reeks of vagueities and doublespeak garbage. Too many undefined "whos". I'll wait until Leighton gets the reins back. And you know what? Leighton was right to threaten legal action. What you did was not only in violation of his IP, but also multiple data theft laws. ~Temia -- When on earth, do as the earthlings do. From jeanpierreda at gmail.com Wed May 9 15:00:11 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 9 May 2012 15:00:11 -0400 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri wrote: > And you know what? Leighton was right to threaten legal action. What > you did was not only in violation of his IP, but also multiple data > theft laws. As far as copyright goes, it was open source, so he's allowed to continue making modifications. I don't think Luke had any patents. There might be something with stealing the name "PyJS" (which was, AFAIK, used as a synonym for "PyJamas") -- apparently "common law trademark" is a thing. Otherwise... The domain was apparently not directly owned by Luke (but pointed to a server luke administered), and its transfer was apparently consensual. It seems like nearly every evil thing the hijacker did is legally permissible. The one other thing was the way he created the new mailing list might not have been legal, apparently. (See http://mail.python.org/pipermail/python-list/2012-May/1291804.html ). -- Devin From toby at tobiah.org Wed May 9 15:26:05 2012 From: toby at tobiah.org (Tobiah) Date: Wed, 09 May 2012 12:26:05 -0700 Subject: Real time event accuracy In-Reply-To: <7xk40lxl5f.fsf@ruckus.brouhaha.com> References: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Message-ID: > I don't think you can really do this accurately enough to get good > sound, but the basic mechanism is time.sleep(t) which takes a floating > point argument. That turns into the appropriate microsleep, I think. I think the time would have to come from a hardware clock. From jstitch at invernalia.homelinux.net Wed May 9 15:38:31 2012 From: jstitch at invernalia.homelinux.net (Javier Novoa C.) Date: Wed, 9 May 2012 19:38:31 +0000 (UTC) Subject: strptime format string nasty default Message-ID: Hi, I am using time.strptime method as follows: I receive an input string, representing some date in the following format: %d%m%Y However, the day part may be a single digit or two, depending on magnitude. For example: '10052012' will be parsed as day 10, month 5, year 2012 Again: '8052012' will be parsed as day 8, month 5, year 2012 What happens when day is 1 or 2? '1052012' will be parsed as day 10, month 5, year 2012 !!!! That's not the expected behaviour! Not for me at least. I mean, in my case, month will always be a 2 digit string, so there's no ambiguity problem by pretending that... say '1052012' is correctly parsed. Is there a way out of here? I know I can pre-parse the string and append a '0' to it when lenght == 7, but I think that a better way would be if strptime allowed me to define my format in a better way... To say that the month is the optional one-two digit part is just a default, isn't it? Why can't I specify that the day part is the one with one-or-two digits on the input string...? Or is there a way out that I don't know yet? -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From rowen at uw.edu Wed May 9 15:39:05 2012 From: rowen at uw.edu (Russell E. Owen) Date: Wed, 09 May 2012 12:39:05 -0700 Subject: pickle question: sequencing of operations References: Message-ID: In article , Ian Kelly wrote: > On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > > In article , > > ?"Russell E. Owen" wrote: > > > >> What is the sequence of calls when unpickling a class with __setstate__? > > I believe it just calls object.__new__ followed by > yourclass.__setstate__. So at the point __setstate__ is called, you > have a pristine instance of whatever class you're unpickling. I was wondering. I override __new__ (and __init__) to print messages and was quite surprised to only see __new__being called when the object was first created, not when it was being unpickled. But maybe there's something funny about my override that caused unpickle to ignore it and use the default version. I hope so. I can't see how the object could be constructed during unpickle without calling __new__. But that's one reason I was curious about the unpickling sequence of operations. -- Russell From yanegomi at gmail.com Wed May 9 15:54:51 2012 From: yanegomi at gmail.com (Garrett Cooper) Date: Wed, 9 May 2012 12:54:51 -0700 Subject: strptime format string nasty default In-Reply-To: References: Message-ID: On May 9, 2012, at 12:38 PM, "Javier Novoa C." wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? Delimiters, e.g. dashes, slashes, etc, can remove ambiguity in the date string. Leading 0s in elements in the date would help as well. HTH! -Garrett From news at idlcoyote.com Wed May 9 16:09:09 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:09:09 -0600 Subject: IDL Books On Sale Message-ID: Folks, My wife says that as long as I'm retired, she wants the bedroom back, so I've put all my books I have in storage there on sale! I only have four copies left of IDL Programming Techniques, 2nd Edition, and I don't plan to print any more of those. If you want one, this may be your last chance! I have a few of Ronn Kling's books left and enough Traditional IDL Graphics books to make the bonfire at the 4th of July picnic more than spectacular. No more need for these once IDL 8.2 comes out, I guess. ;-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From grahn+nntp at snipabacken.se Wed May 9 16:11:02 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 9 May 2012 20:11:02 GMT Subject: strptime format string nasty default References: Message-ID: On Wed, 2012-05-09, Javier Novoa C. wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? You'd have to read the strptime(3) manual page (it's a Unix function, imported straight into Python, I'm sure). Judging from a quick read it's not intended to support things like these. I'm surprised it doesn't parse your last example to (10, 52, 12) and then fail it due to month>12. Can't you use a standard date format, like ISO? Apart from not being possible to parse with standard functions, this one looks quite odd and isn't very human-readable. If you have to use this format, I strongly recommend parsing it "manually" as text first. Then you can create an ISO date and feed that to strptime, or perhaps use your parsed (day, month, year) tuple directly. /Jorgen -- // Jorgen Grahn O o . From news at idlcoyote.com Wed May 9 16:11:02 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:11:02 -0600 Subject: IDL Books On Sale References: Message-ID: David Fanning writes: > > Folks, > > My wife says that as long as I'm retired, she wants the > bedroom back, so I've put all my books I have in storage > there on sale! > > I only have four copies left of IDL Programming Techniques, > 2nd Edition, and I don't plan to print any more of those. > If you want one, this may be your last chance! > > I have a few of Ronn Kling's books left and enough > Traditional IDL Graphics books to make the bonfire > at the 4th of July picnic more than spectacular. > No more need for these once IDL 8.2 comes out, I guess. ;-) > > Cheers, > > David Whoops! A link might be good, I guess. I've been gone so long I've forgotten how to do this: http://www.idlcoyote.com/store David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Wed May 9 16:14:26 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 9 May 2012 14:14:26 -0600 Subject: IDL Books On Sale References: Message-ID: David Fanning writes: > Whoops! A link might be good, I guess. I've been gone so > long I've forgotten how to do this: > > http://www.idlcoyote.com/store Whoops! Sorry again. I just realized I was posting this to my NEW newsgroup. How embarrassing... :-( David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From jstitch at invernalia.homelinux.net Wed May 9 16:25:47 2012 From: jstitch at invernalia.homelinux.net (Javier Novoa C.) Date: Wed, 9 May 2012 20:25:47 +0000 (UTC) Subject: strptime format string nasty default References: Message-ID: On 2012-05-09, Jorgen Grahn wrote: > > You'd have to read the strptime(3) manual page (it's a Unix function, > imported straight into Python, I'm sure). Judging from a quick read > it's not intended to support things like these. I'm surprised it > doesn't parse your last example to (10, 52, 12) and then fail it due > to month>12. Well, it doesn't, at least on my Python. I'm using 2.7.3 version > > Can't you use a standard date format, like ISO? Apart from not being > possible to parse with standard functions, this one looks quite odd > and isn't very human-readable. No, sadly the input doesn't depends on me :-( > > If you have to use this format, I strongly recommend parsing it > "manually" as text first. Then you can create an ISO date and feed > that to strptime, or perhaps use your parsed (day, month, year) tuple > directly. Ok, I'll do that. > > /Jorgen > Thanks! -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From ian.g.kelly at gmail.com Wed May 9 16:34:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 14:34:06 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: > I was wondering. I override __new__ (and __init__) to print messages and > was quite surprised to only see __new__being called when the object was > first created, not when it was being unpickled. But maybe there's > something funny about my override that caused unpickle to ignore it and > use the default version. I hope so. I can't see how the object could be > constructed during unpickle without calling __new__. But that's one > reason I was curious about the unpickling sequence of operations. You're probably pickling with the default protocol. Unpickling calls an overridden __new__ method only if the pickle protocol is at least 2. Using protocol 0 or 1, new-style class instances are constructed with the base object.__new__ instead. From python at mrabarnett.plus.com Wed May 9 16:39:33 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 May 2012 21:39:33 +0100 Subject: strptime format string nasty default In-Reply-To: References: Message-ID: <4FAAD605.5080809@mrabarnett.plus.com> On 09/05/2012 20:38, Javier Novoa C. wrote: > Hi, > > I am using time.strptime method as follows: > > I receive an input string, representing some date in the following > format: > > %d%m%Y > > However, the day part may be a single digit or two, depending on > magnitude. > > For example: > > '10052012' will be parsed as day 10, month 5, year 2012 > > Again: > > '8052012' will be parsed as day 8, month 5, year 2012 > > What happens when day is 1 or 2? > > '1052012' will be parsed as day 10, month 5, year 2012 !!!! > > That's not the expected behaviour! Not for me at least. I mean, in my > case, month will always be a 2 digit string, so there's no ambiguity > problem by pretending that... say '1052012' is correctly parsed. > > Is there a way out of here? I know I can pre-parse the string and > append a '0' to it when lenght == 7, but I think that a better way > would be if strptime allowed me to define my format in a better > way... To say that the month is the optional one-two digit part is > just a default, isn't it? Why can't I specify that the day part is the > one with one-or-two digits on the input string...? > > Or is there a way out that I don't know yet? > You could just right-justify the string to 8 characters, padding with '0': >>> '1052012'.rjust(8, '0') '01052012' From ian.g.kelly at gmail.com Wed May 9 16:40:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 14:40:00 -0600 Subject: pickle question: sequencing of operations In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 2:34 PM, Ian Kelly wrote: > On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: >> I was wondering. I override __new__ (and __init__) to print messages and >> was quite surprised to only see __new__being called when the object was >> first created, not when it was being unpickled. But maybe there's >> something funny about my override that caused unpickle to ignore it and >> use the default version. I hope so. I can't see how the object could be >> constructed during unpickle without calling __new__. But that's one >> reason I was curious about the unpickling sequence of operations. > > You're probably pickling with the default protocol. ?Unpickling calls > an overridden __new__ method only if the pickle protocol is at least > 2. ?Using protocol 0 or 1, new-style class instances are constructed > with the base object.__new__ instead. BTW, in case you're wondering where all this is documented, pull up PEP 307 and read the sections "Case 2" and Case 3". Cheers, Ian From martin.hellwig at gmail.com Wed May 9 16:50:10 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Wed, 09 May 2012 21:50:10 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On 09/05/2012 12:02, anthony at xtfx.me wrote: Hello C Anthony, I am an pyjs user and introduced the project as one of the fundamental parts of a new application that is now core of a company of a reasonable size (30+), customers include several companies in the top 10 of largest IT infrastructures, I can mail you a list in private if you wish so. I agree that the project leadership had certainly room for improvement. I also agree that to move forward there had to be made some choices. However, as the person introducing this project in a commercial venture, I am also the one having the responsibility of it in my setting. I have been put in a position where I have to come up with answers, like why the examples page didn't work, why the project seems fragile and if there is any viability at all. Of course, I still believe in the project, with all it warts and so forth. However my position has been made needlessly difficult, because the action you took did not leave room for choice. Let me explain this, if you had forked the project, created a new domain, mailing list and, took over the majority of the devs, I would be able to make a choice if I go with the new guys or stick with the couple of old ones, just like the xorg fork. If your argument is that this was your intention but was persuaded to do other wise, I would say that is a lapse of judgement and not a very good restart of the project. Unfortunately mistakes made in public, even if arguably they are not mistakes at all, are not easy forgotten and can end up haunting you. I hope you will take these comments with you as a lesson learned, I do wish you all the best and look forward to the improvements you are going to contribute. -- Martin P. Hellwig (mph) From drsalists at gmail.com Wed May 9 16:58:05 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 9 May 2012 13:58:05 -0700 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: You've had some good responses already, but here're two more: 1) Easiest would be to use setvbuf in the child process, if you have access to its source. This allows you to force line-oriented buffering. 2) stdio likes to buffer to tty/pty's in a line-oriented manner, and other things in a block-oriented manner - by default, so users get pleasing output increments, and programs get efficiency. To trick stdio into buffering line-oriented by default when it's sending output to another program, you may have to talk to the child process using a pty, AKA a pseudo terminal. There are a few ways of doing this: A) Use CPython's pty module. B) Use something like pexpect. C) Check out the pty program in comp.sources.unix volume 25. This might be pretty easy too, assuming that pty still builds on a modern *ix. On Wed, May 9, 2012 at 8:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, > stderr=subprocess.STDOUT) > while True: > out = proc.stdout.readline() > if out == '' and proc.poll() != None: > break > sys.stdout.write(out) > logfile.write(out) > > This works so far but always buffers a couple of lines and outputs > them en bloc. The final output is like it is desired but with a > significant delay. Is there a way around that? > > Thanks, > > Florian > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed May 9 17:13:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 09 May 2012 14:13:16 -0700 Subject: __del__ and wisdom Message-ID: <4FAADDEC.6070804@stoneleaf.us> Every time discussion about __del__ had come up I had thought to myself, "yeah, but I'm being careful to not have reference loops -- /my/ classes are okay." and then... BITE! But hey, it wasn't a reference loop that got me, it was data being written back to disk after the disk portion had changed, thus clobbering new data with old. Yeah, I know, that's not really any better. *sigh* Okay, no more __del__ for me! ~Ethan~ Knowledge is knowing that tomatoes are a fruit. Wisdom is not putting them in a fruit salad. From d at davea.name Wed May 9 17:13:57 2012 From: d at davea.name (Dave Angel) Date: Wed, 09 May 2012 17:13:57 -0400 Subject: Real time event accuracy In-Reply-To: References: <7xk40lxl5f.fsf@ruckus.brouhaha.com> Message-ID: <4FAADE15.3030602@davea.name> On 05/09/2012 03:26 PM, Tobiah wrote: >> I don't think you can really do this accurately enough to get good >> sound, but the basic mechanism is time.sleep(t) which takes a floating >> point argument. That turns into the appropriate microsleep, I think. > I think the time would have to come from a hardware clock. Python has a high-res time function when run on an Intel X86 platform, though I forget which one you should use on Windows. The problem is that Windows makes no assurance that you will be executing at that particular point in time. You can approximate it with time.sleep(), which is what Paul Rubin was suggesting. Windows is not a real time operating system. Still, if the system is lightly loaded, sleep() will probably get you within 50 milliseconds. I don't think you should even worry about it till you see the capabilities of whatever MIDI library you choose. I'd be surprised if it doesn't allow you to attach timing hints to the notes, same as the file format I discussed earlier. -- DaveA From alan.ristow at gmail.com Wed May 9 17:25:18 2012 From: alan.ristow at gmail.com (Alan Ristow) Date: Wed, 09 May 2012 23:25:18 +0200 Subject: Pydev configuration In-Reply-To: <1336562181117-4962800.post@n6.nabble.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> <1336562181117-4962800.post@n6.nabble.com> Message-ID: <4FAAE0BE.5080307@gmail.com> On 05/09/2012 01:16 PM, hamiljf wrote: > I suppose this is the nearest thread... editor configuration and all. > I'm using PyDev in a MyEclipse environment and it works fine, except for one > tiny but horrible niggle. > > The editor function I can't find is block indent/exdent... like you can > block comment/uncomment it would be really handy to be able to do the same > with indentation. I cannot believe the function isn't there, but I cannot > find it. Select the code block you want to indent and hit Tab. To do the reverse, hit Shift-Tab. Alan From clp2 at rebertia.com Wed May 9 17:51:35 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 9 May 2012 14:51:35 -0700 Subject: tee-like behavior in Python In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 8:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, shlex.split() should just be used once, at "development time", to determine the form of the argument list. It shouldn't generally be used at runtime. Otherwise, you need to do the proper escaping/quoting yourself, which defeats the entire purpose of bypassing the shell. Cheers, Chris From Joshua.R.English at gmail.com Wed May 9 18:04:40 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 9 May 2012 15:04:40 -0700 (PDT) Subject: PyTextile Question In-Reply-To: <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> References: <28754931.21.1336102787506.JavaMail.geo-discussion-forums@pbbpg8> <15114984.125.1336396408763.JavaMail.geo-discussion-forums@vbak7> Message-ID: <27335393.1619.1336601080479.JavaMail.geo-discussion-forums@pbhb1> On Monday, May 7, 2012 6:13:28 AM UTC-7, dinkyp... at gmail.com wrote: > > Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV. > > import re, textile > ... Wow. Thank you. This works. I'm trying to figure what that regular expression does, but I swear it's copying the lines twice. (Clearly, I don't speak re.) Josh From cyborgv2 at hotmail.com Wed May 9 18:30:15 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Wed, 9 May 2012 23:30:15 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , Message-ID: Hi ya, Not to be confrontative but just because a project is open-source, it doesn't mean IP is open too!! The original idea is still property of the originator... It just has the global community adding their own IP and fixes. This is a core of corporate contracts ensuring that a developers IP become freely usable by the company they work for at the time, but their IP is still their IP. In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. The problem is proving it!!! > From: jeanpierreda at gmail.com > Date: Wed, 9 May 2012 15:00:11 -0400 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: lamialily at cleverpun.com > CC: python-list at python.org > > On Wed, May 9, 2012 at 2:45 PM, Temia Eszteri wrote: > > And you know what? Leighton was right to threaten legal action. What > > you did was not only in violation of his IP, but also multiple data > > theft laws. > > As far as copyright goes, it was open source, so he's allowed to > continue making modifications. I don't think Luke had any patents. > > There might be something with stealing the name "PyJS" (which was, > AFAIK, used as a synonym for "PyJamas") -- apparently "common law > trademark" is a thing. Otherwise... > > The domain was apparently not directly owned by Luke (but pointed to a > server luke administered), and its transfer was apparently consensual. > > It seems like nearly every evil thing the hijacker did is legally > permissible. The one other thing was the way he created the new > mailing list might not have been legal, apparently. (See > http://mail.python.org/pipermail/python-list/2012-May/1291804.html ). > > -- Devin > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed May 9 18:44:01 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 09 May 2012 23:44:01 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , Message-ID: On 09/05/2012 23:30, Adrian Hunt wrote: > > In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. > References please, as this is completely opposite to my understanding. -- Cheers. Mark Lawrence. From ian.g.kelly at gmail.com Wed May 9 19:01:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 9 May 2012 17:01:08 -0600 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > Hi ya, > > Not to be confrontative but just because a project is open-source, it > doesn't mean IP is open too!! The original idea is still property of the > originator... It just has the global community adding their own IP and > fixes.? This is a core of corporate contracts ensuring that a developers IP > become freely usable by the company they work for at the time, but their IP > is still their IP. Luke Leighton was not the originator of the project. James Tauber was, and his original code was a port of Google Web Toolkit. Even if Luke could somehow be considered the "owner" of the project, it was released under the Apache License, which includes a "/perpetual/, worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/ copyright license to reproduce, /prepare Derivative Works of/, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works". I don't agree with what Anthony has done, but I don't see how it violates the license in any way or how Luke has any possible recourse through IP claims. From cyborgv2 at hotmail.com Wed May 9 19:04:11 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Thu, 10 May 2012 00:04:11 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , Message-ID: Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!!!!!! > From: ian.g.kelly at gmail.com > Date: Wed, 9 May 2012 16:59:00 -0600 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > To: cyborgv2 at hotmail.com > > On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > > > Hi ya, > > > > Not to be confrontative but just because a project is open-source, it > > doesn't mean IP is open too!! The original idea is still property of the > > originator... It just has the global community adding their own IP and > > fixes. This is a core of corporate contracts ensuring that a developers IP > > become freely usable by the company they work for at the time, but their IP > > is still their IP. > > Luke Leighton was not the originator of the project. James Tauber > was, and his original code was a port of Google Web Toolkit. Even if > Luke could somehow be considered the "owner" of the project, it was > released under the Apache License, which includes a "/perpetual/, > worldwide, non-exclusive, no-charge, royalty-free, /irrevocable/ > copyright license to reproduce, /prepare Derivative Works of/, > publicly display, publicly perform, sublicense, and distribute the > Work and such Derivative Works". I don't agree with what Anthony has > done, but I don't see how it violates the license in any way or how > Luke has any possible recourse through IP claims. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyborgv2 at hotmail.com Wed May 9 19:19:38 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Thu, 10 May 2012 00:19:38 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, , <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, , <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, , <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , Message-ID: Hi there Mark There has been a few that I know of but going back quite a long time... Soon after I got my qualifications, a small company called Merlio, not only did the court case get passed in UK courts by it went to the European court too... I wasn't directly involved but I know the EU court upheld the decision of the UK courts. Still there are was little to no enforcement of what they decided!!! Any how IP IS the IP of the developer... Proving it and enforcing it is another matter!! > To: python-list at python.org > From: breamoreboy at yahoo.co.uk > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > Date: Wed, 9 May 2012 23:44:01 +0100 > > On 09/05/2012 23:30, Adrian Hunt wrote: > > > > In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. > > > > References please, as this is completely opposite to my understanding. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From merwok at netwok.org Wed May 9 19:20:40 2012 From: merwok at netwok.org (=?UTF-8?B?w4lyaWMgQXJhdWpv?=) Date: Wed, 09 May 2012 19:20:40 -0400 Subject: Distutils2 Sprint in Montreal Message-ID: <4FAAFBC8.9040204@netwok.org> Hi all, The Montreal-Python user group is organizing a second sprint to work on distutils2 on May 12th. If you live in Montreal, take a laptop and come join us! No previous knowledge of Distutils2 is required, just general Python skills. All details are found here: http://montrealpython.org/2012/05/distutils2-sprint-2/ Cheers From breamoreboy at yahoo.co.uk Wed May 9 20:12:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 01:12:12 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, , <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, , <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, , <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, , <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , Message-ID: On 10/05/2012 00:19, Adrian Hunt wrote: > > Hi there Mark > > There has been a few that I know of but going back quite a long time... Soon after I got my qualifications, a small company called Merlio, not only did the court case get passed in UK courts by it went to the European court too... I wasn't directly involved but I know the EU court upheld the decision of the UK courts. Still there are was little to no enforcement of what they decided!!! > > Any how IP IS the IP of the developer... Proving it and enforcing it is another matter!! > > >> To: python-list at python.org >> From: breamoreboy at yahoo.co.uk >> Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack >> Date: Wed, 9 May 2012 23:44:01 +0100 >> >> On 09/05/2012 23:30, Adrian Hunt wrote: >>> >>> In the UK at least, a developers IP cannot be hijacked by a company contract. If you write some code while working for X, then X has free usage of that IP and may restrict you from using the same IP for company Y, but only for a limited time (ie 5 years)? The IP you came up with is still yours and a contract that claims your IP can (and has been in a court of law) judged to be null and void. >>> >> >> References please, as this is completely opposite to my understanding. >> >> -- >> Cheers. >> >> Mark Lawrence. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > Google was a right PITA but eventually I found this http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ It appears to contradict what you've said above, or have I misread it? E.g "Under the (Patents) Act (1977), there is a presumption that an employer will own the patent of an invention made by its employee if the invention was made in the employee?s normal or specifically assigned duties and either, an invention might reasonably be expected to result from such duties or, the employee has a special obligation to further the employee?s interests, arising from the nature of those duties and responsibilities and the employee?s status." -- Cheers. Mark Lawrence. From rosuav at gmail.com Wed May 9 20:27:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 10:27:27 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: > Google was a right PITA but eventually I found this > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ > ?It appears to contradict what you've said above, or have I misread it? ?E.g > "Under the (Patents) Act (1977), there is a presumption that an employer > will own the patent of an invention made by its employee if the invention > was made in the employee?s normal or specifically assigned duties and > either, an invention might reasonably be expected to result from such duties > or, the employee has a special obligation to further the employee?s > interests, arising from the nature of those duties and responsibilities and > the employee?s status." That's patents... intellectual property goes by other rules I think. I am not a lawyer, and I try to avoid getting placed in any position where this sort of thing will come up, because it's messy... especially with internationalization. ChrisA From breamoreboy at yahoo.co.uk Wed May 9 21:48:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 02:48:55 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> Message-ID: On 10/05/2012 01:27, Chris Angelico wrote: > On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: >> Google was a right PITA but eventually I found this >> http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ >> It appears to contradict what you've said above, or have I misread it? E.g >> "Under the (Patents) Act (1977), there is a presumption that an employer >> will own the patent of an invention made by its employee if the invention >> was made in the employee?s normal or specifically assigned duties and >> either, an invention might reasonably be expected to result from such duties >> or, the employee has a special obligation to further the employee?s >> interests, arising from the nature of those duties and responsibilities and >> the employee?s status." > > That's patents... intellectual property goes by other rules I think. I > am not a lawyer, and I try to avoid getting placed in any position > where this sort of thing will come up, because it's messy... > especially with internationalization. > > ChrisA The title of the referenced page is "Intellectual Property and Employees". My quote is from the "Employees and Patents" section, but there are several more sections, so it appears that patents are a part of the intellectual property rule set. I'm with you on avoiding this type of situation, but sadly the whole pyjamas issue is a right pig's ear :( -- Cheers. Mark Lawrence. From cs at zip.com.au Wed May 9 22:12:28 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 10 May 2012 12:12:28 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: Message-ID: <20120510021228.GA11896@cskk.homeip.net> On 10May2012 10:27, Chris Angelico wrote: | On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: | > Google was a right PITA but eventually I found this | > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ | > ?It appears to contradict what you've said above, or have I misread it? ?E.g | > "Under the (Patents) Act (1977), there is a presumption that an employer | > will own the patent of an invention made by its employee if the invention | > was made in the employee?s normal or specifically assigned duties and | > either, an invention might reasonably be expected to result from such duties | > or, the employee has a special obligation to further the employee?s | > interests, arising from the nature of those duties and responsibilities and | > the employee?s status." | | That's patents... intellectual property goes by other rules I think. Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to the author, except that most companies require employees to assign it to the company, including the Berne Convention "moral rights" (such as attribution). Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ People are paid for coming in the morning and leaving at night, and for saying "Good morning" in the morning and "Good afternoon" in the afternoon and never confusing the two. - Albert Shanker, president of the American Federation of Teachers From rosuav at gmail.com Wed May 9 22:13:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 12:13:53 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <20120510021228.GA11896@cskk.homeip.net> References: <20120510021228.GA11896@cskk.homeip.net> Message-ID: On Thu, May 10, 2012 at 12:12 PM, Cameron Simpson wrote: > Patents _are_ IP. You may mean "copyright", also IP. Copyright goes to > the author, except that most companies require employees to assign it to > the company, including the Berne Convention "moral rights" (such as > attribution). Oh. Thanks, I stand corrected. Like I said, not a lawyer. :) ChrisA From pa at see.signature.invalid Wed May 9 22:36:29 2012 From: pa at see.signature.invalid (Pierre Asselin) Date: Thu, 10 May 2012 02:36:29 +0000 (UTC) Subject: __doc__+= """Detailed description""" Message-ID: Hi. Started using python a few months back, still settling on my style. I write docstrings and I use "pydoc mymodule" to refresh my memory. Problem: if I just docstring my classes/methods/functions the output of pydoc more or less works as a reference manual, but if I get sidetracked for even a few weeks I find that documentation inadequate when I return to my code. I need to see some introductory context first, so that the reference material makes sense. Wery well, write a module docstring then. The problem now: the many paragraphs of detailed description at the top of the module get in the way. The pydoc output is good, but the code becomes hard to read. So I come up with this: ###################################################################### #! env python """One-liner docstring.""" # Many classes, methods, functions, attributes, # with docstrings as needed. Docs tend to be # short and the code speaks for itself. # ... # Much further down, ___doc___+= """ Detailed description goes here. Provide some context, explain what the classes are for and what the most important methods are, give simple examples, whatever. Say enough to make the rest understandable.""" if __name__ == "__main__": # test code follows ###################################################################### It seems to work, too. But is that a sound way to write python? Am I relying on undocumented implementation details or am I safe? I guess I am trying to control the order of exposition without resorting to full-fledged Literate Programming. -- pa at panix dot com From rosuav at gmail.com Wed May 9 23:13:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 13:13:48 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? Message-ID: The azet.sk MTA is behaving badly wrt bounced messages from python-list. Instead of sending them to the list software (where they'll result in the subscription being suspended), they're being sent to the original sender of the message. As a result, every message sent to the list triggers a useless bounce message. Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? I've already forwarded a bounce to abuse at azet.sk but have heard nothing back. This isn't the list's fault, but maybe the listowner can deal with the spam coming back. Chris Angelico (Bounce message follows.) ---------- Forwarded message ---------- From: <> Date: Thu, May 10, 2012 at 12:27 PM Subject: Sprava nebola dorucena (Message was not delivered) To: rosuav at gmail.com Vasa sprava Pre: pyjko21 at azet.sk Predmet: Re: Open Source: you're doing it wrong - the Pyjamas hijack Poslana: ?Thu, 10 May 2012 12:13:53 +1000 Sprava nemohla byt dorucena, pretoze e-mailova schranka prijemcu je plna. Pokuste sa tento e-mail zaslat neskor. Tato sprava bola automaticky vygenerova serverom azet.sk. ----- Your message To: pyjko21 at azet.sk Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack Sent: ? Thu, 10 May 2012 12:13:53 +1000 The message could not be delivered because the recipient's mailbox is full. Try to send it later. This message was automatically generated by e-mail server azet.sk. From ben+python at benfinney.id.au Wed May 9 23:18:56 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 May 2012 13:18:56 +1000 Subject: __doc__+= """Detailed description""" References: Message-ID: <8762c467vj.fsf@benfinney.id.au> pa at see.signature.invalid (Pierre Asselin) writes: > Hi. Started using python a few months back, still settling on my > style. Welcome! Please consider your part in the Python community, and found your style on PEP 8 , the Style Guide for Python Code. > I write docstrings and I use "pydoc mymodule" to refresh my memory. Excellent. Please conform to the Docstring Conventions of PEP 257 . > Problem: if I just docstring my classes/methods/functions the output > of pydoc more or less works as a reference manual Hmm. That doesn't sound like a good use for docstrings. They are reference material, but very focussed; a ?reference manual? sounds much more comprehensive and isn't well suited to docstrings, in my opinion. > but if I get sidetracked for even a few weeks I find that > documentation inadequate when I return to my code. Yes, that would be a natural outcome of trying to make docstrings too large. There are other forms of documentation available, such as a separate reference manual, that you could write as well. > Wery well, write a module docstring then. The problem now: the many > paragraphs of detailed description at the top of the module get in the > way. The pydoc output is good, but the code becomes hard to read. So don't put so much into the module docstring. Your module should consist of many smaller pieces, mainly classes and functions. Document the specifics in those more local docstrings. > So I come up with this: > > ###################################################################### > #! env python > > """One-liner docstring.""" > > # Many classes, methods, functions, attributes, > # with docstrings as needed. Docs tend to be > # short and the code speaks for itself. > # ... > # Much further down, > > ___doc___+= """ > > Detailed description goes here. Provide some context, > explain what the classes are for and what the most important > methods are, give simple examples, whatever. Say enough > to make the rest understandable.""" I'm having trouble imagining what would need to be put in that separate chunk of docstring. Can you point to real code online that uses this style? > if __name__ == "__main__": > # test code follows As an aside, if your modules are complex, this style of test code is likely to be too big for shoving into the same module, and too brittle written this way. Instead, make lots of distinct, focussed unit tests using the ?unittest? module, and make other kinds of tests (e.g. feature tests) using other frameworks ? leaving the actual implementation code clear of this cruft. > It seems to work, too. But is that a sound way to write python? > Am I relying on undocumented implementation details or am I safe? I think you're trying to make one file do everything, which is ignoring the better organisation that multiple files can make. > I guess I am trying to control the order of exposition without > resorting to full-fledged Literate Programming. Yes. Maybe you need to let go of this need to control the order in which the reader views your code; we're going to be looking at small, focussed parts anyway, not reading the whole thing in one go. So work with that instead. -- \ ?There are only two ways to live your life. One is as though | `\ nothing is a miracle. The other is as if everything is.? | _o__) ?Albert Einstein | Ben Finney From cs at zip.com.au Thu May 10 01:21:17 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 10 May 2012 15:21:17 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: References: Message-ID: <20120510052117.GA32315@cskk.homeip.net> On 10May2012 13:13, Chris Angelico wrote: | The azet.sk MTA is behaving badly wrt bounced messages from | python-list. Instead of sending them to the list software (where | they'll result in the subscription being suspended), they're being | sent to the original sender of the message. [...] | I've already forwarded a bounce to abuse at azet.sk but have heard | nothing back. This isn't the list's fault, but maybe the listowner can | deal with the spam coming back. Try "postmaster". I'm not sure "abuse" is so widely implemented. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you 'aint falling off, you ar'nt going hard enough. - Fred Gassit From vincent.vandevyvre at swing.be Thu May 10 03:34:11 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Thu, 10 May 2012 09:34:11 +0200 Subject: 2to3 change direct import to relative import Message-ID: <4FAB6F73.4020900@swing.be> Hi, I use 2to3 into a python script wich convert all .py files of an application. 2to3 is executed into the same directory as files. All import are now relative import: ----------------------------------------- --- main_ui.py (original) +++ main_ui.py (refactored) @@ -15,18 +15,18 @@ -from ui_toolBar import ToolBar -from ui_properties import PropertiesPanel -from ui_menu import MenuBar -from ui_statusBar import StatusBar -from trailer import Trailer ... +from .ui_toolBar import ToolBar +from .ui_properties import PropertiesPanel +from .ui_menu import MenuBar +from .ui_statusBar import StatusBar +from .trailer import Trailer ... -------------------------------------------- Of course the application don't run: from .ui_toolBar import ToolBar ValueError: Attempted relative import in non-package 2to3 help don't help me about that. Thank's for any advice. -- Vincent V.V. Oqapy . Qarte+7 . PaQager From rosuav at gmail.com Thu May 10 04:06:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 May 2012 18:06:42 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: <20120510052117.GA32315@cskk.homeip.net> References: <20120510052117.GA32315@cskk.homeip.net> Message-ID: On Thu, May 10, 2012 at 3:21 PM, Cameron Simpson wrote: > On 10May2012 13:13, Chris Angelico wrote: > | The azet.sk MTA is behaving badly wrt bounced messages from > | python-list. Instead of sending them to the list software (where > | they'll result in the subscription being suspended), they're being > | sent to the original sender of the message. [...] > | I've already forwarded a bounce to abuse at azet.sk but have heard > | nothing back. This isn't the list's fault, but maybe the listowner can > | deal with the spam coming back. > > Try "postmaster". I'm not sure "abuse" is so widely implemented. Both are in the spec, but I usually find that postmaster is more often ignored. I'll re-send to postmaster tomorrow if the issue isn't solved. ChrisA From jameskhedley at gmail.com Thu May 10 04:06:47 2012 From: jameskhedley at gmail.com (james hedley) Date: Thu, 10 May 2012 01:06:47 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> > i have not banned anything, or even alluded to it, whatsoever. i asked that > one specific mail not be commented upon OK, sorry if I misunderstood, but that's still suppression in my book. > reading your accounts strewn about is interesting, what exactly are *your* motives? My motives are as I've stated; I'm a commercial user with products in development which use Pyjamas and that I have a long-term stake in. With a bit of thought, anyone should see why I value stability and continued viability. It's a long game but the potential payback to pyjamas could be huge *if* it can keep commercial users on board. This is where the existential threat to pyjamas comes from and why I and many others consider the takeover to be reckless and unjustified. > Luke is a talented developer, there is no doubt of this, but he is one of the most > socially inept persons i have ever encountered I don't think this is the right place to bash people or even defend them on a personal level. We get it though. You didn't get along with the guy. > the idea was to retain Luke I'm sorry but I don't believe this. Luke can speak for himself of course but this is not how you keep people on-board. > he decided to play legal threats as the first card He's claimed that you lifted data from his server without permission. I'm not commenting on that, but if it's true then this is a massive roadblock in the viability of the project. I for one don't want to be involved in it. Can you picture the scene where a developer or businessperaon goes into a meeting with very senior, very conservative executives trying to pitch a product, and it turns out there are serious legal concerns surrounding the technology platform? If it isn't true then perhaps you should put people's minds at rest by giving a detailed explanation of the whole mail server situation, including where the data originated, where it is now, how it got there and why the accidental mailing of so many people occurred. > indeed, you have witnessed little chatter I'd invite anyone to review the pyjamas list for the last 7 days before they make up their minds. Some of the statements I've seen have been regrettable. > by realizing this is not as black-and-white as you's like it to be. I have an ethical objection here, but moreover; it clearly just runs against my interests to support your actions. I'm not sure you considered the commercial users here, and with respect nor do I really get the impression you've understood it, still. By the way; I'm not associated with Luke at all. I've emailed him off-list a few times this week to discuss some angles to do with my work, but that's it. In fact, I support Kees' proposition that Pyjamas should seek sponsorship from the Python/Apache/Free Software Foundation. This would resolve questions of legitimacy and leadership. In my ideal outcome, we could tailor pyjamas more to business use; e.g. tidying up any license issues, offering a commercial support contract (this will help mitigate the damage done to perceptions of credibility), publishing a commercial use policy (one of the foundations could offer support with this I hope). James From jamespic at gmail.com Thu May 10 04:27:16 2012 From: jamespic at gmail.com (James Pic) Date: Thu, 10 May 2012 10:27:16 +0200 Subject: Uploaded package not pip installable Message-ID: Hello everybody, I uploaded a couple of packages: - http://pypi.python.org/pypi/django-cities-light/1.0 - http://pypi.python.org/pypi/django-autocomplete-light/0.1 But they are not pip installable: <<< 10:12.00 Thu May 10 2012!~ <<< jpic at germaine!10012 E:1 env >>> pip install django-autocomplete-light Downloading/unpacking django-autocomplete-light Could not find any downloads that satisfy the requirement django-autocomplete-light No distributions at all found for django-autocomplete-light Storing complete log in /home/jpic/.pip/pip.log <<< 10:20.47 Thu May 10 2012!~ <<< jpic at germaine!10012 E:1 env >>> pip install django-cities-light Downloading/unpacking django-cities-light Could not find any downloads that satisfy the requirement django-cities-light No distributions at all found for django-cities-light Storing complete log in /home/jpic/.pip/pip.log Any idea please ? Regards From steve+comp.lang.python at pearwood.info Thu May 10 04:50:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 May 2012 08:50:42 GMT Subject: __doc__+= """Detailed description""" References: Message-ID: <4fab8161$0$29975$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 May 2012 02:36:29 +0000, Pierre Asselin wrote: > Hi. Started using python a few months back, still settling on my style. > I write docstrings and I use "pydoc mymodule" to refresh my memory. > > Problem: if I just docstring my classes/methods/functions the output of > pydoc more or less works as a reference manual, but if I get sidetracked > for even a few weeks I find that documentation inadequate when I return > to my code. I need to see some introductory context first, so that the > reference material makes sense. It's very difficult to give advice on how to write docstrings when you are talking in such sweeping generalities. Perhaps what you are doing is perfectly fine, and perhaps it is terrible, but without seeing it, how can I tell? Nevertheless, I make some attempt to answer your questions below, although my answers will also be sweeping generalities. > Wery well, write a module docstring then. The problem now: the many > paragraphs of detailed description at the top of the module get in the > way. The pydoc output is good, but the code becomes hard to read. This does not follow. How does a docstring make the code hard to read? Just scroll past the docstring and read the code. Most good editors will colour-code the docstring differently from the actual code, but even if you're using Notepad (shudders), how hard can it be to scroll past a few paragraphs, or pages, of explanatory text in a docstring? I don't understand the nature of your problem here. If your module needs an explanatory module-level docstring to explain what it does, just give it one. > So I come up with this: > > ###################################################################### > #! env python > > """One-liner docstring.""" Why a one-liner? Why not put the detailed description here? > # Many classes, methods, functions, attributes, # with docstrings as > needed. Docs tend to be # short and the code speaks for itself. # Apparently not, since you find the docs insufficient. Perhaps the solution is not to have a huge module docstring and classes with short docstring, but to document the class in the class docstring instead of the module. > ... > # Much further down, > > ___doc___+= """ > > Detailed description goes here. Provide some context, explain what > the classes are for and what the most important methods are, give > simple examples, whatever. Say enough to make the rest > understandable.""" This sounds to me like *exactly* the sort of thing which belongs in the documentation for the classes themselves. The module docstring should document a high-level introduction and show some examples. Detailed description of what the classes do should be in the class docstring, detailed documentation of methods should be in the method docstring, and so forth. Also, as Ben suggests, you don't *have* to put all your documentation in the source code. You can also have a separate documentation document, such as a website or wiki. > if __name__ == "__main__": > # test code follows > ###################################################################### Have you considered turning your tests (at least some of them) into doctests? That way they act as both test and documentation at the same time: executable examples, in the docstrings themselves. > It seems to work, too. But is that a sound way to write python? Am I > relying on undocumented implementation details or am I safe? Are you referring to the part where you define a __doc__ string at the top of the module, and then add to it with __doc__ += "more text"? If not, it isn't clear to me what you mean. -- Steven From research at johnohagan.com Thu May 10 05:16:36 2012 From: research at johnohagan.com (John O'Hagan) Date: Thu, 10 May 2012 19:16:36 +1000 Subject: Real time event accuracy In-Reply-To: References: Message-ID: <20120510191636.e13251e8e8231bccfec4e3b9@johnohagan.com> On Wed, 09 May 2012 08:52:59 -0700 Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. I've done something similar using Fluidsynth (which I think is cross platform) to play the midi. It has the advantage that you can send it midi commands as simple human-readable strings over a socket, like: fluidsynth_socket.send("noteon 0 0 64 \n") making it easy to do things on the fly withoutwriting/reading midi files. On Linux I've found just using: time.sleep(correct_time - time.time()) before sending is accurate to the millisecond, but I understand you have to specify a (hardware) timer to achieve this for Windows. > I'd also appreciate suggestions and pointers to a > suitable python MIDI library, and maybe an outline > of what must be done to get the MIDI events to > the other program's MIDI in. > I haven't used it but python-pypm looks about right: "pyPortMidi is a Python wrapper for PortMidi. PortMidi is a cross-platform C library for realtime MIDI control. Using pyPortMidi, you can send and receive MIDI data in realtime from Python. "Besides using pyPortMidi to communicate to synthesizers and the like, it is possible to use pyPortMidi as a way to send MIDI messages between software packages on the same computer." HTH, John From breamoreboy at yahoo.co.uk Thu May 10 05:31:41 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 May 2012 10:31:41 +0100 Subject: Real time event accuracy In-Reply-To: References: Message-ID: On 09/05/2012 16:52, Tobiah wrote: > I'd like to send MIDI events from python to another > program. I'd like advice as to how to accurately > time the events. I'll have a list of floating point > start times in seconds for the events, and I'd like to send them > off as close to the correct time as possible. > For an idea of how difficult timing can be, search the Python development mailing list for PEP 418 and associated threads. Make sure you have a large supply of sandwiches and coffee cos you'll need it :) > Thanks, > > Tobiah -- Cheers. Mark Lawrence. From d.poreh at gmail.com Thu May 10 05:58:55 2012 From: d.poreh at gmail.com (d.poreh at gmail.com) Date: Thu, 10 May 2012 02:58:55 -0700 (PDT) Subject: which book? In-Reply-To: <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> Message-ID: <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote: > > I am going to learn python for some plot issues. which book or sources, do you recommend please? > The tutorial is pretty good if you already know how to program. > I also heard a lot of good things on "Python Essential Reference". Thanks. Could you please pass the line for tutorial? From jeanmichel at sequans.com Thu May 10 06:47:00 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 10 May 2012 12:47:00 +0200 Subject: __doc__+= """Detailed description""" In-Reply-To: References: Message-ID: <4FAB9CA4.4020109@sequans.com> Pierre Asselin wrote: > Hi. Started using python a few months back, still settling on my style. > I write docstrings and I use "pydoc mymodule" to refresh my memory. > > Problem: if I just docstring my classes/methods/functions the > output of pydoc more or less works as a reference manual, but if > I get sidetracked for even a few weeks I find that documentation > inadequate when I return to my code. I need to see some introductory > context first, so that the reference material makes sense. > > Wery well, write a module docstring then. The problem now: the > many paragraphs of detailed description at the top of the module > get in the way. [snip] How is that a problem ? Having a well detailed description of a module at the top is just fine. If only all modules featured such documentation, the world would be a better place. Cheers, JM From jabba.laci at gmail.com Thu May 10 08:14:47 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 10 May 2012 14:14:47 +0200 Subject: parallel programming in Python Message-ID: Hi, I would like to do some parallel programming with Python but I don't know how to start. There are several ways to go but I don't know what the differences are between them: threads, multiprocessing, gevent, etc. I want to use a single machine with several cores. I want to solve problems like this: iterate over a loop (with millions of steps) and do some work at each step. The steps are independent, so here I would like to process several steps in parallel. I want to store the results in a global list (which should be "synchronised"). Typical use case: crawl webpages, extract images and collect the images in a list. What's the best way? Thanks, Laszlo From d at davea.name Thu May 10 08:34:26 2012 From: d at davea.name (Dave Angel) Date: Thu, 10 May 2012 08:34:26 -0400 Subject: parallel programming in Python In-Reply-To: References: Message-ID: <4FABB5D2.3090808@davea.name> On 05/10/2012 08:14 AM, Jabba Laci wrote: > Hi, > > I would like to do some parallel programming with Python but I don't > know how to start. There are several ways to go but I don't know what > the differences are between them: threads, multiprocessing, gevent, > etc. > > I want to use a single machine with several cores. I want to solve > problems like this: iterate over a loop (with millions of steps) and > do some work at each step. The steps are independent, so here I would > like to process several steps in parallel. I want to store the results > in a global list (which should be "synchronised"). Typical use case: > crawl webpages, extract images and collect the images in a list. > > What's the best way? > > Thanks, > > Laszlo There's no single best-way. First question is your programming environment. That includes the OS you're running, and the version # and implementation of Python. I'll assume you're using CPython 2.7 on Linux, which is what I have the most experience on. But after you answer, others will probably make suggestions appropriate to whatever you're actually using Next question is whether the problem you're solving at any given moment is cpu-bound or i/o bound. I'll try to answer for both cases, here. CPU-bound: In CPython 2.7, there's a GIL, which is a global lock preventing more than one CPU-bound thread from running at the same time. it's more complex than that, but bottom line is that multiple threads won't help (and might hurt) a CPU-bound program, even in a multi-core situation. So use multiple processes, and cooperate between them with queues or shared memory, or even files. In fact, you can use multiple computers, and communicate using sockets, in many cases. IO-bound: This is what CPython is good at solving with threads. Once you make a blocking I/O call, usually the C code involves releases the GIL, and other threads can run. For this situation, the fact that you can share data structures makes threads a performance win. Web crawling is likely to be IO-bound, but i wanted to be as complete as I could. -- DaveA From jeanpierreda at gmail.com Thu May 10 08:46:01 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 10 May 2012 08:46:01 -0400 Subject: parallel programming in Python In-Reply-To: References: Message-ID: On Thu, May 10, 2012 at 8:14 AM, Jabba Laci wrote: > What's the best way? >From what I've heard, http://scrapy.org/ . It is a single-thread single-process web crawler that nonetheless can download things concurrently. Doing what you want in Scrapy would probably involve learning about Twisted, the library Scrapy works on top of. This is somewhat more involved than just throwing threads and urllib and lxml.html together, although most of the Twisted developers are really helpful. It might not be worth it to you, depending on the size of the task. Dave's answer is pretty general and good though. -- Devin From jabba.laci at gmail.com Thu May 10 08:46:31 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 10 May 2012 14:46:31 +0200 Subject: parallel programming in Python In-Reply-To: <4FABB5D2.3090808@davea.name> References: <4FABB5D2.3090808@davea.name> Message-ID: Hi, Thanks for the answer. I use Linux with CPython 2.7. I plan to work with CPU bound and I/O bound problems too. Which packages to use in these cases? Could you redirect me to some guides? When to use multiprocessing / gevent? Thanks, Laszlo On Thu, May 10, 2012 at 2:34 PM, Dave Angel wrote: > On 05/10/2012 08:14 AM, Jabba Laci wrote: >> Hi, >> >> I would like to do some parallel programming with Python but I don't >> know how to start. There are several ways to go but I don't know what >> the differences are between them: threads, multiprocessing, gevent, >> etc. >> >> I want to use a single machine with several cores. I want to solve >> problems like this: iterate over a loop (with millions of steps) and >> do some work at each step. The steps are independent, so here I would >> like to process several steps in parallel. I want to store the results >> in a global list (which should be "synchronised"). Typical use case: >> crawl webpages, extract images and collect the images in a list. >> >> What's the best way? >> >> Thanks, >> >> Laszlo > > There's no single best-way. ?First question is your programming > environment. ?That includes the OS you're running, and the version # and > implementation of Python. > > I'll assume you're using CPython 2.7 on Linux, which is what I have the > most experience on. ?But after you answer, others will probably make > suggestions appropriate to whatever you're actually using > > Next question is whether the problem you're solving at any given moment > is cpu-bound or i/o bound. ?I'll try to answer for both cases, here. > > CPU-bound: > In CPython 2.7, there's a GIL, which is a global lock preventing more > than one CPU-bound thread from running at the same time. ?it's more > complex than that, but bottom line is that multiple threads won't help > (and might hurt) a CPU-bound program, even in a multi-core situation. > So use multiple processes, and cooperate between them with queues or > shared memory, or even files. In fact, you can use multiple computers, > and communicate using sockets, in many cases. > > IO-bound: > This is what CPython is good at solving with threads. ?Once you make a > blocking I/O call, usually the C code involves releases the GIL, and > other threads can run. ?For this situation, the fact that you can share > data structures makes threads a performance win. > > Web crawling is likely to be IO-bound, but i wanted to be as complete as > I could. > > -- > > DaveA > From andreas.tawn at ubisoft.com Thu May 10 09:33:03 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 10 May 2012 15:33:03 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Say I've got a class... class test(object): def __init__(self): self.foo = 1 self.bar = 2 self.baz = 3 I can say... def __str__(self): return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) and everything's simple and clean and I can vary the formatting if I need to. This gets ugly when the class has a lot of attributes because the string construction gets very long. I can do... return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) which is an improvement, but there's still a very long line. And there's also something like... return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) Is there a better way? Cheers, Drea p.s. I may want to substitute __repr__ for __str__ perhaps? From bahamutzero8825 at gmail.com Thu May 10 09:33:09 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 10 May 2012 08:33:09 -0500 Subject: Pydev configuration In-Reply-To: <4FAAE0BE.5080307@gmail.com> References: <1164389878.833569.60710@l39g2000cwd.googlegroups.com> <1336562181117-4962800.post@n6.nabble.com> <4FAAE0BE.5080307@gmail.com> Message-ID: <4FABC395.5020705@gmail.com> On 5/9/2012 4:25 PM, Alan Ristow wrote: > Select the code block you want to indent and hit Tab. To do the reverse, > hit Shift-Tab. You can also select a code block and choose "Shift Right" or "Shift Left" from the context menu. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From p.f.moore at gmail.com Thu May 10 09:46:19 2012 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 10 May 2012 06:46:19 -0700 (PDT) Subject: Instrumenting a class to see how it is used Message-ID: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> I'm trying to reverse-engineer some pretty complex code. One thing that would help me a lot is if I could instrument a key class, so that I'd get a report of when and how each method was called and any properties or attributes were accessed during a typical run. I could do this relatively easily by just adding print calls to each method/attribute, but I was wondering - is there a library that does this sort of wrapping already? I tried writing my own but got bogged down in infinite recursion in _getattribute__ and couldn't see an easy way out. If anyone has any suggestions, I'd be interested. Thanks, Paul. From jhnwsk at gmail.com Thu May 10 09:47:11 2012 From: jhnwsk at gmail.com (John) Date: Thu, 10 May 2012 15:47:11 +0200 Subject: Python SOAP library References: <5942127.283.1335972950164.JavaMail.geo-discussion-forums@pbcgx8> Message-ID: W dniu 2012-05-02 17:35, Alec Taylor pisze: > Would you recommend: http://code.google.com/p/soapbox/ > > Or suggest another? I am having lots of fun and positive experience with https://github.com/arskom/rpclib Awesome doc and example code and, most importantly, it works! :) -- John From g.rodola at gmail.com Thu May 10 10:26:25 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 10 May 2012 16:26:25 +0200 Subject: Creating a Windows installer for Python + a set of dependencies Message-ID: Hi all, I need to create an installer for Windows which should be able to install a specific version of the Python interpreter (2.7) plus a set a dependencies such as ipython, numpy, pandas, etc. Basically this is the same thing Active State did for their Active Python distribution: a single bundle including interpreter + deps. Not being a Windows user I'm not sure where to start with this except maybe looking into NSIS (could that be of any help?). Thanks in advance, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From g2mahendra at gmail.com Thu May 10 10:31:39 2012 From: g2mahendra at gmail.com (Mahendra) Date: Thu, 10 May 2012 07:31:39 -0700 (PDT) Subject: Python ABAQUS debugging problem. Message-ID: Dear all, I am learning to use python script for running ABAQUS (commerical finite element program). I am having a bug in the following chunk of code and am not sure what it is. I have three loops in my code. The first two loops work fine. The third loop is a combination of loop 1 and loop 2. It doesnt work. There is some syntax issue which it is not clear to me. #--------------------------#-------------------# # Creating a list of moduli for parametric study moduli = [ 1000, 500] #--------------------------#-------------------# # This loop works fine for E in moduli: print E lengthE='length'+str(E) print lengthE #--------------------------#-------------------# #--------------------------#-------------------# # This loop works fine. for E in moduli: # lengthE = 'length'+str(E) # print E # print lengthE mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, 0.18), )) job.submit() job.waitForCompletion() print 'Completed job for %s E' % (E) #--------------------------#-------------------# #--------------------------#-------------------# # This loop doesnt work. # It says syntax error in lengthE = 'length' + str(E) #--------------------------#-------------------# for E in moduli: print E lengthE = 'length' + str(E) mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, 0.18), )) job.submit() job.waitForCompletion() # print lengthE print 'Completed job for %s E' % (E) #--------------------------#-------------------# Any help is deeply appreciated in this regard. Sincerely, Mahendra. From rosuav at gmail.com Thu May 10 10:33:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 00:33:13 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn wrote: > Say I've got a class... > > class test(object): > ? ?def __init__(self): > ? ? ? ?self.foo = 1 > ? ? ? ?self.bar = 2 > ? ? ? ?self.baz = 3 > > I can say... > > def __str__(self): > ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) This might be of use: return """foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) You're repeating yourself a bit, but this allows the labels to differ from the format tags. If you're certain that you don't need that flexibility, you could generate the format string dynamically: return "\n".join(x+": {"+x+"}" for x in ("foo","bar","baz")).format(**self.__dict__) That scales more nicely as the number of elements desired increases (while still being 100% explicit - the presence and order of elements is governed by the tuple), but is a bit inflexible and complicated. I'd be inclined toward the triple-quoted-string one. Tim Toady. ChrisA From g2mahendra at gmail.com Thu May 10 10:37:43 2012 From: g2mahendra at gmail.com (Mahendra) Date: Thu, 10 May 2012 07:37:43 -0700 (PDT) Subject: Python ABAQUS debugging problem. References: Message-ID: <4d25a4fe-cf29-434d-a856-0fcfb6caa0c9@g6g2000pbq.googlegroups.com> On May 10, 9:31?am, Mahendra wrote: > Dear all, > ? ? ? ? ? ? I am learning to use python script for running ABAQUS > (commerical finite element program). I am having a bug in the > following chunk of code and am not sure what it is. I have three loops > in my code. The first two loops work fine. The third loop is a > combination of loop 1 and loop 2. It doesnt work. There is some syntax > issue which it is not clear to me. > > #--------------------------#-------------------# > # Creating a list of moduli for parametric study > moduli = [ 1000, 500] > > #--------------------------#-------------------# > # This loop works fine > > for E in moduli: > ? ? print E > ? ? lengthE='length'+str(E) > ? ? print lengthE > #--------------------------#-------------------# > > #--------------------------#-------------------# > # This loop works fine. > > for E in moduli: > # ? lengthE = 'length'+str(E) > # ? ? ? print E > # ? ? ? print lengthE > > mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, > 0.18), )) > ? ? ? ? job.submit() > ? ? ? ? job.waitForCompletion() > ? ? ? ? print 'Completed job for %s E' % (E) > #--------------------------#-------------------# > > #--------------------------#-------------------# > # This loop doesnt work. > # It says syntax error in lengthE = 'length' + str(E) > #--------------------------#-------------------# > for E in moduli: > ? ? print E > ? ? ? ? lengthE = 'length' + str(E) > > mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E, > 0.18), )) > ? ? ? ? job.submit() > ? ? ? ? job.waitForCompletion() > # ? ? ? print lengthE > ? ? ? ? print 'Completed job for %s E' % (E) > #--------------------------#-------------------# > > Any help is deeply appreciated in this regard. > Sincerely, > Mahendra. I think when I pasted the message from the code in this email, the indentation is little off. I used notepad++ for writing the code. It didnt show wrong indentation. However, on notepad it is wrongly indented. The program is working now. Thanks for your time and sorry for the inconvenience. Mahendra. From rkraats at dds.nl Thu May 10 11:09:16 2012 From: rkraats at dds.nl (Roel van de Kraats) Date: Thu, 10 May 2012 17:09:16 +0200 Subject: Running embedded python shell on a separate thread Message-ID: <4FABDA1C.5050008@dds.nl> For those who are interested, In an application I am working on, an embedded python shell needs to be run on a separate thread, since the main thread is already 'taken' (by Qt). This causes an issue with handling SIGINT (Control-C) when using the readline package; the 'KeyboardInterrupt' is only shown/handled after pressing . With a work-around, I was able to get this working 'normally' without modifying the python code itself, which I want to share with you. For completeness, I'm using Python 2.6.5 on Ubuntu Lucid. Our application is in C++. The problem is that Control-C causes a SIGINT signal to be sent to the main/initial thread. Python's signal handler (signal_handler in Modules/signalmodule.c) handles this signal by marking that it occurred and adding a 'pending call'. But the readline functionality (readline_until_enter_or_signal in Modules/readline.c) only notices this when select() returns errno==EINTR. That is, when select() itself was interrupted. And that only happens when the SIGINT signal is sent to the thread on which readline is running. The work-around I made was to install my own SIGINT signal handler with this functionality: - When it receives a signal on a thread different from the 'python' thread, it uses pthread_kill() to forward the signal to that 'python' thread. - When it receives a signal on the 'python' thread, it temporarily restores the 'python' signal handler and raises the signal again. Installing the signal handler is done by a wrapper around the readline function, through the PyOS_ReadlineFunctionPointer hook. My application code (simplified C++) can be found below. I guess all these 'hacks' could be prevented when Python's own signal handler would forward the SIGINT signal (or any signal) to the 'python' thread. Kind regards, Roel van de Kraats typedef void (*sighandler_t)(int); // don't use PyOS_setsig() since we need the SA_NODEFER flag int set_sighandler(int sig, sighandler_t handler, sighandler_t * old_handler = NULL, int flags = SA_NODEFER) { struct sigaction action; struct sigaction oldaction; memset(&action, 0, sizeof(action)); memset(&oldaction, 0, sizeof(oldaction)); action.sa_handler = handler; action.sa_flags = flags; int ret = sigaction(sig,&action,&oldaction); if (old_handler) { *old_handler = oldaction.sa_handler; } return ret; } sighandler_t old_int_signal_handler; void int_signal_handler(int) { if ( this_is_the_python_thread() ) { static volatile bool calling = false; // for error checking if (calling) { // unexpected recursive call return; } calling = true; sighandler_t prev_handler; // restore original handler (void)set_sighandler(SIGINT, old_int_signal_handler,&prev_handler); if (prev_handler != int_signal_handler) { // expected int_signal_handler return; } // raise signal which will be handled by the original handler ::pthread_kill(_python_thread_id, SIGINT); // install our handler again (void)set_sighandler(SIGINT, int_signal_handler); calling = false; } else { // not meant for this thread; redirect to python thread ::pthread_kill(_python_thread_id, SIGINT); } } char *(*old_readline)(FILE *, FILE *, char *); char * my_readline(FILE * a1, FILE * a2, char * a3) { // replace signal handler (void)set_sighandler(SIGINT, int_signal_handler,&old_int_signal_handler); char * ret = (*old_readline)(a1, a2, a3); // restore original handler (void)set_sighandler(SIGINT, old_int_signal_handler, NULL, 0); return ret; } void python_thread_function() { Py_Initialize(); // some other initialization stuff here // make sure readline is initialized before we replace the readline function PyRun_SimpleString("import readline\n"); old_readline = PyOS_ReadlineFunctionPointer; if (old_readline) { PyOS_ReadlineFunctionPointer = my_readline; } else { // PyOS_ReadlineFunctionPointer was not set so don't replace } // the python prompt appears now... int ret = PyRun_InteractiveLoop(stdin, ""); Py_Exit(ret); } From andreas.tawn at ubisoft.com Thu May 10 11:15:12 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 10 May 2012 17:15:12 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> > On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn > wrote: > > Say I've got a class... > > > > class test(object): > > ? ?def __init__(self): > > ? ? ? ?self.foo = 1 > > ? ? ? ?self.bar = 2 > > ? ? ? ?self.baz = 3 > > > > I can say... > > > > def __str__(self): > > ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, > > self.baz) > > This might be of use: > > return """foo: {foo} > bar: {bar} > baz: {baz}""".format(**self.__dict__) > > You're repeating yourself a bit, but this allows the labels to differ from the format > tags. If you're certain that you don't need that flexibility, you could generate the > format string dynamically: > > return "\n".join(x+": {"+x+"}" for x in > ("foo","bar","baz")).format(**self.__dict__) > > That scales more nicely as the number of elements desired increases (while still > being 100% explicit - the presence and order of elements is governed by the tuple), > but is a bit inflexible and complicated. > I'd be inclined toward the triple-quoted-string one. I considered the triple quote string one, but it's not very PEP 8 compatible in a real class because it includes the indentation in the formatted string. To make it print properly, it has to look like this... def __str__(self): return """foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) I didn't realise I could do implicit line continuation inside a list comprehension. That might be the best way. Even more so with continuation lines inside the attribute name tuple. def __str__(self): return "\n".join(x+": {"+x+"}" for x in ("foo", "bar", "baz")).format(**self.__dict__) Still feels a bit icky though. From torriem at gmail.com Thu May 10 12:01:04 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 May 2012 10:01:04 -0600 Subject: parallel programming in Python In-Reply-To: References: Message-ID: <4FABE640.4030805@gmail.com> On 05/10/2012 06:46 AM, Devin Jeanpierre wrote: > On Thu, May 10, 2012 at 8:14 AM, Jabba Laci wrote: >> What's the best way? > >>From what I've heard, http://scrapy.org/ . It is a single-thread > single-process web crawler that nonetheless can download things > concurrently. Yes, for i/o bound things, asynchronous (event-driven callbacks, where events are triggered by the data) will usually beat multi-threaded. Sometimes a combination of multi-threaded and asynchronous is necessary (thread pools). Twisted is another asynchronous framework core that is very popular for lots of things, both clients and servers. From gridsngators at gmail.com Thu May 10 12:07:39 2012 From: gridsngators at gmail.com (ks) Date: Thu, 10 May 2012 09:07:39 -0700 (PDT) Subject: Alternative to subprocess in order to not wait for calling commands to complete Message-ID: Hi All, >From within one Python program, I would like to invoke three other Python programs. Usually I would use the subprocess module to invoke these sequentially. I now have a use case in which I must invoke the first one (not wait for it to complete), then invoke the second (similarly not wait for it to complete) and then go on to the third. I am not sure where I should start looking to be able to do this. I am reading about threads and forking and there are many options out there. So I was wondering if anyone might have suggestions on where I can start. Any hints/references would be very helpful! Thank you, ks From michele.simionato at gmail.com Thu May 10 12:08:33 2012 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 10 May 2012 09:08:33 -0700 (PDT) Subject: Instrumenting a class to see how it is used In-Reply-To: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> References: <3571808.702.1336657579600.JavaMail.geo-discussion-forums@vbvx4> Message-ID: <17323732.904.1336666113137.JavaMail.geo-discussion-forums@vbvx4> This may get you started (warning: not really tested). $ echo instr.py from warnings import warn oget = object.__getattribute__ tget = type.__getattribute__ class Instr(object): class __metaclass__(type): def __getattribute__(cls, name): clsname = tget(cls, '__name__') warn('accessing %s.%s' % (clsname, name), stacklevel=2) return tget(cls, name) def __getattribute__(self, name): warn('accessing %s.%s' % (self, name), stacklevel=2) return oget(self, name) Then change the base classes of the class you want to instrument, i.e. class MyClass(MyBase) -> class MyClass(MyBase, Instr) and see what happens. It should work in simple cases. It will log a lot, so will have to adapt this. From roel at roelschroeven.net Thu May 10 13:06:14 2012 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 10 May 2012 19:06:14 +0200 Subject: Problem with time.time() standing still In-Reply-To: <4FA93EE5.4040200@bobcowdery.plus.com> References: <4FA633CF.7060009@bobcowdery.plus.com> <20120506084915.GA19916@cskk.homeip.net> <4FA6421F.40002@bobcowdery.plus.com> <4FA900CD.7070604@bobcowdery.plus.com> <4FA93EE5.4040200@bobcowdery.plus.com> Message-ID: Hi Bob, This reminds of a problem we had at work some years ago. I've followed the thread from the beginning, but I hadn't a clue about what could possibly cause the problem until you said: Bob Cowdery schreef: > Hopefully somebody can add the last piece of this puzzle. My code didn't > work because I did make a silly mistake. The number of seconds since > EPOC is a large number but it also needs a high precision. Attempting to > put this value into a 32 bit float corrupts the least significant part > because 24 bits cannot hold that precision. Now Python floats are C > doubles and the calculation in timemodule.c is in doubles right back to > Python. Normally this retains the precision. For some inexplicable > reason when I make certain calls into this vendors SDK, ftime() is > getting precision problems and appears to be frozen as a result. Our problem turned out to be caused by a loss of precision in an application of ours, caused by Direct3D. The solution for us was to include the flag D3DCREATE_FPU_PRESERVE in CreateDevice(). The documentation seems to imply that the lower precision only has effect in the Direct3D code, but in reality it lowers precision in the rest of the code too (the whole process or the whole thread, I'm not sure). In your case it seems harder to solve: as far as I understand, the trigger is somewhere in the vendors SDK, which you have no control over. I'm afraid I don't know what you can do about that. Best regards, Roel -- "The reasonable man adapts himself to the world. The unreasonable man persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw roel at roelschroeven.net http://roelschroeven.net From nad at acm.org Thu May 10 13:55:05 2012 From: nad at acm.org (Ned Deily) Date: Thu, 10 May 2012 10:55:05 -0700 Subject: Mailing list assistance: manual unsubscribing of failed recipient? References: Message-ID: In article , Chris Angelico wrote: > Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? http://mail.python.org/mailman/listinfo/python-list -- Ned Deily, nad at acm.org From askutt at gmail.com Thu May 10 13:58:48 2012 From: askutt at gmail.com (Adam Skutt) Date: Thu, 10 May 2012 10:58:48 -0700 (PDT) Subject: Alternative to subprocess in order to not wait for calling commands to complete References: Message-ID: On May 10, 12:07?pm, ks wrote: > Hi All, > > From within one Python program, I would like to invoke three other > Python programs. Usually I would use the subprocess module to invoke > these sequentially. I now have a use case in which I must invoke the > first one (not wait for it to complete), then invoke the second > (similarly not wait for it to complete) and then go on to the third. > > I am not sure where I should start looking to be able to do this. I am > reading about threads and forking and there are many options out > there. So I was wondering if anyone might have suggestions on where I > can start. > subprocess.Popen objects only block for process termination when you request it, via wait() or communicate(). As such, if you never call those methods, you will never block for process termination. What you want is essentially the default behavior if you're creating Popen objects directly (instead of using the call() function). However, you must call the wait() or poll() methods at least once, after the subprocess has terminated, to release system resources. There are many ways to accomplish this, and the best approach depends on your application. One simple option is to call poll() once each time your application goes through its main loop. Another option is to use a dedicated thread for the purpose of reaping processes. Please note that calling Popen.poll() in a loop over many processes does not scale (each call incurs an expensive system call) and will cause noticeable CPU consumption with even a handful of processes (3 is just fine, though). Unfortunately, the subprocess module lacks any way to wait on multiple processes simultaneously. This is possible with operating-system specific code, however. I would not worry about it for now, but it may be something you need to consider in the future. Adam From wescpy at gmail.com Thu May 10 14:07:01 2012 From: wescpy at gmail.com (wesley chun) Date: Thu, 10 May 2012 11:07:01 -0700 Subject: ANN: Intro+Intermediate Python, San Francisco, Aug 1-3 Message-ID: Greetings! I'll be doing another hardcore Python course this summer in the San Francisco area. If you're somewhat new to Python or have tinkered but want to fill-in the holes, this course is for you. It's somewhat true you can learn Python online, watching videos, or reading books, but it still takes time and experience to master... I help accelerate this process. The course is based on my bestselling "Core Python" books and is made up of 3 full days complete with lectures and three hands-on coding labs per day. Please pass on this message to your colleagues who also need to learn Python. It's also a great excuse to coming to beautiful Northern California for a summer vacation! More details at http://goo.gl/uW4oF as well as the links in my .signature below. Since I hate spam, I'll only send out one more reminder as the date gets closer... probably around OSCON's timeframe. Hope to meet some of you soon! --Wesley Chun - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "A computer never does what you want... only what you tell it." ? ? wesley chun : wescpy at gmail?: @wescpy/+wescpy ? ? Python training & consulting :?http://CyberwebConsulting.com ? ? "Core Python" books :?http://CorePython.com ? ? Python blog: http://wescpy.blogspot.com From samdansobe at yahoo.com Thu May 10 16:55:40 2012 From: samdansobe at yahoo.com (Sammy Danso) Date: Thu, 10 May 2012 13:55:40 -0700 (PDT) Subject: Help with how to combine two csv files Message-ID: <1336683340.71877.YahooMailClassic@web161202.mail.bf1.yahoo.com> Hi JM and All, Thank you all very much for your response and help. I managed to work out the problem eventually. But my code is ridiculously long compared to what you have just offered here. I think your code is elegant and should be much faster.? Thanks? a lot Sammy ? Below is my code. ? ?outputfile = codecs.open(csvfile3, 'wb') ?inputfile1 =? codecs.open(csvfile1, 'rb') ?inputfile2 = codecs.open(csvfile2, 'rb') ???????????? ??????????????? ???????????????? dictreader2 = csv.DictReader(inputfile2) ???????????????? dictreader1 = csv.DictReader(inputfile1) ???????????????? mergedDict = {} ???????????????? ???????????????? mergedDictb = {} ???????????????? matchedlistA = [] ???????????????? matchedlistB = [] ???????????????? matchedlist = [] ???????????????? cnt = 0 ???????????????? cntb = 0 ???????????????? for dictline1 in dictreader1: ?????????????????????????cnt? += 1 ???????????????????????? print cnt ???????????????????????? mergedDict = dictline1.copy() ???????????????????????? mergedDict['UniqID']=? cnt ????????????????????????? matchedlistA.append(mergedDict) ???????????????????????? ??????????????? ???????????????? for dictline2 in dictreader2: ????????????????????????? cntb? += 1 ????????????????????????? mergedDictb = dictline2.copy() ????????????????????????? mergedDictb['UniqID']=? cntb ????????????????????????? matchedlistB.append(mergedDictb) ???????????????????????? ?????????????? ???????????????? for dictline1 in matchedlistA: ??????????????????? for dictline2 in matchedlistB: ??????????????????????? if dictline1['UniqID'] == dictline2['UniqID']: ??????????????????????????? entry = dictline1.copy() ??????????????????????????? entry.update(dictline2) ??????????????????????????? matchedlist.append(entry) ? ? --- On Wed, 5/9/12, Jean-Michel Pichavant wrote: From: Jean-Michel Pichavant Subject: Re: Help with how to combine two csv files To: "Sammy Danso" Cc: python-list at python.org Date: Wednesday, May 9, 2012, 11:23 AM Sammy Danso wrote: > Hello Experts, > I am new to python and I have been trying to merge two csv files, and upon several hours of unsuccessful attempts, I have decided to seek for help. >? the format of the file is as follows. file A has? columns a, b, c and values 1,2,3 for several rows. File B also has columns d,e and values 4,5? for same number of rows as A. the files however do not have any unique column between the two. > I want an output file C to have columns? a,b,c,d,e with values 1,2,3,4,5 >? I would be very grateful for your help with some code. >? Thanks very much, > Sammy > Post some code so we may point at your problem. The solution is easy, the code very small. Something like (pseudo code): import csv writer = csv.writer(file3) for index, row in enumerate(csv.reader(file1)): ???writer.writerow(row + csv.reader(file2)[index]) JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 17:39:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 07:39:15 +1000 Subject: Mailing list assistance: manual unsubscribing of failed recipient? In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 3:55 AM, Ned Deily wrote: > In article > , > ?Chris Angelico wrote: >> Who is in charge of the list? Can pyjko21 at azet.sk be unsubscribed manually? > > http://mail.python.org/mailman/listinfo/python-list Doh! I checked the top of that page ("We" this and "We" that) but didn't see the bit at the bottom with email addresses. Whoops! Thanks Ned. ChrisA From rosuav at gmail.com Thu May 10 17:47:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 07:47:03 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <581D4160B04DF541A763BB8BB60E8CC6A6EC597502@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Fri, May 11, 2012 at 1:15 AM, Andreas Tawn wrote: > I considered the triple quote string one, but it's not very PEP 8 compatible in a real class because it includes the indentation in the formatted string. Yeah, that is an annoying side effect. My personal view is that code should be written concisely, even if that means violating indentation. One possible way around that is to break out the format string to a module variable (thus completely unindented); another way is to accept the indentation, for instance: def __str__(self): return """test(): foo: {foo} bar: {bar} baz: {baz}""".format(**self.__dict__) resulting in a string that has a somewhat Pythonic syntax to it. Would work nicely if you have a few "primary" attributes that go onto the first line, and a bunch of "secondary" attributes that get listed below. ChrisA From bob at bobcowdery.plus.com Thu May 10 18:10:42 2012 From: bob at bobcowdery.plus.com (Bob Cowdery) Date: Thu, 10 May 2012 23:10:42 +0100 Subject: Problem with time.time() standing still Message-ID: <4FAC3CE2.4080409@bobcowdery.plus.com> Hi Roel "Our problem turned out to be caused by a loss of precision in an application of ours, caused by Direct3D. The solution for us was to include the flag D3DCREATE_FPU_PRESERVE in CreateDevice(). The documentation seems to imply that the lower precision only has effect in the Direct3D code, but in reality it lowers precision in the rest of the code too (the whole process or the whole thread, I'm not sure). " That is spot on and very likely the cause. Thanks very much for responding. I do have some control over the vendor and have passed that information on to them. Hopefully they will investigate and fix the problem. Bob From ethan at stoneleaf.us Thu May 10 18:38:04 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 10 May 2012 15:38:04 -0700 Subject: ANN: dbf version 0.92.002 released Message-ID: <4FAC434C.40304@stoneleaf.us> Available at http://pypi.python.org/pypi/dbf Fixed issue with Memo fields not returning correct unicode data. Updated many docstrings. Nulls now fully supported. Getting closer to a 1.0 (non-beta!) release; working on PEP 8 compliance, index files, and actual documentation. Biggest change ============== records no longer auto-update back to disk; make sure and use record.write_record() if you want the on-disk version of the table updated, or use the new Write generator which calls .write_record() before returning the next record in the table/list/index/whatever. As always, comments and bug-reports appreciated! From ethan at stoneleaf.us Thu May 10 18:52:10 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 10 May 2012 15:52:10 -0700 Subject: PyPI is being spammed Message-ID: <4FAC469A.1090601@stoneleaf.us> with Dr Sultan Spells of various natures. Can anybody put a stop to that? ~Ethan~ From cyborgv2 at hotmail.com Thu May 10 19:36:00 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 00:36:00 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4FAB205B.8000804@gmail.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , <4FAB205B.8000804@gmail.com> Message-ID: Hi ya, Please don't attack me or pull me into the centre of this conflict... I don't have any idea of what is really happening here; other than that I've read on the python-list mailing list. Your right, I have never released any code, under any license of any description. I have only offered snippets of code to people/projects to be used as they see fit (besides my professional developments and private projects.) All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor have ever had any prior contact with) about releasing code under a license... And, what I said stands: once anyone releases code, they are bound by the license they released it under as much as anyone else that may use it and cannot then withdraw that code from the domain they released it to (except by maybe creating a new and different version.) Being dyslexic, my message (and this one) may not be worded in the best way but that is no reason to start on me! Date: Wed, 9 May 2012 22:56:43 -0300 From: ricaraoz at gmail.com To: cyborgv2 at hotmail.com Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack On 09/05/12 20:04, Adrian Hunt wrote: Hi Ian, Well there you have me... You release code under a license, you bound by it even if later you think better of it... Seller be ware!!!!!! Sorry, but you are not being accurate. "You" don't release code under a license, James Tauber did, or the Google Web Toolkit did. So you are in no positon to "think better of it" even if it was allowed to the original releaser. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 19:57:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 09:57:49 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> <4FAB205B.8000804@gmail.com> Message-ID: On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > have ever had any prior contact with) about releasing code under a > license... And, what I said stands: once anyone releases code, they are > bound by the license they released it under as much as anyone else that may > use it and cannot then withdraw that code from the domain they released it > to (except by maybe creating a new and different version.) And that's absolutely correct. Open source licenses are deliberately worded to guarantee rights in perpetuity, so there's no way to withdraw it or change the license (though of course a copyright owner can release the same code under an additional license). > Being dyslexic, my message (and this one) may not be worded in the best way > but that is no reason to start on me! Your message is fine. Believe you me, I'd much rather read a message posted by a non-native English speaker, or a dyslexic person, or someone who has a clinical aversion to the letter 'q', than someone who's simply sloppy and doesn't care about their language at all. Chris Angelico From cyborgv2 at hotmail.com Thu May 10 20:04:51 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 01:04:51 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , , Message-ID: Hi there, Yes, it's very messy by what I understand and is why Merlio never had it's judgements enforced. Although, employment contracts that were in place at the time (including mine), were declared null and void... I think it was something like: if a programmer has an idea and uses it within an employers project then the employer has a legal claim to that implementation but not to the original idea. And, a contract that claims IP rights would stop a developer from ever working again as a programmer: this again, being illegal and making the contract null and void. With internationalization, the problem is compounded as different countries have different laws. Since my days at Merlio, I have managed to avoid singing any contract that claims IP and I have worked for some large international companies (from within the UK.) > Date: Thu, 10 May 2012 10:27:27 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Thu, May 10, 2012 at 10:12 AM, Mark Lawrence wrote: > > Google was a right PITA but eventually I found this > > http://www.legalcentre.co.uk/intellectual-property/guide/intellectual-property-and-employees/ > > It appears to contradict what you've said above, or have I misread it? E.g > > "Under the (Patents) Act (1977), there is a presumption that an employer > > will own the patent of an invention made by its employee if the invention > > was made in the employee?s normal or specifically assigned duties and > > either, an invention might reasonably be expected to result from such duties > > or, the employee has a special obligation to further the employee?s > > interests, arising from the nature of those duties and responsibilities and > > the employee?s status." > > That's patents... intellectual property goes by other rules I think. I > am not a lawyer, and I try to avoid getting placed in any position > where this sort of thing will come up, because it's messy... > especially with internationalization. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From memilanuk at gmail.com Thu May 10 20:12:11 2012 From: memilanuk at gmail.com (Monte Milanuk) Date: Thu, 10 May 2012 17:12:11 -0700 Subject: Looking for video/slides from PyCon 2011... Message-ID: ...specifically the two lectures on creating GUI applications with Python + QT http://us.pycon.org/2011/schedule/presentations/207/ Various searches on the 'Net don't seem to be turning up much... kinda curious as to why? Anyone here know? TIA, Monte From cs at zip.com.au Thu May 10 20:15:35 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 11 May 2012 10:15:35 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <20120511001535.GA8056@cskk.homeip.net> On 10May2012 15:33, Andreas Tawn wrote: | Say I've got a class... | | class test(object): | def __init__(self): | self.foo = 1 | self.bar = 2 | self.baz = 3 | | I can say... | | def __str__(self): | return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) | | and everything's simple and clean and I can vary the formatting if I need to. | | This gets ugly when the class has a lot of attributes because the string construction gets very long. This issue bit me once too often a few months ago, and now I have a class called "O" from which I often subclass instead of from "object". Its main purpose is a friendly __str__ method, though it also has a friendly __init__. Code: class O(object): ''' A bare object subclass to allow storing arbitrary attributes. It also has a nicer default str() action, and an aggressive repr(). ''' def __init__(self, **kw): ''' Initialise this O. Fill in attributes from any keyword arguments if supplied. This call can be omitted in subclasses if desired. ''' for k in kw: setattr(self, k, kw[k]) def __str__(self): return ( "<%s %s>" % ( self.__class__.__name__, ",".join([ "%s=%s" % (attr, getattr(self, attr)) for attr in sorted(dir(self)) if attr[0].isalpha() ]) ) ) So I have some code thus: from cs.misc import O ...... class FilterModes(O): def __init__(self, **kw): # special case one parameter self._maildb_path = kw.pop('maildb_path') self._maildb_lock = allocate_lock() O.__init__(self, **kw) ...... filter_modes = FilterModes(justone=justone, delay=delay, no_remove=no_remove, no_save=no_save, maildb_path=os.environ['MAILDB'], maildir_cache={}) This removes a lot of guff from some common procedures. Hope this helps, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's a fine line between pathos and pathetic. - David Stivers stiv at stat.rice.edu DoD #857 From cyborgv2 at hotmail.com Thu May 10 20:21:37 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 01:21:37 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com>, <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com>, <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com>, <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8>, <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6>, , , , , , <4FAB205B.8000804@gmail.com>, , Message-ID: lol, Cheers Chris. Just so you know, I care about what and how I write... I almost always run my emails though a word-processor before sending. And, that has paid off for me: thanks to MS Word, MS Works and Open Office, I have better understanding of "correct" punctuation use (if not spelling and grammar) than most school leavers!!! PS. It hasn't gone a miss that you are one of the core python-list responders (and I bet this goes for most of the python-list users): your responses, time and knowledge is appreciated... Thank you. > Date: Fri, 11 May 2012 09:57:49 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > > have ever had any prior contact with) about releasing code under a > > license... And, what I said stands: once anyone releases code, they are > > bound by the license they released it under as much as anyone else that may > > use it and cannot then withdraw that code from the domain they released it > > to (except by maybe creating a new and different version.) > > And that's absolutely correct. Open source licenses are deliberately > worded to guarantee rights in perpetuity, so there's no way to > withdraw it or change the license (though of course a copyright owner > can release the same code under an additional license). > > > Being dyslexic, my message (and this one) may not be worded in the best way > > but that is no reason to start on me! > > Your message is fine. Believe you me, I'd much rather read a message > posted by a non-native English speaker, or a dyslexic person, or > someone who has a clinical aversion to the letter 'q', than someone > who's simply sloppy and doesn't care about their language at all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu May 10 20:46:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 10:46:33 +1000 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <72f3643d-49cb-44f6-918a-639b2ad485f9@r2g2000pbs.googlegroups.com> <30621110.1610.1336468213871.JavaMail.geo-discussion-forums@vbxz8> <22035083.42.1336561324082.JavaMail.geo-discussion-forums@ynca6> <4FAB205B.8000804@gmail.com> Message-ID: On Fri, May 11, 2012 at 10:21 AM, Adrian Hunt wrote: > lol, Cheers Chris. > > Just so you know, I care about what and how I write... I almost always run > my emails though a word-processor before sending. And, that has paid off for > me: thanks to MS Word, MS Works and Open Office, I have better understanding > of "correct" punctuation use (if not spelling and grammar) than most school > leavers!!! Absolutely. Taking care puts you miles ahead of the average (unfortunately for the average). I was home educated, and taught to value correctness, so I tend to speak and write more carefully than most do (people say I sound British for some reason - my accent doesn't sound Australian). That's why I tend to do a lot (note, not "alot", though the cute drawings are fun) of copyediting. > PS. It hasn't gone a miss that you are one of the core python-list > responders (and I bet this goes for most of the python-list users): your > responses, time and knowledge is appreciated... Thank you. Thanks! I'm just a guy who types fast, mainly; but I've been coding for about twenty years, and I'm always happy to help people. But this list is more for me to learn than for me to share. I've learned no end of things from these threads - it's awesome! ChrisA From cyborgv2 at hotmail.com Thu May 10 21:05:05 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Fri, 11 May 2012 02:05:05 +0100 Subject: Creating a Windows installer for Python + a set of dependencies In-Reply-To: References: Message-ID: Hi there, I've use NSIS for quite a few projects... NSIS will do it with ease. You write a script that gets "compiled" into a install exe and the scripting language is not too hard to learn. You can do it in several different ways: 1. You can include the Python installer as a file compressed into your installer (that is decompressed to a temp directory before being run.) 2. The Python installer could be a included along side you installer and run as needed 3. You can specify a URL to the Python install to be downloaded and installed (again using a temp directory.) You can even use a mix... If an internet connection is available download it, if not fall back to one of the other methods. If you can come up with yet another method, it wouldn't be simple to write a script to handle it. If you really need to you can write a dynamic link library that the final NSIS installer will make calls to. If you need any more help on this subject, email me directly... Although I try to keep an eye on python-list, I can't guarantee a quick reply. > Date: Thu, 10 May 2012 16:26:25 +0200 > Subject: Creating a Windows installer for Python + a set of dependencies > From: g.rodola at gmail.com > To: python-list at python.org > > Hi all, > I need to create an installer for Windows which should be able to > install a specific version of the Python interpreter (2.7) plus a set > a dependencies such as ipython, numpy, pandas, etc. > Basically this is the same thing Active State did for their Active > Python distribution: a single bundle including interpreter + deps. > Not being a Windows user I'm not sure where to start with this except > maybe looking into NSIS (could that be of any help?). > > Thanks in advance, > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From suziemrezitti at gmail.com Thu May 10 21:45:08 2012 From: suziemrezitti at gmail.com (Suzi Mrezutttii) Date: Thu, 10 May 2012 18:45:08 -0700 (PDT) Subject: Google the video "9/11 Missing Links". Jews murdered 3000 Americans in 9/11. Message-ID: COPY THIS MESSAGE FAST BECAUSE JEWS AND TRAITORS DELETE IT FAST! JEWS MURDERED 3000 AMERICANS IN 9/11. After Jews created Israel illegally, Israel became the main base of criminal operations for the most insane type of Jews called Zionists. Israeli Jews murdered JFK in 1963 because JFK did not allow them to have atomic bombs. Read the book "Final Judgment" by Michael Piper, available online in pdf, also google for video presentation by author. Israeli Jews murdered 34 servicemen of American Navy, and seriously wounded 174, when Jews tried repeatedly to sink the USS Liberty in 1967 and blame Egypt for it. Watch online the video interviews with the actual survivors, then compare the facts to the lies spread by Jews through their propaganda outlets like wikipedia. One interview with a survivor should have been enough to turn all responsible Jews and American Traitors into fertilizer within 24 hours. Since Americans failed to listen to the USS Liberty survivors, Israeli Jews murdered 3000 Americans in 9/11, this time to make USA invade Afghanistan/Iraq for Jews, and to enable Jews to impose their Jew Laws (Jaws) like "Patriot Act". Watch online the video "9/11 Missing Links" made in cooperation with contacts inside FBI, CIA, National Security Agency, US Military, who are still loyal to USA. All Jews covered up for Israeli Zionists, with help from White Traitors in Washington DC, because all Jews always protect themselves as single Jew Tribe. Jews are not the sweet/smart/suffering individuals as they present themselves using their own Jew propaganda machines. Jews are full of hate and suffer from a whole range of genetic mental diseases like schizophrenia, paranoia, and others that make them prone to criminal/ parasitic/corruptive behavior. Banking Jews started their corruption of USA in 1913 with creation of the Fed. The Great Depression of 1930's was the direct result of Jew corruption. Jews used Great Depression as an opportunity to corrupt/ expand the federal government because parasites like Jews exploit host organisms through central systems. After Hitler came to power in 1933 and removed Jews from all important positions, Germany experienced unprecedented economic growth while the rest of the world controlled by Jews suffered through Great Depression. Jews did not like this precedent and immediately in 1933 Jews declared economic war on Germany. Hitler invaded Poland only because Poland was infested with five million Jews who constantly were harassing Germany. Jews used their media power to brainwash White Americans to fight White Germans for Jews. All the official "history" has been written by lying Jews and it should be called Jewstory instead of History. Jews are not Whites but insane mongrels who hate Whites. Jews started all the jokes about Whites like Dumb Blondes, Rednecks, Polish Jokes. The sheeple merely parroted after the Jew media. Jews are the ones who promote all those Blacks you see in the media, sports, schools, or business. Jews constantly stir up conflicts between Whites and Blacks by propagandizing the shootings of Blacks in order to take your attention away from all Jew scams. Since 9/11 Jews intensified their "Racism" tactics and their famous "Holocaust" tactics because more Americans learn every day that Jews did 9/11. Jews know they are the biggest criminals on Earth, and that is why Jews manufactured the "Holocaust" Scam where Jews masquerade as the biggest victims on Earth. Jews are Masters of biggest Lies and Deceptions. Without their control of brainwashing media, Jews are nothing more than insane rats. Only Jew scams enabled many Jews to masquerade with Ivy League diplomas, Nobel Prizes, Oscars. Jews run their college/ Awards scams like Wall Street or elections scams. Independent investigations of all Ivy League colleges would show that most Jew students are frauds with standardized tests taken by somebody else or their test results falsified by corrupt admissions offices. The biggest Jew Nobel Prize winner Einstein was a fraud and plagiarist. All you know about famous Jew "scientists" is what Jews told you, the same Jews who made you believe the "Manned Moon Landings" or "Man-Made Global Warming". Jews never invented anything but Scams and Hoaxes. Jews in Israel rank well below average in IQ scores among all nations. Basically, Israel is a hellhole where tens of billions of dollars of American taxpayers' money are wasted on worthless Jews each year. Jews control the US Government illegally. The American democracy is a myth. Most of "US Presidents" since 1913 were Jews (FDR, Eisenhower, LBJ, Obama with Jew mother) or Jew puppets. Recently, Jews in US Congress imposed on Americans yet another Jew Law (Jaw) called "National Defense Authorization Act" that threatens any American who tries to defend The US Constitution. However, the ultimate power lies in the economies, now all mortally wounded by Jews. Jews were too greedy by exporting all real American jobs and forcing Americans to live on debt for too long. Once enough good White Americans reach poverty levels, the game will be over for Jews, especially if their psychotic relatives in Israel pull another USS Liberty or 9/11. Eventually, Jews will have to take head on the real American laws like The Second Amendment of The US Constitution. From rosuav at gmail.com Thu May 10 22:48:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 12:48:26 +1000 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 5:07 AM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our > application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in > the > standalone interpreter. Greetings! The standalone interpreter - I assume you mean the interactive prompt? It has slightly different handling of things (for instance, naked expressions being written to standard output) from the more "usual" invocation of the interpreter. For your embedded Python, probably the easiest thing to do is to not try to use interactive mode, but script mode: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals) Pass it a string of Python code and a dictionary to use for globals and locals (they can be the same dict). Then when that finishes, retrieve from that dictionary some predetermined name (eg "Output"). The Python code then needs simply to assign to Output and all will work. Another way to do it is to call a function inside the Python code, and retrieve its return value. > We are using python 2.7. > > Any suggestions? Unless you have particular need to stick to the 2.x branch, I would suggest moving to 3.3; many things are easier (especially Unicode). But both work. > Also, I'm new to mailling lists, what is the proper way to reply to someone? > Should I > reply directly to someone's email adress or is there a way to answer trough > the server. The usual convention is to reply on-list, unless it's particularly private. Many mail clients will handle this conveniently; otherwise, just manually replace the To address with the list address. As long as you use reply (rather than starting a fresh email), all posts will be correctly threaded both on the list and on the synchronized newsgroup (comp.lang.python). Chris Angelico From me at marmida.com Fri May 11 00:35:44 2012 From: me at marmida.com (Michael Rene Armida) Date: Thu, 10 May 2012 21:35:44 -0700 Subject: Finding the line number of an 'else' statement via ast Message-ID: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the "else:" line, using the ast module? The grammar only includes the 'orelse' list: If(expr test, stmt* body, stmt* orelse) ...but 'orelse' is the list of statements under the 'else' token, not a node representing the token itself. I have a suspicion that this isn't possible, and shouldn't be, and the giveaway word above was "token." Because the tokens themselves aren't part of the abstract syntax tree. Here's an interactive session showing me poking around the If node: >>> import ast >>> tree = ast.parse(''' ... if True: ... pass ... else: ... pass ... ''') >>> tree.body[0].orelse [<_ast.Pass object at 0x7f1301319390>] >>> tree.body[0]._fields ('test', 'body', 'orelse') >>> for i in ast.iter_child_nodes(tree.body[0]): ... print i.__class__.__name__ ... Name Pass Pass Is my suspicion correct? Or is there a way to get the line number of that 'else:'? From stefan_ml at behnel.de Fri May 11 00:45:21 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 11 May 2012 06:45:21 +0200 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: F L, 08.05.2012 21:07: > We are trying to implement our own interactive interpreter in our > applicationusing an embedded Python interpreter. I was wondering what > would be the best way to retreive as text the result of executing > Python code. The text must be exactly the same as it would be in > thestandalone interpreter. We used to do this by changing the embedded > interpreter's sys.stdout and sys.stderrwith a FILE created in C++. We > could then execute code using the PyRun_InteractiveOnefunction and > easily retrieve the result from the FILE. The problem is, our > applicationshouldn't create any files if possible. We also tried > replacing sys.stdout and sys.stderr with a custom made Python > objectwhich could be more easily read from C++. We then used the > function PyRun_Stringto execute the code. The problem here is that using > the Py_file_input start tokendoesn't write everything we need to > sys.stdout. (i.e. executing 2+2 does not write 4).It also doesn't print > a traceback to sys.stderr when there is an exception. Using theother two > start tokens is impossible since we need to be able to execute more than > one instruction at once. We also tried using the function > PyRun_SimpleString but weencounter the same problems. As was already suggested, the PyRun_*() functions are a better choice for executing code from C code, but they will not automatically divert sys.stdout and sys.stderr for you, which are global settings of the interpreter, not local to an execution. So you will get the result of the evaluation back, but not any output that may have been printed during the execution. You have to change those yourself, as you apparently already did. However, have you tried using a pipe for them instead of a real file? That would allow you to retrieve the output without needing to pass through a file in the file system. You can also replace sys.stdout/err with arbitrary objects in Python space, which could then forward the output in any way you want. But, if you control the code that is being executed, it would really be best to *not* print anything out directly, but to use the logging module for output, where you can control much better what exactly gets propagated and to what target. And when the code fails and raises an exception, you can get at the stack trace (that the normal interpreter would just print out) using the traceback module. > Also, I'm new to mailling lists, what is the proper way to reply to > someone? Should Ireply directly to someone's email adress or is there a > way to answer trough the server. A couple of more hints in addition to what Chris Angelico said: reply below the text your are responding to (i.e. not above the text) or split it into sections and reply inline (as I did). Cut down the original text to what is needed for readers to understand the context of your answer. Write plain text mails instead of HTML mails. Your problem description was very good, BTW. It included the perfect amount of information about what you tried and what didn't work for you about it. Stefan From john.terrak at gmail.com Fri May 11 01:55:57 2012 From: john.terrak at gmail.com (John Terrak) Date: Thu, 10 May 2012 22:55:57 -0700 Subject: Newbie naive question ... int() throws ValueError Message-ID: Hi Sorry for such a naive question. I couldnt find anywhere in the documentation that int() can throw a ValueError. I checked the "The Python Language Reference", and the "The Python Standard Library " to no avail. Did I missed something? So here is the question - if it is not in the documentation - how does one find out the exceptions that are thrown by a constructor, a method or a function? Example:? int("not_an_int") >>> int("not_an_int") Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'not_an_int' >From what I gathered: class int(object): ? """ int(x[, base]) -> integer ? Convert a string or number to an integer, if possible.? A floating point ? argument will be truncated towards zero (this does not include a string ? representation of a floating point number!)? When converting a string, use ? the optional base.? It is an error to supply a base when converting a ? non-string.? If base is zero, the proper base is guessed based on the ? string content.? If the argument is outside the integer range a ? long object will be returned instead. """ Thanks for your help - and sorry again for such a naive question. John T. From maha.jabeen92 at gmail.com Fri May 11 02:04:17 2012 From: maha.jabeen92 at gmail.com (Maha Jabeen) Date: Thu, 10 May 2012 23:04:17 -0700 (PDT) Subject: "pakistani girls" "pakistani girls lahore" "pakistani girls phone numbers" "pakistani girls mobile number" "pakistani girls wallpapers" "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com References: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> <11301667.0.1332592235130.JavaMail.geo-discussion-forums@vbtw24> Message-ID: fuck you dude http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ From rosuav at gmail.com Fri May 11 02:10:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 May 2012 16:10:41 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 3:55 PM, John Terrak wrote: > I couldnt find anywhere in the documentation that int() can throw a ValueError. > I checked the "The Python Language Reference", and the "The Python > Standard Library " to no avail. > Did I missed something? Unlike in Java, a function's list of things it can throw isn't part of its signature. Instead of trying to catch every possible exception, it's generally best to simply let exceptions propagate unless you KNOW you're expecting them. In the case of int(), that would mean that you catch ValueError if you're taking arbitrary strings from the user and want integers (and then you could handle the ValueError by using a default, for instance); but if you're writing a function that's documented as taking a number as a parameter, let the exception go up to the caller. If it helps, think of all Python's exceptions as deriving from RuntimeException - anything can happen, worry only about what really worries you :) > Thanks for your help - and sorry again for such a naive question. It's a perfectly legitimate question, and you clearly did read the docs before asking. Nothing to apologize for there! Chris Angelico From maha.jabeen92 at gmail.com Fri May 11 02:13:34 2012 From: maha.jabeen92 at gmail.com (Maha Jabeen) Date: Thu, 10 May 2012 23:13:34 -0700 (PDT) Subject: Pakistani Girls Mopbile Number For Friendship Message-ID: <5f80460b-67f1-4417-b36a-9e53a6af8c35@nl1g2000pbc.googlegroups.com> http://numbersofgirlsinpakistan.blogspot.com/ visit http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ http://numbersofgirlsinpakistan.blogspot.com/ pakistani girl 0.14 550000 18100 pakistani girl names 0.17 18100 1300 pakistani girls 0.15 673000 22200 pakistani girls names 0.17 18100 1300 beautiful pakistani girls 0.23 14800 390 pakistani girl photo 0.28 40500 720 pakistani girls pictures 0.21 74000 1300 pakistani girls photos 0.21 49500 1000 pakistani girls for marriage 0.84 5400 260 pakistani girls pic 0.21 22200 390 pakistani girls phone numbers 0.74 3600 170 pakistani girls photo 0.29 40500 720 pakistani girls mobile numbers 0.61 74000 260 pakistani girls images 0.29 33100 590 pakistani girl number 0.61 74000 480 pakistani girls picture 0.27 40500 720 pakistani girl name 0.16 18100 1000 pakistani girls dating 0.71 1000 91 pakistani girl pictures 0.22 60500 1300 pakistani girl pic 0.22 18100 320 pakistani girls in usa 0.69 480 110 pakistani girls chat 0.61 5400 140 pakistani girl picture 0.29 40500 590 pakistani girls in usa for marriage 0.92 210 73 pakistani girl pics 0.17 40500 720 beautiful girl 0.07 1830000 301000 pretty pakistani girls 0.05 720 73 pakistani girl images 0.29 33100 590 pakistani girl wallpaper 0.3 8100 73 pakistani girl video 0.06 27100 720 pakistani girls numbers 0.6 90500 480 pakistani girl photos 0.22 49500 880 pakistani girls marriage 0.84 5400 260 pakistani girls phone number 0.74 3600 170 pakistani names for girls 0.17 18100 1300 pakistani girls feet 0.04 1300 58 pakistani girls number 0.6 90500 480 pakistani hot girl 0.12 27100 1000 pakistani girls scandals 0.04 3600 91 pakistani girls mobile number 0.62 74000 260 pakistani girls pics 0.16 40500 880 pakistani girls numbers for friendship 0.54 3600 46 dating pakistani girls 0.71 1000 91 hot pakistani girl 0.12 27100 1000 pics of pakistani girls 0.16 40500 880 meet pakistani girls 0.84 170 16 chat with pakistani girls 0.61 5400 140 indian pakistani girls 0.07 14800 880 pakistani girls friendship 0.76 8100 110 hot pakistani girls pics 0.21 3600 73 pictures of pakistani girls 0.21 74000 1300 cute pakistani girl 0.09 6600 210 pakistani girls name 0.16 18100 1000 pakistani girls videos 0.06 40500 880 pakistani girls video 0.06 27100 720 pakistani girl for marriage 0.83 5400 260 pakistani punjabi girls 0.14 880 36 pakistani dance 0.06 40500 1600 pakistani girls wallpapers 0.3 8100 73 young pakistani girls 0.06 4400 210 cute pakistani girls 0.11 6600 210 pakistani girl scandal 0.03 5400 140 pretty pakistani girl 0.05 720 73 pakistani girls online 0.58 2400 58 pakistani girls mms 0.04 2400 91 pakistani beautiful girls 0.23 14800 390 pakistani baby girl names 0.22 1000 73 pakistani girl mobile number 0.63 74000 210 pakistani girls dance 0.05 4400 140 pakistani girl feet 0.04 590 36 pakistani girls kissing 0.06 5400 140 hot pakistani girls photos 0.25 4400 91 pakistani girl phone number 0.76 3600 170 pakistani girls clothes 0.8 2900 140 beautiful girls 0.08 2240000 368000 japanese girls 0.09 1500000 246000 pia 0.06 6120000 823000 desi 0.04 13600000 1220000 russian girls 0.41 673000 110000 pretty girls 0.06 1000000 450000 pakistani girls photo album 0.46 390 0 pakistani girls scandal 0.04 4400 140 hot girl 0.06 6120000 1830000 pakistani food 0.14 49500 12100 chinese girls 0.2 450000 110000 pakistani girl chat 0.76 4400 110 pakistani clothes 0.82 165000 22200 ptv 0.12 1500000 90500 pak 0.18 9140000 1500000 urdu news 0.04 1000000 40500 pakistani news 0.04 550000 90500 pakistani girl kissing 0.06 4400 140 desibaba 0.04 246000 6600 pakistani girls kiss 0.07 2400 58 thai girls 0.19 450000 60500 pakistani girls gallery 0.18 1900 46 desibaba.com 0.04 49500 880 pakistani girls dress design 0.72 320 0 desi girls 0.06 550000 27100 russian girl 0.38 673000 110000 pakistani dresses 0.84 165000 22200 pakistani women 0.23 90500 9900 desi girl 0.06 550000 27100 hotgirl 0.04 1830000 368000 desi baba 0.04 301000 6600 pakistani fashion 0.58 74000 6600 pakistani culture 0.07 14800 3600 arab girls 0.08 550000 49500 girl baby names 0.27 1220000 450000 baby girl names 0.27 1220000 450000 nice girls 0.08 550000 74000 russian brides 0.82 201000 74000 pakistani songs 0.09 450000 9900 photos of pakistani girls 0.21 49500 1000 pakistani music 0.11 301000 8100 pakistani girls for friendship 0.76 8100 110 geo news urdu 0.06 165000 2900 beautiful pakistani girls pictures 0.36 4400 58 british pakistani girls 0.06 1600 46 pakistani college girls 0.12 14800 320 pakistani girl hot 0.12 27100 1000 baby names girl 0.27 1220000 450000 bad girl 0.03 1830000 368000 pakistani movies 0.1 450000 14800 pakistani models 0.05 74000 4400 muslim girls 0.17 368000 27100 baby names meaning 0.19 450000 201000 female baby names 0.22 368000 135000 beautiful pakistani girl 0.22 14800 390 pakistani girls cell numbers 0.54 18100 140 pakistani tv 0.13 201000 18100 pakistani chat 0.41 74000 2900 muslim girl 0.15 368000 33100 pakistani mujra 0.1 135000 3600 pakistani girls hot 0.13 40500 1300 male baby names 0.22 246000 110000 hottest pakistani girls 0.04 480 22 pakistani girls blog 0.2 880 36 pakistani girl raped 0.03 1600 73 punjabi girls 0.13 135000 6600 desigirl 0.05 201000 9900 hot pakistani girl photo 0.22 1900 46 russian ladies 0.71 301000 90500 pakistani dress 0.79 165000 18100 pakistani beauty girls 0.16 1600 58 baby name list 0.27 33100 8100 pakistani song 0.08 450000 9900 pakistannews 0.13 3600 720 pakistani tv channels 0.34 49500 2900 ptv home 0.07 165000 1600 pixpux 0.04 27100 390 pakistani girls mobile no 0.55 74000 170 online girls 0.31 2740000 550000 pakistani brides 0.64 49500 5400 baby names with meaning 0.19 450000 201000 youtube pakistani 0.05 110000 4400 bangladeshi girls 0.2 135000 6600 pakista 0.07 33100 1900 pakistani girl dance 0.04 4400 110 girl baby name 0.25 823000 246000 pakistani clothes for girls 0.8 2900 140 pakistani girls image 0.35 8100 110 pakistani girls wallpaper 0.31 8100 73 pakistani girls mobile numbers 2011 0.51 1900 5 pakistani school girls 0.16 9900 260 pakistani girl image 0.19 6600 110 pakistani girl kiss 0.06 1900 58 youtube pakistani girls 0.09 2900 58 pakistani girls mobile number list 0.54 880 0 indiangirl 0.05 550000 60500 bangladeshi girl 0.2 135000 6600 pakistani baby names 0.21 3600 390 popular pakistani girl names 0.08 91 28 beautiful pakistani women 0.15 3600 320 pakistani chat rooms 0.51 33100 880 afghani girl 0.13 18100 1900 beautiful pakistani girls pics 0.32 2400 36 pakstan 0.11 18100 720 pakistani woman 0.18 60500 8100 meaning of girl names 0.13 201000 60500 pakistani boy names 0.15 4400 480 hot pakistani girls pictures photos 0.25 3600 91 single pakistani girls 0.91 140 16 pakistani cute girls 0.11 6600 210 pakistani girls exbii 0.01 880 28 pakestan 0.08 6600 590 baby name girl 0.25 823000 246000 images of pakistani girls 0.29 33100 590 pakistani names for boys 0.15 4400 590 desi pakistani girls 0.13 6600 170 names of baby girls 0.27 1220000 450000 beautifull pakistani girls 0.26 720 12 parkistan 0.09 3600 390 name for baby girl 0.25 823000 246000 pakisan 0.08 8100 590 pakistani desi girls 0.13 6600 170 baby boy names with meaning 0.28 49500 14800 pakistn 0.11 9900 480 pakitan 0.08 12100 720 pakistani girls hot photos 0.25 4400 91 girl names with meaning 0.13 201000 60500 pakistansong 0.11 5400 73 baby girl names list 0.44 9900 2400 babies names meaning 0.22 27100 4400 pakistani beautiful girl 0.22 14800 390 pakistani girls college 0.12 14800 320 youtubepakistan 0.03 2400 110 pakistani girls in bikini 0.1 1000 36 pakistani dating girls 0.71 1000 91 baby girl names meanings 0.26 60500 14800 islamic female names 0.15 110000 4400 pakistani girls club 0.06 880 36 cute pakistani girls pics 0.12 1000 16 girls mobile numbers 0.58 450000 3600 pakist 0.07 18100 1600 girls name list 0.2 49500 14800 pakistantv 0.17 1300 91 pakistani school girl 0.14 12100 320 girls name meaning 0.14 110000 33100 pakistanigirls 0.44 3600 110 pakistani single girls 0.91 140 16 name with meaning 0.09 6120000 2240000 pakistani mujra girls 0.04 1600 46 popular pakistani boy names 0.04 73 22 pakistani girls in america 0.22 140 22 pakistani beautiful girls wallpaper 0.33 880 0 pakistanimujra 0.15 22200 480 xnxxpakistan 0.27 1600 73 baby names female 0.22 368000 135000 pakistani girls mobile numbers for friendship 0.56 3600 12 girls names with meaning 0.14 201000 74000 pakistani girls dancing 0.04 3600 110 www.pakistani girl 0.32 6600 110 young pakistani girl 0.05 3600 170 pak girls 0.16 33100 880 hot girl youtube 0.02 18100 3600 pakistani desi girl 0.15 5400 140 pakistani boys names 0.15 4400 590 unique pakistani baby names 0.16 22 0 list of baby names girls 0.44 9900 2400 pakistani dresses for girls 0.77 3600 170 mobile numbers of pakistani girls 0.61 74000 260 boys names with meaning 0.16 135000 49500 baby name with meaning 0.16 301000 135000 baby name girls 0.25 823000 246000 girl babies names 0.33 40500 9900 names for a girl baby 0.27 1220000 450000 name of baby girl 0.25 823000 246000 girl pakistani 0.14 550000 18100 pak girl 0.12 27100 880 girls names and meaning 0.14 201000 74000 pakistani girls hot pics 0.21 3600 73 pakistani male names 0.12 2900 320 pakistani baby boy names 0.33 480 58 pakistane 0.15 40500 1000 name of meaning 0.09 6120000 2240000 baby name for girl 0.25 823000 246000 pakistani google 0.14 4400 320 gorgeous pakistani girls 0.09 110 12 pakistanigirl 0.41 2400 91 female baby names list 0.4 4400 1300 names of girl 0.13 5000000 1830000 pakistani sax 0.23 3600 58 names of baby girl 0.27 1220000 450000 pakistani women culture 0.3 320 170 pakistani cute girl 0.09 6600 210 pakistani muslim girls 0.16 18100 1000 female baby name 0.11 165000 49500 female pakistani names 0.16 18100 1000 pakistangirl 0.27 1600 46 names for girl babies 0.33 40500 9900 baby names & meaning 0.19 450000 201000 pakistani collage girls 0.14 1600 28 pakistani beautiful girls pictures 0.36 4400 58 pakistangirls 0.12 27100 880 list baby girl names 0.44 9900 2400 name girl baby 0.25 823000 246000 girls name and meaning 0.14 110000 33100 girls name with meaning 0.14 110000 33100 pakistani beauty girl 0.21 1000 28 name of baby girls 0.25 823000 246000 girl baby names with a 0.27 1220000 450000 pakistani grils 0.25 5400 140 pakistani hairstyles for girls 0.14 1300 28 pakistani dress for girls 0.73 4400 140 pakistani sweet girls 0.08 720 12 pakistani kissing 0.04 12100 320 pakistani ladies 0.59 8100 320 desi pakistani 0.34 49500 5400 hot pakistani guy 0.05 320 73 pakistani boys name 0.15 2900 260 pakistani pretty girls 0.05 720 73 pakistani names and meanings 0.18 1900 140 pakistani muslim girl names 0.17 14800 880 pakistani local girls 0.49 2400 36 girl baby name list 0.36 6600 1000 you tube pakistani 0.05 74000 2900 pakistani indian girls 0.07 14800 880 pakistani girl wallpapers 0.3 8100 58 www.pakistani girls 0.44 8100 140 attractive girls names 0.05 590 320 pakistani saxy girls 0.55 590 0 pakistani girl friendship 0.77 5400 91 female baby names meanings 0.19 18100 5400 name of girls baby 0.25 823000 246000 meaning of names baby 0.19 450000 201000 baby names girl a 0.27 1220000 450000 pakgirl 0.13 1000 28 pakistani dancing 0.04 18100 720 beautiful for women 0.16 1220000 450000 pakistani desi 0.34 49500 5400 list of female baby names 0.4 4400 1300 list of male baby names 0.38 2900 1000 girl name with meaning 0.12 110000 33100 baby girls name list 0.36 5400 1000 girl name and meaning 0.12 110000 33100 list of names for baby girls 0.44 9900 2400 islam girl names 0.1 135000 6600 names for girl baby 0.27 1220000 450000 boy baby names with meaning 0.28 49500 14800 girl pakistani names 0.17 18100 1300 boy baby names and meaning 0.28 49500 14800 new girls name 0.23 18100 1900 girls pakistani 0.15 673000 22200 wallpapers pakistani girls 0.3 8100 73 pakistani beautiful womens 0.34 170 0 pakistani hair styles for girls 0.15 880 16 pakistani shalwar kameez for girls 0.58 880 28 girl name baby 0.25 823000 246000 male baby names meanings 0.29 18100 6600 muslim pakistani names 0.16 18100 1000 www.pakistani girls mobile numbers 0.7 1300 0 baby boy name with meaning 0.2 27100 5400 girl meaning names 0.13 201000 60500 list of baby girls name 0.36 5400 1000 baby names from a 0.22 6120000 2740000 wallpaper pakistani girl 0.3 8100 73 email address of pakistani girls 0.61 590 0 pakistani girl slutload 0.01 880 16 baby names for boys with meaning 0.31 49500 12100 pixpux pakistani girls 0.2 320 0 names girl baby 0.27 1220000 450000 list of baby girl name 0.36 6600 1000 meaning of pakistani names 0.16 2400 140 pakistani girls mobile numbers list 0.58 880 0 islamic girl baby names 0.18 27100 2400 beautiful pakistani woman 0.17 2900 260 cell numbers of pakistani girls 0.54 18100 140 name for girl baby 0.25 823000 246000 girl baby name s 0.06 18100 6600 local pakistani girls 0.49 2400 36 desi pakistani girl 0.15 5400 140 baby names boy meaning 0.28 49500 14800 boy name with meaning 0.12 74000 22200 pakistani boy name 0.15 2900 260 new pakistani names 0.31 390 28 pakistani girls for dating 0.71 1000 91 hot pakistani video 0.11 12100 260 pakistani boy baby names 0.33 480 58 women pakistani 0.23 90500 9900 name of the meaning 0.09 6120000 2240000 phone numbers of pakistani girls 0.74 3600 170 names of girl babies 0.33 40500 9900 cool pakistani girls 0.19 320 0 names for female babies 0.3 9900 2400 images pakistani girls 0.29 33100 590 pakistani baby names for boys 0.34 480 58 youtube girl hot 0.02 18100 3600 pakistani girls online chat 0.88 590 5 baby girls name meaning 0.22 33100 8100 wallpapers of pakistani girls 0.3 8100 73 search for girl 0.24 110000 40500 name of the baby girl 0.25 823000 246000 free chat with pakistani girls 0.81 480 12 free chat pakistani girls 0.81 480 12 meet pakistani girls online 0.97 36 0 name & meaning 0.09 6120000 2240000 new pakistani girls 0.29 1900 73 pakistani girls beautiful 0.23 14800 390 wallpaper of pakistani girl 0.3 8100 73 cute pakistani girls images 0.16 590 12 wallpaper pakistani girls 0.31 8100 73 pakistani girls dress 0.73 4400 140 numbers of pakistani girls 0.6 90500 480 beautiful pakistani girls images 0.39 1900 28 teenage pakistani girls 0.12 1000 36 online pakistani girls 0.58 2400 58 pakistani school girls pictures 0.24 880 16 smart pakistani girls 0.14 210 0 simple pakistani girl 0.15 590 0 you tube girls dance 0.01 90500 1600 pakistani girls fashion 0.52 1300 16 pakistani school girls photos 0.25 880 12 pakistani girls in bra 0.09 1000 16 google pakistani girls 0.3 170 0 desi pakistani girls pictures 0.16 1000 16 pakistani girl in bra 0.07 880 16 pakistani saxy girl 0.46 590 0 pakistani chat girls 0.61 5400 140 beautiful pakistani girls photo 0.4 2400 36 mobile no of pakistani girls 0.55 74000 170 pakistani girls wallpapers hot 0.18 480 0 phone number of pakistani girls 0.74 3600 170 pakistani girls in hijab 0.07 480 16 pakistani girls chatting 0.74 880 16 pakistani girls photo gallery 0.27 1000 22 pakistani girls chat rooms 0.69 1600 0 pakistani girle 0.27 1000 22 pakistani girl pitcher 0.57 480 0 pakistani girl marriage 0.83 5400 260 pakistani girls email address 0.61 590 0 pakistani s girl 0.05 720 58 british pakistani girl 0.05 1600 46 picture of pakistani girls 0.27 40500 720 mobile phone numbers of pakistani girls 0.8 590 16 pakistani girls on date 0.54 480 36 pakistani girl in bikini 0.08 880 28 pakistani desi girls picture 0.17 590 5 indian pakistani girl 0.06 12100 720 pakistani girls photos pictures 0.21 49500 880 pic of pakistani girls 0.21 22200 390 sweet pakistani girl 0.07 720 12 pakistani girl dating 0.91 880 91 pictures of beautiful pakistani girls 0.36 4400 58 pakistani girls cleavage 0.01 390 0 beautiful pakistani girls photos 0.34 2900 46 image of pakistani girls 0.35 8100 110 pakistani girl id 0.19 1300 22 pakistani girls mobile phone numbers 0.8 590 16 pakistanis girls 0.14 110000 4400 pakistani girls picture gallery 0.24 480 0 pakistani girles 0.28 880 12 muslim pakistani girls 0.16 18100 1000 wallpaper of pakistani girls 0.31 8100 73 pakistani date girls 0.54 480 36 pakistani girls hostel 0.06 720 12 free pakistani girls 0.14 6600 210 pakistani girls id 0.2 1600 28 cute pakistani girl pictures 0.12 1600 28 pakistani girls for sale 0.43 73 0 pakistani girls looking for marriage 0.93 140 12 beautiful pakistani girls wallpaper 0.33 880 0 pakistani girls picturs 0.27 390 0 pakistani girls on beach 0.09 390 12 beautiful pakistani girl photo 0.4 2400 36 pakistani girls breast 0.04 1000 22 pakistani girl s 0.05 720 58 indian and pakistani girls 0.07 14800 880 hot pakistani girls wallpapers 0.18 480 0 beautiful pakistani girls wallpapers 0.32 880 0 beutiful pakistani girls 0.2 320 0 pakistani girls eyes 0.04 140 16 photo pakistani girl 0.28 40500 720 dirty pakistani girls 0.05 480 28 pakistani girl friend 0.29 4400 170 pakistani girl school 0.14 12100 320 contact numbers of pakistani girls 0.74 4400 170 all pakistani girls 0.14 1000 22 pakistani girls friend ship 0.79 1600 28 pakistani girls bra 0.09 1000 16 image pakistani girls 0.35 8100 110 pakistani girls movies 0.07 18100 390 chat with pakistani girl 0.76 4400 110 pakistany girls 0.22 480 22 pakistani girl six 0.43 590 0 pakistani girls bikini 0.1 1000 36 pakistani girls dresses 0.77 3600 170 attractive pakistani girl 0.09 110 0 pakistani girls pitcher 0.56 480 0 pakistani girl cleavage 0 320 0 pakistani girls hot images 0.21 1600 46 local pakistani girl 0.52 1900 28 pakistani girl bra 0.07 880 16 pakistani girls clips 0.08 9900 170 dasi pakistani girl 0.14 260 0 beautiful pakistani girl wallpaper 0.34 720 0 pakistani girls hot pictures 0.25 5400 110 pakistani girls names in urdu 0.23 390 16 pakistani girls in saree 0.19 170 0 pakistani girls in school 0.16 9900 260 pakistani girl online 0.56 1900 46 beauty of pakistani girls 0.16 1600 58 pakistany girl 0.18 390 22 pakistani girls school 0.16 9900 260 best pakistani girls 0.14 1300 46 nice pakistani girls 0.26 3600 140 pakistani girls in salwar kameez 0.69 1000 36 pakistani girls phone no 0.7 2900 140 pakistani girl beautiful 0.22 14800 390 new pakistani girl 0.19 1600 91 pakistani girls mobile phone number 0.79 590 16 pakistani girls hot wallpapers 0.18 480 0 pakistani girls hot pic 0.18 1900 36 image of pakistani girl 0.19 6600 110 beautiful pakistani girls pic 0.42 1000 12 hot pakistani girl images 0.22 1300 36 pakistani girls vagina 0.03 170 0 pakistani girls in college 0.12 14800 320 pakistani girls six 0.48 590 0 cool pakistani girl 0.19 260 0 photo of pakistani girls 0.29 40500 720 pakistani girls without clothes 0.1 480 0 pakistani girls bathing 0.03 390 28 innocent pakistani girls 0.05 320 0 image pakistani girl 0.19 6600 110 pakistani girls models 0.07 720 22 pakistani girls breasts 0.03 2400 73 images of beautiful pakistani girls 0.39 1900 28 hot desi pakistani girls 0.06 590 12 wet pakistani girls 0.04 260 0 pakistani girls fight 0.03 390 0 pakistani girls model 0.06 880 22 hot pakistani girls images 0.21 1600 46 pakistani girl bikini 0.08 880 28 pakistani picture girls 0.27 40500 720 hot pakistani girls pictures 0.25 5400 110 chat pakistani girl 0.76 4400 110 pakistani girl model 0.06 720 22 pics of beautiful pakistani girls 0.32 2400 36 pakistani free girls 0.14 6600 210 pakistani girl dancing 0.03 3600 110 pakistani girls no 0.55 74000 390 hot pakistani girls pic 0.18 1900 36 pakistani girl hot image 0.3 260 0 pakistani girls hot photo 0.41 2400 58 hot pakistani girls photo 0.41 2400 58 pakistani girl breast 0.04 880 16 desi girls pakistani 0.13 6600 170 pakistani girls mobile numbers friendship 0.56 3600 12 cute pakistani girls pictures 0.12 1900 28 image girls pakistani 0.35 8100 110 real pakistani girls 0.1 1900 28 nangi pakistani girls 0.14 480 0 names of pakistani boys 0.15 4400 590 hot pics of pakistani girls 0.21 3600 73 pakistani girls chat room 0.69 1600 12 pakistani girls shalwar kameez 0.58 880 28 new pakistani boys names 0.36 91 0 hot pakistani girl image 0.3 260 0 pakistani girls scandle 0.04 720 0 pakistani girl in saree 0.15 140 0 pakistani girls beauty 0.16 1600 58 girls pictures pakistani 0.21 74000 1300 online chat with pakistani girls 0.88 590 5 unique pakistani names 0.12 110 16 chatting with pakistani girls 0.74 880 16 new pakistani baby names 0.38 91 5 youtube hot pakistani 0.04 2900 58 pakistani pictures girls 0.21 74000 1300 baby name & meaning 0.16 301000 135000 pakistani girls hot image 0.33 320 0 pakistani baby girls name 0.17 590 36 pakistani girl games 0.14 390 12 list of names of baby girl 0.44 9900 2400 name of the girl baby 0.25 823000 246000 most beautiful pakistani girl 0.12 720 12 sweet pakistani girls 0.08 720 12 pakistani girl sara 0.02 46 0 chat online with pakistani girls 0.88 590 5 chat pakistani girls 0.61 5400 140 pakistani girl chat room 0.67 1300 0 chat with pakistani girls online 0.88 590 5 friendship with pakistani girls 0.76 8100 110 most beautiful pakistani girls 0.15 720 16 online chat pakistani girls 0.88 590 5 online pakistani girls chat 0.88 590 5 mobile number of pakistani girls 0.62 74000 260 pakistani beautiful girls wallpapers 0.32 880 0 pakistani punjabi girl 0.12 880 46 pakistani wallpapers girls 0.3 8100 73 find pakistani girls 0.49 260 22 pakistani girls contact numbers 0.74 4400 170 pakistani girl numbers 0.61 74000 390 beautiful pakistani muslim girls 0.19 91 0 pakistani girls friendship mobile number 0.62 3600 12 pakistani girls on line 0.54 1300 16 pakistani hostel girls 0.06 720 12 hot pakistani college girls 0.08 720 16 pakistani girls cell numbers for friendship 0.63 2900 12 hot pakistani desi girls 0.06 590 12 chat rooms pakistani girls 0.69 1600 0 friendship pakistani girls 0.76 8100 110 pakistani girls cell number 0.55 18100 140 pakistani girl chatting 0.79 880 12 pakistani girls in home 0.05 1300 28 pakistani hot guy 0.05 320 73 pakistani simple girls 0.16 590 0 pakistani girls mobile 0.59 90500 260 pakistani collage girl 0.14 1600 28 pakistani girls in new york 0.43 36 16 pakistani cute girls pictures 0.12 1900 28 pakistani girls in jeans 0.24 260 0 date pakistani girls 0.54 480 36 friendship in pakistani girls 0.76 8100 110 pakistani schools girls 0.16 1600 58 pakistani girls mobile number for friendship 0.62 3600 12 pakistani girl photo album 0.49 390 0 pakistani girl for friendship 0.77 5400 91 pakistani girls email 0.48 880 12 pakistani girls to marry 0.28 320 36 pakistani local girls pictures 0.57 1000 12 pakistani good girls 0.1 260 16 pakistani college girls images 0.26 1000 16 pakistani friendship girls 0.76 8100 110 pakistani college girls hot 0.08 720 16 pakistani local girl 0.52 1900 28 pakistani model girls 0.06 880 22 hot pakistani school girls 0.1 480 12 pakistani wallpaper girls 0.31 8100 73 pakistani village girls 0.04 590 22 pakistani images girls 0.29 33100 590 pakistani sixy girl 0.4 260 0 pakistani desi girls pictures 0.16 1000 16 pakistani christian girls 0.54 170 12 pakistani muslim girl 0.16 18100 1000 pakistani sweet girl 0.07 720 12 pakistani simple girl 0.15 590 0 pakistani bikini girl 0.08 880 28 pakistani girl mobile numbers 0.63 74000 210 pakistani girl names with meaning 0.15 1000 28 pakistani beautiful girls images 0.39 1900 28 pakistani online girls 0.58 2400 58 pakistani girls for chat 0.61 5400 140 picture pakistani girls 0.27 40500 720 pakistani muslim girls names 0.16 14800 880 beautiful pictures of pakistani girls 0.36 4400 58 pakistani hot girl image 0.3 260 0 scandals of pakistani girls 0.04 3600 91 pakistani desi girls images 0.21 480 0 pakistani model girl 0.06 720 22 pakistani beautiful girls pics 0.32 2400 36 cute pakistani baby girls 0.07 260 0 pakistani dresses girls 0.77 3600 170 mobile number pakistani girls 0.62 74000 260 pakistani wedding girls 0.36 1300 28 pakistani college girls photos 0.23 1600 22 pakistani games for girls 0.14 1300 28 pakistani nice girl 0.24 3600 140 pakistani girls youtube 0.09 2900 58 pakistani beautiful girls pic 0.42 1000 12 pakistani marriage girls 0.84 5400 260 pakistani bad girl 0.09 590 28 pakistani university girls 0.09 1300 28 cell no of pakistani girls 0.56 14800 91 youtube pakistani girl 0.08 2400 58 pakistani smart girls 0.14 210 0 pakistani beautifull girls 0.26 720 12 pakistani boys and girls 0.03 3600 170 pakistani home girls 0.05 1300 28 pakistani girl email address 0.64 480 0 pakistani girls chat online 0.88 590 5 pakistani girls chating 0.88 210 0 pakistani girls mujra 0.04 1600 46 hot pakistani school girl 0.06 480 0 pakistani girl mobile no 0.56 60500 140 pakistani british girls 0.06 1600 46 pakistani beautiful girls photos 0.34 2900 46 pakistani smart girl 0.07 210 0 pakistani girls for chatting 0.74 880 16 pakistani hot girl photo 0.22 1900 46 pakistani student girls 0.1 320 0 hot pakistani college girl 0.06 720 16 beautiful pakistani girls picture 0.41 2400 36 chating with pakistani girls 0.88 210 0 pakistani girl cell number 0.55 9900 110 pakistani girls wedding pictures 0.28 170 0 pakistani models girls 0.07 720 22 pakistani beutiful girls 0.2 320 0 pakistani lahori girls 0.18 320 0 pakistani teenage girls 0.12 1000 36 pakistani muslim girls photo 0.35 210 12 pakistani girls in saudi 0.12 320 16 pakistani dancing girls 0.04 3600 110 pakistani colleges girls 0.27 390 0 pakistani beautiful girls picture 0.41 2400 36 pakistani beautiful girl wallpaper 0.34 720 0 pakistani college girls pictures 0.24 1900 28 number of pakistani girls 0.6 90500 480 pakistani nangi girls 0.14 480 0 pakistani private girls 0.23 880 12 pakistani girl photo gallery 0.32 880 16 pakistani college girls pics 0.2 1600 22 pakistani girl dress 0.75 2400 91 pakistani college girls photo 0.27 880 12 pakistani beautiful girls photo 0.4 2400 36 pakistani girls numbers mobile 0.61 74000 260 pakistani school girls kissing 0.06 170 0 cute pakistani college girls 0.06 140 0 From varma.nikhil22 at gmail.com Fri May 11 05:55:24 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Fri, 11 May 2012 15:25:24 +0530 Subject: increment date present list of tuple by weeks python Message-ID: Hi All I have a list like this :- [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] how can i increment date in the above list for the next months on weekly basis ? [ ('7 May monday AM Neuropancreatic'),('14May monday AM Neuropancreatic')('21 May monday AM Neuropancreatic')('28 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular'),('15 May monday AM Neuropancreatic'),('22 May monday AM Neuropancreatic'),('29 May monday AM Neuropancreatic')] Thanks -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri May 11 06:14:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 11:14:16 +0100 Subject: increment date present list of tuple by weeks python In-Reply-To: References: Message-ID: On 11/05/2012 10:55, Nikhil Verma wrote: > Hi All > > > I have a list like this :- > > [ ('7 May monday AM Neuropancreatic'), ('8 May tuesday PM Cardiovascular')] > > how can i increment date in the above list for the next months on weekly > basis ? > > [ ('7 May monday AM Neuropancreatic'),('14May monday AM > Neuropancreatic')('21 May monday AM Neuropancreatic')('28 May monday AM > Neuropancreatic'), > ('8 May tuesday PM Cardiovascular'),('15 May monday AM > Neuropancreatic'),('22 May monday AM Neuropancreatic'),('29 May monday AM > Neuropancreatic')] > > > Thanks > See http://docs.python.org/library/time.html#time.strptime and it's cousin strftime, and http://docs.python.org/library/datetime.html#module-datetime date and timedelta types. -- Cheers. Mark Lawrence. From sandeep0242 at gmail.com Fri May 11 06:38:28 2012 From: sandeep0242 at gmail.com (googlewellwisher) Date: Fri, 11 May 2012 03:38:28 -0700 (PDT) Subject: Clicking a sub menu item Message-ID: <76acd538-2825-4c1e-8cc0-c182193f4c14@l4g2000pbv.googlegroups.com> Hello, Im a newbie to automation testing.Im using python scripting in selenium to automate a website. Now im facing a difficulty in clicking a submenu item.I have 5 buttons in the main menu.I am able to click each of the menu button using self.driver.find_element_by_id("MainMenuButton1").click() But how can I click the MenuButton1_Submenu button? For this purpose I think I have to move hover the menu button and wait for some time, then click the submenus using their ids or whatever property.Is this the right way to click the sub menu items? If yes can abybody provide me the code for mouse hover a control? If this is not the right procedure please provide me with appropriate code to click on a sub menu item? From breamoreboy at yahoo.co.uk Fri May 11 06:43:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 11:43:55 +0100 Subject: Finding the line number of an 'else' statement via ast In-Reply-To: References: Message-ID: On 11/05/2012 05:35, Michael Rene Armida wrote: > Given this source: > > def do_something(val): > if val: > return 'a' > else: > return 'b' > > How do I get the line number of the "else:" line, using the ast > module? The grammar only includes the 'orelse' list: > > If(expr test, stmt* body, stmt* orelse) > > ...but 'orelse' is the list of statements under the 'else' token, not > a node representing the token itself. > > I have a suspicion that this isn't possible, and shouldn't be, and the > giveaway word above was "token." Because the tokens themselves aren't > part of the abstract syntax tree. > > Here's an interactive session showing me poking around the If node: > >>>> import ast >>>> tree = ast.parse(''' > ... if True: > ... pass > ... else: > ... pass > ... ''') >>>> tree.body[0].orelse > [<_ast.Pass object at 0x7f1301319390>] >>>> tree.body[0]._fields > ('test', 'body', 'orelse') >>>> for i in ast.iter_child_nodes(tree.body[0]): > ... print i.__class__.__name__ > ... > Name > Pass > Pass > > > Is my suspicion correct? Or is there a way to get the line number of > that 'else:'? Get the line number of the first pass and add one? -- Cheers. Mark Lawrence. From varma.nikhil22 at gmail.com Fri May 11 07:13:35 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Fri, 11 May 2012 16:43:35 +0530 Subject: How can we covert string into Datetime object Message-ID: Hi All I was going through this link http://docs.python.org/library/datetime.html#strftime-strptime-behavior. I practised strftime() and strptime() functions. Finally i stuck into a situation where i want to get the datetime object so that i can save it in my db. What i want is :- I have a string let say date_created = '11 May Friday PM ' and i want to convert it into datetime object like this datetime.datetime(2012, 5, 11, 4, 12, 44, 24734) Thanks in advance. Any help will be appreciated -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Fri May 11 07:16:48 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 13:16:48 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <20120511001535.GA8056@cskk.homeip.net> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> > This issue bit me once too often a few months ago, and now I have a class called > "O" from which I often subclass instead of from "object". > Its main purpose is a friendly __str__ method, though it also has a friendly __init__. > > Code: > > class O(object): > ''' A bare object subclass to allow storing arbitrary attributes. > It also has a nicer default str() action, and an aggressive repr(). > ''' > > def __init__(self, **kw): > ''' Initialise this O. > Fill in attributes from any keyword arguments if supplied. > This call can be omitted in subclasses if desired. > ''' > for k in kw: > setattr(self, k, kw[k]) > > def __str__(self): > return ( "<%s %s>" > % ( self.__class__.__name__, > ",".join([ "%s=%s" % (attr, getattr(self, attr)) > for attr in sorted(dir(self)) if attr[0].isalpha() > ]) > ) > ) This is a very interesting solution. I think it might be better suited (for my purpose) to __repr__ rather than __str__, mostly because I still lose control of the order the attributes appear. I really like the general idea of subclassing object though, because I often have classes with dozens of attributes and __init__ gets very messy. Chris' dynamically generated format string looks to be my best bet in the absence of a perfect solution. Cheers, Drea From python at mrabarnett.plus.com Fri May 11 07:51:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 May 2012 12:51:06 +0100 Subject: How can we covert string into Datetime object In-Reply-To: References: Message-ID: <4FACFD2A.8060607@mrabarnett.plus.com> On 11/05/2012 12:13, Nikhil Verma wrote: > Hi All > > I was going through this link > http://docs.python.org/library/datetime.html#strftime-strptime-behavior. > I practised strftime() and strptime() functions. > > Finally i stuck into a situation where i want to get the datetime > object so that i can save it in my db. > What i want is :- > > I have a string let say > date_created = '11 May Friday PM ' > > and i want to convert it into datetime object like this > datetime.datetime(2012, 5, 11, 4, 12, 44, 24734) > > Thanks in advance. Any help will be appreciated > As it says in the documentation: %d matches the day of the month %B matches the name of the month %A matches the day of the week %p matches AM/AM so: >>> datetime.datetime.strptime('11 May Friday PM', '%d %B %A %p') datetime.datetime(1900, 5, 11, 0, 0) (I've stripped off the trailing space.) Note that as you haven't supplied a year, the year defaults to 1900, and as you haven't supplied an hour but only "PM", the hour defaults to 0 (and there's no way to tell whether it was AM or PM). (The minutes and seconds also default to 0.) You can't convert something as vague as '11 May Friday PM' to a datetime object. If all of the times are just AM/PM you could try appending an hour (eg '12') before parsing and ignore it when you convert it back to a string for display. From d at davea.name Fri May 11 07:58:18 2012 From: d at davea.name (Dave Angel) Date: Fri, 11 May 2012 07:58:18 -0400 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FACFEDA.1040808@davea.name> On 05/11/2012 07:16 AM, Andreas Tawn wrote: >> >> This is a very interesting solution. >> >> I think it might be better suited (for my purpose) to __repr__ rather than __str__, mostly because I still lose control of the order the attributes appear. I have no idea why using __repr__ versus __str__ would make any difference in the order of the attributes. They're going to come out in the order you specify, regardless of what you name your method. If you don't like the arbitrary order you get from the dictionary, then either sort it, or provide an explicit list. -- DaveA From jaroslav.dobrek at gmail.com Fri May 11 08:04:10 2012 From: jaroslav.dobrek at gmail.com (Jaroslav Dobrek) Date: Fri, 11 May 2012 05:04:10 -0700 (PDT) Subject: parallel subprocess.getoutput Message-ID: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Hello, I wrote the following code for using egrep on many large files: MY_DIR = '/my/path/to/dir' FILES = os.listdir(MY_DIR) def grep(regex): i = 0 l = len(FILES) output = [] while i < l: command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + FILES[i] result = subprocess.getoutput(command) if result: output.append(result) i += 1 return output Yet, I don't think that the files are searched in parallel. Am I right? How can I search them in parallel? Jaroslav From jaroslav.dobrek at gmail.com Fri May 11 08:11:06 2012 From: jaroslav.dobrek at gmail.com (Jaroslav Dobrek) Date: Fri, 11 May 2012 05:11:06 -0700 (PDT) Subject: parallel subprocess.getoutput References: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Message-ID: <3cad8848-3a31-4570-9b17-c436c1e3ff4b@w10g2000vbc.googlegroups.com> Sorry, for code-historical reasons this was unnecessarily complicated. Should be: MY_DIR = '/my/path/to/dir' FILES = os.listdir(MY_DIR) def grep(regex): output = [] for f in FILES: command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + f result = subprocess.getoutput(command) if result: output.append(result) return output From askutt at gmail.com Fri May 11 08:39:00 2012 From: askutt at gmail.com (Adam Skutt) Date: Fri, 11 May 2012 05:39:00 -0700 (PDT) Subject: parallel subprocess.getoutput References: <918ab685-a670-4a3f-8948-2935e7322f0a@v24g2000vbx.googlegroups.com> Message-ID: On May 11, 8:04?am, Jaroslav Dobrek wrote: > Hello, > > I wrote the following code for using egrep on many large files: > > MY_DIR = '/my/path/to/dir' > FILES = os.listdir(MY_DIR) > > def grep(regex): > ? ? i = 0 > ? ? l = len(FILES) > ? ? output = [] > ? ? while i < l: > ? ? ? ? command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + > FILES[i] > ? ? ? ? result = subprocess.getoutput(command) > ? ? ? ? if result: > ? ? ? ? ? ? output.append(result) > ? ? ? ? i += 1 > ? ? return output > > Yet, I don't think that the files are searched in parallel. Am I > right? How can I search them in parallel? subprocess.getoutput() blocks until the command writes out all of its output, so no, they're not going to be run in parallel. You really shouldn't use it anyway, as it's very difficult to use it securely. Your code, as it stands, could be exploited if the user can supply the regex or the directory. There are plenty of tools to do parallel execution in a shell, such as: http://code.google.com/p/ppss/. I would use one of those tools first. Nevertheless, if you must do it in Python, then the most portable way to accomplish what you want is to: 0) Create a thread-safe queue object to hold the output. 1) Create each process using a subprocess.Popen object. Do this safely and securely, which means NOT passing shell=True in the constructor, passing stdin=False, and passing stderr=False unless you intend to capture error output. 2) Spawn a new thread for each process. That thread should block reading the Popen.stdout file object. Each time it reads some output, it should then write it to the queue. If you monitor stderr as well, you'll need to spawn two threads per subprocess. When EOF is reached, close the descriptor and call Popen.wait() to terminate the process (this is trickier with two threads and requires additional synchronization). 3) After spawning each process, monitor the queue in the first thread and capture all of the output. 4) Call the join() method on all of the threads to terminate them. The easiest way to do this is to have each thread write a special object (a sentinel) to the queue to indicate that it is done. If you don't mind platform specific code (and it doesn't look like you do), then you can use fcntl.fcntl to make each file-object non- blocking, and then use any of the various asynchronous I/O APIs to avoid the use of threads. You still need to clean up all of the file objects and processes when you are done, though. From darnold992000 at yahoo.com Fri May 11 09:29:22 2012 From: darnold992000 at yahoo.com (darnold) Date: Fri, 11 May 2012 06:29:22 -0700 (PDT) Subject: which book? References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> Message-ID: <1b8fe79d-60e2-4713-ba1a-7ad442b2e4a3@s9g2000vbg.googlegroups.com> On May 10, 4:58?am, d.po... at gmail.com wrote: > On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote: > > > I am going to learn python for some plot issues. which book or sources, do you recommend please? > > The tutorial is pretty good if you already know how to program. > > I also heard a lot of good things on "Python Essential Reference". > > Thanks. > Could you please pass the line for tutorial? i believe that would be the tutorial at http://docs.python.org/tutorial/ . From andreas.tawn at ubisoft.com Fri May 11 10:32:35 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 16:32:35 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <4FACFEDA.1040808@davea.name> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> > I have no idea why using __repr__ versus __str__ would make any difference in the > order of the attributes. They're going to come out in the order you specify, > regardless of what you name your method. If you don't like the arbitrary order you > get from the dictionary, then either sort it, or provide an explicit list. Only that, as the docs say, __repr__ should represent the entire object that could be used to build a new object with the same value. For that task the order of the attributes is immaterial. I want __str__ to give me something easily readable and ordered in a way that's conveys some meaning about the attributes. It's also helpful to not have to display every attribute, of which there may be dozens. From breamoreboy at yahoo.co.uk Fri May 11 10:40:46 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 11 May 2012 15:40:46 +0100 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On 11/05/2012 15:32, Andreas Tawn wrote: > It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? -- Cheers. Mark Lawrence. From tjreedy at udel.edu Fri May 11 10:58:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 May 2012 10:58:51 -0400 Subject: Finding the line number of an 'else' statement via ast In-Reply-To: References: Message-ID: On 5/11/2012 12:35 AM, Michael Rene Armida wrote: > Given this source: > > def do_something(val): > if val: > return 'a' > else: > return 'b' > > How do I get the line number of the "else:" line, using the ast > module? The grammar only includes the 'orelse' list: > > If(expr test, stmt* body, stmt* orelse) > > ...but 'orelse' is the list of statements under the 'else' token, not > a node representing the token itself. > > I have a suspicion that this isn't possible, and shouldn't be, and the > giveaway word above was "token." Because the tokens themselves aren't > part of the abstract syntax tree. The main reason to record line numbers in the parse tree and hence the CPython code object is to print the line number and corresponding line in exception tracebacks. Since 'else:' on a line by itself is not a statement in itself and does not contain an expression that could raise, there is no need to record a line number. So I would not be surprised if it is not directly recorded. 'else: 1/0' and "elif 1/0" will have recorded line numbers. If you can get the last line of the if-block and first line of the else-block, and there is a gap, you might guess that the else is in between ;-). -- Terry Jan Reedy From jeanmichel at sequans.com Fri May 11 11:09:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 11 May 2012 17:09:24 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FAD2BA4.6000701@sequans.com> Mark Lawrence wrote: > On 11/05/2012 15:32, Andreas Tawn wrote: > >> It's also helpful to not have to display every attribute, of which >> there may be dozens. > > Do I detect a code smell here? > I think so, Murphy's law dictates that the attribute you're interested in will not be displayed anyway. JM From andreas.tawn at ubisoft.com Fri May 11 11:10:50 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 17:10:50 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597B2B@PDC-MAIL-CMS01.ubisoft.org> > > It's also helpful to not have to display every attribute, of which there may be > dozens. > > Do I detect a code smell here? Possibly. I'll often try to subdivide into several simpler types, but sometimes that makes the code more complex than it needs to be. From andreas.tawn at ubisoft.com Fri May 11 11:24:46 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 May 2012 17:24:46 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <4FAD2BA4.6000701@sequans.com> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <20120511001535.GA8056@cskk.homeip.net> <581D4160B04DF541A763BB8BB60E8CC6A6EC5978E6@PDC-MAIL-CMS01.ubisoft.org> <4FACFEDA.1040808@davea.name> <581D4160B04DF541A763BB8BB60E8CC6A6EC597AAD@PDC-MAIL-CMS01.ubisoft.org> <4FAD2BA4.6000701@sequans.com> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A6EC597B51@PDC-MAIL-CMS01.ubisoft.org> > >> It's also helpful to not have to display every attribute, of which > >> there may be dozens. > > > > Do I detect a code smell here? > > > I think so, Murphy's law dictates that the attribute you're interested in will not be > displayed anyway. That's what __repr__'s for. From sageandecho at gmail.com Fri May 11 11:25:20 2012 From: sageandecho at gmail.com (Coyote) Date: Fri, 11 May 2012 08:25:20 -0700 (PDT) Subject: Newby Python Programming Question Message-ID: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Folks, I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. I have two programs. The first is in a file I named file_utils.py: def pwd(): import os print os.getcwd() The second is in a file I named pwd.py: import os print os.getcwd() Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory: >>>from file_utils import pwd >>>pwd() C:\Users\coyote\pyscripts But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? Thanks! Cheers, David From tjreedy at udel.edu Fri May 11 11:51:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 May 2012 11:51:47 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On 5/11/2012 1:55 AM, John Terrak wrote: > I couldnt find anywhere in the documentation that int() can throw a ValueError. > I checked the "The Python Language Reference", and the "The Python > Standard Library " to no avail. > Did I missed something? To add to Chris' answer: If the domain of a function is truly all Python objects, it cannot raise an error. I believe id(x) is such an example. Even if the domain is intended to be all Python objects, you cannot be sure if the function uses any special method defined on the object or its class. For examples, type(x) *should* always work, but I would not be surprised if a buggy __getattribute__ method or buggy metaclass could result in an exception instead. If the arguments for a function include a function, for example map(f, 'abc'), then the passed function can raise any exception and hence the called function will pass along the exception unless, unusually, it catches it. As to your specific question, if the domain of a function is a subset of types and values of allowed types, then you should expect that it can raise either TypeError or ValueError. If the domain > So here is the question - if it is not in the documentation - how does > one find out the > exceptions that are thrown by a constructor, a method or a function? One way is to try specific examples, as you did. Following what Chris said, especially do that for bad input whose exception you want to catch. Sometimes this is faster than trying to find the answer in the doc, and it gives the actual answer rather than the intended answer. > Example: int("not_an_int") >>>> int("not_an_int") > Traceback (most recent call last): > File "", line 1, in > ValueError: invalid literal for int() with base 10: 'not_an_int' Some strings are legal input, hence not a TypeError, but not all, hence ValueError. >> From what I gathered: > class int(object): > """ int(x[, base]) -> integer > > Convert a string or number to an integer, if possible. A floating point > argument will be truncated towards zero (this does not include a string > representation of a floating point number!) When converting a string, use > the optional base. It is an error to supply a base when converting a > non-string. If base is zero, the proper base is guessed based on the > string content. If the argument is outside the integer range a > long object will be returned instead. """ 'error' should say 'TypeError' as it is a TypeError to provide the wrong number of args. However, the current 3.3 manual entry is more accurate and informative, starting with the signature. -- Terry Jan Reedy From lists at cheimes.de Fri May 11 12:15:05 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 11 May 2012 18:15:05 +0200 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: Am 11.05.2012 17:51, schrieb Terry Reedy: > If the domain of a function is truly all Python objects, it cannot raise > an error. I believe id(x) is such an example. Even id() can raise an exception, for example MemoryError when you are running out of memory. Christian From rosuav at gmail.com Fri May 11 12:23:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 02:23:04 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 2:15 AM, Christian Heimes wrote: > Am 11.05.2012 17:51, schrieb Terry Reedy: >> If the domain of a function is truly all Python objects, it cannot raise >> an error. I believe id(x) is such an example. > > Even id() can raise an exception, for example MemoryError when you are > running out of memory. KeyboardInterrupt can also be raised at (effectively) any time, but I'm not sure that that really counts as id() raising the exception. If I understand it correctly, MemoryError would be because the interpreter can't allocate an int object for id's return value. But these are definitely part of why you don't just catch all exceptions. Hmm. What happens if the interpreter can't construct a MemoryError exception? ChrisA From maarten.sneep at knmi.nl Fri May 11 12:38:29 2012 From: maarten.sneep at knmi.nl (Maarten) Date: Fri, 11 May 2012 09:38:29 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> On Friday, May 11, 2012 5:25:20 PM UTC+2, Coyote wrote: > I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. Welcome here. > I have two programs. The first is in a file I named file_utils.py: > > def pwd(): > import os > print os.getcwd() Move the import tot the root level of the file: import os def pwd(): print(os.getcwd()) (and print() is a function these days) > The second is in a file I named pwd.py: > > import os > print os.getcwd() > > Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory. > > But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? I'd say this is a bug or feature of the IDE. If I use ipython I get: In [1]: %run mypwd /nobackup/users/maarten/tmp/coyote I tried to use Eclipse, but I don't think I'll do that again. I otherwise never use an IDE, it makes me confused. I don't know what the IDE is doing. Note that there is a standard module (at least on unix/linux) with the name pwd, but I guess that the IDE is not confused. I do recommend you read http://docs.python.org/howto/doanddont.html as a starting point to avoid learning some bad habits, especially on importing. You probably already found https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html For scripts that are intended to be run from the command line, I use: #!/usr/bin/env python import os def pwd(): return os.getcwd() if __name__ == "__main__": print(pwd()) This will allow you to import the module (without side effects) and call the function, as well as 'running' the file. This increases the usefullness of the module. There are other advantages, especially when the scripts involves (many) variables. Maarten From ethan at stoneleaf.us Fri May 11 12:41:49 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 May 2012 09:41:49 -0700 Subject: __all__, public API, private stuff, and leading _ Message-ID: <4FAD414D.1020209@stoneleaf.us> Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? ~Ethan~ From emile at fenx.com Fri May 11 13:01:15 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 11 May 2012 10:01:15 -0700 Subject: __all__, public API, private stuff, and leading _ In-Reply-To: <4FAD414D.1020209@stoneleaf.us> References: <4FAD414D.1020209@stoneleaf.us> Message-ID: On 5/11/2012 9:41 AM Ethan Furman said... > Style question: > > Since __all__ (if defined) is the public API, if I am using that should > I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the internal vs exposed nature of things. Emile From ian.g.kelly at gmail.com Fri May 11 13:12:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 May 2012 11:12:43 -0600 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 10:23 AM, Chris Angelico wrote: > Hmm. What happens if the interpreter can't construct a MemoryError exception? I believe that a MemoryError instance is pre-allocated for just this scenario. You can see it in the result of gc.get_objects(). >>> [x for x in gc.get_objects() if isinstance(x, MemoryError)] [MemoryError()] Cheers, Ian From rosuav at gmail.com Fri May 11 13:27:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 03:27:48 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 3:12 AM, Ian Kelly wrote: > I believe that a MemoryError instance is pre-allocated for just this > scenario. Ah, wise move. It's one of those largely-imponderables, like figuring out how to alert the sysadmin to a router failure. ChrisA From jeanpierreda at gmail.com Fri May 11 13:36:06 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 11 May 2012 13:36:06 -0400 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: > However, have you tried using a pipe for them instead of a real file? That > would allow you to retrieve the output without needing to pass through a > file in the file system. You can also replace sys.stdout/err with arbitrary > objects in Python space, which could then forward the output in any way you > want. Surely a pipe would cause a deadlock if the pipe fills up if Python and the C program are running in the same process/thread? I'm not too familiar with these sorts of things. -- Devin From david at idlcoyote.com Fri May 11 14:00:51 2012 From: david at idlcoyote.com (Coyote) Date: Fri, 11 May 2012 11:00:51 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> <11410300.1550.1336754309016.JavaMail.geo-discussion-forums@vbep19> Message-ID: <31904384.15.1336759251460.JavaMail.geo-discussion-forums@yneh4> Maarten writes: > I do recommend you read http://docs.python.org/howto/doanddont.html as a starting point to avoid learning some bad habits, especially on importing. You probably already found https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html Yikes! I'm sure that first reference is in English, but I don't have much of an idea what it means yet. :-) I have found the second reference very helpful. I've bookmarked both of these for future consideration. Thanks for your good advice. Cheers, David From rosuav at gmail.com Fri May 11 14:05:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 04:05:00 +1000 Subject: Retrieving result from embedded execution In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 3:36 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 12:45 AM, Stefan Behnel wrote: >> However, have you tried using a pipe for them instead of a real file? That >> would allow you to retrieve the output without needing to pass through a >> file in the file system. You can also replace sys.stdout/err with arbitrary >> objects in Python space, which could then forward the output in any way you >> want. > > Surely a pipe would cause a deadlock if the pipe fills up if Python > and the C program are running in the same process/thread? Yes, it would; how much data are you looking at retrieving, and is it all at script-end or do you need to process it concurrently? If the latter, then your two best options are a pipe (and running the Python script in another thread, possibly a separate process) or a callback of some sort (in which case the script hands you a line or block of output and says "Deal with this and get back to me") - eg by replacing sys.stdout, or defining a function that the Python script calls explicitly. This is starting to sound similar to something I did at work. A C++ program uses a block of Python code as a sort of uber-config-file. It would initialize the Python environment, import some modules, etc, once, and keep the globals around (this allows Python globals to be retained). Every time script-configurable code is to be run: 1) Prepare a dictionary called Input with a whole lot of parameters/information/etc 2) Create an empty dictionary and call it Output 3) Execute a block of code (retrieved from the database) 4) Inspect the Output dictionary and use that to control subsequent behaviour. As a concept, it worked quite well. I do not, however, advise doing this if your Python scripts come from untrusted sources, as it is impossible to guarantee safety. (For that reason we actually shifted to Javascript for that project.) But if you're using this as a powerful and simple config-file and you know you can trust everything that will be run, then it's a pretty awesome way of doing things. It takes deliberately malicious code to break the system. ChrisA From ethan at stoneleaf.us Fri May 11 14:26:40 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 May 2012 11:26:40 -0700 Subject: __all__, public API, private stuff, and leading _ In-Reply-To: References: <4FAD414D.1020209@stoneleaf.us> Message-ID: <4FAD59E0.7090801@stoneleaf.us> Emile van Sebille wrote: > On 5/11/2012 9:41 AM Ethan Furman said... >> Style question: >> >> Since __all__ (if defined) is the public API, if I am using that should >> I also still use a leading underscore on my private data/functions/etc? > > I would, even if only to alert any future maintainer of the internal vs > exposed nature of things. I find that a persuasive argument, thanks. ~Ethan~ From vacu001 at gmail.com Fri May 11 14:58:01 2012 From: vacu001 at gmail.com (vacu) Date: Fri, 11 May 2012 11:58:01 -0700 (PDT) Subject: %d not working in re at Python 2.7? Message-ID: I am frustrated to see %d not working in my Python 2.7 re.search, like this example: >>> (re.search('%d', "asdfdsf78asdfdf")).group(0) Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'group' \d works fine: >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) '78' And google search ignores % in their search, so I failed to find answer from Python mailing list or web, Do you have any idea what's problem here? Thanks a head Vacu From john.terrak at gmail.com Fri May 11 15:01:15 2012 From: john.terrak at gmail.com (John Terrak) Date: Fri, 11 May 2012 12:01:15 -0700 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: Thank you all for your help. Greatly appreciated. John From jason at deadtreepages.com Fri May 11 15:32:35 2012 From: jason at deadtreepages.com (Jason) Date: Fri, 11 May 2012 12:32:35 -0700 (PDT) Subject: specify end of line character for readline Message-ID: <485824.173.1336764755682.JavaMail.geo-discussion-forums@yngp11> Is there any way to specify the end of line character to use in file.readline() ? I would like to use '\r\n' as the end of line and allow either \r or \n by itself within the line. Thanks, Jason From jeanpierreda at gmail.com Fri May 11 15:34:34 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 11 May 2012 15:34:34 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: > Unlike in Java, a function's list of things it can throw isn't part of > its signature. Instead of trying to catch every possible exception, > it's generally best to simply let exceptions propagate unless you KNOW > you're expecting them. How am I supposed to know to expect them, if they are undocumented? Trial and error? That seems like a poor replacement for documented error conditions. -- Devin From raunakgup90 at gmail.com Fri May 11 15:41:31 2012 From: raunakgup90 at gmail.com (raunakgup90 at gmail.com) Date: Fri, 11 May 2012 12:41:31 -0700 (PDT) Subject: Sharing Data in Python Message-ID: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> I have some Pickled data, which is stored on disk, and it is about 100 MB in size. When my python program is executed, the picked data is loaded using the cPickle module, and all that works fine. If I execute the python multiple times using python main.py for example, each python process will load the same data multiple times, which is the correct behaviour. How can I make it so, all new python process share this data, so it is only loaded a single time into memory? asked the same question on SO, but could not get any constructive responses.. http://stackoverflow.com/questions/10550870/sharing-data-in-python/10551845 From leomcallister at gmail.com Fri May 11 15:53:19 2012 From: leomcallister at gmail.com (leomcallister at gmail.com) Date: Fri, 11 May 2012 12:53:19 -0700 (PDT) Subject: Scrapy - importing files from local, rather than www In-Reply-To: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> References: <98452517-f52c-4158-bd69-6b29a468e5f1@t2g2000pbl.googlegroups.com> Message-ID: <29279774.1982.1336765999380.JavaMail.geo-discussion-forums@vbki8> You can try running Python's web server on the folder (python -m SimpleHTTPServer) and point Scrapy to it. On Monday, May 7, 2012 4:57:22 AM UTC-3, nbw wrote: > Hi everyone, I'm new to Python (loving it!) and Scrapy. I have a > question I just can't seem to get my head around. I can get a simple > Scrapy spider to pick up URLs and download them fine, but the HTML > files I have are stored locally. The reason for this, is for some > reason when I "Save As" the pages I get everything, whereas if Scrapy > runs over them it seems to miss certain areas where there's > Javascript. > > So, I have them sitting in a directory (C:/scrapy_test) but can't for > the life of me get Scrapy to find them. Is there anyone who's had this > problem and solved it, or can help? > > Any help is much appreciated. > Kind regards, > nbw From georgeryoung at gmail.com Fri May 11 17:29:39 2012 From: georgeryoung at gmail.com (gry) Date: Fri, 11 May 2012 14:29:39 -0700 (PDT) Subject: tiny script has memory leak Message-ID: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 [gcc-4_3-branch revision 141291]] I thought this script would be very lean and fast, but with a large value for n (like 150000), it uses 26G of virtural memory, and things start to crumble. #!/usr/bin/env python '''write a file of random integers. args are: file-name how-many''' import sys, random f = open(sys.argv[1], 'w') n = int(sys.argv[2]) for i in xrange(n): print >>f, random.randint(0, sys.maxint) f.close() What's using so much memory? What would be a better way to do this? (aside from checking arg values and types, I know...) From cmpython at gmail.com Fri May 11 17:57:10 2012 From: cmpython at gmail.com (CM) Date: Fri, 11 May 2012 14:57:10 -0700 (PDT) Subject: Newby Python Programming Question References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: On May 11, 11:25?am, Coyote wrote: > Folks, > > I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed. > > I have two programs. The first is in a file I named file_utils.py: > > ? ?def pwd(): > ? ? ? ?import os > ? ? ? ?print os.getcwd() > > The second is in a file I named pwd.py: > > ? ?import os > ? ?print os.getcwd() > > Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory: > > ? ?>>>from file_utils import pwd > ? ?>>>pwd() > ? ?C:\Users\coyote\pyscripts > > But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that? I don't know Spyder IDE, but I don't think this should happen; could there just be a simple mistake? Because you first refer to the .py file as 'file_utils.py' but then you refer to the file as 'pwd.py'...which is also the name of your function. Room for confusion...so could you test this by saving only your one function (below), give the .py a new name to avoid confusion (like test_pwd.py) and then running *that* through Spyder IDE? def pwd(): import os print os.getcwd() From david at idlcoyote.com Fri May 11 18:25:40 2012 From: david at idlcoyote.com (Coyote) Date: Fri, 11 May 2012 15:25:40 -0700 (PDT) Subject: Newby Python Programming Question In-Reply-To: References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> Message-ID: <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> CM writes: > I don't know Spyder IDE, but I don't think this should happen; could > there just be a simple mistake? Because you first refer to the .py > file as 'file_utils.py' but then you refer to the file as > 'pwd.py'...which is also the name of your function. Room for > confusion...so could you test this by saving only your one function > (below), give the .py a new name to avoid confusion (like test_pwd.py) > and then running *that* through Spyder IDE? > > def pwd(): > import os > print os.getcwd() I probably explained the situation badly. I have a file pwd.py with these two lines of code in it: import os print os.getcwd() If I start a new Spyder IDL session and "run" this file by choosing RUN from the menu bar, the directory is printed twice. This appears to me now to be an IDE error, because if I use a runfile command, the directory is printed only once, as I expect. >>>runfile('pwd.py') C:\Users\coyote\pyscripts I've been playing around with a couple of IDEs because I liked the one I used with IDL and I wanted to use something similar for Python. The IDLDE was an Eclipse variant, but I've tried installing Eclipse before for something else and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. Unless, of course, I need a good excuse to head over to the Rio for the margaritas. :-) Cheers, David From cs at zip.com.au Fri May 11 18:44:34 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 12 May 2012 08:44:34 +1000 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: Message-ID: <20120511224434.GA27120@cskk.homeip.net> On 11May2012 15:40, Mark Lawrence wrote: | On 11/05/2012 15:32, Andreas Tawn wrote: | > It's also helpful to not have to display every attribute, of which there may be dozens. | | Do I detect a code smell here? Not necessarily. (Well, yeah, "dozens" may indicate time to partition stuff.) My "O" class (back in the thread) deliberately shows only the [a-z]* attributes so the user gets the public object state without the noise of private attributes. For __repr__ I might print everything. Haven't gone that far yet. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ That is 27 years ago, or about half an eternity in computer years. - Alan Tibbetts From miki.tebeka at gmail.com Fri May 11 20:30:49 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 11 May 2012 17:30:49 -0700 (PDT) Subject: Sharing Data in Python In-Reply-To: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> References: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> Message-ID: <1735448.70.1336782649463.JavaMail.geo-discussion-forums@vbfx1> > How can I make it so, all new python process share this data, so it is only loaded a single time into memory? You can have one process as server and client ask for parts of data. You might be able to do something smart with mmap but I can't think of a way. I Linux systems, if you first load the data and then fork, the OS will keep all the read only data shared. From rosuav at gmail.com Fri May 11 23:21:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 13:21:14 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 5:34 AM, Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 2:10 AM, Chris Angelico wrote: >> Unlike in Java, a function's list of things it can throw isn't part of >> its signature. Instead of trying to catch every possible exception, >> it's generally best to simply let exceptions propagate unless you KNOW >> you're expecting them. > > How am I supposed to know to expect them, if they are undocumented? > Trial and error? That seems like a poor replacement for documented > error conditions. Expect exceptions any time anything goes wrong. Don't try to code to prevent them. Here's an example. Suppose you write a function that takes a number and returns that many copies of your club's charter. (Yeah, pretty stupid, but examples usually are!) def charter(copies): return _chartertext * copies Does this function need to catch any exceptions? No. Can that expression throw exceptions? Totally! You might be given a non-number (can't give "foo" copies); you might get a floating point (can't get three-and-a-half copies); your charter text might have been replaced with a pizza; the user might hit Ctrl-C right while it's copying; the number might be so large that you run out of memory; all sorts of things. But they're not your problems - they're your caller's problems. If you caught all those exceptions, what would you do? You'd have to signal the error conditions yourself, which probably means... raising an exception. There are times when you want to catch all exceptions, though. Top-level code will often want to replace exception tracebacks with error messages appropriate to some external caller, or possibly log the exception and return to some primary loop. Otherwise, though, most code will just let unexpected exceptions through. This is one of those massively freeing leaps of thinking. Java binds you to a bureaucracy of catching exceptions or declaring them (but then still has RuntimeException - and I'm sure there've been MANY programmers who just derive all their exceptions from that); Python sets you free to care only about what you want to care about. ChrisA From jeanpierreda at gmail.com Sat May 12 00:11:18 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 12 May 2012 00:11:18 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 11:21 PM, Chris Angelico wrote: > There are times when you want to catch all exceptions, though. > Top-level code will often want to replace exception tracebacks with > error messages appropriate to some external caller, or possibly log > the exception and return to some primary loop. Otherwise, though, most > code will just let unexpected exceptions through. I'm not talking about unexpected exceptions. I'm saying, if I expect invalid input for int, where should I go to find out how to deal with said invalid input properly? How do I know that int raises ValueError on failure, and not, for example, something like ArgumentError (something that Python doesn't have) or (like chr) TypeError? Apparently the answer is to read the documentation for ValueError. It's a bit like putting the documentation on the return type for `map` in the list documentation. Kinda hard to get there without already knowing the answer. -- Devin From rosuav at gmail.com Sat May 12 01:50:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 15:50:56 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 2:11 PM, Devin Jeanpierre wrote: > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? Ah, I see what you mean. The easiest way to find out what exception gets thrown is to try it. For obvious things like int("foo") you can simply test it in the interactive interpreter; unusual cases you'll discover as you run your script. ChrisA From anthony at xtfx.me Sat May 12 03:10:01 2012 From: anthony at xtfx.me (anthony at xtfx.me) Date: Sat, 12 May 2012 00:10:01 -0700 (PDT) Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> Message-ID: <15657786.192.1336806601102.JavaMail.geo-discussion-forums@yngo1> On Thursday, May 10, 2012 3:06:47 AM UTC-5, james hedley wrote: > > i have not banned anything, or even alluded to it, whatsoever. i asked that > > one specific mail not be commented upon > > OK, sorry if I misunderstood, but that's still suppression in my book. James, how can you realistically condemn a simple request with such colorful words, now and in previous messages, yet simultaneously claim to support Luke's many impositions ... https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/ZTK-9bZ5TisJ https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/xp63LbOYO6oJ ... i could easily drum up a hundred more, if i were both inclined and extremely bored. i have been in contact by other users who claim a similar state as yourself, and frankly, everyone save yourself expresses a far more genuine interest ... your comments are riddled with dissonance ... > > reading your accounts strewn about is interesting, what exactly are *your* motives? > > My motives are as I've stated; I'm a commercial user with products in development > which use Pyjamas and that I have a long-term stake in. With a bit of thought, anyone > should see why I value stability and continued viability. It's a long game but the > potential payback to pyjamas could be huge *if* it can keep commercial users on board. > This is where the existential threat to pyjamas comes from and why I and many others > consider the takeover to be reckless and unjustified. perhaps. in retrospect i would have approached some aspects a bit differently. interestingly ... things seem to be panning out in ways that will benefit all ... isn't that right, James? to be honest though, of all the commercial users i'm aware, none have responded as you describe. this was not a lone wolf operation, and neither are discussions in flight. i think if you temper your reactions, and turn down the volume, you will find that things are shaping up rather well ... i am very much aware of the events unfolding, as are you. whilst you paint me the enemy, new paths have been opened ... achievement? unlocked! > > Luke is a talented developer, there is no doubt of this, but he is one of the most > > socially inept persons i have ever encountered > > I don't think this is the right place to bash people or even defend them on a personal > level. i'm doing neither. this is an mere observation after multiple years of interaction, and my own research into past endeavors. > We get it though. You didn't get along with the guy. well, no, i don't think you get it ... are you paying attention, at all? i got along with him just fine; i've already detailed this elsewhere. > > the idea was to retain Luke > > I'm sorry but I don't believe this. Luke can speak for himself of course but this is > not how you keep people on-board. well, don't then :-( ... but several did, and it's the cross-my-heart-pinky-swear'in truth. after many months of lengthy discussion it felt right. after 10 minutes of reactionary thought it feels less right to you ... that's certainly understandable, and maybe even correct. was it *really* the right thing to do? maybe not, this was unprecedented. already however, great things are in motion, and i feel good about the feedback received, outside and in. > > he decided to play legal threats as the first card > > He's claimed that you lifted data from his server without permission. I'm not commenting > on that, but if it's true then this is a massive roadblock in the viability of the > project. I for one don't want to be involved in it. Can you picture the scene where a > developer or businessperaon goes into a meeting with very senior, very conservative > executives trying to pitch a product, and it turns out there are serious legal concerns > surrounding the technology platform? unrelated ... the technology is freely available. > If it isn't true then perhaps you should put people's minds at rest by giving a detailed > explanation of the whole mail server situation, including where the data originated, where > it is now, how it got there and why the accidental mailing of so many people occurred. acting as an agent of the organization, i reinstated services people had purposefully subscribed to, in accordance with an infrastructure transition. these were pre-existing relationships to a service i managed. alas, i was unaware of the reasons to -- or existence of -- joining a list, but opting for "nomail" ... thus the state was reset, ie. resuming reception thereto. following this realization, all existing members were simply requested to join a new list at their willful discretion. data was/is neither leaked nor compromised in any way. if anything, organization leaders failed to register with the Ministry their collection of personal data, and also failed to train agents on proper handling, if need be. ... that's the official statement, but like i said 100 times, i don't give a {explicit deleted} about this, and never wanted to: i seek the best for everyone. this thought stream is more likely a shoot yourself in the foot kind of path ... and not my own. while i do sincerely apologize to those affected/upset, the reality is a handful of people received a handful of mail, in a good faith attempt to reinstate a service they had both requested and retained. this was subsequently ceased once it was clear there was an issue with the latter, and a final, good faith attempt was made to detail and offer resumed services elsewhere ... so what? lets hypothetically suggest there was some transgression, people/Luke/whomever feverishly pursue, and the book get thrown my way ... what will anyone have gained? nothing. all that results is my life gets difficult, my fiance in final year of grad school is possibly compromised due to finances, and my toddler son must endure any hardship along with us ... more blood please? or revenge? or [...]? there is a positive resolution for everyone, and it will be found. > > indeed, you have witnessed little chatter > > I'd invite anyone to review the pyjamas list for the last 7 days before they make > up their minds. Some of the statements I've seen have been regrettable. i don't know what you're referring to, or even talking about, at all. things have been rather peachy keen ... we even had some emerge from the shadows! ;-) > > by realizing this is not as black-and-white as you's like it to be. > > I have an ethical objection here, but moreover; it clearly just runs against my > interests to support your actions. I'm not sure you considered the commercial users > here, and with respect nor do I really get the impression you've understood it, still. alright ... i *am* a commercial user. while the events may run afoul something, it certainly isn't your interests. when i give presentations, and early questions are not about the project, but some particular member, that signifies a problem ... i'll let you fill in the gaps. > By the way; I'm not associated with Luke at all. I've emailed him off-list a few times > this week to discuss some angles to do with my work, but that's it. "it" you say? ok ... > In fact, I support Kees' proposition that Pyjamas should seek sponsorship from the > Python/Apache/Free Software Foundation. This would resolve questions of legitimacy and > leadership. > > In my ideal outcome, we could tailor pyjamas more to business use; e.g. > tidying up any license issues, offering a commercial support contract (this will help > mitigate the damage done to perceptions of credibility), publishing a commercial > use policy (one of the foundations could offer support with this I hope). oddly enough, your goals are inline with the advancements being made, and the some of the inadequacies behind the transition. understand that several inconsistencies were *introduced* by former leadership, and are only now being reconciled. regardless of your stance on the actual methods employed, you stand to benefit, and i daresay, *WILL* benefit. we are on the same side, James. contingent upon acceptance of an agreeable resolution, i am more than happy to transfer assets to the PSF, so we can simply absolve each other and get back to writing some damn code. however, such decisions will be made with the same care and consideration as those which brought us here ... i'm not in a hurry to witness the very encumbrances i worked hard -- and received much flak -- be reinstated. so far so good ... let's just continue working toward that goal, together. i am tight on time and resources, so this is be my last correspondence here ... best to everyone. -- C Anthony From alec.taylor6 at gmail.com Sat May 12 04:30:32 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 May 2012 18:30:32 +1000 Subject: Python web-framework with the widest scalability? Message-ID: I am building a project requiring high performance and scalability, entailing: - Role-based authenticationwith API-keylicensing to access data of specific users - API exposed with REST (XML, JSON ), XMLRPC, JSONRPC and SOAP - "Easily" configurable getters and settersto create APIs accessing the same data but with input/output in different schemas A conservative estimate of the number of tables?often whose queries require joins?is: 20. Which database type?e.g.: NoSQL or DBMS ?key-value data store or object-relational database ?e.g.: Redis or PostgreSQL?and web-framework ?e.g. Django , Web2Pyor Flask ?would you recommend? -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Sat May 12 04:32:09 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 12 May 2012 01:32:09 -0700 (PDT) Subject: Python web-framework+db with the widest scalability? Message-ID: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> I am building a project requiring high performance and scalability, entailing: ? Role-based authentication with API-key licensing to access data of specific users ? API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP ? "Easily" configurable getters and setters to create APIs accessing the same data but with input/output in different schemas A conservative estimate of the number of tables?often whose queries require joins?is: 20. Which database type?e.g.: NoSQL or DBMS?key-value data store or object-relational database?e.g.: Redis or PostgreSQL?and web-framework?e.g. Django, Web2Py or Flask?would you recommend? Thanks for all suggestions, Alec Taylor From elektrrrus at gmail.com Sat May 12 06:38:58 2012 From: elektrrrus at gmail.com (elektrrrus at gmail.com) Date: Sat, 12 May 2012 03:38:58 -0700 (PDT) Subject: Python web-framework+db with the widest scalability? In-Reply-To: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> References: <6056192.196.1336811529345.JavaMail.geo-discussion-forums@pbyy9> Message-ID: <29590505.429.1336819138658.JavaMail.geo-discussion-forums@vbez20> Hi, >From my experience while NoSQL databases are very fast and scalable, there is lack of _good_ support for popular frameworks. I've try with django and mongoengine, but results was poor. In my company we're building now large api-driven application with django and postgresql as a base. Django has two great api engines - piston and tastypie. Consider looking to nosql eg. mongodb as caching engine and session storage. Django is mature and stable framework, it has some limitations but there are good and documented use cases for doing almost everything You may need. Look also at server layer - popular apache and cgi-like solutions has very poor performance. Maybe You have use-cases to develop with messages queues like celery. W dniu sobota, 12 maja 2012 10:32:09 UTC+2 u?ytkownik Alec Taylor napisa?: > I am building a project requiring high performance and scalability, entailing: > > ? Role-based authentication with API-key licensing to access data of specific users > ? API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP > ? "Easily" configurable getters and setters to create APIs accessing the same data but with input/output in different schemas > > A conservative estimate of the number of tables?often whose queries require joins?is: 20. > > Which database type?e.g.: NoSQL or DBMS?key-value data store or object-relational database?e.g.: Redis or PostgreSQL?and web-framework?e.g. Django, Web2Py or Flask?would you recommend? > > Thanks for all suggestions, > > Alec Taylor From research at johnohagan.com Sat May 12 06:41:30 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 12 May 2012 20:41:30 +1000 Subject: Minor gripe about module names Message-ID: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Not sure if this is only package-manager specific, but occasionally I come across a module that sounds interesting, install it (in my case by apt-get), and then can't find it, because the actual module has a different name from what it says on the package - unlike the majority, which if they are called "python-whatever", are imported using "import whatever". Today's example was python-ecasound, which after some fruitless guessing followed by scanning the hundreds of entries returned by help('modules') and trying to import anything with a promising filename, turned out to really be called pyeca. Are there any rules about this kind of thing? (I did say "minor gripe".) -- John From rosuav at gmail.com Sat May 12 06:51:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 May 2012 20:51:23 +1000 Subject: Minor gripe about module names In-Reply-To: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> References: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Message-ID: On Sat, May 12, 2012 at 8:41 PM, John O'Hagan wrote: > Not sure if this is only package-manager specific, but occasionally I come > across a module that sounds interesting, install it (in my case by apt-get), > and then can't find it, because the actual module has a different name from > what it says on the package - unlike the majority, which if they are called > "python-whatever", are imported using "import whatever". You import based on the filename, so all you need is the list of files from the package: $ dpkg -L python-ecasound This works only after the package has been installed successfully. Not a solution to your problem, but possibly a viable workaround. ChrisA From python.list at tim.thechases.com Sat May 12 07:45:15 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 12 May 2012 06:45:15 -0500 Subject: Minor gripe about module names In-Reply-To: References: <20120512204130.f1c9bda7933346f407844df1@johnohagan.com> Message-ID: <4FAE4D4B.2000300@tim.thechases.com> On 05/12/12 05:51, Chris Angelico wrote: > On Sat, May 12, 2012 at 8:41 PM, John O'Hagan > wrote: >> Not sure if this is only package-manager specific, but >> occasionally I come across a module that sounds interesting, >> install it (in my case by apt-get), and then can't find it, >> because the actual module has a different name from what it >> says on the package - unlike the majority, which if they are >> called "python-whatever", are imported using "import >> whatever". > > $ dpkg -L python-ecasound > > This works only after the package has been installed > successfully. Not a solution to your problem, but possibly a > viable workaround. I use the dpkg method on my Debian-based systems, but (1) I never remember the syntax and only occasionally need it, so I have to look it up EVERY time and (2) it can return a lot of chaff if the module includes auxiliary files. If only we had some way to develop a simple program that knew about where Python modules were stored... ;-) ===================================== import os import sys if len(sys.argv) < 2: print("Usage:") print("%s module_text [or_module_text ...]" % argv[0]) sys.exit(1) mods_to_find = [s.lower() for s in sys.argv[1:]] for d in sys.path: if os.path.isdir(d): for modname in os.listdir(d): for piece in mods_to_find: if piece in modname.lower(): print(os.path.join(d, modname)) else: sys.stderr.write("Unable to check %r\n" % d) ====================================== should about do the trick and return less chaff. Could be tweaked to refine even further. Or to deduplicate results if the same file is found due to search criteria. -tkc From jeandaniel.browne at gmail.com Sat May 12 08:17:40 2012 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sat, 12 May 2012 14:17:40 +0200 Subject: Good data structure for finding date intervals including a given date Message-ID: Hello, I have a long list of n date intervals that gets added or suppressed intervals regularly. I am looking for a fast way to find the intervals containing a given date, without having to check all intervals (less than O(n)). Do you know the best way to do this in Python with the stdlib? A variant of the red black trees can do the job quickly [1], is this a good enough use case to discuss the inclusion of a red black tree implementation in the stdlib? This has been discussed here: http://bugs.python.org/issue1324770 , and lack of good use case was the reason the bug was closed. A dict implemented with red black trees is slower (but not too slow) at inserting, searching and deleting but the dict is always kept ordered. Bigger projects have their own implementation of ordered dict so such datastructures in the standard library would help the porting of the project to other platforms. Take the example of the zodb and the C-only implementation of the btree: btree in the stdlib in Python would help the porting to GAE or pypy [2]. Cheers, [1] in the "Cormen" book: http://en.wikipedia.org/wiki/Introduction_to_Algorithms [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency From zahlman at gmail.com Sat May 12 08:27:14 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:27:14 -0400 Subject: Fwd: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: I really wish gmail picked up the mailing list as a default reply-to address... ---------- Forwarded message ---------- From: Karl Knechtel Date: Sat, May 12, 2012 at 8:25 AM Subject: Re: Newbie naive question ... int() throws ValueError To: Devin Jeanpierre On Sat, May 12, 2012 at 12:11 AM, Devin Jeanpierre wrote: > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? > > Apparently the answer is to read the documentation for ValueError. The easiest way is to try it. In fact, in most cases, this will be easier than looking it up in the documentation could ever be, because looking something up in documentation requires you to read through a bunch of documentation until you find key info like 'raises FooError in bar circumstance', and then interpret it; by trial and error, you see exactly what happens right away, and you can do it by just banging out a couple of lines on the REPL. You should have already read the documentation for things like ValueError as a part of learning the language (i.e. the first time something raised a ValueError and you wanted to know what that meant); or at the very least you should have a good idea of what the "standard" exceptions are all named, and *develop an intuition* for which apply to what circumstances. As noted by others, you should not expect `int` to throw a `TypeError` when fed a bad string, because a `TypeError` means "something is wrong with the type of some object", and the problem with the bad string isn't that it's a string (its type), but that the string contents are not interpretable as int (its value, hence ValueError). -- ~Zahlman {:> -- ~Zahlman {:> From zahlman at gmail.com Sat May 12 08:30:44 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:30:44 -0400 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel wrote: > I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). Since you say "intervals" in plural here, I assume that they can overlap? -- ~Zahlman {:> From zahlman at gmail.com Sat May 12 08:36:02 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 12 May 2012 08:36:02 -0400 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote: > And there's also something like... > > return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) > > which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) > > Is there a better way? If you don't care about being able to change the attributes dynamically, define the `__slots__` of your class, and then you can use return '\n'.join('%s: %s' % (name, getattr(self, name)) for name in self.__slots__) Calling `getattr` is probably more Pythonic than looking things up in `__dict__`, string formatting can take care of "casting" (converting, really) for you, and the nested `join` is really overkill :) Anyway the main point is that `__slots__` is a list, and thus has a defined order. > > p.s. I may want to substitute __repr__ for __str__ perhaps? Depending. Sometimes you want them to behave the same way. Since functions are objects, this is as simple as `__repr__ = __str__`. :) p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal interest (or perhaps both)? -- ~Zahlman {:> From breamoreboy at yahoo.co.uk Sat May 12 08:45:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 May 2012 13:45:24 +0100 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 12/05/2012 13:17, Jean-Daniel wrote: > Hello, > Do you know the best way to do this in Python with the stdlib? Sorry, not part of the stdlib but search for red black tree here http://pypi.python.org/pypi. While you're there also take a look at the blist package. -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Sat May 12 08:49:41 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 12 May 2012 07:49:41 -0500 Subject: Python web-framework with the widest scalability? In-Reply-To: References: Message-ID: <4FAE5C65.2010202@tim.thechases.com> On 05/12/12 03:30, Alec Taylor wrote: > I am building a project requiring high performance and scalability, > entailing: Most of the frameworks are sufficiently scalable. Scalability usually stems from design decisions (architecture and algorithm) and caching, and you'll usually hit bandwidth or algorithm/architecture limits long before the frameworks are your primary bottleneck. -tkc From ethan at stoneleaf.us Sat May 12 09:10:13 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 12 May 2012 06:10:13 -0700 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4FAE6135.7070500@stoneleaf.us> Karl Knechtel wrote: > On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote: >> And there's also something like... >> >> return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in self.__dict__)) >> >> which is a nice length, but I lose control of the order of the attributes and the formatting is fixed. It also looks a bit too much like Lisp ;o) >> >> Is there a better way? > > If you don't care about being able to change the attributes > dynamically, define the `__slots__` of your class [...] Firstly, __slots__ is a tuple. Secondly, this is bad advice. __slots__ is there as a memory optimization for classes that will have thousands of instances and do not need the ability to have arbitrary attributes added after creation. __slots__ is an advanced feature, and as such is easier to get wrong. It is *not* there to make __str__ nor __repr__ easier to write. 8<----------------------------------------------------------------------- Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Test1(object): ... __slots__ = ('item', 'size') ... desc = 'class-only attribute' ... >>> t1 = Test1() >>> t1.desc = 'read-only attribute' # fails because 'desc' is # not in __slots__ Traceback (most recent call last): File "", line 1, in AttributeError: 'Test1' object attribute 'desc' is read-only >>> print t1.item # fails because 'item' was # not set Traceback (most recent call last): File "", line 1, in AttributeError: item >>> class Test2(Test1): ... def __init__(self, price): ... self.price = price ... >>> t2 = Test2(7.99) # __slots__ not defined in # subclass, optimizations lost >>> t2.oops = '__slots__ no longer active' >>> print t2.oops __slots__ no longer active 8<----------------------------------------------------------------------- ~Ethan~ From ethan at stoneleaf.us Sat May 12 09:13:34 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 12 May 2012 06:13:34 -0700 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: <4FAE61FE.6070402@stoneleaf.us> Devin Jeanpierre wrote: > On Fri, May 11, 2012 at 11:21 PM, Chris Angelico wrote: >> There are times when you want to catch all exceptions, though. >> Top-level code will often want to replace exception tracebacks with >> error messages appropriate to some external caller, or possibly log >> the exception and return to some primary loop. Otherwise, though, most >> code will just let unexpected exceptions through. > > I'm not talking about unexpected exceptions. I'm saying, if I expect > invalid input for int, where should I go to find out how to deal with > said invalid input properly? How do I know that int raises ValueError > on failure, and not, for example, something like ArgumentError > (something that Python doesn't have) or (like chr) TypeError? > > Apparently the answer is to read the documentation for ValueError. > > It's a bit like putting the documentation on the return type for `map` > in the list documentation. Kinda hard to get there without already > knowing the answer. Unit tests. :) ~Ethan~ From contropinion at gmail.com Sat May 12 09:30:04 2012 From: contropinion at gmail.com (contro opinion) Date: Sat, 12 May 2012 09:30:04 -0400 Subject: to solve the simple equation Message-ID: there is a simple equation, 50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0 i input : >>> from sympy import * >>> x=Symbol('x') >>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 332, in solve result = tsolve(f, *symbols) File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve "(tsolve: at least one Function expected at this point") NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) Traceback (most recent call last): File "", line 1, in File "/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve "(tsolve: at least one Function expected at this point") NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point 1.how can i solve it with sympy? 2.how can i solve it with other package? -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.s.mcgee115 at gmail.com Sat May 12 10:09:09 2012 From: j.s.mcgee115 at gmail.com (Josh McGee) Date: Sat, 12 May 2012 07:09:09 -0700 (PDT) Subject: %d not working in re at Python 2.7? In-Reply-To: References: Message-ID: <8356205.412.1336831749576.JavaMail.geo-discussion-forums@pbcoz4> % On Friday, May 11, 2012 11:58:01 AM UTC-7, vacu wrote: > I am frustrated to see %d not working in my Python 2.7 re.search, like > this example: > > >>> (re.search('%d', "asdfdsf78asdfdf")).group(0) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'group' > > > \d works fine: > > >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) > '78' > > > And google search ignores % in their search, so I failed to find > answer from Python mailing list or web, > Do you have any idea what's problem here? > > Thanks a head > Vacu %d and %s and such are format strings, not regex. From jeandaniel.browne at gmail.com Sat May 12 10:18:07 2012 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sat, 12 May 2012 16:18:07 +0200 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: > Since you say "intervals" in plural here, I assume that they can overlap? Yes, For instance, there are the following intervals : [[1, 10], [4, 7], [6, 15], [11, 17]] asking for the intervals including 5, the returned value should be [[1, 10], [4, 7]] The idea here to make it fast is to have done some preprocessing at insertion time, so that not all intervals are processed at query time. On Sat, May 12, 2012 at 2:30 PM, Karl Knechtel wrote: > On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel > wrote: >> I am looking for a fast way to find the intervals >> containing a given date, without having to check all intervals (less >> than O(n)). > > Since you say "intervals" in plural here, I assume that they can overlap? > > -- > ~Zahlman {:> > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Sat May 12 10:58:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 12 May 2012 10:58:56 -0400 Subject: to solve the simple equation In-Reply-To: References: Message-ID: On 5/12/2012 9:30 AM, contro opinion wrote: > there is a simple equation, > 50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045=0 > i input : >>>> from sympy import * >>>> x=Symbol('x') >>>>solve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) > Traceback (most recent call last): > File"", line 1, in > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 332, in solve > result = tsolve(f, *symbols) > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve > "(tsolve: at least one Function expected at this point") > NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point > > tsolve(50/((1+x)**0.9389)+50/((1+x)**1.9389)+1050/((1+x)**2.9389)-1045, x) > Traceback (most recent call last): > File"", line 1, in > File"/usr/lib/pymodules/python2.6/sympy/solvers/solvers.py", line 697, in tsolve > "(tsolve: at least one Function expected at this point") > NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point > > 1.how can i solve it with sympy? Read the sympy doc and learn how to make a Function and use tsolve correctly? -- Terry Jan Reedy From ndbecker2 at gmail.com Sat May 12 14:23:50 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 12 May 2012 14:23:50 -0400 Subject: Good data structure for finding date intervals including a given date References: Message-ID: Probably boost ITL (Interval Template Library) would serve as a good example. I noticed recently someone created an interface for python. From jeanpierreda at gmail.com Sat May 12 14:25:17 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 12 May 2012 14:25:17 -0400 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 8:27 AM, Karl Knechtel wrote: > I really wish gmail picked up the mailing list as a default reply-to address... There is some labs thing that makes "reply to all" the default if you click the button on the top-right. Unfortunately, that applies for non-mailing-lists too... > The easiest way is to try it. In fact, in most cases, this will be > easier than looking it up in the documentation could ever be, because > looking something up in documentation requires you to read through a > bunch of documentation until you find key info like 'raises FooError > in bar circumstance', and then interpret it; by trial and error, you > see exactly what happens right away, and you can do it by just banging > out a couple of lines on the REPL. Eh, this doesn't make sense. Before I would ever try the int() function, I would've read about it in the documentation -- otherwise how would I know what it does at all? How would I even know that it exists? What having to try-it-and-see does is give me extra steps to know what it does. Instead of only reading the documentation, now I have to both read the documentation *and* try it out in the interactive interpreter to see its behaviour in a bunch of undocumented error cases. What should actually happen is that the error cases should be documented explicitly, so that I don't have to run around in the REPL or orthogonal bits of documentation trying to figure out the behaviour of the function. > You should have already read the documentation for things like > ValueError as a part of learning the language (i.e. the first time > something raised a ValueError and you wanted to know what that meant); > or at the very least you should have a good idea of what the > "standard" exceptions are all named, and *develop an intuition* for > which apply to what circumstances. As noted by others, you should not > expect `int` to throw a `TypeError` when fed a bad string, because a > `TypeError` means "something is wrong with the type of some object", > and the problem with the bad string isn't that it's a string (its > type), but that the string contents are not interpretable as int (its > value, hence ValueError). And yet this is what ord does. Every rule has an exception. I concede that reading the docs on ValueError is probably worth doing the first time you see it. Although, it's also one of those exceptions that has a "clear" name, so it isn't something everyone will do. I'm not sure if I ever did it. And certainly the OP never looked there. -- Devin From sverreodegard at gmail.com Sat May 12 15:40:28 2012 From: sverreodegard at gmail.com (Sverre) Date: Sat, 12 May 2012 12:40:28 -0700 (PDT) Subject: Are there any instrumentation widgets for wxpython or tkinter? Message-ID: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> I searched for widgets used for PLC automation or lab instrumentation like gauges, led's etc. in the net, but didn't found anything because of those massive link spam sites. In the case there isn't any solution, with which toolkit would it be easiest to build gauges? From bheese at optonline.net Sat May 12 18:50:48 2012 From: bheese at optonline.net (Brian Heese) Date: Sat, 12 May 2012 18:50:48 -0400 Subject: Opening a csv file in python on a mac Message-ID: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> I created a csv file called python test file.csv. It is stored on my Desktop directory. When I try to open it using the command open ('Desktop python test file.csv') I get the following error: "No such file or directory". The same thing happens if I use open ('python test file.csv'). What I am I doing wrong? From rosuav at gmail.com Sat May 12 18:53:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 May 2012 08:53:20 +1000 Subject: Newbie naive question ... int() throws ValueError In-Reply-To: References: Message-ID: On Sun, May 13, 2012 at 4:25 AM, Devin Jeanpierre wrote: > What having to try-it-and-see does is give me extra steps to know what > it does. Instead of only reading the documentation, now I have to both > read the documentation *and* try it out in the interactive interpreter > to see its behaviour in a bunch of undocumented error cases. Point to note: The Python documentation tells you about the language. Trying it in the interpreter tells you about your implementation. There can be differences. I doubt there will be in something as simple as casting to int, but in other functions, it wouldn't surprise me to find that CPython (the one that most people think of as Python) and IronPython, PyPy, or Jython have differences in what they can throw. ChrisA From alec.taylor6 at gmail.com Sat May 12 21:01:07 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 13 May 2012 11:01:07 +1000 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: Import csv Lookup usage in the python docs On 13/05/2012 9:22 AM, "Brian Heese" wrote: > I created a csv file called python test file.csv. It is stored on my > Desktop directory. When I try to open it using the command open ('Desktop > python test file.csv') I get the following error: "No such file or > directory". The same thing happens if I use open ('python test file.csv'). > What I am I doing wrong? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sat May 12 21:06:21 2012 From: d at davea.name (Dave Angel) Date: Sat, 12 May 2012 21:06:21 -0400 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: <4FAF090D.9080108@davea.name> On 05/12/2012 06:50 PM, Brian Heese wrote: > I created a csv file called python test file.csv. It is stored on my Desktop directory. When I try to open it using the command open ('Desktop python test file.csv') I get the following error: "No such file or directory". The same thing happens if I use open ('python test file.csv'). What I am I doing wrong? It is totally unclear just where you "used" these "commands." Please identify your OS and python version, and paste a complete log of what you typed and saw on your console. Do NOT retype it, copy/paste it. -- DaveA From python at mrabarnett.plus.com Sat May 12 21:33:05 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 13 May 2012 02:33:05 +0100 Subject: Opening a csv file in python on a mac In-Reply-To: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> References: <752F44C1-F026-4020-91B1-239103A0C7D5@optonline.net> Message-ID: <4FAF0F51.50105@mrabarnett.plus.com> On 12/05/2012 23:50, Brian Heese wrote: > I created a csv file called python test file.csv. It is stored on my > Desktop directory. When I try to open it using the command open > ('Desktop python test file.csv') I get the following error: "No such > file or directory". The same thing happens if I use open ('python > test file.csv'). What I am I doing wrong? You should provide the full absolute path of the file. 'python test file.csv' is the name of the file, but it doesn't say where it is, and 'Desktop python test file.csv' is also just a name. (Is the file called 'Desktop python test file.csv'? No. It's called 'python test file.csv' and it's in the 'Desktop' directory, wherever that is.) From neolo12 at yandex.ru Sun May 13 03:14:31 2012 From: neolo12 at yandex.ru (jimmy970) Date: Sun, 13 May 2012 00:14:31 -0700 (PDT) Subject: http://porn-extreme.2304310.n4.nabble.com/ In-Reply-To: <1335955532204-4945863.post@n6.nabble.com> References: <1334334574674-4879088.post@n6.nabble.com> <1334385003417-4880911.post@n6.nabble.com> <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> <1335847182281-4942868.post@n6.nabble.com> <1335955532204-4945863.post@n6.nabble.com> Message-ID: <1336893271019-4974351.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4974351.html Sent from the Python - python-list mailing list archive at Nabble.com. From alec.taylor6 at gmail.com Sun May 13 08:29:57 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 13 May 2012 22:29:57 +1000 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. If you are looking for the best possible self-sorting structure for searching, then perhaps you are looking for what's outlined in the 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) Expected Time and Linear Space[3]. [1] http://www.python.org/getit/releases/3.1/ [2] http://www.python.org/getit/releases/2.7.3/ [3] http://dl.acm.org/citation.cfm?id=645413.652131 On Sat, May 12, 2012 at 10:17 PM, Jean-Daniel wrote: > > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). > > Do you know the best way to do this in Python with the stdlib? > > A variant of the red black trees can do the job quickly [1], is this a > good enough use case to discuss the inclusion of a red black tree > implementation in the stdlib? > > This has been discussed here: http://bugs.python.org/issue1324770 , > and lack of good use case was the reason the bug was closed. A dict > implemented with red black trees is slower (but not too slow) at > inserting, searching and deleting but the dict is always kept ordered. > Bigger projects have their own implementation of ordered dict so such > datastructures in the standard library would help the porting of the > project to other platforms. Take the example of the zodb and the > C-only implementation of the btree: btree in the stdlib in Python > would help the porting to GAE or pypy [2]. > > Cheers, > > [1] in the "Cormen" book: > http://en.wikipedia.org/wiki/Introduction_to_Algorithms > [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency > -- > http://mail.python.org/mailman/listinfo/python-list From davidgshi at yahoo.co.uk Sun May 13 09:25:54 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Sun, 13 May 2012 14:25:54 +0100 (BST) Subject: How to call and execute C code in Python? In-Reply-To: References: Message-ID: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Can anyone tell me how to call and exectute C code in Python? Regards. David ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Friday, 11 May 2012, 5:35 Subject: Python-list Digest, Vol 104, Issue 57 ----- Forwarded Message ----- 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. Looking for video/slides from PyCon 2011... (Monte Milanuk) ? 2. Re: Dealing with the __str__ method in classes with lots of ? ? ? attributes (Cameron Simpson) ? 3. RE: Open Source: you're doing it wrong - the Pyjamas hijack ? ? ? (Adrian Hunt) ? 4. RE: Creating a Windows installer for Python + a set of ? ? ? dependencies (Adrian Hunt) ? 5. Re: Open Source: you're doing it wrong - the Pyjamas hijack ? ? ? (Chris Angelico) ? 6. Re: Retrieving result from embedded execution (Chris Angelico) ? 7. Finding the line number of an 'else' statement via ast ? ? ? (Michael Rene Armida) ...specifically the two lectures on creating GUI applications with Python + QT http://us.pycon.org/2011/schedule/presentations/207/ Various searches on the 'Net don't seem to be turning up much... kinda curious as to why? Anyone here know? TIA, Monte On 10May2012 15:33, Andreas Tawn wrote: | Say I've got a class... | | class test(object): |? ? def __init__(self): |? ? ? ? self.foo = 1 |? ? ? ? self.bar = 2 |? ? ? ? self.baz = 3 | | I can say... | | def __str__(self): |? ? return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz) | | and everything's simple and clean and I can vary the formatting if I need to. | | This gets ugly when the class has a lot of attributes because the string construction gets very long. This issue bit me once too often a few months ago, and now I have a class called "O" from which I often subclass instead of from "object". Its main purpose is a friendly __str__ method, though it also has a friendly __init__. Code: ? ? class O(object): ? ? ? ''' A bare object subclass to allow storing arbitrary attributes. ? ? ? ? ? It also has a nicer default str() action, and an aggressive repr(). ? ? ? ''' ? ? ? def __init__(self, **kw): ? ? ? ? ''' Initialise this O. ? ? ? ? ? ? Fill in attributes from any keyword arguments if supplied. ? ? ? ? ? ? This call can be omitted in subclasses if desired. ? ? ? ? ''' ? ? ? ? for k in kw: ? ? ? ? ? setattr(self, k, kw[k]) ? ? ? def __str__(self): ? ? ? ? return ( "<%s %s>" ? ? ? ? ? ? ? ? % ( self.__class__.__name__, ? ? ? ? ? ? ? ? ? ? ",".join([ "%s=%s" % (attr, getattr(self, attr)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for attr in sorted(dir(self)) if attr[0].isalpha() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ]) ? ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ) So I have some code thus: ? from cs.misc import O ? ...... ? class FilterModes(O): ? ? def __init__(self, **kw): ? ? ? ? # special case one parameter ? ? ? ? self._maildb_path = kw.pop('maildb_path') ? ? ? ? self._maildb_lock = allocate_lock() ? ? ? ? O.__init__(self, **kw) ? ...... ? filter_modes = FilterModes(justone=justone, ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay=delay, ? ? ? ? ? ? ? ? ? ? ? ? ? ? no_remove=no_remove, ? ? ? ? ? ? ? ? ? ? ? ? ? ? no_save=no_save, ? ? ? ? ? ? ? ? ? ? ? ? ? ? maildb_path=os.environ['MAILDB'], ? ? ? ? ? ? ? ? ? ? ? ? ? ? maildir_cache={}) This removes a lot of guff from some common procedures. Hope this helps, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's a fine line between pathos and pathetic. ? ? ? ? - David Stivers stiv at stat.rice.edu DoD #857 lol, Cheers Chris. Just so you know, I care about what and how I write... I almost always run my emails though a word-processor before sending. And, that has paid off for me: thanks to MS Word, MS Works and Open Office, I have better understanding of "correct" punctuation use (if not spelling and grammar) than most school leavers!!! PS. It hasn't gone a miss that you are one of the core python-list responders (and I bet this goes for most of the python-list users): your responses, time and knowledge is appreciated... Thank you. > Date: Fri, 11 May 2012 09:57:49 +1000 > Subject: Re: Open Source: you're doing it wrong - the Pyjamas hijack > From: rosuav at gmail.com > To: python-list at python.org > > On Fri, May 11, 2012 at 9:36 AM, Adrian Hunt wrote: > > All I did was to answer a mail sent to me by Ian Kelly (who I don't konw nor > > have ever had any prior contact with) about releasing code under a > > license... And, what I said stands: once anyone releases code, they are > > bound by the license they released it under as much as anyone else that may > > use it and cannot then withdraw that code from the domain they released it > > to (except by maybe creating a new and different version.) > > And that's absolutely correct. Open source licenses are deliberately > worded to guarantee rights in perpetuity, so there's no way to > withdraw it or change the license (though of course a copyright owner > can release the same code under an additional license). > > > Being dyslexic, my message (and this one) may not be worded in the best way > > but that is no reason to start on me! > > Your message is fine. Believe you me, I'd much rather read a message > posted by a non-native English speaker, or a dyslexic person, or > someone who has a clinical aversion to the letter 'q', than someone > who's simply sloppy and doesn't care about their language at all. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list Hi there, I've use NSIS for quite a few projects... NSIS will do it with ease. You write a script that gets "compiled" into a install exe and the scripting language is not too hard to learn. You can do it in several different ways: 1. You can include the Python installer as a file compressed into your installer (that is decompressed to a temp directory before being run.) 2. The Python installer could be a included along side you installer and run as needed 3. You can specify a URL to the Python install to be downloaded and installed (again using a temp directory.) You can even use a mix... If an internet connection is available download it, if not fall back to one of the other methods. If you can come up with yet another method, it wouldn't be simple to write a script to handle it.? If you really need to you can write a dynamic link library that the final NSIS installer will make calls to. If you need any more help on this subject, email me directly... Although I try to keep an eye on python-list, I can't guarantee a quick reply. > Date: Thu, 10 May 2012 16:26:25 +0200 > Subject: Creating a Windows installer for Python + a set of dependencies > From: g.rodola at gmail.com > To: python-list at python.org > > Hi all, > I need to create an installer for Windows which should be able to > install a specific version of the Python interpreter (2.7) plus a set > a dependencies such as ipython, numpy, pandas, etc. > Basically this is the same thing Active State did for their Active > Python distribution: a single bundle including interpreter + deps. > Not being a Windows user I'm not sure where to start with this except > maybe looking into NSIS (could that be of any help?). > > Thanks in advance, > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > -- > http://mail.python.org/mailman/listinfo/python-list On Fri, May 11, 2012 at 10:21 AM, Adrian Hunt wrote: > lol, Cheers Chris. > > Just so you know, I care about what and how I write... I almost always run > my emails though a word-processor before sending. And, that has paid off for > me: thanks to MS Word, MS Works and Open Office, I have better understanding > of "correct" punctuation use (if not spelling and grammar) than most school > leavers!!! Absolutely. Taking care puts you miles ahead of the average (unfortunately for the average). I was home educated, and taught to value correctness, so I tend to speak and write more carefully than most do (people say I sound British for some reason - my accent doesn't sound Australian). That's why I tend to do a lot (note, not "alot", though the cute drawings are fun) of copyediting. > PS. It hasn't gone a miss that you are one of the core python-list > responders (and I bet this goes for most of the python-list users): your > responses, time and knowledge is appreciated... Thank you. Thanks! I'm just a guy who types fast, mainly; but I've been coding for about twenty years, and I'm always happy to help people. But this list is more for me to learn than for me to share. I've learned no end of things from these threads - it's awesome! ChrisA On Wed, May 9, 2012 at 5:07 AM, F L wrote: > Hello everyone, > > We are trying to implement our own interactive interpreter in our > application > using an embedded Python interpreter. > > I was wondering what would be the best way to retreive as text the result of > executing Python code. The text must be exactly the same as it would be in > the > standalone interpreter. Greetings! The standalone interpreter - I assume you mean the interactive prompt? It has slightly different handling of things (for instance, naked expressions being written to standard output) from the more "usual" invocation of the interpreter. For your embedded Python, probably the easiest thing to do is to not try to use interactive mode, but script mode: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals) Pass it a string of Python code and a dictionary to use for globals and locals (they can be the same dict). Then when that finishes, retrieve from that dictionary some predetermined name (eg "Output"). The Python code then needs simply to assign to Output and all will work. Another way to do it is to call a function inside the Python code, and retrieve its return value. > We are using python 2.7. > > Any suggestions? Unless you have particular need to stick to the 2.x branch, I would suggest moving to 3.3; many things are easier (especially Unicode). But both work. > Also, I'm new to mailling lists, what is the proper way to reply to someone? > Should I > reply directly to someone's email adress or is there a way to answer trough > the server. The usual convention is to reply on-list, unless it's particularly private. Many mail clients will handle this conveniently; otherwise, just manually replace the To address with the list address. As long as you use reply (rather than starting a fresh email), all posts will be correctly threaded both on the list and on the synchronized newsgroup (comp.lang.python). Chris Angelico Given this source: def do_something(val): ? ? if val: ? ? ? ? return 'a' ? ? else: ? ? ? ? return 'b' How do I get the line number of the "else:" line, using the ast module?? The grammar only includes the 'orelse' list: ? ? If(expr test, stmt* body, stmt* orelse) ...but 'orelse' is the list of statements under the 'else' token, not a node representing the token itself. I have a suspicion that this isn't possible, and shouldn't be, and the giveaway word above was "token."? Because the tokens themselves aren't part of the abstract syntax tree. Here's an interactive session showing me poking around the If node: >>> import ast >>> tree = ast.parse(''' ... if True: ...? ? pass ... else: ...? ? pass ... ''') >>> tree.body[0].orelse [<_ast.Pass object at 0x7f1301319390>] >>> tree.body[0]._fields ('test', 'body', 'orelse') >>> for i in ast.iter_child_nodes(tree.body[0]): ...? ? print i.__class__.__name__ ... Name Pass Pass Is my suspicion correct?? Or is there a way to get the line number of that 'else:'? -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Sun May 13 09:30:34 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 13 May 2012 14:30:34 +0100 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 13 May 2012 13:29, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. I don't think that'll help the OP. Python's OrderedDict keeps track of the order in which the keys were inserted into the dictionary (a bit like a list), it doesn't keep the keys sorted. > If you are looking for the best possible self-sorting structure for > searching, then perhaps you are looking for what's outlined in the > 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) > Expected Time and Linear Space[3]. I can't access it but it seems to me it's not about self sorted data structures, which is what the OP is looking for. -- Arnaud From emile at fenx.com Sun May 13 11:29:37 2012 From: emile at fenx.com (Emile van Sebille) Date: Sun, 13 May 2012 08:29:37 -0700 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On 5/12/2012 5:17 AM Jean-Daniel said... > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). ISTM the fastest way is to retrieve the list of intervals from a dict using the date as a key. You don't say how long your list of intervals is, nor how large each interval can be so I don't have enough info to determine the setup reqs, but I'd suspect that a list of tens of thousands of intervals covering ranges of days to weeks would be doable. If instead you're talking about millions of ranges covering years to decades I'd start elsewhere. Emile From rosuav at gmail.com Sun May 13 11:39:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 May 2012 01:39:42 +1000 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: > Can anyone tell me how to call and exectute C code in Python? Browse the documentation about Extending and Embedding Python, there's an extensive API. Chris Angelico From stefan_ml at behnel.de Sun May 13 11:58:32 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 17:58:32 +0200 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: David Shi, 13.05.2012 15:25: > Can anyone tell me how to call and exectute C code in Python? Take a look at Cython, a Python-like language that supports native calls to and from C/C++ code. It translates your code into very efficient C code, so the wrapping code tends to be very fast (often faster than hand written C code). http://cython.org/ Here are a couple of examples: http://docs.cython.org/src/tutorial/external.html There's also the "ctypes" package in the standard library, which is usable for simple wrapping cases that are not performance critical. Stefan From breamoreboy at yahoo.co.uk Sun May 13 13:23:45 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:23:45 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 16:39, Chris Angelico wrote: > On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >> Can anyone tell me how to call and exectute C code in Python? > > Browse the documentation about Extending and Embedding Python, there's > an extensive API. > > Chris Angelico I like your response, my first thought was to say "yes" :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun May 13 13:27:28 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:27:28 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 16:58, Stefan Behnel wrote: > David Shi, 13.05.2012 15:25: >> Can anyone tell me how to call and exectute C code in Python? > > Take a look at Cython, a Python-like language that supports native calls to > and from C/C++ code. It translates your code into very efficient C code, so > the wrapping code tends to be very fast (often faster than hand written C > code). > > http://cython.org/ > > Here are a couple of examples: > > http://docs.cython.org/src/tutorial/external.html > > There's also the "ctypes" package in the standard library, which is usable > for simple wrapping cases that are not performance critical. > > Stefan > Stefan, you appear to have a lot to do with Cython. It would be polite to mention this when replying. -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Sun May 13 13:38:55 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 19:38:55 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:23: > On 13/05/2012 16:39, Chris Angelico wrote: >> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Browse the documentation about Extending and Embedding Python, there's >> an extensive API. > > I like your response, my first thought was to say "yes" :) It has a serious learning curve all by itself, though, with a lot of major pitfalls not only for new users. It also requires C fluency, which not everyone has or wants to learn just to be able to talk to existing C code. And even when you're up to speed with all that, you will waste a substantial part of your time debugging crashes, making your code reference leak free and eventually maintaining it and porting it to different CPython versions and platforms. Time that IMHO is much better spent adding features and tuning the code for performance. Stefan From stefan_ml at behnel.de Sun May 13 13:42:35 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 19:42:35 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:27: > On 13/05/2012 16:58, Stefan Behnel wrote: >> David Shi, 13.05.2012 15:25: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Take a look at Cython, a Python-like language that supports native calls to >> and from C/C++ code. It translates your code into very efficient C code, so >> the wrapping code tends to be very fast (often faster than hand written C >> code). >> >> http://cython.org/ >> >> Here are a couple of examples: >> >> http://docs.cython.org/src/tutorial/external.html >> >> There's also the "ctypes" package in the standard library, which is usable >> for simple wrapping cases that are not performance critical. > > Stefan, you appear to have a lot to do with Cython. It would be polite to > mention this when replying. Well, my name is pretty far up both on the project home page and on PyPI, so it's not like I'm hiding this information. But sure, I'm one of the core developers and initial founders of the project. So I can assure you that I know what I'm talking about. Stefan From breamoreboy at yahoo.co.uk Sun May 13 13:44:50 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 18:44:50 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 18:38, Stefan Behnel wrote: > Mark Lawrence, 13.05.2012 19:23: >> On 13/05/2012 16:39, Chris Angelico wrote: >>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>> Can anyone tell me how to call and exectute C code in Python? >>> >>> Browse the documentation about Extending and Embedding Python, there's >>> an extensive API. >> >> I like your response, my first thought was to say "yes" :) > > It has a serious learning curve all by itself, though, with a lot of major > pitfalls not only for new users. It also requires C fluency, which not > everyone has or wants to learn just to be able to talk to existing C code. > And even when you're up to speed with all that, you will waste a > substantial part of your time debugging crashes, making your code reference > leak free and eventually maintaining it and porting it to different CPython > versions and platforms. Time that IMHO is much better spent adding features > and tuning the code for performance. > > Stefan > Haven't the faintest idea what you're on about so please explain. -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Sun May 13 14:14:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 20:14:26 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 19:44: > On 13/05/2012 18:38, Stefan Behnel wrote: >> Mark Lawrence, 13.05.2012 19:23: >>> On 13/05/2012 16:39, Chris Angelico wrote: >>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>>> Can anyone tell me how to call and exectute C code in Python? >>>> >>>> Browse the documentation about Extending and Embedding Python, there's >>>> an extensive API. >>> >>> I like your response, my first thought was to say "yes" :) >> >> It has a serious learning curve all by itself, though, with a lot of major >> pitfalls not only for new users. It also requires C fluency, which not >> everyone has or wants to learn just to be able to talk to existing C code. >> And even when you're up to speed with all that, you will waste a >> substantial part of your time debugging crashes, making your code reference >> leak free and eventually maintaining it and porting it to different CPython >> versions and platforms. Time that IMHO is much better spent adding features >> and tuning the code for performance. > > Haven't the faintest idea what you're on about so please explain. Sure. Learning curve and pitfalls: almost all C-API code I've seen from new users had at least one reference leak, usually more than one. This even happens to core developers from time to time, so I think it's reasonable to assume that pretty much all users of the C-API have produced at least one reference leak in their time as programmers and at least some do so frequently while learning to use it. I call that a common pitfall. C fluency: obviously, you need to be able to (and want to) write C if you want to make effective use of CPython's C-API from C code. Not every Python developer knows C, and why should they? Wasting time debugging crashes and making your code reference leak free: well, if you have ref-counting bugs in your code, you have to find them and fix them. First of all, you have to know they are there, which isn't always obvious, especially for leaks. The problem with ref-counting bugs is that the effects (even crashes) are not local in most cases but can happen anywhere in your program at unpredictable times, so you will spend more time on average debugging them than with other, more local bugs. Wasting time maintaining: arguably, maintaining C code requires more work than maintaining Python code. That's why we use high-level languages in the first place, isn't it? Wasting time porting: well, the C-API has subtle to major differences between CPython versions, so you not only have to learn "the" C-API, but the differences between these C-APIs, then write or adapt your code in order to make it work with different versions. Also, being able to write C code doesn't mean that that code will compile and run with different C compilers and on different platforms, so more work on that front. Spending more time adding features and tuning code instead: well, we designed Cython to relieve programmers from all of the above, so that they can focus on functionality and performance. And it's pretty good in that (you may want to read the testimonials on our project home page). Basically, the idea is that we write C so you don't have to. Is it clearer what I mean now? Stefan From breamoreboy at yahoo.co.uk Sun May 13 14:25:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 May 2012 19:25:25 +0100 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 13/05/2012 19:14, Stefan Behnel wrote: > Mark Lawrence, 13.05.2012 19:44: >> On 13/05/2012 18:38, Stefan Behnel wrote: >>> Mark Lawrence, 13.05.2012 19:23: >>>> On 13/05/2012 16:39, Chris Angelico wrote: >>>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>>>> Can anyone tell me how to call and exectute C code in Python? >>>>> >>>>> Browse the documentation about Extending and Embedding Python, there's >>>>> an extensive API. >>>> >>>> I like your response, my first thought was to say "yes" :) >>> >>> It has a serious learning curve all by itself, though, with a lot of major >>> pitfalls not only for new users. It also requires C fluency, which not >>> everyone has or wants to learn just to be able to talk to existing C code. >>> And even when you're up to speed with all that, you will waste a >>> substantial part of your time debugging crashes, making your code reference >>> leak free and eventually maintaining it and porting it to different CPython >>> versions and platforms. Time that IMHO is much better spent adding features >>> and tuning the code for performance. >> >> Haven't the faintest idea what you're on about so please explain. > > Sure. > > Learning curve and pitfalls: almost all C-API code I've seen from new users > had at least one reference leak, usually more than one. This even happens > to core developers from time to time, so I think it's reasonable to assume > that pretty much all users of the C-API have produced at least one > reference leak in their time as programmers and at least some do so > frequently while learning to use it. I call that a common pitfall. > > C fluency: obviously, you need to be able to (and want to) write C if you > want to make effective use of CPython's C-API from C code. Not every Python > developer knows C, and why should they? > > Wasting time debugging crashes and making your code reference leak free: > well, if you have ref-counting bugs in your code, you have to find them and > fix them. First of all, you have to know they are there, which isn't always > obvious, especially for leaks. The problem with ref-counting bugs is that > the effects (even crashes) are not local in most cases but can happen > anywhere in your program at unpredictable times, so you will spend more > time on average debugging them than with other, more local bugs. > > Wasting time maintaining: arguably, maintaining C code requires more work > than maintaining Python code. That's why we use high-level languages in the > first place, isn't it? > > Wasting time porting: well, the C-API has subtle to major differences > between CPython versions, so you not only have to learn "the" C-API, but > the differences between these C-APIs, then write or adapt your code in > order to make it work with different versions. Also, being able to write C > code doesn't mean that that code will compile and run with different C > compilers and on different platforms, so more work on that front. > > Spending more time adding features and tuning code instead: well, we > designed Cython to relieve programmers from all of the above, so that they > can focus on functionality and performance. And it's pretty good in that > (you may want to read the testimonials on our project home page). > Basically, the idea is that we write C so you don't have to. > > Is it clearer what I mean now? > > Stefan > No, I'm completely baffled. My response to Chris Angelico was simple and you've gone off at a complete tangent whilst writing "War and Peace". Or is it a simple matter that my newsreader is better than your newsreader? -- Cheers. Mark Lawrence. p.s. completely off topic, but will be back later, just going off to extract the urine from Manchester United fans. From stefan_ml at behnel.de Sun May 13 14:31:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 13 May 2012 20:31:26 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Mark Lawrence, 13.05.2012 20:25: > My response to Chris Angelico was simple and > you've gone off at a complete tangent whilst writing "War and Peace". Or is > it a simple matter that my newsreader is better than your newsreader? Ah, sorry. I didn't know we were discussing at *that* level. Stefan From bob.grommes at gmail.com Sun May 13 15:11:21 2012 From: bob.grommes at gmail.com (Bob Grommes) Date: Sun, 13 May 2012 12:11:21 -0700 (PDT) Subject: Hashability questions Message-ID: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library. As such, I've done the following for starters: def __str__(self): return str(type(self)) # def __eq__(self,other): # return hash(self) == hash(other) The commented-out method is what I'm questioning. As-is, I can do the following from my test harness: u = Utility() print(str(u)) print(hash(u)) u2 = Utility() print(hash(u2)) print(hash(u) == hash(u2)) However if I uncomment the above _eq_() implementation, I get the following output: Traceback (most recent call last): File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in print(hash(u)) TypeError: unhashable type: 'Utility' Process finished with exit code 1 Obviously there is some sort of default implementation of __hash__() at work and my implementation of _eq_() has somehow broken it. Can anyone explain what's going on? From tjreedy at udel.edu Sun May 13 16:10:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 May 2012 16:10:22 -0400 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 5/13/2012 9:25 AM, David Shi wrote: > Can anyone tell me how to call and exectute C code in Python? > > Regards. > > David > > ------------------------------------------------------------------------ > *From:* "python-list-request at python.org" > *To:* python-list at python.org > *Sent:* Friday, 11 May 2012, 5:35 > *Subject:* Python-list Digest, Vol 104, Issue 57 > > ----- Forwarded Message ----- [snip the remaining hundread of lines of the digist] David, please post just your message as a new thread and do not include the whole digist. -- Terry Jan Reedy From massi_srb at msn.com Sun May 13 17:14:58 2012 From: massi_srb at msn.com (Massi) Date: Sun, 13 May 2012 14:14:58 -0700 (PDT) Subject: Yet another "split string by spaces preserving single quotes" problem Message-ID: <0470db1a-5399-408d-bab4-18937bd21a08@n16g2000vbn.googlegroups.com> Hi everyone, I know this question has been asked thousands of times, but in my case I have an additional requirement to be satisfied. I need to handle substrings in the form 'string with spaces':'another string with spaces' as a single token; I mean, if I have this string: s ="This is a 'simple test':'string which' shows 'exactly my' problem" I need to split it as follow (the single quotes must be mantained in the splitted list): ["This", "is", "a", "'simple test':'string which'", "shows", "'exactly my'", "problem"] Up to know I have written some ugly code which uses regular expression: splitter = re.compile("(?=\s|^)('[^']+') | ('[^']+')(?=\s|$)") temp = [t for t in splitter.split(s) if t not in [None, '']] print temp t = [] for i, p in enumerate(temp) : for x in ([p] if (p[0] == "'" and p[1] == "'") else p.split(' ')) : t.append(x) But it does not handle "colon" case. Any hints? Thanks in advance! From adminlewis at gmail.com Sun May 13 17:25:15 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 13 May 2012 23:25:15 +0200 Subject: write a bot Message-ID: Hi, I want write a bot in python, it should explore a site, click links and extract some info. I know mechanize but I would like to know if there is something better for performance. Thanks a lot lewis. -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From cjw at ncf.ca Sun May 13 17:27:14 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 13 May 2012 17:27:14 -0400 Subject: .py to .pyc Message-ID: Is there some way to ensure that a .pyc file is produced when executing a .py file? It seems that for small files the .pyc file is not produced. Colin W. From irmen.NOSPAM at xs4all.nl Sun May 13 17:36:02 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 13 May 2012 23:36:02 +0200 Subject: .py to .pyc In-Reply-To: References: Message-ID: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> On 13-5-2012 23:27, Colin J. Williams wrote: > Is there some way to ensure that a .pyc file is produced when executing a .py file? > > It seems that for small files the .pyc file is not produced. > > Colin W. All modules no matter how small produce a .pyc file *when they are imported*. If you start a module directly though, no .pyc is produced. (Notice that Python 3 puts the pyc files in a subdirectory.) Why do you care anyway? Pyc files are an implementation detail. Irmen From cjw at ncf.ca Sun May 13 17:43:12 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 13 May 2012 17:43:12 -0400 Subject: .py to .pyc Message-ID: Is there some way to ensure that a .pyc file is produced when executing a .py file? It seems that for small files the .pyc file is not produced. Colin W. PLEASE IGNORE - I was in the wrong directory. Colin W. From rosuav at gmail.com Sun May 13 17:45:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 May 2012 07:45:13 +1000 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Mon, May 14, 2012 at 3:23 AM, Mark Lawrence wrote: > On 13/05/2012 16:39, Chris Angelico wrote: >> >> On Sun, May 13, 2012 at 11:25 PM, David Shi ?wrote: >>> >>> Can anyone tell me how to call and exectute C code in Python? >> >> >> Browse the documentation about Extending and Embedding Python, there's >> an extensive API. >> >> Chris Angelico > > I like your response, my first thought was to say "yes" :) Hehe. Never ask a geek a yes-no question, eh. Regarding Cython vs direct use of the API: I cannot in good faith recommend Cython, as I've never used it, but it very likely could be the right option. However, my answer to a vague and nonspecific question would still have been a simple pointer to documentation, whether to Cython's or to the underlying API. To the OP: Be more specific about what you're trying to do, and you'll likely get more helpful answers. :) Incidentally, one of the easiest ways to deal with refcounting imho is to write a thin C++ layer around the PyObject* for locally owned references. Of course, that works only if you're writing C++ code, but it did save me a lot of hassle when I was embedding Python in C++. ChrisA From python.list at tim.thechases.com Sun May 13 18:00:49 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 13 May 2012 17:00:49 -0500 Subject: .py to .pyc In-Reply-To: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> Message-ID: <4FB02F11.9060406@tim.thechases.com> On 05/13/12 16:36, Irmen de Jong wrote: > Why do you care anyway? Pyc files are an implementation detail. I could see wanting to pre-compile .pyc files for performance if they'll then be stored on a read-only medium (a CD/DVD, a RO network share, or a RO drive partition all come to mind). You can read up on forcing the compile at http://effbot.org/zone/python-compile.htm#compiling-python-modules -tkc From jeanpierreda at gmail.com Sun May 13 19:19:56 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 13 May 2012 19:19:56 -0400 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On Sun, May 13, 2012 at 11:58 AM, Stefan Behnel wrote: > David Shi, 13.05.2012 15:25: >> Can anyone tell me how to call and exectute C code in Python? > > Take a look at Cython, a Python-like language that supports native calls to > and from C/C++ code. It translates your code into very efficient C code, so > the wrapping code tends to be very fast (often faster than hand written C > code). More than just speed -- it's, IME, way easier to use and debug than ctypes (thanks to having incredible gdb support and compiler warnings). I swear, this is black magic: http://docs.cython.org/src/userguide/debugging.html Now if only my editor would bold those "cdef"s... :) -- Devin From steve+comp.lang.python at pearwood.info Sun May 13 20:03:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 May 2012 00:03:54 GMT Subject: .py to .pyc References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> Message-ID: <4fb04bea$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 May 2012 23:36:02 +0200, Irmen de Jong wrote: > On 13-5-2012 23:27, Colin J. Williams wrote: >> Is there some way to ensure that a .pyc file is produced when executing >> a .py file? >> >> It seems that for small files the .pyc file is not produced. >> >> Colin W. > > All modules no matter how small produce a .pyc file *when they are > imported*. If you start a module directly though, no .pyc is produced. > (Notice that Python 3 puts the pyc files in a subdirectory.) That's only the case for Python 3.2 and higher, not 3.1. You can also use this: python -m compileall to produce .pyc files without waiting for them to be imported. -- Steven From xxxxxxxx at xxxxxx.xxx Sun May 13 20:50:23 2012 From: xxxxxxxx at xxxxxx.xxx (TommyVee) Date: Sun, 13 May 2012 20:50:23 -0400 Subject: Need to get Tags and Values from Dom Message-ID: <4fb056d7$0$370$607ed4bc@cv.net> I have a very simple XML document that I need to "walk", and I'm using xml.dom.minidom. No attributes, just lots of nested tags and associated values. All I'm looking to do is iterate through each of the highest sibling nodes, check what the tag is, and process its value accordingly. If a node has children, same thing - iterate through the nodes, check the tags and process the values accordingly. I see where each node object has a "childNodes" attribute, so I can drill down the tree. But what are the node attributes which indicate Tag and Value? I thought it would have been nodeName and nodeValue, but that doesn't seem to be. Does anyone know? Thanks in advance, TommyVee From emile at fenx.com Sun May 13 21:06:33 2012 From: emile at fenx.com (Emile van Sebille) Date: Sun, 13 May 2012 18:06:33 -0700 Subject: write a bot In-Reply-To: References: Message-ID: On 5/13/2012 2:25 PM admin lewis said... > Hi, > I want write a bot in python, it should explore a site, click links > and extract some info. I know mechanize but I would like to know if > there is something better for performance. Have you looked into Scrapy? http://scrapy.org Emile From adminlewis at gmail.com Mon May 14 00:29:05 2012 From: adminlewis at gmail.com (admin lewis) Date: Mon, 14 May 2012 06:29:05 +0200 Subject: write a bot In-Reply-To: References: Message-ID: 2012/5/14 Emile van Sebille : > On 5/13/2012 2:25 PM admin lewis said... > >> Hi, >> I want write a bot in python, it should explore a site, click links >> and extract some info. I know mechanize but I would like to know if >> there is something better for performance. > > > Have you looked into Scrapy? ?http://scrapy.org No, and it looks exactly what I'm looking for. thanks :) > > Emile > luigi -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From kushal.kumaran+python at gmail.com Mon May 14 00:42:57 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 14 May 2012 10:12:57 +0530 Subject: Looking for video/slides from PyCon 2011... In-Reply-To: References: Message-ID: On Fri, May 11, 2012 at 5:42 AM, Monte Milanuk wrote: > ...specifically the two lectures on creating GUI applications with Python + > QT > > http://us.pycon.org/2011/schedule/presentations/207/ > > Various searches on the 'Net don't seem to be turning up much... kinda > curious as to why? > > Anyone here know? > Is it one of the videos at http://blip.tv/pycon-us-videos-2009-2010-2011 -- regards, kushal From kushal.kumaran+python at gmail.com Mon May 14 00:44:19 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 14 May 2012 10:14:19 +0530 Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb056d7$0$370$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> Message-ID: On Mon, May 14, 2012 at 6:20 AM, TommyVee wrote: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. ?No attributes, just lots of nested tags and associated > values. ?All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. ?If > a node has children, same thing - iterate through the nodes, check the tags > and process the values accordingly. ?I see where each node object has a > "childNodes" attribute, so I can drill down the tree. ?But what are the node > attributes which indicate Tag and Value? ?I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. ?Does anyone know? > A sample of the document you are trying to parse will help people answer. -- regards, kushal From stefan_ml at behnel.de Mon May 14 02:50:31 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 14 May 2012 08:50:31 +0200 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: Devin Jeanpierre, 14.05.2012 01:19: > Now if only my editor would bold those "cdef"s... :) Cython syntax support in editors is definitely not ubiquitous, but it's getting more and more widespread, so you may be lucky at some point (or find a way to add it yourself). Pygments also does a pretty good job on it for documentation and talk slides, but what I find really cool is that even major IDEs have started to pick it up, namely WingIDE, PyCharm (Jetbrains) and PyDev (Eclipse). From the PyCharm developers, I heard that it was one of the most heavily requested features for them, and they got it pretty much right (didn't try the others). Stefan From stefan_ml at behnel.de Mon May 14 02:54:26 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 14 May 2012 08:54:26 +0200 Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb056d7$0$370$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> Message-ID: TommyVee, 14.05.2012 02:50: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. No attributes, just lots of nested tags and associated > values. All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. > If a node has children, same thing - iterate through the nodes, check the > tags and process the values accordingly. I see where each node object has > a "childNodes" attribute, so I can drill down the tree. But what are the > node attributes which indicate Tag and Value? I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. Does anyone know? Use the xml.etree.ElementTree module instead. It makes this kind of work really easy, e.g.: import xml.etree.cElementTree as ET # using fast C accelerator module root = ET.parse("afile.xml").getroot() for child in root: if child.tag == 'abc': print("abc tag found") else: print("other tag found") There's also an incremental iterparse() function, in case your documents are large. Stefan From mailinglists at xgm.de Mon May 14 05:15:57 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Mon, 14 May 2012 11:15:57 +0200 Subject: Remove root handler from logger Message-ID: <1694679.NInCbTCQzc@horus> Hello, I configure my logging on application startup like that: logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile) ch = logging.StreamHandler() ch.setFormatter(logging.Formatter(FORMAT)) logging.getLogger().addHandler(ch) In one module of my application I want a logger that does not log to logfile but to another file. How can I get a logger that is either plain (no handlers attached) or remove a handler? The handlers that are derived from the root logger are not shown in handlers: (Pdb) logger1.handlers [] (Pdb) logging.getLogger().handlers [, ] How can I remove the FileHandler and StreamHandler from logger1 without affecting the root logger? logger1.removeHandler() does not work since there are no handlers on logger1. Thanks, Florian From andreas.tawn at ubisoft.com Mon May 14 05:16:40 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Mon, 14 May 2012 11:16:40 +0200 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A71AA746E2@PDC-MAIL-CMS01.ubisoft.org> > p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal interest (or > perhaps both)? We do use Python a fair bit, mostly for build systems and data mining, but also because it's the built-in script language for Motionbuilder. From jeanmichel at sequans.com Mon May 14 05:34:50 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 14 May 2012 11:34:50 +0200 Subject: Remove root handler from logger In-Reply-To: <1694679.NInCbTCQzc@horus> References: <1694679.NInCbTCQzc@horus> Message-ID: <4FB0D1BA.2000002@sequans.com> Florian Lindner wrote: > Hello, > > I configure my logging on application startup like that: > > logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile) > ch = logging.StreamHandler() > ch.setFormatter(logging.Formatter(FORMAT)) > logging.getLogger().addHandler(ch) > > In one module of my application I want a logger that does not log to logfile > but to another file. How can I get a logger that is either plain (no handlers > attached) or remove a handler? > > The handlers that are derived from the root logger are not shown in handlers: > > (Pdb) logger1.handlers > [] > (Pdb) logging.getLogger().handlers > [, at 0x7f3e8f731450>] > > How can I remove the FileHandler and StreamHandler from logger1 without > affecting the root logger? > > logger1.removeHandler() does not work since there are no handlers on logger1. > > Thanks, > > Florian > The usual pattern is that the root logger is handling all the events. Sub loggers are only raising log events. Try to stick with this most of the time. However in your case you need a sub logger to handle its logs in a different way. For that you have to add a handler to your sub logger and tells it to not sent log event to its parent. If I remeber correctly, this is done by setting the 'propagate' attribute of you logger to 0. That could look like (not tested): import logging root = logging.getLogger() foo = logging.getLogger('foo') root.addHandler(logging.StreamHandler()) foo.addHandler(logging.FileHandler('foo.log')) foo.propagate = 0 Cheers, JM From jameskhedley at gmail.com Mon May 14 09:19:35 2012 From: jameskhedley at gmail.com (james hedley) Date: Mon, 14 May 2012 06:19:35 -0700 (PDT) Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb056d7$0$370$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> Message-ID: <11852803.89.1337001575700.JavaMail.geo-discussion-forums@vbmd2> On Monday, 14 May 2012 01:50:23 UTC+1, TommyVee wrote: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. No attributes, just lots of nested tags and associated > values. All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. If > a node has children, same thing - iterate through the nodes, check the tags > and process the values accordingly. I see where each node object has a > "childNodes" attribute, so I can drill down the tree. But what are the node > attributes which indicate Tag and Value? I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. Does anyone know? > > Thanks in advance, TommyVee Ah maybe you're confused about how text nodes work in minidom. Every element will have a nodeName attribute (not callable) but if you try el.nodeValue on a text node you get None. That's because the text is represented by a child node with nodeName '#text', so you want (el.nodeName, el.firstChild.nodeValue). General tips - try the docs: http://docs.python.org/library/xml.dom.minidom.html and also use dir() a lot on objects when you're learning a new api. Hope that helps. Disclaimer: haven't used minidom in anger for some time. From torriem at gmail.com Mon May 14 10:36:03 2012 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 May 2012 08:36:03 -0600 Subject: How to call and execute C code in Python? In-Reply-To: References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: <4FB11853.7060604@gmail.com> On 05/13/2012 11:27 AM, Mark Lawrence wrote: > Stefan, you appear to have a lot to do with Cython. It would be polite > to mention this when replying. > Why? Do you think this is some sort of weird conflict of interest? As anyone who follows this list for several years would know, Cython is a very tool that more than a few python developers seem to be using to practically extend python in C. From rosuav at gmail.com Mon May 14 10:41:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 00:41:24 +1000 Subject: How to call and execute C code in Python? In-Reply-To: <4FB11853.7060604@gmail.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> <4FB11853.7060604@gmail.com> Message-ID: On Tue, May 15, 2012 at 12:36 AM, Michael Torrie wrote: > On 05/13/2012 11:27 AM, Mark Lawrence wrote: >> Stefan, you appear to have a lot to do with Cython. It would be polite >> to mention this when replying. > > Why? ?Do you think this is some sort of weird conflict of interest? ?As > anyone who follows this list for several years would know, Cython is a > very tool that more than a few python developers seem to be using to > practically extend python in C. Or mention it as a mark of authority. If I talk about Cython, it's with no authority, as I've never used it. When a core Cython developer mentions it, we can expect the information to be reliable. ChrisA From ssawyer at stephensawyer.com Mon May 14 12:01:49 2012 From: ssawyer at stephensawyer.com (Steve Sawyer) Date: Mon, 14 May 2012 12:01:49 -0400 Subject: Extracting DB schema (newbie Q) Message-ID: Brand-new to Python (that's a warning, folks) Trying to write a routine to import a CSV file into a SQL Server table. To ensure that I convert the data from the CSV appropriately, I"m executing a query that gives me the schema (data column names, data types and sizes) from the target table. What I think I want to do is to construct a dictionary using the column names as the index value, and a list containing the various attributes (data type, lenghth, precision). If this is NOT a good approach (or if there is a better approach), please issue a dope-slap, ignore the rest of this post and set me straight. If this is a good approach, I ran into a problem populating the dictionary as I couldn't seem to figure out how to make the update() method work by passing the name property of the row object; I kept getting a "keyword can't be an expression" error. What I was able to make work was to construct the command as a string and run exec(), but seems there shoudl be a more direct way of updating the dictionary. TIA. From rosuav at gmail.com Mon May 14 12:11:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 02:11:06 +1000 Subject: Extracting DB schema (newbie Q) In-Reply-To: References: Message-ID: On Tue, May 15, 2012 at 2:01 AM, Steve Sawyer wrote: > Brand-new to Python (that's a warning, folks) It's one we're familiar with :) Welcome! > Trying to write a routine to import a CSV file into a SQL Server > table. To ensure that I convert the data from the CSV appropriately, > I"m executing a query that gives me the schema (data column names, > data types and sizes) from the target table. > > What I think I want to do is to construct a dictionary using the > column names as the index value, and a list containing the various > attributes (data type, lenghth, precision). That seems reasonable; I might consider a namedtuple or perhaps another dictionary, but what you have is usable. > If this is a good approach, I ran into a problem populating the > dictionary as I couldn't seem to figure out how to make the update() > method work by passing the name property of the row object; I kept > getting a "keyword can't be an expression" error. Not sure what you're attempting to do; you'd do well to post your code (preferably a minimal test-case) and the exact traceback. But my guess is that you're creating a list and then trying to use the update() method. If that's so, you can simplify it a lot: columninfo[columnname] = [type, length, precision] > What I was able to make work was to construct the command as a string > and run exec(), but seems there shoudl be a more > direct way of updating the dictionary. Agreed, you shouldn't normally need to exec to achieve what you want! But post your failing code and we'll be better able to help. Chris Angelico From jameskhedley at gmail.com Mon May 14 12:28:06 2012 From: jameskhedley at gmail.com (james hedley) Date: Mon, 14 May 2012 09:28:06 -0700 (PDT) Subject: Extracting DB schema (newbie Q) In-Reply-To: References: Message-ID: <28618981.415.1337012886784.JavaMail.geo-discussion-forums@vbez18> On Monday, 14 May 2012 17:01:49 UTC+1, Steve Sawyer wrote: > Brand-new to Python (that's a warning, folks) > > Trying to write a routine to import a CSV file into a SQL Server > table. To ensure that I convert the data from the CSV appropriately, > I"m executing a query that gives me the schema (data column names, > data types and sizes) from the target table. > > What I think I want to do is to construct a dictionary using the > column names as the index value, and a list containing the various > attributes (data type, lenghth, precision). > > If this is NOT a good approach (or if there is a better approach), > please issue a dope-slap, ignore the rest of this post and set me > straight. > > If this is a good approach, I ran into a problem populating the > dictionary as I couldn't seem to figure out how to make the update() > method work by passing the name property of the row object; I kept > getting a "keyword can't be an expression" error. > > What I was able to make work was to construct the command as a string > and run exec( > ), but seems there shoudl be a more > direct way of updating the dictionary. > > TIA. Could you provide some demo code? Something minimal but runnable, which results in the error you're getting would be best. From jeanmichel at sequans.com Mon May 14 12:36:15 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 14 May 2012 18:36:15 +0200 Subject: Extracting DB schema (newbie Q) In-Reply-To: References: Message-ID: <4FB1347F.90203@sequans.com> Steve Sawyer wrote: > Brand-new to Python (that's a warning, folks) > > Trying to write a routine to import a CSV file into a SQL Server > table. To ensure that I convert the data from the CSV appropriately, > I"m executing a query that gives me the schema (data column names, > data types and sizes) from the target table. > > What I think I want to do is to construct a dictionary using the > column names as the index value, and a list containing the various > attributes (data type, lenghth, precision). > > If this is NOT a good approach (or if there is a better approach), > please issue a dope-slap, ignore the rest of this post and set me > straight. > > If this is a good approach, I ran into a problem populating the > dictionary as I couldn't seem to figure out how to make the update() > method work by passing the name property of the row object; I kept > getting a "keyword can't be an expression" error. > > What I was able to make work was to construct the command as a string > and run exec(), but seems there shoudl be a more > direct way of updating the dictionary. > > TIA. > Please post the exact traceback and the code associated with it. Using csv.DictReader should allow you to do this in 3 lines, something like: reader = csv.DictReader('acsvfile.csv') myDict.update(reader) uploadDictToDb(myDict) From gordon at panix.com Mon May 14 13:05:17 2012 From: gordon at panix.com (John Gordon) Date: Mon, 14 May 2012 17:05:17 +0000 (UTC) Subject: Extracting DB schema (newbie Q) References: Message-ID: In Steve Sawyer writes: > What I think I want to do is to construct a dictionary using the > column names as the index value, and a list containing the various > attributes (data type, lenghth, precision). If you're using just the column name as the dictionary key, make sure there are no duplicate column names among all your tables. > If this is a good approach, I ran into a problem populating the > dictionary as I couldn't seem to figure out how to make the update() > method work by passing the name property of the row object; I kept > getting a "keyword can't be an expression" error. The general syntax for assigning to a dictionary is: my_dictionary[key] = value What are you trying that isn't working? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From zahlman at gmail.com Mon May 14 13:15:28 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Mon, 14 May 2012 13:15:28 -0400 Subject: Dealing with the __str__ method in classes with lots of attributes In-Reply-To: <4FAE6135.7070500@stoneleaf.us> References: <581D4160B04DF541A763BB8BB60E8CC6A6EC5973CF@PDC-MAIL-CMS01.ubisoft.org> <4FAE6135.7070500@stoneleaf.us> Message-ID: On Sat, May 12, 2012 at 9:10 AM, Ethan Furman wrote: > > Firstly, __slots__ is a tuple. I object: conceptually, the "slots" of a class are set in stone, but the `__slots__` attribute of a class object is just an attribute, and any iterable (as long as it yields valid identifier names) can be used when the `__slots__` magic is invoked in the class definition. FWIW, all the ordinary examples I've seen use a list, although a tuple arguably makes more sense. Observe: >>> class Evil(object): ... __slots__ = ('a%s' % a for a in range(10)) ... >>> Evil().__slots__ at 0x01EDFAA8> >>> list(Evil().__slots__) [] # the generator was consumed by the metaclass during class creation >>> dir(Evil()) ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__has h__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__rep r__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', ' a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9'] # yep, the expected attributes are there, and can be set. >>> Evil.__slots__ = 42 # no exception > > Secondly, this is bad advice. ?__slots__ is there as a memory optimization > for classes that will have thousands of instances and do not need the > ability to have arbitrary attributes added after creation. I did explicitly indicate the latter part. > ?__slots__ is an > advanced feature, and as such is easier to get wrong. ?It is *not* there to > make __str__ nor __repr__ easier to write. Of course not, but it seems to me that it serves well in this particular case. >>>> class Test1(object): > ... ? ? __slots__ = ('item', 'size') > ... ? ? desc = 'class-only attribute' > ... > >>>> t1 = Test1() >>>> t1.desc = 'read-only attribute' ? ? ?# fails because 'desc' is > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # not in __slots__ Well, sure; expecting to modify a class attribute via an instance is a bit naughty anyway. >>>> print t1.item ? ? ? ? ? ? ? ? ? ? ? ?# fails because 'item' was > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # not set Well, yes, that's what `__init__` is for; the same line would fail without `__slots__` and for the same reason. Arguably, this is a gotcha for people coming from C-like languages who are expecting `__slots__` to make the class behave as if it had a defined layout, but there isn't actually any more work involved here. >>>> class Test2(Test1): > ... ? ? def __init__(self, price): > ... ? ? ? ? self.price = price > ... >>>> t2 = Test2(7.99) ? ? ? ? ?# __slots__ not defined in > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# subclass, optimizations lost Well, yes, but we aren't using it for the optimizations here! But I see your point; explicit is better than implicit, and our explicit purpose here is to have an explicit list of the attributes we're interested in for __str__/__repr__ - which could be any other named class attribute, without magic associated with it. That said, `__slots__` is as close to a canonical listing of instance-specific attributes as we have (`dir()` clearly won't cut it, as we don't want methods or other class-specific stuff). -- ~Zahlman {:> From zahlman at gmail.com Mon May 14 13:22:31 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Mon, 14 May 2012 13:22:31 -0400 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On Sat, May 12, 2012 at 10:18 AM, Jean-Daniel wrote: >> Since you say "intervals" in plural here, I assume that they can overlap? > > Yes, > > For instance, there are the following intervals : > [[1, 10], > [4, 7], > [6, 15], > [11, 17]] > > asking for the intervals including ?5, the returned value should be > > [[1, 10], > [4, 7]] > > The idea here to make it fast is to have done some preprocessing at > insertion time, so that not all intervals are processed at query time. > How about this: Set up a list of lists of intervals. Insert the intervals one at a time thus: for each existing list, check if the new interval overlaps any existing intervals - you can use the `bisect` module to check for where the new interval would "fit". If there is no overlap, insert it into that list at the discovered "insertion point"; otherwise move on to the next list. If no lists are found that can hold the new interval, append a new list for it. Then at query time, you just iterate over the lists, using `bisect` again to find the unique interval (if any) in each list that spans the specified point in time. -- ~Zahlman {:> From lists at cheimes.de Mon May 14 13:48:29 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 14 May 2012 19:48:29 +0200 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: Am 12.05.2012 14:17, schrieb Jean-Daniel: > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). > > Do you know the best way to do this in Python with the stdlib? > > A variant of the red black trees can do the job quickly [1], is this a > good enough use case to discuss the inclusion of a red black tree > implementation in the stdlib? A more general data structure for spatial search are R-Trees [1]. In few words R-Tree optimize indexing and containment tests in n dimensions. Christian [1] http://en.wikipedia.org/wiki/R-tree From zahlman at gmail.com Mon May 14 13:52:32 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Mon, 14 May 2012 13:52:32 -0400 Subject: dynamically selecting a class to instantiate based on the object attributes. In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 7:02 AM, J. Mwebaze wrote: > > During object instantiaton, i would like to use ?the specific class, that > corresponds to the version of the class that was used to create the object. I don't understand; "the version of the class that was used to create" **what** object? We're still in the middle of object instantiation! Where is the version information coming from? Are you perhaps trying to do something with (un)serialization? Could you show any relevant code at all? -- ~Zahlman {:> From bv8bv8bv8 at gmail.com Mon May 14 13:52:35 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Mon, 14 May 2012 10:52:35 -0700 (PDT) Subject: ISLAM AND WOMEN Message-ID: ISLAM AND WOMEN In Islam, men and women are different from each other and each has their respective roles. Honoring and respecting women in Islam is a sign of a good, wholesome character and an unadulterated nature. The Messenger of Islam, Muhammad said: "The best of you are the best of you towards their wives." (Tirmidhi) The woman is also the first person to whom a man must act righteously, maintain ties with, and treat well. When a man asked the Messenger of Islam, Muhammad to whom he should show the best companionship, he replied: "Your mother." He said, "Then who?" He said, "Your mother." He said, "Then who?" He said, "Your mother." He said, "Then who?" He said, "Your father." (Bukhari) The Messenger of Islam, Muhammad said: "Women are the twin halves of men." (Abu Dawud) 1. Women are equal to men in their humanity. They are not the source of sin nor are they the reason Adam was expelled from Jannah (Heavenly Gardens). 2. Women are equal to men in their individuality. They neither lose their names nor the names of their family upon marriage. They do not fade away and blend into the identity of men. 3. Women are equal to men in regards to reward and punishment in this life as well as the next. 4. Women are equal to men in that Islam seeks to maintain and uphold their honor and chastity. 5. Women are equal to men in that they have a right to inheritance, as do men. 6. Women are equal to men in that they have full right to do as they please with their wealth. 7. Women are equal to men in regards to the obligation of shouldering the responsibility of social reform. 8. Women are equal to men in their right to receive an education and proper upbringing. 9. Woman and man have an equal share of rights in matters pertaining to good rearing, proper teaching and caring. Islam assures that when applying these rights of women they would be put at a higher position. 10. ? Women have the right to provisions from her husband for all her needs and more. If she?s not married then she has the right to provisions from her brother(s). If she doesn?t have brothers then the closest of kin to her. 11. ? A woman has the right to keep all of her own money. She is not responsible for maintaining the family financially. 12. ? Women have the right to get sexual satisfaction from her husband. 13. ? A woman has the right to get custody of her children in case of divorce unless she is unable to raise them for a valid reason. 14. ? Women have the right to re-marry after divorce or after becoming a widow. The Prophet of Allah said: "Whoever has three daughters or three sisters, and fears Allah in their guardianship, will be together with me in Paradise like this." He indicated with his index and second fingers. (Ahmad & others ) For more information about Islam and women please click here http://www.womeninislam.ws/en/ From anthra.norell at bluewin.ch Mon May 14 14:02:23 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Mon, 14 May 2012 20:02:23 +0200 Subject: tkinter: is there a way to switch a widget's master? Message-ID: <1337018543.2312.45.camel@hatchbox-one> Hi there, I would like to prepare a bunch of info text widgets to be displayed in Toplevel windows at the user's command (when ever he needs directions). I know how to remove and restore widgets without destroying them in between. The problem with a Toplevel is that it is a master that comes and goes, of a Text that is supposed to stay as long as the program runs. (Building the Text involves reading a file and compiling lots of edited-in formatting symbols. Repeating this every time the Toplevel is called seems rather inelegant.) toplevel = Toplevel (root, ...) info_text = MyText (toplevel, ...) info_text.pack () # No problem, except for the inelegant remake of the text on every call. I tried: text = MyText (root, ...) # Later, on user demand toplevel = Toplevel (root, ...) info_text.lower (belowThis = toplevel) info_text.pack () This doesn't work! toplevel is empty and text appears in the root window. Is there a way to switch a widget's master? Thanks for comments Frederic From ian.g.kelly at gmail.com Mon May 14 14:30:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 May 2012 12:30:43 -0600 Subject: dynamically selecting a class to instantiate based on the object attributes. In-Reply-To: References: Message-ID: On Wed, May 9, 2012 at 5:02 AM, J. Mwebaze wrote: > > I have a ?bunch of objects of the same type. Each object has a version > attribute and this refers to source code that was used to make the object. > SouceCode is maintained in separate files. eg. > myclass_01.py,?myclass_02.py,?myclass_03.py,?myclass_04.py .. > > During object instantiaton, i would like to use ?the specific class, that > corresponds to the version of the class that was used to create the object. > However i cant know the specific "myclass_??.py" before i read the version > attribute of the object. > > Seems like a situation where i have to partially instantiate the object to > read the version attribute, and after that continue with?instantiaton?with > the specific version of the version.. > > Is this doeable? Why can't you read the version before creating the object? That said, the class's __new__ method can customize what instance is actually constructed. Override it to take an optional version argument (or whatever else you need to pass in to extract the version from), and use it to select the type that is actually returned. If version is omitted, then you would just create the most recent version as normal. For example, you might put this in a shared base class: def __new__(cls, version=None, *args, **kw): class_dict = {1: myclass_1, 2: myclass_2, 3: myclass_3} cls = class_dict.get(version, cls) return object.__new__(cls) If you're serializing the objects using pickle version 2 or higher, then you can use a __getnewargs__ method to have it pass the version argument to __new__ during deserialization: def __getnewargs__(self): return (self.version,) Alternatively, it is possible to change the class of an object after it has been created: def __init__(self, version=None): class_dict = {1: myclass_1, 2: myclass_2, 3: myclass_3} if version is not None: self.__class__ = class_dict[version] You should only do this if you really know what you're doing, as it can potentially get your objects into weird states that are hard to debug. Cheers, Ian From ssawyer at stephensawyer.com Mon May 14 15:09:50 2012 From: ssawyer at stephensawyer.com (Steve Sawyer) Date: Mon, 14 May 2012 15:09:50 -0400 Subject: Extracting DB schema (newbie Q) References: Message-ID: Thanks, John. >What are you trying that isn't working? Typical newbie trick - trying to make things more complicated than they are. I didn't realize that syntax would establish the key/value pairs of the dictionary - I thought that would only allow you to establish the value to correspond to a specified (and pre-exiting) key, not establish the key as well. I was establishing the dictionary then trying to use dict.update() to append key/value pairs. Thanks - now, given my query that returns the table structure, this works fine: table_dict = {} table_specs = cursor.execute(query_string) for row in table_specs: row_dict = {} row_dict['type'] = row.DataType row_dict['size'] = row.Length table_dict[row.name] = row_dict table_dict['path']['type'] #-> 'nvarchar' table_dict['path']['size'] # -> 200 table_dict['Artist']['size'] #-> 50 Is this (nesting dictionaries) a good way to store multiple attributes associated with a single key value? On Mon, 14 May 2012 17:05:17 +0000 (UTC), John Gordon wrote: >In Steve Sawyer writes: > >> What I think I want to do is to construct a dictionary using the >> column names as the index value, and a list containing the various >> attributes (data type, lenghth, precision). > >If you're using just the column name as the dictionary key, make sure >there are no duplicate column names among all your tables. > >> If this is a good approach, I ran into a problem populating the >> dictionary as I couldn't seem to figure out how to make the update() >> method work by passing the name property of the row object; I kept >> getting a "keyword can't be an expression" error. > >The general syntax for assigning to a dictionary is: > > my_dictionary[key] = value > >What are you trying that isn't working? --Steve-- From rosuav at gmail.com Mon May 14 17:49:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 07:49:47 +1000 Subject: Extracting DB schema (newbie Q) In-Reply-To: References: Message-ID: On Tue, May 15, 2012 at 5:09 AM, Steve Sawyer wrote: > Thanks - now, given my query that returns the table structure, this > works fine: > > table_dict = {} > table_specs = cursor.execute(query_string) > for row in table_specs: > ? ? ? ?row_dict = {} > ? ? ? ?row_dict['type'] = row.DataType > ? ? ? ?row_dict['size'] = row.Length > ? ? ? ?table_dict[row.name] = row_dict > > table_dict['path']['type'] #-> 'nvarchar' > table_dict['path']['size'] # -> 200 > table_dict['Artist']['size'] #-> 50 > > Is this (nesting dictionaries) a good way to store multiple attributes > associated with a single key value? There's lots of options. The dictionary works; or you could create a class for your record - also, check out namedtuple from the collections module, which is a shortcut to the second option. # Option 2 class Field: def __init__(self,datatype,length): self.datatype=datatype self.length=length # Option 3: import collections Field=collections.namedtuple('Field',('datatype','length')) table_dict = {} table_specs = cursor.execute(query_string) for row in table_specs: # Option 1: no need to start with an empty dictionary and then populate it table_dict[row.name] = {'type': row.DataType, 'size': row.Length} # Option 2 or 3: your own record type, or a namedtuple table_dict[row.name] = Field(row.DataType,row.Length) # Option 1: table_dict['path']['type'] #-> 'nvarchar' table_dict['path']['size'] # -> 200 table_dict['Artist']['size'] #-> 50 # Option 2 or 3 table_dict['path'].datatype #-> 'nvarchar' table_dict['path'].size # -> 200 table_dict['Artist'].size #-> 50 You'll notice that I've used 'datatype' rather than 'type' - the latter would work, but since 'type' has other meaning (it's the class that all classes subclass, if that makes sense), I like to avoid using it. The choice between these three options comes down to style, so pick whichever one "feels best" to you. ChrisA From breamoreboy at yahoo.co.uk Mon May 14 18:35:36 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 May 2012 23:35:36 +0100 Subject: which book? In-Reply-To: <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> <25862276.3906.1336643935781.JavaMail.geo-discussion-forums@ynei13> Message-ID: On 10/05/2012 10:58, d.poreh at gmail.com wrote: > On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote: >>> I am going to learn python for some plot issues. which book or sources, do you recommend please? >> The tutorial is pretty good if you already know how to program. >> I also heard a lot of good things on "Python Essential Reference". > > Thanks. > Could you please pass the line for tutorial? google for python tutorial - IIRC first hit is to the tutorial for version 2.7.3 -- Cheers. Mark Lawrence. From benjamin.kaplan at case.edu Mon May 14 19:19:19 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 14 May 2012 19:19:19 -0400 Subject: %d not working in re at Python 2.7? In-Reply-To: References: Message-ID: On May 14, 2012 7:06 PM, "vacu" wrote: > > I am frustrated to see %d not working in my Python 2.7 re.search, like > this example: > > >>> (re.search('%d', "asdfdsf78asdfdf")).group(0) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'group' > > > \d works fine: > > >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) > '78' > > > And google search ignores % in their search, so I failed to find > answer from Python mailing list or web, > Do you have any idea what's problem here? > > Thanks a head > Vacu > -- There's no problem at all. This is re.search, not scanf. They aren't supposed to behave the same. In fact, the docs specifically describe how to simulate scanf using re because python doesn't have a scanf function. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon May 14 19:20:27 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 14 May 2012 18:20:27 -0500 Subject: %d not working in re at Python 2.7? In-Reply-To: References: Message-ID: <4FB1933B.6060403@tim.thechases.com> On 05/11/12 13:58, vacu wrote: > I am frustrated to see %d not working in my Python 2.7 re.search, like > this example: > >>>> (re.search('%d', "asdfdsf78asdfdf")).group(0) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'group' > > > \d works fine: > >>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) > '78' > > Do you have any idea what's problem here? Because the regexp module doesn't support using "%d" in this way? I'd be curious is you can point to Python documentation to the contrary. You know what the problem is, you didn't spell it r"\d+" so I'm not sure why you're asking. I've tested as far back as Python2.3 and "%d" hasn't worked like you seem to expect it to in any of those versions. As an aside, use raw strings (as in r"\d+" with the leading "r") instead of regular strings to ensure escaping applies as you expect it to. -tkc From breamoreboy at yahoo.co.uk Mon May 14 19:23:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 15 May 2012 00:23:07 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <15657786.192.1336806601102.JavaMail.geo-discussion-forums@yngo1> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <8296697.199.1336637207425.JavaMail.geo-discussion-forums@vbx14> <15657786.192.1336806601102.JavaMail.geo-discussion-forums@yngo1> Message-ID: On 12/05/2012 08:10, anthony at xtfx.me wrote: > On Thursday, May 10, 2012 3:06:47 AM UTC-5, james hedley wrote: My nose and my stomach give me a very strong feeling that something is very, very wrong with the pyjamas project. I've personally never used it, but given the adverse publicity I wouldn't touch it with a barge pole. -- Cheers. Mark Lawrence. From ckaynor at zindagigames.com Mon May 14 19:38:26 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 14 May 2012 16:38:26 -0700 Subject: Hashability questions In-Reply-To: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: On Sun, May 13, 2012 at 12:11 PM, Bob Grommes wrote: > Noob alert: writing my first Python class library. > > I have a straightforward class called Utility that lives in Utility.py. > > I'm trying to get a handle on best practices for fleshing out a library. ?As such, I've done the following for starters: > > ?def __str__(self): > ? ?return str(type(self)) > > # ?def __eq__(self,other): > # ? ?return hash(self) == hash(other) > > The commented-out method is what I'm questioning. ?As-is, I can do the following from my test harness: > > u = Utility() > print(str(u)) > print(hash(u)) > u2 = Utility() > print(hash(u2)) > print(hash(u) == hash(u2)) > > However if I uncomment the above _eq_() implementation, I get the following output: > > > Traceback (most recent call last): > ?File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in > ? ?print(hash(u)) > TypeError: unhashable type: 'Utility' > > Process finished with exit code 1 > > Obviously there is some sort of default implementation of __hash__() at work and my implementation of _eq_() has somehow broken it. ?Can anyone explain what's going on? In Python, the default implementations of __hash__ and __eq__ are set to return the id of the object. Thus, an object by default compares equal only to itself, and it hashes the same everytime. In Python3, if you override __eq__, the default __hash__ is removed, however it can also be overridden to provide better hashing support. In Python2, the default removal of __hash__ did not exist, which could lead to stubble bugs where a class would override __eq__ by leave __hash__ as the default implementation. Generally, the default __eq__ and __hash__ functions provide the correct results, and are nice and convenient to have. From there, the case where __eq__ is overridden is the next most common, and if it is overridden, the default __hash__ is almost never correct, and thus the object should either not be hashable (the default in Python3) or should also be overriden to produce the correct results. The rule is that, if two objects return different results from __hash__, they should never compare equal. The opposite rule also holds true: if two objects compare equal, they should return the same value from __hash__. See http://docs.python.org/reference/datamodel.html#object.__hash__ and http://docs.python.org/reference/datamodel.html#object.__lt__ for more information. From clp2 at rebertia.com Mon May 14 19:40:04 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 14 May 2012 16:40:04 -0700 Subject: Hashability questions In-Reply-To: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: On Sun, May 13, 2012 at 12:11 PM, Bob Grommes wrote: > Noob alert: writing my first Python class library. > > I have a straightforward class called Utility that lives in Utility.py. > > I'm trying to get a handle on best practices for fleshing out a library. ?As such, I've done the following for starters: > > ?def __str__(self): > ? ?return str(type(self)) > > # ?def __eq__(self,other): > # ? ?return hash(self) == hash(other) > > The commented-out method is what I'm questioning. ?As-is, I can do the following from my test harness: > > u = Utility() > print(str(u)) > print(hash(u)) > u2 = Utility() > print(hash(u2)) > print(hash(u) == hash(u2)) > > However if I uncomment the above _eq_() implementation, I get the following output: > > > Traceback (most recent call last): > ?File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in > ? ?print(hash(u)) > TypeError: unhashable type: 'Utility' > > Process finished with exit code 1 > > Obviously there is some sort of default implementation of __hash__() at work and my implementation of _eq_() has somehow broken it. ?Can anyone explain what's going on? See the 3rd, 5th, and 4th paragraphs of: http://docs.python.org/dev/reference/datamodel.html#object.__hash__ Also, for future reference, it's advisable to state whether your question concerns Python 2.x or Python 3.x. Cheers, Chris -- http://chrisrebert.com From xxxxxxxx at xxxxxx.xxx Mon May 14 19:51:45 2012 From: xxxxxxxx at xxxxxx.xxx (TommyVee) Date: Mon, 14 May 2012 19:51:45 -0400 Subject: Need to get Tags and Values from Dom In-Reply-To: <11852803.89.1337001575700.JavaMail.geo-discussion-forums@vbmd2> References: <4fb056d7$0$370$607ed4bc@cv.net> <11852803.89.1337001575700.JavaMail.geo-discussion-forums@vbmd2> Message-ID: <4fb19a9d$0$5715$607ed4bc@cv.net> "james hedley" wrote in message news:11852803.89.1337001575700.JavaMail.geo-discussion-forums at vbmd2... On Monday, 14 May 2012 01:50:23 UTC+1, TommyVee wrote: > I have a very simple XML document that I need to "walk", and I'm using > xml.dom.minidom. No attributes, just lots of nested tags and associated > values. All I'm looking to do is iterate through each of the highest > sibling nodes, check what the tag is, and process its value accordingly. > If > a node has children, same thing - iterate through the nodes, check the > tags > and process the values accordingly. I see where each node object has a > "childNodes" attribute, so I can drill down the tree. But what are the > node > attributes which indicate Tag and Value? I thought it would have been > nodeName and nodeValue, but that doesn't seem to be. Does anyone know? > > Thanks in advance, TommyVee Ah maybe you're confused about how text nodes work in minidom. Every element will have a nodeName attribute (not callable) but if you try el.nodeValue on a text node you get None. That's because the text is represented by a child node with nodeName '#text', so you want (el.nodeName, el.firstChild.nodeValue). General tips - try the docs: http://docs.python.org/library/xml.dom.minidom.html and also use dir() a lot on objects when you're learning a new api. Hope that helps. Disclaimer: haven't used minidom in anger for some time. Confused? That's an understatement. Part of the problem is that it's been a long time since I learned DOM and now I'm trying to cram to get this program done. Anyway, your suggestion to access el.firstChild.nodeValue did the trick. Thanks From vacu001 at gmail.com Mon May 14 19:56:03 2012 From: vacu001 at gmail.com (Vacu) Date: Mon, 14 May 2012 16:56:03 -0700 Subject: %d not working in re at Python 2.7? In-Reply-To: <4FB1933B.6060403@tim.thechases.com> References: <4FB1933B.6060403@tim.thechases.com> Message-ID: Thanks Tim, it is my mis-understanding of usage of %d in Python. After reading it carefully, it should be used in re.scan. The reason I made this dump mistake is because I got a script from our expert and I am totally new on Python, before reading your email, I hadn't a doubt it is wrong usage and didn't examine document carefully. I apologize for you time spent on it. -Vacu On Mon, May 14, 2012 at 4:20 PM, Tim Chase wrote: > On 05/11/12 13:58, vacu wrote: > > I am frustrated to see %d not working in my Python 2.7 re.search, like > > this example: > > > >>>> (re.search('%d', "asdfdsf78asdfdf")).group(0) > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'NoneType' object has no attribute 'group' > > > > > > \d works fine: > > > >>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) > > '78' > > > > Do you have any idea what's problem here? > > Because the regexp module doesn't support using "%d" in this way? > I'd be curious is you can point to Python documentation to the contrary. > > You know what the problem is, you didn't spell it r"\d+" so I'm not > sure why you're asking. I've tested as far back as Python2.3 and > "%d" hasn't worked like you seem to expect it to in any of those > versions. > > As an aside, use raw strings (as in r"\d+" with the leading "r") > instead of regular strings to ensure escaping applies as you expect > it to. > > -tkc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon May 14 20:19:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 May 2012 18:19:24 -0600 Subject: tiny script has memory leak In-Reply-To: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> References: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> Message-ID: On Fri, May 11, 2012 at 3:29 PM, gry wrote: > sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 > [gcc-4_3-branch revision 141291]] > I thought this script would be very lean and fast, but with a large > value for n (like 150000), it uses 26G of virtural memory, and things > start to crumble. > > #!/usr/bin/env python > '''write a file of random integers. ?args are: file-name how-many''' > import sys, random > > f = open(sys.argv[1], 'w') > n = int(sys.argv[2]) > for i in xrange(n): > ? ?print >>f, random.randint(0, sys.maxint) > f.close() > > What's using so much memory? I don't know, I'm not able to replicate the problem you're reporting. When I try your script with a value of 150000, it runs in under a second and does not appear to consume any more virtual memory than what is normally used by the Python interpreter. I suspect there is something else at play here. > What would be a better way to do this? ?(aside from checking arg > values and types, I know...) I don't see anything wrong with the way you're currently doing it, assuming you can solve your memory leak issue. Ian From python.list at tim.thechases.com Mon May 14 20:23:50 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 14 May 2012 19:23:50 -0500 Subject: Yet another "split string by spaces preserving single quotes" problem In-Reply-To: <0470db1a-5399-408d-bab4-18937bd21a08@n16g2000vbn.googlegroups.com> References: <0470db1a-5399-408d-bab4-18937bd21a08@n16g2000vbn.googlegroups.com> Message-ID: <4FB1A216.70907@tim.thechases.com> On 05/13/12 16:14, Massi wrote: > Hi everyone, > I know this question has been asked thousands of times, but in my case > I have an additional requirement to be satisfied. I need to handle > substrings in the form 'string with spaces':'another string with > spaces' as a single token; I mean, if I have this string: > > s ="This is a 'simple test':'string which' shows 'exactly my' > problem" > > I need to split it as follow (the single quotes must be mantained in > the splitted list): The "quotes must be maintained" bit is what makes this different from most common use-cases. Without that condition, using shlex.split() from the standard library does everything else that you need. Alternatively, one might try hacking csv.reader() to do the splitting for you, though I had less luck than with shlex. > Up to know I have written some ugly code which uses regular > expression: > > splitter = re.compile("(?=\s|^)('[^']+') | ('[^']+')(?=\s|$)") You might try r = re.compile(r"""(?:'[^']*'|"[^"]*"|[^'" ]+)+""") print r.findall(s) which seems to match your desired output. It doesn't currently handle tabs, but by breaking it out, it's easy to modify (and may help understand what it's doing) >>> single_quoted = "'[^']*'" >>> double_quoted = '"[^"]*"' >>> other = """[^'" \t]+""" # added a "\t" tab here >>> matches = '|'.join((single_quoted, double_quoted, other)) >>> regex = r'(?:%s)+' % matches >>> r = re.compile(regex) >>> r.findall(s) ['This', 'is', 'a', "'simple test':'string which'", 'shows', "'exactly my'", 'problem'] Hope this helps, -tkc From rosuav at gmail.com Mon May 14 20:45:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 10:45:54 +1000 Subject: tiny script has memory leak In-Reply-To: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> References: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> Message-ID: On Sat, May 12, 2012 at 7:29 AM, gry wrote: > f = open(sys.argv[1], 'w') What are you passing as the file name argument? Could that device be the cause of your memory usage spike? ChrisA From d at davea.name Mon May 14 21:19:03 2012 From: d at davea.name (Dave Angel) Date: Mon, 14 May 2012 21:19:03 -0400 Subject: Hashability questions In-Reply-To: References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: <4FB1AF07.6000805@davea.name> On 05/14/2012 07:38 PM, Chris Kaynor wrote: > On Sun, May 13, 2012 at 12:11 PM, Bob Grommes wrote: >> >> >> The rule is that, if two objects return different results from >> __hash__, they should never compare equal. The opposite rule also >> holds true: if two objects compare equal, they should return the same >> value from __hash__. >> You state those as if they were different rules. Those are contrapositives of each other, and therefore equivalent. The inverse would be that two objects with the same __hash__ should compare equal, and that's clearly not true. -- DaveA From wuwei23 at gmail.com Mon May 14 21:35:36 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 May 2012 18:35:36 -0700 (PDT) Subject: Hashability questions References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: <2a53e700-81a9-4269-aed7-e12ed6745a68@nl1g2000pbc.googlegroups.com> On May 14, 5:11?am, Bob Grommes wrote: > Obviously there is some sort of default implementation of __hash__() > at work and my implementation of _eq_() has somehow broken it. > Can anyone explain what's going on? It looks like this has changed between Python 2 and 3: "If a class does not define an __eq__() method it should not define a __hash__() operation either; if it defines __eq__() but not __hash__(), its instances will not be usable as items in hashable collections." From: http://docs.python.org/dev/reference/datamodel.html#object.__hash__ You should just be able to add a __hash__ to Utility and it'll be fine. From lists at cheimes.de Mon May 14 21:50:27 2012 From: lists at cheimes.de (Christian Heimes) Date: Tue, 15 May 2012 03:50:27 +0200 Subject: Hashability questions In-Reply-To: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: Am 13.05.2012 21:11, schrieb Bob Grommes: > Noob alert: writing my first Python class library. > > I have a straightforward class called Utility that lives in Utility.py. > > I'm trying to get a handle on best practices for fleshing out a library. As such, I've done the following for starters: > > def __str__(self): > return str(type(self)) > > # def __eq__(self,other): > # return hash(self) == hash(other) > > The commented-out method is what I'm questioning. As-is, I can do the following from my test harness: By the way, that's a dangerous and broken way to implement __eq__(). You mustn't rely on hash() in __eq__() if you want to use your object in sets and dicts. You must implement __hash__ and __eq__ in a way that takes all relevant attributes into account. The attributes must be read only, otherwise you are going to break sets and dicts. Here is a best practice example: class Example(object): def __init__(self, attr1, attr2): self._attr1 = attr1 self._attr2 = attr2 @property def attr1(self): return self._attr1 @property def attr2(self): return self._attr2 def __eq__(self, other): if not isinstance(other, Example): return NotImplemented return (self._attr1 == other._attr1 and self._attr2 == other._attr2) def __hash__(self): return hash((self._attr1, self._attr2)) # optional def __ne__(self, other): if not isinstance(other, Example): return NotImplemented return not self == other From rosuav at gmail.com Mon May 14 22:18:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 12:18:21 +1000 Subject: Newby Python Programming Question In-Reply-To: <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> Message-ID: On Sat, May 12, 2012 at 8:25 AM, Coyote wrote: > I've been playing around with a couple of IDEs because I liked the one I used with IDL and I wanted to use something similar for Python. The IDLDE was an Eclipse variant, but I've tried installing Eclipse before for something else and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. Unless, of course, I need a good excuse to head over to the Rio for the margaritas. :-) When it comes to IDEs, I've never really gone for any. My current setup at work (which I convinced my boss to deploy to all our developers, himself included) is all open-source: SciTE (Scintilla-based Text Editor) with a few in-house configurations, a good makefile, and m4 (plus git for source control). SciTE has syntax highlighting for all the languages we use, and is set to save and 'make' on press of F7, and the makefile handles everything else. There's a couple of in-house scripts such as a cache-control script (looks through our HTML and PHP pages for references to .js files and adds ?tag to them where tag comes from git) and a rapid deployment handler, but the upshot is that I edit a file, hit F7, and everything happens for me. That's about as good as any IDE would give, but without the overhead of most IDEs. ChrisA From simoncropper at fossworkflowguides.com Mon May 14 22:32:17 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 15 May 2012 12:32:17 +1000 Subject: Newby Python Programming Question In-Reply-To: References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> Message-ID: <4FB1C031.2030002@fossworkflowguides.com> On 15/05/12 12:18, Chris Angelico wrote: > On Sat, May 12, 2012 at 8:25 AM, Coyote wrote: >> I've been playing around with a couple of IDEs because I liked the one I used with IDL and I wanted to use something similar for Python. The IDLDE was an Eclipse variant, but I've tried installing Eclipse before for something else and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. Unless, of course, I need a good excuse to head over to the Rio for the margaritas. :-) > > When it comes to IDEs, I've never really gone for any. My current > setup at work (which I convinced my boss to deploy to all our > developers, himself included) is all open-source: SciTE > (Scintilla-based Text Editor) with a few in-house configurations, a > good makefile, and m4 (plus git for source control). SciTE has syntax > highlighting for all the languages we use, and is set to save and > 'make' on press of F7, and the makefile handles everything else. > There's a couple of in-house scripts such as a cache-control script > (looks through our HTML and PHP pages for references to .js files and > adds ?tag to them where tag comes from git) and a rapid deployment > handler, but the upshot is that I edit a file, hit F7, and everything > happens for me. That's about as good as any IDE would give, but > without the overhead of most IDEs. > > ChrisA Sorry for responding to you post Chris but I missed Davids post. David, I really like SPE IDE - Stani's Python Editor (http://pythonide.stani.be/). It and the bundled packages work really well. I note it works on Windows, Mac and Linux. -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From ian.g.kelly at gmail.com Tue May 15 01:27:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 May 2012 23:27:08 -0600 Subject: Hashability questions In-Reply-To: References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: On Mon, May 14, 2012 at 7:50 PM, Christian Heimes wrote: > Am 13.05.2012 21:11, schrieb Bob Grommes: >> Noob alert: writing my first Python class library. >> >> I have a straightforward class called Utility that lives in Utility.py. >> >> I'm trying to get a handle on best practices for fleshing out a library. ?As such, I've done the following for starters: >> >> ? def __str__(self): >> ? ? return str(type(self)) >> >> # ?def __eq__(self,other): >> # ? ?return hash(self) == hash(other) >> >> The commented-out method is what I'm questioning. ?As-is, I can do the following from my test harness: > > By the way, that's a dangerous and broken way to implement __eq__(). You > mustn't rely on hash() in __eq__() if you want to use your object in > sets and dicts. You must implement __hash__ and __eq__ in a way that > takes all relevant attributes into account. The attributes must be read > only, otherwise you are going to break sets and dicts. Why? I can't see any purpose in implementing __eq__ this way, but I don't see how it's "broken" (assuming that __hash__ is actually implemented somehow and doesn't just raise TypeError). The requirement is that if two objects compare equal, then they must have the same hash, and that clearly holds true here. Can you give a concrete example that demonstrates how this __eq__ method is dangerous and broken? Cheers, Ian From stefan_ml at behnel.de Tue May 15 01:55:22 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 15 May 2012 07:55:22 +0200 Subject: Need to get Tags and Values from Dom In-Reply-To: <4fb19a9d$0$5715$607ed4bc@cv.net> References: <4fb056d7$0$370$607ed4bc@cv.net> <11852803.89.1337001575700.JavaMail.geo-discussion-forums@vbmd2> <4fb19a9d$0$5715$607ed4bc@cv.net> Message-ID: TommyVee, 15.05.2012 01:51: > Confused? That's an understatement. Part of the problem is that it's been > a long time since I learned DOM and now I'm trying to cram to get this > program done. Thus my recommendation to use ElementTree. Why go the complicated route when you can just get your code working without having to learn all of this again? Stefan From ian.g.kelly at gmail.com Tue May 15 02:29:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 15 May 2012 00:29:01 -0600 Subject: specify end of line character for readline In-Reply-To: <485824.173.1336764755682.JavaMail.geo-discussion-forums@yngp11> References: <485824.173.1336764755682.JavaMail.geo-discussion-forums@yngp11> Message-ID: On Fri, May 11, 2012 at 1:32 PM, Jason wrote: > Is there any way to specify the end of line character to use in file.readline() ? > > I would like to use '\r\n' as the end of line and allow either \r or \n by itself within the line. In Python 3 you can pass the argument newline='\r\n' to the open function when you open the file. I don't know of anything comparable in Python 2. From storchaka at gmail.com Tue May 15 03:20:55 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 15 May 2012 10:20:55 +0300 Subject: specify end of line character for readline In-Reply-To: References: <485824.173.1336764755682.JavaMail.geo-discussion-forums@yngp11> Message-ID: On 15.05.12 09:29, Ian Kelly wrote: > In Python 3 you can pass the argument newline='\r\n' to the open > function when you open the file. I don't know of anything comparable > in Python 2. io.open supports "newline" argument. From rosuav at gmail.com Tue May 15 03:30:32 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 17:30:32 +1000 Subject: Hashability questions In-Reply-To: References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: On Tue, May 15, 2012 at 3:27 PM, Ian Kelly wrote: > Why? ?I can't see any purpose in implementing __eq__ this way, but I > don't see how it's "broken" (assuming that __hash__ is actually > implemented somehow and doesn't just raise TypeError). ?The > requirement is that if two objects compare equal, then they must have > the same hash, and that clearly holds true here. > > Can you give a concrete example that demonstrates how this __eq__ > method is dangerous and broken? Its brokenness is that hash collisions result in potentially-spurious equalities. But I can still invent a (somewhat contrived) use for such a setup: class Modulo: base = 256 def __init__(self,n): self.val=int(n) def __str__(self): return str(self.val) __repr__=__str__ def __hash__(self): return self.val%self.base def __eq__(self,other): return hash(self)==hash(other) def __iadd__(self,other): try: self.val+=other.val except: try: self.val+=int(other) except: pass return self Two of these numbers will hash and compare equal if they are equal modulo 'base'. Useful? Probably not. But it's plausibly defined. ChrisA From steve+comp.lang.python at pearwood.info Tue May 15 04:30:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2012 08:30:53 GMT Subject: ANNOUNCE: byteformat0.2a Message-ID: <4fb2143d$0$29975$c3e8da3$5496439d@news.astraweb.com> I am pleased to announce a new release of byteformat. http://pypi.python.org/pypi/byteformat byteformat is a Python module for intelligently formatting numbers of bytes using common human-readable strings: >>> from byteformat import format >>> format(12000) '12 KB' >>> format(5100000, style='ABBREV') '5.1 Mbytes' >>> format(48500000000000, style='LONG') '48.5 terabytes' byteformat understands SI decimal units, IEC binary units, and mixed units: >>> format(12000, scheme='IEC') '11.7 KiB' >>> format(12000, scheme='MIXED') '11.7 KB' You can also specify which prefix to use: >>> format(48500000000000, style='LONG', prefix='M') '48500000 megabytes' byteformat can be used as a command-line tool: [steve at ando ~]$ python -m byteformat --prefix=K 1000 12300 145000 1 KB 12.3 KB 145 KB byteformat understands all the relevant SI and IEC unit prefixes, and is released under the MIT licence. -- Steven From kliateni at gmail.com Tue May 15 04:52:24 2012 From: kliateni at gmail.com (Karim) Date: Tue, 15 May 2012 10:52:24 +0200 Subject: ANNOUNCE: byteformat0.2a In-Reply-To: <4fb2143d$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4fb2143d$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FB21948.2060407@gmail.com> Cool steven, very helpful I have a db which holds units data it will avoids me to do such format conversion. Thnx Cheers Karim Le 15/05/2012 10:30, Steven D'Aprano a ?crit : > I am pleased to announce a new release of byteformat. > > > http://pypi.python.org/pypi/byteformat > > > byteformat is a Python module for intelligently formatting numbers of > bytes using common human-readable strings: > >>>> from byteformat import format >>>> format(12000) > '12 KB' >>>> format(5100000, style='ABBREV') > '5.1 Mbytes' >>>> format(48500000000000, style='LONG') > '48.5 terabytes' > > > byteformat understands SI decimal units, IEC binary units, and mixed > units: > >>>> format(12000, scheme='IEC') > '11.7 KiB' >>>> format(12000, scheme='MIXED') > '11.7 KB' > > > You can also specify which prefix to use: > >>>> format(48500000000000, style='LONG', prefix='M') > '48500000 megabytes' > > > byteformat can be used as a command-line tool: > > [steve at ando ~]$ python -m byteformat --prefix=K 1000 12300 145000 > 1 KB > 12.3 KB > 145 KB > > > byteformat understands all the relevant SI and IEC unit prefixes, and is > released under the MIT licence. > > > From lists at cheimes.de Tue May 15 05:25:45 2012 From: lists at cheimes.de (Christian Heimes) Date: Tue, 15 May 2012 11:25:45 +0200 Subject: Hashability questions In-Reply-To: References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: Am 15.05.2012 07:27, schrieb Ian Kelly: > Why? I can't see any purpose in implementing __eq__ this way, but I > don't see how it's "broken" (assuming that __hash__ is actually > implemented somehow and doesn't just raise TypeError). The > requirement is that if two objects compare equal, then they must have > the same hash, and that clearly holds true here. > > Can you give a concrete example that demonstrates how this __eq__ > method is dangerous and broken? Code explains more than words. I've created two examples that some issues. Mutable values break dicts as you won't be able to retrieve the same object again: >>> class Example(object): ... def __init__(self, value): ... self.value = value ... def __hash__(self): ... return hash(self.value) ... def __eq__(self, other): ... if not isinstance(other, Example): ... return NotImplemented ... return self.value == other.value ... >>> ob = Example("egg") >>> d = {} >>> d[ob] = True >>> d["egg"] = True >>> d["spam"] = True >>> ob in d True >>> d {'egg': True, <__main__.Example object at 0x7fab66cb7450>: True, 'spam': True} >>> ob.value = "spam" >>> ob in d False >>> d {'egg': True, <__main__.Example object at 0x7fab66cb7450>: True, 'spam': True} When you mess up __eq__ you'll get funny results and suddenly the insertion order does unexpected things to you: >>> class Example2(object): ... def __init__(self, value): ... self.value = value ... def __hash__(self): ... return hash(self.value) ... def __eq__(self, other): ... return hash(self) == hash(other) ... >>> d = {} >>> ob = Example2("egg") >>> d[ob] = True >>> d {<__main__.Example2 object at 0x7fab66cb7610>: True} >>> d["egg"] = True >>> d {<__main__.Example2 object at 0x7fab66cb7610>: True} >>> d2 = {} >>> d2["egg"] = True >>> d2[ob] = True >>> d2 {'egg': True} From jeanmichel at sequans.com Tue May 15 05:26:15 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 15 May 2012 11:26:15 +0200 Subject: Newby Python Programming Question In-Reply-To: <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> References: <7499801.219.1336749920076.JavaMail.geo-discussion-forums@vbjy4> <4199475.114.1336775140689.JavaMail.geo-discussion-forums@ynff7> Message-ID: <4FB22137.3010006@sequans.com> Coyote wrote: > CM writes: > > >> I don't know Spyder IDE, but I don't think this should happen; could >> there just be a simple mistake? Because you first refer to the .py >> file as 'file_utils.py' but then you refer to the file as >> 'pwd.py'...which is also the name of your function. Room for >> confusion...so could you test this by saving only your one function >> (below), give the .py a new name to avoid confusion (like test_pwd.py) >> and then running *that* through Spyder IDE? >> >> def pwd(): >> import os >> print os.getcwd() >> > > I probably explained the situation badly. I have a file pwd.py with these two lines of code in it: > > import os > print os.getcwd() > > If I start a new Spyder IDL session and "run" this file by choosing RUN from the menu bar, the directory is printed twice. This appears to me now to be an IDE error, because if I use a runfile command, the directory is printed only once, as I expect. > > >>>runfile('pwd.py') > C:\Users\coyote\pyscripts > > I've been playing around with a couple of IDEs because I liked the one I used with IDL and I wanted to use something similar for Python. The IDLDE was an Eclipse variant, but I've tried installing Eclipse before for something else and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. Unless, of course, I need a good excuse to head over to the Rio for the margaritas. :-) > > Cheers, > > David > Could be that the IDE is first importing the file before executing it, that would be strange. Since you have print statements at the module level it is executed on import. Anyway in order to avoid any issue, as everybody does, you better write : pwd.py: import os def getcwd(): print os.getcwd() if __name__ == '__main__': # true if this file is used as program entry point getcwd() That way you can either execute your script as a program, or use it as a module. JM Note : there is a 'pwd' module (linux password db), thus it would be wise to avoid naming any file pwd.py, or your statement 'import pwd' may yield unexpected results. From jeanmichel at sequans.com Tue May 15 05:36:46 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 15 May 2012 11:36:46 +0200 Subject: Sharing Data in Python In-Reply-To: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> References: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> Message-ID: <4FB223AE.2010700@sequans.com> raunakgup90 at gmail.com wrote: > I have some Pickled data, which is stored on disk, and it is about 100 MB in size. > > When my python program is executed, the picked data is loaded using the cPickle module, and all that works fine. > > If I execute the python multiple times using python main.py for example, each python process will load the same data multiple times, which is the correct behaviour. > > How can I make it so, all new python process share this data, so it is only loaded a single time into memory? > > asked the same question on SO, but could not get any constructive responses.. http://stackoverflow.com/questions/10550870/sharing-data-in-python/10551845 > Well a straightforward way of solving this is to use threads. Have your main program spawn threads for processing data. Now what triggers a thread is up to you, your main program can listen to commands, or catch keyboard events ... If you want to make sure your using all CPU cores, you may want to use the module http://docs.python.org/library/multiprocessing.html It emulates threads with subprocesses, and features a way to share memory. I do tend to prefer processes over threads, I find them easier to monitor and control. Cheers, JM From alan at pin.ee Tue May 15 06:01:59 2012 From: alan at pin.ee (Alan Kesselmann) Date: Tue, 15 May 2012 03:01:59 -0700 (PDT) Subject: ucs2 and ucs4 python Message-ID: Hello I tried using one compiled library and got this error: ImportError: /home/alan/Downloads/pdftron/PDFNetC64/Lib/ _PDFNetPython2.so: undefined symbol: PyUnicodeUCS2_AsUTF8String I googled around and found some info about the meaning of the error. The creators of PDFNet suggested i install UCS2 python next to my UCS4 version to try their library. Can someone point me towards a resource or two which will tell me how to do this - im not very good with whole linux/servers stuff. Im using ubuntu linux - if that makes any difference. Alan From pythoniks at gmail.com Tue May 15 06:39:01 2012 From: pythoniks at gmail.com (Pascal Chambon) Date: Tue, 15 May 2012 12:39:01 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> Message-ID: <4FB23245.4010804@gmail.com> Hi, cool down, people, if anything gave FOSS a bad reputation, that's well the old pyjamas website (all broken, because "wheel must be reinvented here"), and most of all the "terror management" that occurred on its mailing list. Previously I had always considered open-source as a benevolent state of mind, until I got, there, the evidence that it could also be, for some people, an irrational and harmful cult (did you know github were freaking evildoers ?). Blatantly the pyjs ownership change turned out to be an awkward operation (as reactions on that ML show it), but a fork could also have very harmfully "split" pyjs-interested people, so all in all I don't think there was a perfect solution - dictatorships never fall harmlessly. The egos of some might have been hurt, the legal sense of others might have been questioned, but believe me all this fuss is pitiful compared to the real harm that was done numerous time to willing newcomers, on pyjs' old ML, when they weren't aware about the heavy dogmas lying around. A demo sample (I quote it each time the suvject arises, sorry for duplicates) ------------------------------------------------------------------------ | Please get this absolutely clear in your head: that | | you do not "understand" my reasoning is completely and utterly | | irrelevant. i understand *your* reasoning; i'm the one making the | | decisions, that's my role to understand the pros and cons. i make a | | decision: that's the end of it. | | You present reasoning to me: i weight it up, against the other | | reasoning, and i make a decision. you don't have to understand that | | decision, you do not have to like that decision, you do not have to | | accept that decision. | ------------------------------------------------------------------------ Ling live pyjs, ++ PKL Le 08/05/2012 07:37, alex23 a ?crit : > On May 8, 1:54 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Seriously, this was a remarkably ham-fisted and foolish way to "resolve" >> a dispute over the direction of an open source project. That's the sort >> of thing that gives open source a bad reputation. > The arrogance and sense of entitlement was so thick you could choke on > it. Here's a sampling from the circle jerk of self-justification that > flooded my inbox over the weekend: > > "i did not need to consult Luke, nor would that have be productive" > > No, it's generally _not_ productive to ask someone if you can steal > their project from them. > > "i have retired Luke of the management duties, particularly, *above* > the source" > > Who is this C Anthony Risinger asshole and in what way did he _hire_ > the lead developer? > > "What I have wondered is, what are effects of having the project > hostage to the whims of an individuals often illogically radical > software libre beliefs which are absolutely not up for discussion at > all with anyone." > > What I'm wondering is: how is the new set up any different? Why were > Luke Leighton's philosophies/"whims" any more right or wrong than > those held by the new Gang of Dicks? > > "Further more, the reason I think it's a bad idea to have this drawn > out discussion is that pretty much the main reason for this fork is > because of Luke leadership and project management decisions and > actions. To have discussions of why the fork was done would invariably > lead to quite a bit of personal attacks and petty arguments." > > Apparently it's nicer to steal someone's work than be mean to them. > > "I agree, Lex - this is all about moving on. This is a software > project, not a cult of personality." > > Because recognising the effort of the lead developer is cult-like. > > "My only quibble is with the term "fork." A fork is created when you > disagree with the technical direction of a project. That's not the > issue here. This is a reassignment of the project administration only > - a shuffling of responsibility among *current leaders* of the > community. There is no "divine right of kings" here." > > My quibble is over the term "fork" too, as this is outright theft. I > don't remember the community acknowledging _any other leadership_ over > Luke Leighton's. > > "I suspect Luke will be busy with other projects and not do much more > for Pyjamas/pyjs, Luke correct me if you see this and I am wrong." > > How about letting the man make his own fucking decisions? > > "All of you spamming the list with your unsubscribe attempts: Anthony > mentioned in a previous email that he's using mailman now" > > Apparently it's the responsibility of the person who was subscribed > without their permission to find out the correct mechanism for > unsubscribing from that list. > > "apparantly a bunch of people were marked as "POSTING" in the DB, but > not receiving mail (?)" > > Oh I see, the sudden rush of email I received was due to an error in > the data they stole... > > "Nobody wins if we spend any amount of time debating the details of > this transition, what's done is done." > > Truly the justification of assholes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rmorgan466 at gmail.com Tue May 15 07:54:50 2012 From: rmorgan466 at gmail.com (Rita) Date: Tue, 15 May 2012 07:54:50 -0400 Subject: compiling Tkinter Message-ID: Hello, I understand Tkinter is part of the python distribution but for me it always fails when I try to load the module. I get: >>> import Tkinter ... import _tkinter # if this fails your Python may not be configured for Tk ImportError: No module named _tkinter So, here is how I am compiling tcl/tk and Python please let me know if you see any issues with this. assuming, my prefix is /tmp/testdir wget http://prdownloads.sourceforge.net/tcl/tcl8.5.11-src.tar.gz wget http://prdownloads.sourceforge.net/tcl/tk8.5.11-src.tar.gz tar -xzpf tcl8.5.11-src.tar.gz && tar -xzpf tk8.5.11-src.tar.gz #compile tcl cd tcl8.5.11/unix/ ./configure --prefix=/tmp/testdir --enable-64bit --enable-threads make make test make install #compile tk cd tk8.5.11/unix/ ./configure --prefix=/tmp/testdir --enable-threads --enable-64-bit --with-tcl=/tmp/testdir/lib make make install #compile python wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar -xzpvf Python-2.7.3.tgz cd Python-2.7.3/ ./configure --prefix=/tmp/testdir --enable-shared LDFLAGS="-Wl,-rpath,/tmp/testdir/lib" Any thoughts? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidgshi at yahoo.co.uk Tue May 15 08:08:14 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 15 May 2012 13:08:14 +0100 (BST) Subject: How to call and execute C code in Python? In-Reply-To: References: Message-ID: <1337083694.7923.YahooMailNeo@web171602.mail.ir2.yahoo.com> How to call and execute C code in Python? Is there any publication/documentation for this??? For the worst scenario, how many ways are there to call and execute C codes, in Python. For instance, having got hold some C codes, attempting to use Python to call and execute C codes.? I.e.? Python, as the integrating language. Can anyone send publications/instructions to davidgshi at yahoo.co.uk? All the best to everyone! Regards. David ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Sunday, 13 May 2012, 19:14 Subject: Python-list Digest, Vol 104, Issue 67 ----- Forwarded Message ----- Send Python-list mailing list submissions to ??? python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to ??? python-list-request at python.org You can reach the person managing the list at ??? python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: ? 1. Re: Good data structure for finding date intervals including ? ? ? a given??? date (Arnaud Delobelle) ? 2. Re: Good data structure for finding date intervals including ? ? ? a given??? date (Emile van Sebille) ? 3. Re: How to call and execute C code in Python? (Chris Angelico) ? 4. Re: How to call and execute C code in Python? (Stefan Behnel) ? 5. Re: How to call and execute C code in Python? (Mark Lawrence) ? 6. Re: How to call and execute C code in Python? (Mark Lawrence) ? 7. Re: How to call and execute C code in Python? (Stefan Behnel) ? 8. Re: How to call and execute C code in Python? (Stefan Behnel) ? 9. Re: How to call and execute C code in Python? (Mark Lawrence) ? 10. Re: How to call and execute C code in Python? (Stefan Behnel) On 13 May 2012 13:29, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. I don't think that'll help the OP.? Python's OrderedDict keeps track of the order in which the keys were inserted into the dictionary (a bit like a list), it doesn't keep the keys sorted. > If you are looking for the best possible self-sorting structure for > searching, then perhaps you are looking for what's outlined in the > 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) > Expected Time and Linear Space[3]. I can't access it but it seems to me it's not about self sorted data structures, which is what the OP is looking for. -- Arnaud On 5/12/2012 5:17 AM Jean-Daniel said... > Hello, > > I have a long list of n date intervals that gets added or suppressed > intervals regularly. I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). ISTM the fastest way is to retrieve the list of intervals from a dict using the date as a key.? You don't say how long your list of intervals is, nor how large each interval can be so I don't have enough info to determine the setup reqs, but I'd suspect that a list of tens of thousands of intervals covering ranges of days to weeks would be doable.? If instead you're talking about millions of ranges covering years to decades I'd start elsewhere. Emile On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: > Can anyone tell me how to call and exectute C code in Python? Browse the documentation about Extending and Embedding Python, there's an extensive API. Chris Angelico David Shi, 13.05.2012 15:25: > Can anyone tell me how to call and exectute C code in Python? Take a look at Cython, a Python-like language that supports native calls to and from C/C++ code. It translates your code into very efficient C code, so the wrapping code tends to be very fast (often faster than hand written C code). http://cython.org/ Here are a couple of examples: http://docs.cython.org/src/tutorial/external.html There's also the "ctypes" package in the standard library, which is usable for simple wrapping cases that are not performance critical. Stefan On 13/05/2012 16:39, Chris Angelico wrote: > On Sun, May 13, 2012 at 11:25 PM, David Shi? wrote: >> Can anyone tell me how to call and exectute C code in Python? > > Browse the documentation about Extending and Embedding Python, there's > an extensive API. > > Chris Angelico I like your response, my first thought was to say "yes" :) -- Cheers. Mark Lawrence. On 13/05/2012 16:58, Stefan Behnel wrote: > David Shi, 13.05.2012 15:25: >> Can anyone tell me how to call and exectute C code in Python? > > Take a look at Cython, a Python-like language that supports native calls to > and from C/C++ code. It translates your code into very efficient C code, so > the wrapping code tends to be very fast (often faster than hand written C > code). > > http://cython.org/ > > Here are a couple of examples: > > http://docs.cython.org/src/tutorial/external.html > > There's also the "ctypes" package in the standard library, which is usable > for simple wrapping cases that are not performance critical. > > Stefan > Stefan, you appear to have a lot to do with Cython. It would be polite to mention this when replying. -- Cheers. Mark Lawrence. Mark Lawrence, 13.05.2012 19:23: > On 13/05/2012 16:39, Chris Angelico wrote: >> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Browse the documentation about Extending and Embedding Python, there's >> an extensive API. > > I like your response, my first thought was to say "yes" :) It has a serious learning curve all by itself, though, with a lot of major pitfalls not only for new users. It also requires C fluency, which not everyone has or wants to learn just to be able to talk to existing C code. And even when you're up to speed with all that, you will waste a substantial part of your time debugging crashes, making your code reference leak free and eventually maintaining it and porting it to different CPython versions and platforms. Time that IMHO is much better spent adding features and tuning the code for performance. Stefan Mark Lawrence, 13.05.2012 19:27: > On 13/05/2012 16:58, Stefan Behnel wrote: >> David Shi, 13.05.2012 15:25: >>> Can anyone tell me how to call and exectute C code in Python? >> >> Take a look at Cython, a Python-like language that supports native calls to >> and from C/C++ code. It translates your code into very efficient C code, so >> the wrapping code tends to be very fast (often faster than hand written C >> code). >> >> http://cython.org/ >> >> Here are a couple of examples: >> >> http://docs.cython.org/src/tutorial/external.html >> >> There's also the "ctypes" package in the standard library, which is usable >> for simple wrapping cases that are not performance critical. > > Stefan, you appear to have a lot to do with Cython. It would be polite to > mention this when replying. Well, my name is pretty far up both on the project home page and on PyPI, so it's not like I'm hiding this information. But sure, I'm one of the core developers and initial founders of the project. So I can assure you that I know what I'm talking about. Stefan On 13/05/2012 18:38, Stefan Behnel wrote: > Mark Lawrence, 13.05.2012 19:23: >> On 13/05/2012 16:39, Chris Angelico wrote: >>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>> Can anyone tell me how to call and exectute C code in Python? >>> >>> Browse the documentation about Extending and Embedding Python, there's >>> an extensive API. >> >> I like your response, my first thought was to say "yes" :) > > It has a serious learning curve all by itself, though, with a lot of major > pitfalls not only for new users. It also requires C fluency, which not > everyone has or wants to learn just to be able to talk to existing C code. > And even when you're up to speed with all that, you will waste a > substantial part of your time debugging crashes, making your code reference > leak free and eventually maintaining it and porting it to different CPython > versions and platforms. Time that IMHO is much better spent adding features > and tuning the code for performance. > > Stefan > Haven't the faintest idea what you're on about so please explain. -- Cheers. Mark Lawrence. Mark Lawrence, 13.05.2012 19:44: > On 13/05/2012 18:38, Stefan Behnel wrote: >> Mark Lawrence, 13.05.2012 19:23: >>> On 13/05/2012 16:39, Chris Angelico wrote: >>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote: >>>>> Can anyone tell me how to call and exectute C code in Python? >>>> >>>> Browse the documentation about Extending and Embedding Python, there's >>>> an extensive API. >>> >>> I like your response, my first thought was to say "yes" :) >> >> It has a serious learning curve all by itself, though, with a lot of major >> pitfalls not only for new users. It also requires C fluency, which not >> everyone has or wants to learn just to be able to talk to existing C code. >> And even when you're up to speed with all that, you will waste a >> substantial part of your time debugging crashes, making your code reference >> leak free and eventually maintaining it and porting it to different CPython >> versions and platforms. Time that IMHO is much better spent adding features >> and tuning the code for performance. > > Haven't the faintest idea what you're on about so please explain. Sure. Learning curve and pitfalls: almost all C-API code I've seen from new users had at least one reference leak, usually more than one. This even happens to core developers from time to time, so I think it's reasonable to assume that pretty much all users of the C-API have produced at least one reference leak in their time as programmers and at least some do so frequently while learning to use it. I call that a common pitfall. C fluency: obviously, you need to be able to (and want to) write C if you want to make effective use of CPython's C-API from C code. Not every Python developer knows C, and why should they? Wasting time debugging crashes and making your code reference leak free: well, if you have ref-counting bugs in your code, you have to find them and fix them. First of all, you have to know they are there, which isn't always obvious, especially for leaks. The problem with ref-counting bugs is that the effects (even crashes) are not local in most cases but can happen anywhere in your program at unpredictable times, so you will spend more time on average debugging them than with other, more local bugs. Wasting time maintaining: arguably, maintaining C code requires more work than maintaining Python code. That's why we use high-level languages in the first place, isn't it? Wasting time porting: well, the C-API has subtle to major differences between CPython versions, so you not only have to learn "the" C-API, but the differences between these C-APIs, then write or adapt your code in order to make it work with different versions. Also, being able to write C code doesn't mean that that code will compile and run with different C compilers and on different platforms, so more work on that front. Spending more time adding features and tuning code instead: well, we designed Cython to relieve programmers from all of the above, so that they can focus on functionality and performance. And it's pretty good in that (you may want to read the testimonials on our project home page). Basically, the idea is that we write C so you don't have to. Is it clearer what I mean now? Stefan -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Tue May 15 08:19:29 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 15 May 2012 13:19:29 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4FB23245.4010804@gmail.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <4FB23245.4010804@gmail.com> Message-ID: <1337084369.20488.19.camel@tim-laptop> On Tue, 2012-05-15 at 12:39 +0200, Pascal Chambon wrote: > believe me all this fuss is pitiful compared to the real harm that was > done numerous time to willing newcomers, on pyjs' old ML, when they > weren't aware about the heavy dogmas lying around. > > A demo sample (I quote it each time the suvject arises, sorry for > duplicates) > ------------------------------------------------------------------------ > | Please get this absolutely clear in your head: that > | > | you do not "understand" my reasoning is completely and utterly > | > | irrelevant. i understand *your* reasoning; i'm the one making the > | > | decisions, that's my role to understand the pros and cons. i make a > | > | decision: that's the end of it. > | > | You present reasoning to me: i weight it up, against the other > | > | reasoning, and i make a decision. you don't have to understand that > | > | decision, you do not have to like that decision, you do not have to > | > | accept that decision. > | > ------------------------------------------------------------------------ The above seems perfectly reasonable to me. You're working with Python anyway - a language organised by a team that gives full control to the BDFL... Imagine instead that you were talking about a bug in a proprietary piece of software (Oracle / Internet Explorer / etc) - do you think they'd let *you* make the decision, or keep the option under discussion until *you* fully understood the reasoning of the company that owned the code? No - they'd listen to your argument, weigh up the two sides, and make a decision on their own. The idea of having two sides able to make their cases and one person rule on them is incredibly common - it's how courts across the world work, and it's how management of any team (software related or not) goes. Tim From rosuav at gmail.com Tue May 15 08:32:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 May 2012 22:32:40 +1000 Subject: How to call and execute C code in Python? In-Reply-To: <1337083694.7923.YahooMailNeo@web171602.mail.ir2.yahoo.com> References: <1337083694.7923.YahooMailNeo@web171602.mail.ir2.yahoo.com> Message-ID: On Tue, May 15, 2012 at 10:08 PM, David Shi wrote: > How to call and execute C code in Python? > > Is there any publication/documentation for this??? For the worst scenario, > how many ways are there to call and execute C codes, in Python. > > For instance, having got hold some C codes, attempting to use Python to call > and execute C codes.? I.e.? Python, as the integrating language. > > Can anyone send publications/instructions to davidgshi at yahoo.co.uk? > [chomp lots of digest] As you've seen, there've been quite a few posts on the subject. Please don't simply repeat your question and quote them all underneath - we've all seen those posts already. The polite thing to do would be to read through all the responses so far and respond to them with clarifications and/or more information so that we are better able to help you. You've been given two or three separate lines of inquiry to follow up; have you looked into any of them? What did you find out? Also, this might be a handy reference: http://www.catb.org/~esr/faqs/smart-questions.html Chris Angelico From steve+comp.lang.python at pearwood.info Tue May 15 09:15:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 May 2012 13:15:19 GMT Subject: Yet another "split string by spaces preserving single quotes" problem References: <0470db1a-5399-408d-bab4-18937bd21a08@n16g2000vbn.googlegroups.com> Message-ID: <4fb256e7$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 May 2012 14:14:58 -0700, Massi wrote: > Hi everyone, > I know this question has been asked thousands of times, but in my case I > have an additional requirement to be satisfied. I need to handle > substrings in the form 'string with spaces':'another string with spaces' > as a single token; I mean, if I have this string: > > s ="This is a 'simple test':'string which' shows 'exactly my' problem" > > I need to split it as follow (the single quotes must be mantained in the > splitted list): > > ["This", "is", "a", "'simple test':'string which'", "shows", "'exactly > my'", "problem"] > > Up to know I have written some ugly code which uses regular expression: And now you have two problems *wink* > Any hints? Thanks in advance! >>> s = "This is a 'simple test':'string which' shows 'exactly my' problem" >>> import shlex >>> result = shlex.split(s, posix=True) >>> result ['This', 'is', 'a', 'simple test:string which', 'shows', 'exactly my', 'problem'] Then do some post-processing on the result: >>> ["'"+s+"'" if " " in s else s for s in result] ['This', 'is', 'a', "'simple test:string which'", 'shows', "'exactly my'", 'problem'] -- Steven From bob.grommes at gmail.com Tue May 15 10:52:41 2012 From: bob.grommes at gmail.com (Bob Grommes) Date: Tue, 15 May 2012 07:52:41 -0700 (PDT) Subject: Hashability questions In-Reply-To: <2a53e700-81a9-4269-aed7-e12ed6745a68@nl1g2000pbc.googlegroups.com> References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> <2a53e700-81a9-4269-aed7-e12ed6745a68@nl1g2000pbc.googlegroups.com> Message-ID: <20058773.1246.1337093561971.JavaMail.geo-discussion-forums@ynjm4> On Monday, May 14, 2012 8:35:36 PM UTC-5, alex23 wrote: > It looks like this has changed between Python 2 and 3: > > "If a class does not define an __eq__() method it should not define a > __hash__() operation either; if it defines __eq__() but not > __hash__(), its instances will not be usable as items in hashable > collections." > > From: http://docs.python.org/dev/reference/datamodel.html#object.__hash__ > > You should just be able to add a __hash__ to Utility and it'll be fine. Thanks, Alex. I should have mentioned I was using Python 3. I guess all this is a bit over-thought to just crank out some code -- in practice, comparing two classes for equality is mostly YAGNI -- but it's my way of coming to a reasonably in-depth understanding of how things work ... From miki.tebeka at gmail.com Tue May 15 12:42:51 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 15 May 2012 09:42:51 -0700 (PDT) Subject: ucs2 and ucs4 python In-Reply-To: References: Message-ID: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> > Can someone point me towards a resource or two which will tell me how > to do this - im not very good with whole linux/servers stuff. Im using > ubuntu linux - if that makes any difference. Did not test, but this is the direction I would take: * Download Python sources * Open Terminal * Run the following commands in the Terminal window - sudo apt-get build-dep python - tar -xjf Python-2.7.3.tar.bz2 - cd Python-2.7.3 - ./configure --prefix=/opt --enable-unicode=ucs2 && make - sudo make install * Now you should have /opt/bin/python with ucs2 HTH -- Miki Tebeka http://pythonwise.blogspot.com From fetchinson at googlemail.com Tue May 15 12:44:33 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 15 May 2012 18:44:33 +0200 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: <4FB23245.4010804@gmail.com> References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <4FB23245.4010804@gmail.com> Message-ID: > Blatantly the pyjs ownership change turned out to be an awkward > operation (as reactions on that ML show it), but a fork could also have > very harmfully "split" pyjs-interested people, so all in all I don't > think there was a perfect solution - dictatorships never fall harmlessly. You say "fork could also have very harmfully split", what harms are you referring to? In the open source world there were tons of forks of projects and it proved to be a useful mechanism for resolving serious management issues. On the other hand the kind of hostile takeover that happened with pyjs is virtually unparalleled in the open source world. What made you think such a unique operation will be less harmful than the other which has already been tried many times? > ------------------------------------------------------------------------ > | Please get this absolutely clear in your head: that | > | you do not "understand" my reasoning is completely and utterly | > | irrelevant. i understand *your* reasoning; i'm the one making the | > | decisions, that's my role to understand the pros and cons. i make a | > | decision: that's the end of it. | > | You present reasoning to me: i weight it up, against the other | > | reasoning, and i make a decision. you don't have to understand that | > | decision, you do not have to like that decision, you do not have to | > | accept that decision. | > ------------------------------------------------------------------------ Again, if you don't like the lead developer just fork the project, come up with a new name, new website and new infrastructure and start building a new community. Why didn't the rebels do that? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From msmucr at gmail.com Tue May 15 15:06:05 2012 From: msmucr at gmail.com (msmucr) Date: Tue, 15 May 2012 12:06:05 -0700 (PDT) Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? Message-ID: Hello, i would like to ask you for some information regarding Carbon Event Manager ( Carbon.CarbonEvt ) library in Python. I need to recieve and work with few Carbon events in my program. I've followed some examples on PyObjC site, but wasn't successful. I know, that both Carbon library and this Python module is deprecated, but frankly i didn't find any usable alternative except of writing of something from scratch.. I ended on basic import of required objects from Carbon.CarbonEvt module - like "from Carbon.CarbonEvt import RegisterEventHotKey" I tried it in Python 2.7.1 (standard distribution in OS X 10.7 Lion) and Python 2.6.1 (standard Apple distribution in OS X 10.6). Do I have something wrong or is it simply broken and unmaintained now? Thank You, Michal From gordon at panix.com Tue May 15 15:21:24 2012 From: gordon at panix.com (John Gordon) Date: Tue, 15 May 2012 19:21:24 +0000 (UTC) Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? References: Message-ID: In msmucr writes: > Do I have something wrong or is it simply broken and unmaintained now? We have no idea if you did anything wrong, because you didn't tell us exactly what you did and exactly what error message you received. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nad at acm.org Tue May 15 15:55:54 2012 From: nad at acm.org (Ned Deily) Date: Tue, 15 May 2012 12:55:54 -0700 Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? References: Message-ID: In article , msmucr wrote: > i would like to ask you for some information regarding Carbon Event > Manager ( Carbon.CarbonEvt ) library in Python. > I need to recieve and work with few Carbon events in my program. I've > followed some examples on PyObjC site, but wasn't successful. I know, > that both Carbon library and this Python module is deprecated, but > frankly i didn't find any usable alternative except of writing of > something from scratch.. > I ended on basic import of required objects from Carbon.CarbonEvt > module - > like "from Carbon.CarbonEvt import RegisterEventHotKey" > I tried it in Python 2.7.1 (standard distribution in OS X 10.7 Lion) > and Python 2.6.1 (standard Apple distribution in OS X 10.6). > Do I have something wrong or is it simply broken and unmaintained now? You may want to ask OS X specific questions on the macpython mailing list (http://www.python.org/community/sigs/current/pythonmac-sig/). The main reason that these modules are deprecated (and have been removed in Python 3) is because they depend on obsolete APIs in OS X that are only available in 32-bit versions. Apple has made it clear that they will not be made available as 64-bit and will eventually go away. You should try to find ways not to use the Carbon model in your applications. That said, you can use these modules, even with the Apple-supplied Pythons in OS X 10.6 and 10.7, if you force Python to run in 32-bit-mode. For those Apple-supplied Pythons, see the Apple man page (man 1 python) for system Python specific ways to force 32-bit mode persistently. Another way that should work for any OS X universal Python 2.7.x: arch -i386 python2.7 -- Ned Deily, nad at acm.org From kw at codebykevin.com Tue May 15 17:00:56 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 15 May 2012 17:00:56 -0400 Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? In-Reply-To: References: Message-ID: On 5/15/12 3:06 PM, msmucr wrote: > Do I have something wrong or is it simply broken and unmaintained now? Support for Carbon Events was removed in Python 3.x and it does not work in 64-bit, to my knowledge--most of the Carbon API's are not supported by Apple anymore. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From breamoreboy at yahoo.co.uk Tue May 15 17:37:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 15 May 2012 22:37:53 +0100 Subject: Open Source: you're doing it wrong - the Pyjamas hijack In-Reply-To: References: <4fa898e3$0$29975$c3e8da3$5496439d@news.astraweb.com> <0976d620-3c21-43c9-885c-4822b7370228@ot8g2000pbb.googlegroups.com> <4FB23245.4010804@gmail.com> Message-ID: On 15/05/2012 17:44, Daniel Fetchinson wrote: >> Blatantly the pyjs ownership change turned out to be an awkward >> operation (as reactions on that ML show it), but a fork could also have >> very harmfully "split" pyjs-interested people, so all in all I don't >> think there was a perfect solution - dictatorships never fall harmlessly. > > You say "fork could also have very harmfully split", what harms are > you referring to? > In the open source world there were tons of forks of projects and it > proved to be a useful mechanism for resolving serious management > issues. On the other hand the kind of hostile takeover that happened > with pyjs is virtually unparalleled in the open source world. What > made you think such a unique operation will be less harmful than the > other which has already been tried many times? > >> ------------------------------------------------------------------------ >> | Please get this absolutely clear in your head: that | >> | you do not "understand" my reasoning is completely and utterly | >> | irrelevant. i understand *your* reasoning; i'm the one making the | >> | decisions, that's my role to understand the pros and cons. i make a | >> | decision: that's the end of it. | >> | You present reasoning to me: i weight it up, against the other | >> | reasoning, and i make a decision. you don't have to understand that | >> | decision, you do not have to like that decision, you do not have to | >> | accept that decision. | >> ------------------------------------------------------------------------ > > Again, if you don't like the lead developer just fork the project, > come up with a new name, new website and new infrastructure and start > building a new community. Why didn't the rebels do that? > > Cheers, > Daniel > > Typical shabby Nazi trick. -- Cheers. Mark Lawrence. From msmucr at gmail.com Tue May 15 17:39:40 2012 From: msmucr at gmail.com (msmucr) Date: Tue, 15 May 2012 14:39:40 -0700 (PDT) Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? References: Message-ID: <8fa56e29-44dc-4538-99ec-aa1b70189589@d17g2000vbv.googlegroups.com> On 15 kv?, 21:21, John Gordon wrote: > In msmucr writes: > > > Do I have something wrong or is it simply broken and unmaintained now? > > We have no idea if you did anything wrong, because you didn't tell us > exactly what you did and exactly what error message you received. > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gor... at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Edward Gorey, "The Gashlycrumb Tinies" Hello, i'm sorry for my very vague specification. I had problems with importing of anything from Carbon.CarbonEvt module and i wasn't sure what is wrong and was little bit stucked. I tried several desperate things before that as i've never worked with this module and it is my first thing with Carbon library.. Just before i read Kevin's reply i've figured, problem was, that OS X shipped Python wrapper /usr/bin/python runs by default 64bit version on recent Macs. So bindings for 32bit Carbon lib didn't work. Here is my output (i've choose RegisterEventHotKey as example): macmini-E514:~ macek$ /usr/bin/python -c "import sys; print sys.maxint; from Carbon.CarbonEvt import RegisterEventHotKey; print(RegisterEventHotKey.__doc__)" 9223372036854775807 Traceback (most recent call last): File "", line 1, in ImportError: cannot import name RegisterEventHotKey macmini-E514:~ macek$ env VERSIONER_PYTHON_PREFER_32_BIT=yes /usr/bin/ python -c "import sys; print sys.maxint; from Carbon.CarbonEvt import RegisterEventHotKey; print(RegisterEventHotKey.__doc__)" 2147483647 (UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef) So, now i could start playing with it.. :-) I'm trying to do something like this in Python http://www.macosxguru.net/article.php?story=20060204132802111 Best regards and thank you for replies Michal From arnodel at gmail.com Tue May 15 17:42:41 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 15 May 2012 22:42:41 +0100 Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? In-Reply-To: References: Message-ID: On 15 May 2012 20:55, Ned Deily wrote: > In article > , > ?msmucr wrote: >> i would like to ask you for some information regarding Carbon Event >> Manager ( Carbon.CarbonEvt ) library in Python. >> I need to recieve and work with few Carbon events in my program. I've >> followed some examples on PyObjC site, but wasn't successful. I know, >> that both Carbon library and this Python module is deprecated, but >> frankly i didn't find any usable alternative except of writing of >> something from scratch.. >> I ended on basic import of required objects from Carbon.CarbonEvt >> module - >> like "from Carbon.CarbonEvt import RegisterEventHotKey" >> I tried it in Python 2.7.1 (standard distribution in OS X 10.7 Lion) >> and Python 2.6.1 (standard Apple distribution in OS X 10.6). >> Do I have something wrong or is it simply broken and unmaintained now? > > You may want to ask OS X specific questions on the macpython mailing > list (http://www.python.org/community/sigs/current/pythonmac-sig/). The > main reason that these modules are deprecated (and have been removed in > Python 3) is because they depend on obsolete APIs in OS X that are only > available in 32-bit versions. ?Apple has made it clear that they will > not be made available as 64-bit and will eventually go away. ?You should > try to find ways not to use the Carbon model in your applications. ?That > said, you can use these modules, even with the Apple-supplied Pythons in > OS X 10.6 and 10.7, if you force Python to run in 32-bit-mode. ?For > those Apple-supplied Pythons, see the Apple man page (man 1 python) for > system Python specific ways to force 32-bit mode persistently. ?Another > way that should work for any OS X universal Python 2.7.x: > > ? ?arch -i386 python2.7 This is what I have with system python 2.6: $ cat ~/bin/python_32 #! /bin/bash export VERSIONER_PYTHON_PREFER_32_BIT=yes /usr/bin/python "$@" I use it for wxpython, which only seems to work in 32 bit mode. I can't remember where I found it. Maybe I read the man page? -- Arnaud From nad at acm.org Tue May 15 19:06:46 2012 From: nad at acm.org (Ned Deily) Date: Tue, 15 May 2012 16:06:46 -0700 Subject: Carbon Event Manager (Carbon.CarbonEvt module) - working? References: Message-ID: In article , Arnaud Delobelle wrote: > This is what I have with system python 2.6: > > $ cat ~/bin/python_32 > #! /bin/bash > export VERSIONER_PYTHON_PREFER_32_BIT=yes > /usr/bin/python "$@" > > I use it for wxpython, which only seems to work in 32 bit mode. I > can't remember where I found it. Maybe I read the man page? Yes, that is one of the two documented ways in the Apple man page to force 32-bit mode; the other way is to set a plist using the "defaults" command. Keep in mind that these are Apple modifications to Python so they won't work with other OS X Python distributions like those from python.org. The "arch" command should work with all of them, as long as you use "python2.7"; it won't work with the Apple wrapper program /usr/bin/python. And I believe the Apple modifications only work when you use /usr/bin/python. -- Ned Deily, nad at acm.org From ian.g.kelly at gmail.com Tue May 15 20:50:06 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 15 May 2012 18:50:06 -0600 Subject: Hashability questions In-Reply-To: References: <3803676.538.1336936281052.JavaMail.geo-discussion-forums@ynbq3> Message-ID: On Tue, May 15, 2012 at 3:25 AM, Christian Heimes wrote: > Code explains more than words. I've created two examples that some issues. > > Mutable values break dicts as you won't be able to retrieve the same > object again: Sure, you'll get no argument from me on that. I was more interested in the other one. > When you mess up __eq__ you'll get funny results and suddenly the > insertion order does unexpected things to you: > >>>> class Example2(object): > ... ? ? def __init__(self, value): > ... ? ? ? ? self.value = value > ... ? ? def __hash__(self): > ... ? ? ? ? return hash(self.value) > ... ? ? def __eq__(self, other): > ... ? ? ? ? return hash(self) == hash(other) > ... >>>> d = {} >>>> ob = Example2("egg") >>>> d[ob] = True >>>> d > {<__main__.Example2 object at 0x7fab66cb7610>: True} >>>> d["egg"] = True >>>> d > {<__main__.Example2 object at 0x7fab66cb7610>: True} >>>> d2 = {} >>>> d2["egg"] = True >>>> d2[ob] = True >>>> d2 > {'egg': True} That's just how sets and dicts work with distinct objects that compare equal. I don't see any fundamental difference between that and this: >>> d = {} >>> d[42] = True >>> d {42: True} >>> d[42.0] = True >>> d {42: True} >>> d2 = {} >>> d2[42.0] = True >>> d2 {42.0: True} >>> d2[42] = True >>> d2 {42.0: True} I wouldn't consider the hashing of ints and floats to be broken. From k.sharagovind at gmail.com Wed May 16 00:46:44 2012 From: k.sharagovind at gmail.com (sharadha devi) Date: Tue, 15 May 2012 21:46:44 -0700 (PDT) Subject: PAYPAL - $1000 PAYMENT RECIEVED !! Message-ID: <08663439-f82a-4dcf-b7b8-5a3c721bd10b@vy9g2000pbc.googlegroups.com> REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX +++ Jesus Loves You +++ http://jesuslovesyou-youlovejesus.blogspot.in/ CHECK ALL THESE AMAZING HUGE DISCOUNTED PRODUCTS & BUY THEM WHAT YOU LIKE !!! http://alloffersblog.blogspot.in/ http://myblog-mycash.blogspot.in/ http://stephenanand.blogspot.in/ http://clickforgreatoffers.blogspot.in/ http://buyallamazonproducts.blogspot.in/ CHECK OUT THIS AMAZING ONLINE BUSSINESS STORES : http://linkshareoffers.blogspot.in/ http://buythemwhatyoulike.blogspot.com/ http://paydotoffers.blogspot.com/ SEARCH & BUY FROM OVER 10,000 INFO-PRODUCTS INSTANTLY : http://cbglobe.com/x.cgi?id=stephen1 WORLD BEST DIAMOND RINGS & JEWELRY WEBSITE : CHOOSE FROM A WIDE RANGE ALL @ WHOLESALE PRICES http://www.shireeodiz.com/diamond-engagement-rings/4d6a526826ecd/08898bec.html REFRESH THIS LINKS EACH TIME TO SEE AMAZING OFFERS http://bit.ly/AiKisb http://bit.ly/wDpAll http://bit.ly/yCrUBU http://bit.ly/x7UJRX @@@@@ AMAZING HUGE DISCOUNTED PRODUCTS @@@@@@ >>>> BUY THEM WHAT YOU LIKE !!! <<<<<<<<< Resell Products Monthly (Lifetime Member) - Get Instant Access To 1,132 Private Label Rights And Master Resale Rights Products http://payspree.com/4644/stephen1 Prosperity Party ($608 of Inspiring Vid/Aud/etc) http://payspree.com/2084/stephen1 Hot Marketing Videos - Lifetime Membership http://payspree.com/3242/stephen1 The Art Of Making Money Online Get rid of fear once and for all. Make money on your PC from home with your own stuff. http://payspree.com/4304/stephen1 Nikon D3100 14.2 Megapixel Digital SLR Camera - Overview of Nikon D3100 14.2 Megapixel Digital SLR Camera (Body with Lens Kit) - 18 mm-55 mm - Black http://payspree.com/5242/stephen1 Take Control | Health | Life | MP3 and ebook - "Who Else Is Ready To Be Healthy NOW?" | Take Control ...it's your health ... it's your life | by Donald M. Alanen http://payspree.com/3996/stephen1 Fireball Internet Marketing Course - 2-Month Internet Marketing Course with Ian del Carmen http://payspree.com/858/stephen1 eCover Crusher - High Quality Photoshop Action Scripts with photoshop how to videos, sales page writing template and how to start a ecover design business http://payspree.com/2733/stephen1 Squeeze Synergy One-Time Offer For Fast Track Cash http://payspree.com/3885/stephen1 10 Strategy Sessions With Experts (+transcripts) - Converts like crazy! http://payspree.com/4311/stephen1 Answer Marketing Traffic No Hard Selling, No Product Of Your Own An NO Risk! http://payspree.com/1169/stephen1 Niche Hunting For Newbies, which converts like crazy. http://payspree.com/1391/stephen1 Ezine Articles Quick Niche Secrets - Uncover Complete Gold Mine Niches From Ezine Articles In 10 Minutes Or Less... http://payspree.com/1517/stephen1 Social Marketing Tips http://payspree.com/1398/stephen1 OTO Firesale http://payspree.com/5667/stephen1 Sniper List Building - List building Crushing it online http://payspree.com/3559/stephen1 One Time Offer Blueprint http://payspree.com/1173/stephen1 Easy Offline SEO - How to make money as an offline SEO consultant without doing ANY of the work yourself and with zero expert knowledge! http://payspree.com/4922/stephen1 List Building Conquest - Build Quick In Demand Products And Create A 10,000+ Subscriber Traffic Machine. http://payspree.com/3262/stephen1 Online Paycheck Blueprint - Learn everything you need to start your Internet business. http://payspree.com/5209/stephen1 EASY MONEY - 100% COMMISSIONS INSTANT PAYMENTS NICE PRODUCTS http://payspree.com/5308/stephen1 $20 Dollar Bill Blaster - Get $20 Instantly Blasted into your PayPal Account Every Time Someone Joins through your $20 Bill Blaster Referral Link! http://payspree.com/4406/stephen1 WordPress Product Automator - WP product delivery plugin, includes great bonuses 5 WP themes, making money with PLR/MRR http://payspree.com/1504/stephen1 Quick and Easy CB Riches http://payspree.com/3883/stephen1 20 Newbie Videos - Firesale OTO ($10 Off) - 20 Newbie Videos http://payspree.com/5823/stephen1 From timr at probo.com Wed May 16 01:32:47 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 15 May 2012 22:32:47 -0700 Subject: %d not working in re at Python 2.7? References: Message-ID: vacu wrote: > >I am frustrated to see %d not working in my Python 2.7 re.search, like >this example: > >>>> (re.search('%d', "asdfdsf78asdfdf")).group(0) >Traceback (most recent call last): > File "", line 1, in >AttributeError: 'NoneType' object has no attribute 'group' > >\d works fine: > >>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0) >'78' > >And google search ignores % in their search, so I failed to find >answer from Python mailing list or web, >Do you have any idea what's problem here? Yes. %d has never worked. \d+ is the right answer. It's just that simple. Where did you read that %d should work? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From neolo12 at yandex.ru Wed May 16 01:59:32 2012 From: neolo12 at yandex.ru (jimmy970) Date: Tue, 15 May 2012 22:59:32 -0700 (PDT) Subject: http://porn-extreme.2304310.n4.nabble.com/ In-Reply-To: <1336893271019-4974351.post@n6.nabble.com> References: <1334385003417-4880911.post@n6.nabble.com> <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> <1335847182281-4942868.post@n6.nabble.com> <1335955532204-4945863.post@n6.nabble.com> <1336893271019-4974351.post@n6.nabble.com> Message-ID: <1337147972283-4974741.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4974741.html Sent from the Python - python-list mailing list archive at Nabble.com. From memilanuk at gmail.com Wed May 16 02:24:58 2012 From: memilanuk at gmail.com (Monte Milanuk) Date: Tue, 15 May 2012 23:24:58 -0700 Subject: Looking for video/slides from PyCon 2011... In-Reply-To: References: Message-ID: On 05/13/2012 09:42 PM, Kushal Kumaran wrote: > On Fri, May 11, 2012 at 5:42 AM, Monte Milanuk wrote: >> ...specifically the two lectures on creating GUI applications with Python + >> QT >> >> http://us.pycon.org/2011/schedule/presentations/207/ >> >> Various searches on the 'Net don't seem to be turning up much... kinda >> curious as to why? >> >> Anyone here know? >> > > Is it one of the videos at http://blip.tv/pycon-us-videos-2009-2010-2011 > Unless its buried in one of the lightning talk vids, I'm not seein' it. Thanks tho, Monte From info at egenix.com Wed May 16 03:47:50 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 16 May 2012 09:47:50 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.0-1.0.0j Message-ID: <4FB35BA6.4050307@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.0-1.0.0j An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.0-1.0.0j-1.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included included OpenSSL version to 1.0.0g. New features in OpenSSL 1.0.0j since 1.0.0g ------------------------------------------- OpenSSL 1.0.0j fixes several vulnerabilities relative to 1.0.0g: http://openssl.org/news/vulnerabilities.html and includes a number of stability enhancements as well as extra protection against attacks: http://openssl.org/news/changelog.html New features in the eGenix pyOpenSSL Distribution ------------------------------------------------- * Fixed a compatibility problem with Python 2.7's distutils that was introduced in Python 2.7.3 As always, we provide binaries that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distributon, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 16 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-07-02: EuroPython 2012, Florence, Italy 47 days to go 2012-04-26: Released mxODBC 3.1.2 http://egenix.com/go28 2012-04-25: Released eGenix mx Base 3.2.4 http://egenix.com/go27 ::: 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 alan.kesselmann at gmail.com Wed May 16 04:22:20 2012 From: alan.kesselmann at gmail.com (zayatzz) Date: Wed, 16 May 2012 01:22:20 -0700 (PDT) Subject: ucs2 and ucs4 python References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> Message-ID: <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> On May 15, 7:42?pm, Miki Tebeka wrote: > > Can someone point me towards a resource or two which will tell me how > > to do this - im not very good with whole linux/servers stuff. Im using > > ubuntu linux - if that makes any difference. > > Did not test, but this is the direction I would take: > * Download Python sources > * Open Terminal > * Run the following commands in the Terminal window > ? - sudo apt-get build-dep python > ? - tar -xjf Python-2.7.3.tar.bz2 > ? - cd Python-2.7.3 > ? - ./configure --prefix=/opt --enable-unicode=ucs2 && make > ? - sudo make install > * Now you should have /opt/bin/python with ucs2 > > HTH > -- > Miki Tebeka http://pythonwise.blogspot.com Thanks for reply :) And it seems to work... When i type in /opt/bin/python import sys sys.maxunicode then i get the desired answer - 65535 But it seems the work only begins now, because i cant use other python libraries now with this version of python and i probably have to install them all again somehow... But thanks for your help :) Alan From alan.kesselmann at gmail.com Wed May 16 04:36:39 2012 From: alan.kesselmann at gmail.com (zayatzz) Date: Wed, 16 May 2012 01:36:39 -0700 (PDT) Subject: ucs2 and ucs4 python References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> Message-ID: <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> There is one problem though... when i start script with shebang like #!/opt/bin/python and then try to run the script i get: /opt/bin/python^M: bad interpreter: No such file or directory /opt/bin/python /opt/bin/python2 /opt/bin/python2.7 all start this new version of python, but none of those work in shebang Alan From stefan_ml at behnel.de Wed May 16 04:43:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 16 May 2012 10:43:06 +0200 Subject: ucs2 and ucs4 python In-Reply-To: <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> Message-ID: zayatzz, 16.05.2012 10:22: > On May 15, 7:42 pm, Miki Tebeka wrote: >>> Can someone point me towards a resource or two which will tell me how >>> to do this - im not very good with whole linux/servers stuff. Im using >>> ubuntu linux - if that makes any difference. >> >> Did not test, but this is the direction I would take: >> * Download Python sources >> * Open Terminal >> * Run the following commands in the Terminal window >> - sudo apt-get build-dep python >> - tar -xjf Python-2.7.3.tar.bz2 >> - cd Python-2.7.3 >> - ./configure --prefix=/opt --enable-unicode=ucs2 && make >> - sudo make install >> * Now you should have /opt/bin/python with ucs2 >> >> HTH >> -- >> Miki Tebeka http://pythonwise.blogspot.com > > Thanks for reply :) > > And it seems to work... When i type in > /opt/bin/python > import sys > sys.maxunicode > > then i get the desired answer - 65535 > > But it seems the work only begins now, because i cant use other python > libraries now with this version of python and i probably have to > install them all again somehow... You should install "distribute" and "pip" into it, then you can use pip to install packages directly and automatically from the Python Package Index (PyPI), including any dependencies. Even better, use "virtualenv" to create a local copy of your installation and then install packages into that. This allows you to use completely separate environments of the same Python installation, which can be very handy for testing. Stefan From mcepl at redhat.com Wed May 16 04:50:50 2012 From: mcepl at redhat.com (Matej Cepl) Date: Wed, 16 May 2012 10:50:50 +0200 Subject: ucs2 and ucs4 python In-Reply-To: <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> Message-ID: <4FB36A6A.6040308@redhat.com> On 16.5.2012 10:36, zayatzz wrote: > /opt/bin/python^M: bad interpreter: No such file or directory Your script has CRLF end-of-lines. Change it to plain Unix LF. Mat?j From rosuav at gmail.com Wed May 16 05:05:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 May 2012 19:05:23 +1000 Subject: ucs2 and ucs4 python In-Reply-To: <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> Message-ID: On Wed, May 16, 2012 at 6:36 PM, zayatzz wrote: > There is one problem though... > > when i start script with shebang like > #!/opt/bin/python > > and then try to run the script i get: > > /opt/bin/python^M: bad interpreter: No such file or directory You have a Windows end-of-line \r\n instead of a Unix end-of-line \n - how are you editing the files? If nothing else, run the script through dos2unix or equivalent before executing. ChrisA From alan.kesselmann at gmail.com Wed May 16 05:20:51 2012 From: alan.kesselmann at gmail.com (zayatzz) Date: Wed, 16 May 2012 02:20:51 -0700 (PDT) Subject: ucs2 and ucs4 python References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> <4FB36A6A.6040308@redhat.com> Message-ID: On May 16, 11:50?am, Matej Cepl wrote: > On 16.5.2012 10:36, zayatzz wrote: > > > /opt/bin/python^M: bad interpreter: No such file or directory > > Your script has CRLF end-of-lines. Change it to plain Unix LF. > > Mat?j Thanks :) but i have no idea what that means or how to achieve that. Alan From d at davea.name Wed May 16 05:54:30 2012 From: d at davea.name (Dave Angel) Date: Wed, 16 May 2012 05:54:30 -0400 Subject: ucs2 and ucs4 python In-Reply-To: References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> <4FB36A6A.6040308@redhat.com> Message-ID: <4FB37956.2090909@davea.name> On 05/16/2012 05:20 AM, zayatzz wrote: > On May 16, 11:50 am, Matej Cepl wrote: >> On 16.5.2012 10:36, zayatzz wrote: >> >>> /opt/bin/python^M: bad interpreter: No such file or directory >> Your script has CRLF end-of-lines. Change it to plain Unix LF. >> >> Mat?j > Thanks :) but i have no idea what that means or how to achieve that. > > Alan See in the echo of the shebang line the "^M" at the end ? That's a carriage return, hex(0d). Unix/Linux use a single linefeed (hex(0a)) at the end of the line. At some point, you probably edited this file with a Windows (aka DOS) editor, and it used the CRLF form (hex(0d0a)), carriage return/line feed at the end of each line. Your Linux text editor probably has a menu option to convert them back to simple linefeeds, but if not, your Linux/Unix probably has a utility dos2unix which can do the job. -- DaveA From alan.kesselmann at gmail.com Wed May 16 06:29:25 2012 From: alan.kesselmann at gmail.com (zayatzz) Date: Wed, 16 May 2012 03:29:25 -0700 (PDT) Subject: ucs2 and ucs4 python References: <4246752.24.1337100171530.JavaMail.geo-discussion-forums@ynam14> <5e75ec84-ae5d-4ec4-9897-424060bacd15@5g2000vbf.googlegroups.com> <2f8fd143-3a42-43fb-8195-d1ad81a2090b@v10g2000vbe.googlegroups.com> <4FB36A6A.6040308@redhat.com> Message-ID: <8f73a029-4a41-4a81-8fd5-f78bbc6fdf78@m10g2000vbn.googlegroups.com> No need to answer that now, Dave explained this to me via personal reply. Thanks man! And thanks again to everybody else :) From jeandaniel.browne at gmail.com Wed May 16 08:38:01 2012 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Wed, 16 May 2012 14:38:01 +0200 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On Sun, May 13, 2012 at 2:29 PM, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. Ordered dict are useful, but they only remember the ordered in which they were added, you can not order them a on key. Thanks for the links. > > If you are looking for the best possible self-sorting structure for > searching, then perhaps you are looking for what's outlined in the > 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) > Expected Time and Linear Space[3]. > > [1] http://www.python.org/getit/releases/3.1/ > [2] http://www.python.org/getit/releases/2.7.3/ > [3] http://dl.acm.org/citation.cfm?id=645413.652131 > > On Sat, May 12, 2012 at 10:17 PM, Jean-Daniel > wrote: >> >> Hello, >> >> I have a long list of n date intervals that gets added or suppressed >> intervals regularly. I am looking for a fast way to find the intervals >> containing a given date, without having to check all intervals (less >> than O(n)). >> >> Do you know the best way to do this in Python with the stdlib? >> >> A variant of the red black trees can do the job quickly [1], is this a >> good enough use case to discuss the inclusion of a red black tree >> implementation in the stdlib? >> >> This has been discussed here: http://bugs.python.org/issue1324770 , >> and lack of good use case was the reason the bug was closed. A dict >> implemented with red black trees is slower (but not too slow) at >> inserting, searching and deleting but the dict is always kept ordered. >> Bigger projects have their own implementation of ordered dict so such >> datastructures in the standard library would help the porting of the >> project to other platforms. Take the example of the zodb and the >> C-only implementation of the btree: btree in the stdlib in Python >> would help the porting to GAE or pypy [2]. >> >> Cheers, >> >> [1] in the "Cormen" book: >> http://en.wikipedia.org/wiki/Introduction_to_Algorithms >> [2] https://blueprints.launchpad.net/zodb/+spec/remove-btree-dependency >> -- >> http://mail.python.org/mailman/listinfo/python-list From mgbg25171 at blueyonder.co.uk Wed May 16 10:08:52 2012 From: mgbg25171 at blueyonder.co.uk (e-mail mgbg25171) Date: Wed, 16 May 2012 15:08:52 +0100 Subject: what does newP = func(code,p) do? Message-ID: def execute (code) : p = 0 while p < len(code) : func = code[p] p += 1 newP = func(code,p) if newP != None : p = newP I'm trying to work out what this does.... code is a list of function addresses and numbers What on earth is funct(code,p) doing??? My understanding so far is... set p to 0 while p is less than the number of elements in list code keep doing what follows... set func to the first element in the list increment the list index p ? if newP is not null then set the list index p to ? Can someone please explain in english what ? is Thank you in anticipation BTW the link for this stuff is http://openbookproject.net/py4fun/forth/forth.html to see the thing in action ie the download link is on the above page Here's a listing of the output from this proc for the following forth input i.e. I put some print statements in but have no idea how newP set to func( [, 4] , 1 ) i.e. 2 results in 2 and then newP set to func( [] , 1 ) i.e. None results in None ??? Forth> 5 4 + . 1st line of execute__________________ code = [, 5] p = 0 1st line of while__________________ func = code[ 0 ] i.e. incrementing p to 1 newP set to func( [, 5] , 1 ) i.e. 2 p = newP i.e. 2 1st line of execute__________________ code = [, 4] p = 0 1st line of while__________________ func = code[ 0 ] i.e. incrementing p to 1 newP set to func( [, 4] , 1 ) i.e. 2 p = newP i.e. 2 1st line of execute__________________ code = [] p = 0 1st line of while__________________ func = code[ 0 ] i.e. incrementing p to 1 newP set to func( [] , 1 ) i.e. None 1st line of execute__________________ code = [] p = 0 1st line of while__________________ func = code[ 0 ] i.e. incrementing p to 1 13 newP set to func( [] , 1 ) i.e. 5 None Forth> -------------- next part -------------- An HTML attachment was scrubbed... URL: From nibinvm at gmail.com Wed May 16 10:16:04 2012 From: nibinvm at gmail.com (Nibin V M) Date: Wed, 16 May 2012 19:46:04 +0530 Subject: python and xml Message-ID: Hi, I am trying to use cPanel XML-API and every API call return data in XML format. I would like to know how to manipulate the data here. For eg: How can I read the CPU load data from the below output 0.000.000.00 Thank you, -- Regards.... Nibin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed May 16 10:23:34 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 16 May 2012 16:23:34 +0200 Subject: python and xml In-Reply-To: References: Message-ID: Nibin V M, 16.05.2012 16:16: > I am trying to use cPanel XML-API and every API call return data in XML > format. I would like to know how to manipulate the data here. > > For eg: How can I read the CPU load data from the below output > > > 0.000.000.00 Here's some untested code to print the text values: import xml.etree.ElementTree as ET loadavg = ET.fromstring('0.000.00' '0.00') for interval_tag in ('one', 'five', 'fifteen'): print(loadavg.findtext(interval_tag)) Stefan From info at wingware.com Wed May 16 10:27:10 2012 From: info at wingware.com (Wingware) Date: Wed, 16 May 2012 10:27:10 -0400 Subject: Wing IDE 4.1.6 released Message-ID: <4FB3B93E.50603@wingware.com> Hi, Wingware has released version 4.1.6 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE is a cross-platform Python IDE that provides a professional code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. **Changes** This release includes: * Support for Django 1.4 * Syntax highlighting Qt Style Sheet (.qss) files * Command to show selected file in OS-provided file manager * Per-project configuration of Debug Network Port for remote debugging * Several auto-editing fixes * Several turbo completion mode fixes * Replace All preserves fold state when possible * Git blame support * Fixed debugging QThreads in older PyQt versions * Shorter delay in restarting Python Shell or debug process * About 15 other bug fixes and minor improvements Complete change log: http://wingware.com/pub/wingide/4.1.6/CHANGELOG.txt **New Features in Version 4** Version 4 adds the following new major features: * Refactoring -- Rename/move symbols, extract to function/method, and introduce variable * Find Uses -- Find all points of use of a symbol * Auto-Editing -- Reduce typing by auto-entering expected code * Diff/Merge -- Graphical file and repository comparison and merge * Django Support -- Debug Django templates, run Django unit tests, and more * matplotlib Support -- Maintains live-updating plots in shell and debugger * Simplified Licensing -- Includes all OSes and adds Support+Upgrades subscriptions Details on licensing changes: http://wingware.com/news/2011-02-16 **About Wing IDE** Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching beginning programming courses with Python. Version 4 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, find uses, goto-definition, error indicators, refactoring, context-aware auto-editing, smart indent and rewrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tooltips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing with unittest, nose, and doctest frameworks * Django support: Debugs Django templates, provides project setup tools, and runs Django unit tests * Many other features including project manager, bookmarks, code snippets, diff/merge tool, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts * Extensive product documentation and How-Tos for Django, matplotlib, Plone, wxPython, PyQt, mod_wsgi, Autodesk Maya, and many other frameworks Please refer to http://wingware.com/wingide/featuresfor a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9or later (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.2.x and Stackless Python. For more information, see the http://wingware.com/ **Downloads** Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial can be obtained directly from the product when launched. Wing IDE Pro -- Full-featured product: http://wingware.com/downloads/wingide/4.1 Wing IDE Personal -- A simplified IDE: http://wingware.com/downloads/wingide-personal/4.1 Wing IDE 101 -- For teaching with Python: http://wingware.com/downloads/wingide-101/4.1 **Purchasing and Upgrading** Wing 4.x requires an upgrade for Wing IDE 2.x and 3.x users at a cost of 1/2 the full product pricing. Upgrade a license: https://wingware.com/store/upgrade Purchase a new license: https://wingware.com/store/purchase Optional Support+Upgrades subscriptions are available for expanded support coverage and free upgrades to new major releases: http://wingware.com/support/agreement Thanks! -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From nibinvm at gmail.com Wed May 16 10:30:33 2012 From: nibinvm at gmail.com (Nibin V M) Date: Wed, 16 May 2012 20:00:33 +0530 Subject: python and xml In-Reply-To: References: Message-ID: thank you Stefan. but the XML output is assigned to a variable; how to process the variable with XML contents? On Wed, May 16, 2012 at 7:53 PM, Stefan Behnel wrote: > Nibin V M, 16.05.2012 16:16: > > I am trying to use cPanel XML-API and every API call return data in XML > > format. I would like to know how to manipulate the data here. > > > > For eg: How can I read the CPU load data from the below output > > > > > > > 0.000.000.00 > > Here's some untested code to print the text values: > > import xml.etree.ElementTree as ET > > loadavg = ET.fromstring('0.000.00' > '0.00') > > for interval_tag in ('one', 'five', 'fifteen'): > print(loadavg.findtext(interval_tag)) > > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards.... Nibin. http://TechsWare.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed May 16 10:36:03 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 16 May 2012 16:36:03 +0200 Subject: python and xml In-Reply-To: References: Message-ID: Hi, please don't top-post (I fixed the citation order below). Nibin V M, 16.05.2012 16:30: > On Wed, May 16, 2012 at 7:53 PM, Stefan Behnel wrote: >> Nibin V M, 16.05.2012 16:16: >>> I am trying to use cPanel XML-API and every API call return data in XML >>> format. I would like to know how to manipulate the data here. >>> >>> For eg: How can I read the CPU load data from the below output >>> >>> >>> >> 0.000.000.00 >> >> >> Here's some untested code to print the text values: >> >> import xml.etree.ElementTree as ET >> >> loadavg = ET.fromstring('0.000.00' >> '0.00') >> >> for interval_tag in ('one', 'five', 'fifteen'): >> print(loadavg.findtext(interval_tag)) > > thank you Stefan. but the XML output is assigned to a variable; how to > process the variable with XML contents? Not sure what you mean. Maybe something like this? xml = '0.000.00...' loadavg = ET.fromstring(xml) Stefan From ytj000 at gmail.com Wed May 16 10:59:31 2012 From: ytj000 at gmail.com (ytj) Date: Wed, 16 May 2012 07:59:31 -0700 (PDT) Subject: How to embed python2 into python3? Message-ID: <770e6701-983a-4a3e-8727-2a4b0e2d8169@oe8g2000pbb.googlegroups.com> Hello, all: I have two programs, one is written in py3k, the other is written in python 2. I am wondering how to make them work together except port the python 2 code to py3k? Is that possible to expose python2's function to py3k? In other words, I want to embed the Python 2 interpreter into my py3k program. So I can call python2's function in py3k's code. Regards, Tianjiao From ian.g.kelly at gmail.com Wed May 16 11:32:41 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 09:32:41 -0600 Subject: what does newP = func(code,p) do? In-Reply-To: References: Message-ID: On Wed, May 16, 2012 at 8:08 AM, e-mail mgbg25171 wrote: > def execute (code) : > ??? p = 0 > ??? while p < len(code) : > ??????? func = code[p] > ??????? p += 1 > ??????? newP = func(code,p) > ??????? if newP != None : > ??????????? p = newP > > I'm trying to work out what this does.... > > code is a list of function addresses and numbers > What on earth is funct(code,p) doing??? code represents the bytecode of the Forth program being executed. It contains functions that represent operations and the data arguments used by those operations. p is the program counter, keeping track of which opcode should be executed next. func is the operation function that was pulled from code at the current program counter. func(code, p) calls that function, passing in both the entire bytecode, and the index into the bytecode at which the operation can find its data (if any). If the function returns a value, it means that the program counter should be updated -- either to skip past a data element used for the operation just executed, or to perform a jump to somewhere else in the bytecode. If the program counter ever falls off the end of the bytecode, then the program terminates. From marco_u at nsgmail.com Wed May 16 11:48:19 2012 From: marco_u at nsgmail.com (Marco) Date: Wed, 16 May 2012 17:48:19 +0200 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 Message-ID: Hi all, because "There should be one-- and preferably only one --obvious way to do it", there should be a difference between the two methods in the subject, but I can't find it: >>> '123'.isdecimal(), '123'.isdigit() (True, True) >>> print('\u0660123') ?123 >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() (True, True) >>> print('\u216B') ? >>> '\u216B'.isdecimal(), '\u216B'.isdigit() (False, False) Can anyone give me some help? Regards, Marco From ian.g.kelly at gmail.com Wed May 16 12:08:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 10:08:58 -0600 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: References: Message-ID: On Wed, May 16, 2012 at 9:48 AM, Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but I > can't find it: > >>>> '123'.isdecimal(), '123'.isdigit() > (True, True) >>>> print('\u0660123') > ?123 >>>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() > (True, True) >>>> print('\u216B') > ? >>>> '\u216B'.isdecimal(), '\u216B'.isdigit() > (False, False) > > Can anyone give me some help? Here's one example: >>> '\u00B2'.isdecimal() False >>> '\u00B2'.isdigit() True >>> '\u00B2' '?' The distinction is explained in the docs at: http://docs.python.org/py3k/library/stdtypes.html#str.isdigit Cheers, Ian From mgbg25171 at blueyonder.co.uk Wed May 16 12:09:18 2012 From: mgbg25171 at blueyonder.co.uk (e-mail mgbg25171) Date: Wed, 16 May 2012 17:09:18 +0100 Subject: what does newP = func(code,p) do? Message-ID: It's been a long time since I did any Python and I've never done that In C I'm used to storing function ptrs and then having to use some other constructs to call them. To be able to store func and then use func to call itself like that threw me...it's very elegant. Thank you very much for your very lucid explanation and for taking the time to provide it. Best Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed May 16 12:11:05 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 May 2012 17:11:05 +0100 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: References: Message-ID: <4FB3D199.10503@mrabarnett.plus.com> On 16/05/2012 16:48, Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but > I can't find it: > > >>> '123'.isdecimal(), '123'.isdigit() > (True, True) > >>> print('\u0660123') > ?123 > >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() > (True, True) > >>> print('\u216B') > ? > >>> '\u216B'.isdecimal(), '\u216B'.isdigit() > (False, False) > > Can anyone give me some help? > Regards, Marco Try this: >>> different = [chr(c) for c in range(0x10000) if chr(c).isdigit() != chr(c).isdecimal()] >>> print(different) ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'] From doomster at knuut.de Wed May 16 12:24:57 2012 From: doomster at knuut.de (Ulrich Eckhardt) Date: Wed, 16 May 2012 18:24:57 +0200 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: Message-ID: Marco wrote: > >>> '123'.isdecimal(), '123'.isdigit() > (True, True) > >>> print('\u0660123') > ?123 > >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() > (True, True) > >>> print('\u216B') > ? > >>> '\u216B'.isdecimal(), '\u216B'.isdigit() > (False, False) [chr(a) for a in range(0x20000) if chr(a).isdigit()] Congratulations, you found a bug! Or maybe not, it all depends on whether Roman numbers are considered digits or not. I could imagine there being a difference. :) Uli From ian.g.kelly at gmail.com Wed May 16 13:02:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 11:02:22 -0600 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: References: Message-ID: On Wed, May 16, 2012 at 10:24 AM, Ulrich Eckhardt wrote: > Marco wrote: >> ?>>> '123'.isdecimal(), '123'.isdigit() >> (True, True) >> ?>>> print('\u0660123') >> ?123 >> ?>>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() >> (True, True) >> ?>>> print('\u216B') >> ? >> ?>>> '\u216B'.isdecimal(), '\u216B'.isdigit() >> (False, False) > > [chr(a) for a in range(0x20000) if chr(a).isdigit()] > > Congratulations, you found a bug! Or maybe not, it all depends on whether > Roman numbers are considered digits or not. I could imagine there being a > difference. They're not. The word "digit" specifically refers to the symbols used by a positional numeral system, e.g. Arabic numerals. Roman numerals are not a positional system. The word "decimal" in this case more specifically means a digit character that is actually suitable for using to compose a decimal number. From clp2 at rebertia.com Wed May 16 14:00:22 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 16 May 2012 11:00:22 -0700 Subject: How to embed python2 into python3? In-Reply-To: <770e6701-983a-4a3e-8727-2a4b0e2d8169@oe8g2000pbb.googlegroups.com> References: <770e6701-983a-4a3e-8727-2a4b0e2d8169@oe8g2000pbb.googlegroups.com> Message-ID: On Wed, May 16, 2012 at 7:59 AM, ytj wrote: > Hello, all: > > I have two programs, one is written in py3k, the other is written in > python 2. I am wondering how to make them work together except port > the python 2 code to py3k? Porting the Python 3 code to Python 2 is also an option: http://pypi.python.org/pypi/3to2 But unless you're dependent on a library not available for Python 3 yet, the normal 2to3 route is probably preferable. In either direction, this library may help ease the transition: http://pypi.python.org/pypi/six/ > Is that possible to expose python2's > function to py3k? In other words, I want to embed the Python 2 > interpreter into my py3k program. So I can call python2's function in > py3k's code. That's very likely possible using the C API; I don't know of any prepackaged solution though. Another obvious approach to connect the two interpreters would be to use some form of IPC or RPC (e.g. XML-RPC, Unix domain sockets, etc.). There will be some degree of extra overhead involved no matter which route you go. Cheers, Chris -- http://rebertia.com From ian.g.kelly at gmail.com Wed May 16 14:10:30 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 12:10:30 -0600 Subject: How to embed python2 into python3? In-Reply-To: <770e6701-983a-4a3e-8727-2a4b0e2d8169@oe8g2000pbb.googlegroups.com> References: <770e6701-983a-4a3e-8727-2a4b0e2d8169@oe8g2000pbb.googlegroups.com> Message-ID: On Wed, May 16, 2012 at 8:59 AM, ytj wrote: > Hello, all: > > I have two programs, one is written in py3k, the other is written in > python 2. I am wondering how to make them work together except port > the python 2 code to py3k? Is that possible to expose python2's > function to py3k? In other words, I want to embed the Python 2 > interpreter into my py3k program. So I can call python2's function in > py3k's code. I think you're likely to run into conflicts doing that. Here's the result of a quick test using ctypes: Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes import * >>> python27 = cdll.python27 >>> python27.Py_Initialize() File "c:\python32\lib\site.py", line 159 file=sys.stderr) ^ SyntaxError: invalid syntax For some reason, even though I loaded the Python 2.7 DLL, it's then trying to import the Python 3.2 libraries. My suggestion: instead of embedding, use the subprocess module, and keep both Python interpreters firmly entrenched in separate processes. Cheers, Ian From marco_u at nsgmail.com Wed May 16 14:45:49 2012 From: marco_u at nsgmail.com (Marco) Date: Wed, 16 May 2012 20:45:49 +0200 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: Message-ID: On 05/16/2012 06:24 PM, Ulrich Eckhardt wrote: > Marco wrote: >> > >>> '123'.isdecimal(), '123'.isdigit() >> > (True, True) >> > >>> print('\u0660123') >> > ?123 >> > >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() >> > (True, True) >> > >>> print('\u216B') >> > ? >> > >>> '\u216B'.isdecimal(), '\u216B'.isdigit() >> > (False, False) > [chr(a) for a in range(0x20000) if chr(a).isdigit()] Thanks to your list comprehension I found they are not equal: >>> set([chr(a) for a in range(0x10FFFF) if chr(a).isdigit()]) - \ ... set([chr(a) for a in range(0x10FFFF) if chr(a).isdecimal()]) Marco From wxjmfauth at gmail.com Wed May 16 15:41:45 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 16 May 2012 12:41:45 -0700 (PDT) Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: Message-ID: <4d3db1da-e0cf-4d33-9420-451e27219792@8g2000vbu.googlegroups.com> On 16 mai, 17:48, Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but > I can't find it: > > ?>>> '123'.isdecimal(), '123'.isdigit() > (True, True) > ?>>> print('\u0660123') > ?123 > ?>>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() > (True, True) > ?>>> print('\u216B') > ? > ?>>> '\u216B'.isdecimal(), '\u216B'.isdigit() > (False, False) > > Can anyone give me some help? > Regards, Marco It seems to me that it is correct, and the reason lies in this: >>> import unicodedata as ud >>> ud.category('\u216b') 'Nl' >>> ud.category('1') 'Nd' >>> >>> # Note >>> ud.numeric('\u216b') 12.0 jmf From eng.ashraf.fouda at gmail.com Wed May 16 16:35:05 2012 From: eng.ashraf.fouda at gmail.com (Ashraf Fouda) Date: Wed, 16 May 2012 23:35:05 +0300 Subject: which book? In-Reply-To: <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> References: <24540309.317.1336500961264.JavaMail.geo-discussion-forums@vbak7> <12116929.1438.1336572834449.JavaMail.geo-discussion-forums@ynjj16> Message-ID: I recommend this book :- "beginning python from novice to professional" On Wed, May 9, 2012 at 4:13 PM, Miki Tebeka wrote: > > I am going to learn python for some plot issues. which book or sources, > do you recommend please? > The tutorial is pretty good if you already know how to program. > I also heard a lot of good things on "Python Essential Reference". > > -- > http://mail.python.org/mailman/listinfo/python-list > -- yours Ashraf Fouda Software Engineer * * -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Wed May 16 17:07:28 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 16 May 2012 23:07:28 +0200 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: Message-ID: <1370342.Eu8Q8A6FV8@PointedEars.de> Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but > I can't find it: > > >>> '123'.isdecimal(), '123'.isdigit() > (True, True) > >>> print('\u0660123') > ?123 > >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() > (True, True) > >>> print('\u216B') > ? > >>> '\u216B'.isdecimal(), '\u216B'.isdigit() > (False, False) > > Can anyone give me some help? RTFM. $ python3 -c 'print("42".isdecimal.__doc__ + "\n"); print("42".isdigit.__doc__)' S.isdecimal() -> bool Return True if there are only decimal characters in S, False otherwise. S.isdigit() -> bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. -- PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From ethan at stoneleaf.us Wed May 16 17:33:41 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 16 May 2012 14:33:41 -0700 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) Message-ID: <4FB41D35.3010904@stoneleaf.us> Just hit a snag: In cPython the deterministic garbage collection allows me a particular optimization when retrieving records from a dbf file -- namely, by using weakrefs I can tell if the record is still in memory and active, and if so not hit the disk to get the data; with PyPy (and probably the others) this doesn't work because the record may still be around even when it is no longer active because it hasn't been garbage collected yet. For PyPy I can use `'PyPy' in sys.version` to set a constant (REFRESH_FROM_DISK in this case) to disable the cPython optimization; does anyone know what strings to look for for the other implementations? ~Ethan~ From barry at barrys-emacs.org Wed May 16 17:52:08 2012 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 16 May 2012 22:52:08 +0100 Subject: How to call and execute C code in Python? In-Reply-To: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1336915554.39066.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: <4CF45B37-AF83-46CF-9142-07D8A7163612@barrys-emacs.org> There are many choices rather then raw python C API calls. Boost, PyCXX and ctypes are worth investigating. PyCXX requires you code in C++ but hides lots of the issues of using the Python API from you. It also supports python 2 and 3. Barry - PyCXX maintainer From charleshixsn at earthlink.net Wed May 16 17:52:33 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Wed, 16 May 2012 14:52:33 -0700 Subject: non-pickle persistance for dicts? Message-ID: <4FB421A1.9040408@earthlink.net> I want to persist simple dicts, but due to the security problems with (un)pickle, I'd prefer to not use shelve, and the only way I could see to persist them onto sqlite also invoked pickle. As (un)pickle allows arbitrary system commands to be issued, I'd really rather just use a simple convert to and from either bytes or strings. repr works well for the conversion into string (I said they were simple), but I'd really rather be able to turn "{'a': 'A', 1: 23, 2: ['b', 2]}" back into a dict without allowing the execution of arbitrary commands. Any suggestions? -- Charles Hixson From ian.g.kelly at gmail.com Wed May 16 17:54:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 15:54:03 -0600 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: <1370342.Eu8Q8A6FV8@PointedEars.de> References: <1370342.Eu8Q8A6FV8@PointedEars.de> Message-ID: On Wed, May 16, 2012 at 3:07 PM, Thomas 'PointedEars' Lahn wrote: > RTFM. > > $ python3 -c 'print("42".isdecimal.__doc__ + "\n"); > print("42".isdigit.__doc__)' > S.isdecimal() -> bool > > Return True if there are only decimal characters in S, > False otherwise. > > S.isdigit() -> bool > > Return True if all characters in S are digits > and there is at least one character in S, False otherwise. Those doc strings are not very helpful at all. I read them myself and then had to go to the library docs to figure out what the actual difference was. From ian.g.kelly at gmail.com Wed May 16 18:01:41 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 16:01:41 -0600 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: <4FB41D35.3010904@stoneleaf.us> References: <4FB41D35.3010904@stoneleaf.us> Message-ID: On Wed, May 16, 2012 at 3:33 PM, Ethan Furman wrote: > Just hit a snag: > > In cPython the deterministic garbage collection allows me a particular > optimization when retrieving records from a dbf file -- namely, by using > weakrefs I can tell if the record is still in memory and active, and if so > not hit the disk to get the data; ?with PyPy (and probably the others) this > doesn't work because the record may still be around even when it is no > longer active because it hasn't been garbage collected yet. > > For PyPy I can use `'PyPy' in sys.version` to set a constant > (REFRESH_FROM_DISK in this case) to disable the cPython optimization; does > anyone know what strings to look for for the other implementations? Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.subversion ('CPython', 'tags/r271', '86832') Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_31 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.subversion ('Jython', 'tags/Release_2_5_2', '7206') I don't know what IronPython or PyPy return, but it should be something other than 'CPython'. From ian.g.kelly at gmail.com Wed May 16 18:11:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 16:11:21 -0600 Subject: non-pickle persistance for dicts? In-Reply-To: <4FB421A1.9040408@earthlink.net> References: <4FB421A1.9040408@earthlink.net> Message-ID: On Wed, May 16, 2012 at 3:52 PM, Charles Hixson wrote: > I want to persist simple dicts, but due to the security problems with > (un)pickle, I'd prefer to not use shelve, and the only way I could see to > persist them onto sqlite also invoked pickle. > > As (un)pickle allows arbitrary system commands to be issued, I'd really > rather just use a simple convert to and from either bytes or strings. ?repr > works well for the conversion into string (I said they were simple), but I'd > really rather be able to turn "{'a': 'A', 1: 23, 2: ['b', 2]}" back into a > dict without allowing the execution of arbitrary commands. > > Any suggestions? Either json, or repr with ast.literal_eval will be safe. >>> import json >>> d = {'a': 'A', 1: 23, 2: ['b', 2]} >>> json.dumps(d) '{"a": "A", "1": 23, "2": ["b", 2]}' >>> json.loads(json.dumps(d)) {'a': 'A', '1': 23, '2': ['b', 2]} >>> import ast >>> ast.literal_eval(repr(d)) {'a': 'A', 1: 23, 2: ['b', 2]} Cheers, Ian From timothy.c.delaney at gmail.com Wed May 16 18:32:30 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 17 May 2012 08:32:30 +1000 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: <4FB41D35.3010904@stoneleaf.us> References: <4FB41D35.3010904@stoneleaf.us> Message-ID: On 17 May 2012 07:33, Ethan Furman wrote: > Just hit a snag: > > In cPython the deterministic garbage collection allows me a particular > optimization when retrieving records from a dbf file -- namely, by using > weakrefs I can tell if the record is still in memory and active, and if so > not hit the disk to get the data; with PyPy (and probably the others) this > doesn't work because the record may still be around even when it is no > longer active because it hasn't been garbage collected yet. > What is the distinguishing feature of an "active" record? What is the problem if you get back a reference to an inactive record? And if there is indeed a problem, don't you already have a race condition on CPython? 1. Record is active; 2. Get reference to record through weak ref; 3. Record becomes inactive; 4. Start trying to use the (now inactive) record. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed May 16 18:45:20 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 16 May 2012 15:45:20 -0700 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: References: <4FB41D35.3010904@stoneleaf.us> Message-ID: <4FB42E00.4020300@stoneleaf.us> Ian Kelly wrote: > On Wed, May 16, 2012 at 3:33 PM, Ethan Furman wrote: >> Just hit a snag: >> >> In cPython the deterministic garbage collection allows me a particular >> optimization when retrieving records from a dbf file -- namely, by using >> weakrefs I can tell if the record is still in memory and active, and if so >> not hit the disk to get the data; with PyPy (and probably the others) this >> doesn't work because the record may still be around even when it is no >> longer active because it hasn't been garbage collected yet. >> >> For PyPy I can use `'PyPy' in sys.version` to set a constant >> (REFRESH_FROM_DISK in this case) to disable the cPython optimization; does >> anyone know what strings to look for for the other implementations? > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.subversion > ('CPython', 'tags/r271', '86832') > > Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) > [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_31 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.subversion > ('Jython', 'tags/Release_2_5_2', '7206') > > I don't know what IronPython or PyPy return, but it should be > something other than 'CPython'. Thanks! That will do the trick. On CPython 2.4 .subversion does not exist, so I'll use: subversion = getattr(sys, 'subversion', None) if subversion is not None and subversion[0] != 'CPython': ... Hopefully all the others do have it defined (PyPy does, at least as of 1.8). ~Ethan~ From charleshixsn at earthlink.net Wed May 16 18:53:31 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Wed, 16 May 2012 15:53:31 -0700 Subject: non-pickle persistance for dicts? In-Reply-To: References: <4FB421A1.9040408@earthlink.net> Message-ID: <4FB42FEB.9000607@earthlink.net> On 05/16/2012 03:11 PM, Ian Kelly wrote: > On Wed, May 16, 2012 at 3:52 PM, Charles Hixson > wrote: > >> I want to persist simple dicts, but due to the security problems with >> (un)pickle, I'd prefer to not use shelve, and the only way I could see to >> persist them onto sqlite also invoked pickle. >> >> As (un)pickle allows arbitrary system commands to be issued, I'd really >> rather just use a simple convert to and from either bytes or strings. repr >> works well for the conversion into string (I said they were simple), but I'd >> really rather be able to turn "{'a': 'A', 1: 23, 2: ['b', 2]}" back into a >> dict without allowing the execution of arbitrary commands. >> >> Any suggestions? >> > Either json, or repr with ast.literal_eval will be safe. > > >>>> import json >>>> d = {'a': 'A', 1: 23, 2: ['b', 2]} >>>> json.dumps(d) >>>> > '{"a": "A", "1": 23, "2": ["b", 2]}' > >>>> json.loads(json.dumps(d)) >>>> > {'a': 'A', '1': 23, '2': ['b', 2]} > >>>> import ast >>>> ast.literal_eval(repr(d)) >>>> > {'a': 'A', 1: 23, 2: ['b', 2]} > > Cheers, > Ian > > Thanks. It looks like either would do what I need. Any suggestion as to how to choose between them? E.g., is AST better supported? faster? (I'm tending towards AST purely because it seems more tied to Python, but of course that *could* be a disadvantage, if there were more external tools for working with json.) -- Charles Hixson From ethan at stoneleaf.us Wed May 16 19:01:33 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 16 May 2012 16:01:33 -0700 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: References: <4FB41D35.3010904@stoneleaf.us> Message-ID: <4FB431CD.6080707@stoneleaf.us> Tim Delaney wrote: > On 17 May 2012 07:33, Ethan Furman wrote: >> Just hit a snag: >> >> In cPython the deterministic garbage collection allows me a >> particular optimization when retrieving records from a dbf file -- >> namely, by using weakrefs I can tell if the record is still in >> memory and active, and if so not hit the disk to get the data; with >> PyPy (and probably the others) this doesn't work because the record >> may still be around even when it is no longer active because it >> hasn't been garbage collected yet. > > > What is the distinguishing feature of an "active" record? What is the > problem if you get back a reference to an inactive record? And if there > is indeed a problem, don't you already have a race condition on CPython? > > 1. Record is active; > 2. Get reference to record through weak ref; > 3. Record becomes inactive; > 4. Start trying to use the (now inactive) record. A record is an interesting critter -- it is given life either from the user or from the disk-bound data; its fields can then change, but those changes are not reflected on disk until .write_record() is called; I do this because I am frequently moving data from one table to another, making changes to the old record contents before creating the new record with the changes -- since I do not call .write_record() on the old record those changes do not get backed up to disk. With CPython as soon as a record goes out of scope it dies, and the next time I try to access that record I will get the disk version, without the temporary changes I had made earlier (this is good). However, with PyPy (and others) not all records are destroyed before I try to access them again, and I end up seeing the temp data instead of the disk data. ~Ethan~ From ian.g.kelly at gmail.com Wed May 16 19:07:59 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 May 2012 17:07:59 -0600 Subject: non-pickle persistance for dicts? In-Reply-To: <4FB42FEB.9000607@earthlink.net> References: <4FB421A1.9040408@earthlink.net> <4FB42FEB.9000607@earthlink.net> Message-ID: On Wed, May 16, 2012 at 4:53 PM, Charles Hixson wrote: > On 05/16/2012 03:11 PM, Ian Kelly wrote: >> >> On Wed, May 16, 2012 at 3:52 PM, Charles Hixson >> ?wrote: >> >>> >>> I want to persist simple dicts, but due to the security problems with >>> (un)pickle, I'd prefer to not use shelve, and the only way I could see to >>> persist them onto sqlite also invoked pickle. >>> >>> As (un)pickle allows arbitrary system commands to be issued, I'd really >>> rather just use a simple convert to and from either bytes or strings. >>> ?repr >>> works well for the conversion into string (I said they were simple), but >>> I'd >>> really rather be able to turn "{'a': 'A', 1: 23, 2: ['b', 2]}" back into >>> a >>> dict without allowing the execution of arbitrary commands. >>> >>> Any suggestions? >>> >> >> Either json, or repr with ast.literal_eval will be safe. >> >> >>>>> >>>>> import json >>>>> d = {'a': 'A', 1: 23, 2: ['b', 2]} >>>>> json.dumps(d) >>>>> >> >> '{"a": "A", "1": 23, "2": ["b", 2]}' >> >>>>> >>>>> json.loads(json.dumps(d)) >>>>> >> >> {'a': 'A', '1': 23, '2': ['b', 2]} >> >>>>> >>>>> import ast >>>>> ast.literal_eval(repr(d)) >>>>> >> >> {'a': 'A', 1: 23, 2: ['b', 2]} >> >> Cheers, >> Ian >> >> > > Thanks. ?It looks like either would do what I need. ?Any suggestion as to > how to choose between them? ?E.g., is AST better supported? ?faster? ?(I'm > tending towards AST purely because it seems more tied to Python, but of > course that *could* be a disadvantage, if there were more external tools for > working with json.) You pretty much just summed it up. JSON is more portable because it's a well-known standard with implementations in a lot of different languages. On the downside, since it essentially involves translating your data into *JavaScript* literals and back, it's not going to be quite as faithful. Notice in the example that the numeric dictionary keys got turned into strings. AST will do a cleaner job since you're just converting Python objects into Python literals and back, but the serialized data will only be easily readable using Python. From steve+comp.lang.python at pearwood.info Wed May 16 20:15:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2012 00:15:26 GMT Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: Message-ID: <4fb4431d$0$29984$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 May 2012 17:48:19 +0200, Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but > I can't find it: The Fine Manual has more detail, although I admit it isn't *entirely* clear what it is talking about if you're not a Unicode expert: http://docs.python.org/py3k/library/stdtypes.html#str.isdecimal str.isdecimal() Return true if all characters in the string are decimal characters and there is at least one character, false otherwise. Decimal characters are those from general category ?Nd?. This category includes digit characters, and all characters that can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO. str.isdigit() Return true if all characters in the string are digits and there is at least one character, false otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal. And also: str.isnumeric() Return true if all characters in the string are numeric characters, and there is at least one character, false otherwise. Numeric characters include digit characters, and all characters that have the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION ONE FIFTH. Formally, numeric characters are those with the property value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric. Examples: py> c = '\u2155' py> print(c) ? py> c.isdecimal(), c.isdigit(), c.isnumeric() (False, False, True) py> import unicodedata py> unicodedata.numeric(c) 0.2 py> c = '\u00B2' py> print(c) ? py> c.isdecimal(), c.isdigit(), c.isnumeric() (False, True, True) py> unicodedata.numeric(c) 2.0 -- Steven From jeanpierreda at gmail.com Wed May 16 20:33:16 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 16 May 2012 20:33:16 -0400 Subject: non-pickle persistance for dicts? In-Reply-To: <4FB42FEB.9000607@earthlink.net> References: <4FB421A1.9040408@earthlink.net> <4FB42FEB.9000607@earthlink.net> Message-ID: On Wed, May 16, 2012 at 6:53 PM, Charles Hixson wrote: > Thanks. ?It looks like either would do what I need. ?Any suggestion as to > how to choose between them? ?E.g., is AST better supported? ?faster? ?(I'm > tending towards AST purely because it seems more tied to Python, but of > course that *could* be a disadvantage, if there were more external tools for > working with json.) I'd pick json, because it will tell you if you try to serialize something that can't be deserialized. repr() will just dump it, and then you'll find out later (on load) that it wasn't serialized properly. repr() is not meant for storing data, it's meant for presenting it to a programmer. -- Devin From rosuav at gmail.com Wed May 16 21:13:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 May 2012 11:13:00 +1000 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: <4FB431CD.6080707@stoneleaf.us> References: <4FB41D35.3010904@stoneleaf.us> <4FB431CD.6080707@stoneleaf.us> Message-ID: On Thu, May 17, 2012 at 9:01 AM, Ethan Furman wrote: > A record is an interesting critter -- it is given life either from the user > or from the disk-bound data; ?its fields can then change, but those changes > are not reflected on disk until .write_record() is called; ?I do this > because I am frequently moving data from one table to another, making > changes to the old record contents before creating the new record with the > changes -- since I do not call .write_record() on the old record those > changes do not get backed up to disk. I strongly recommend being more explicit about usage and when it gets written and re-read, rather than relying on garbage collection. Databasing should not be tied to a language's garbage collection. Imagine you were to reimplement the equivalent logic in some other language - could you describe it clearly? If so, then that's your algorithm. If not, you have a problem. ChrisA From timothy.c.delaney at gmail.com Wed May 16 21:30:51 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 17 May 2012 11:30:51 +1000 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: References: <4FB41D35.3010904@stoneleaf.us> <4FB431CD.6080707@stoneleaf.us> Message-ID: On 17 May 2012 11:13, Chris Angelico wrote: > On Thu, May 17, 2012 at 9:01 AM, Ethan Furman wrote: > > A record is an interesting critter -- it is given life either from the > user > > or from the disk-bound data; its fields can then change, but those > changes > > are not reflected on disk until .write_record() is called; I do this > > because I am frequently moving data from one table to another, making > > changes to the old record contents before creating the new record with > the > > changes -- since I do not call .write_record() on the old record those > > changes do not get backed up to disk. > > I strongly recommend being more explicit about usage and when it gets > written and re-read, rather than relying on garbage collection. > Databasing should not be tied to a language's garbage collection. > Imagine you were to reimplement the equivalent logic in some other > language - could you describe it clearly? If so, then that's your > algorithm. If not, you have a problem. > Agreed. To me, this sounds like a perfect case for with: blocks and explicit reference counting. Something like (pseudo-python - not runnable): class Record: def __init__(self): self.refs = 0 self.lock = threading.Lock() def __enter__(self): with self.lock: self.refs += 1 def __exit__(self): with self.lock: self.refs -=1 if self.refs == 0: self.write_record() rec = record_weakrefs.get('record_name') if rec is None: rec = load_record() record_weakrefs.put('record_name', rec) with rec: do_stuff Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed May 16 21:35:55 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 16 May 2012 18:35:55 -0700 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: References: <4FB41D35.3010904@stoneleaf.us> <4FB431CD.6080707@stoneleaf.us> Message-ID: <4FB455FB.9020004@stoneleaf.us> Chris Angelico wrote: > On Thu, May 17, 2012 at 9:01 AM, Ethan Furman wrote: >> A record is an interesting critter -- it is given life either from the user >> or from the disk-bound data; its fields can then change, but those changes >> are not reflected on disk until .write_record() is called; I do this >> because I am frequently moving data from one table to another, making >> changes to the old record contents before creating the new record with the >> changes -- since I do not call .write_record() on the old record those >> changes do not get backed up to disk. > > I strongly recommend being more explicit about usage and when it gets > written and re-read, rather than relying on garbage collection. > Databasing should not be tied to a language's garbage collection. > Imagine you were to reimplement the equivalent logic in some other > language - could you describe it clearly? If so, then that's your > algorithm. If not, you have a problem. Yeah, I've been thinking about this for a couple hours now; initially (waaaaay back when) I didn't want to keep hitting the disk unnecessarily -- but all my other supporting data structures go to great lengths to not keep records in memory unless the user has them explicitly named or contained... I think I've been fighting against myself! Good news is I'm winning. ;) ~Ethan~ From gwhite at ti.com Wed May 16 21:45:39 2012 From: gwhite at ti.com (gwhite) Date: Wed, 16 May 2012 18:45:39 -0700 (PDT) Subject: Newbie questions on import & cmd line run Message-ID: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Hi, I am a newbie running the latest pythonxy (2.7.2.1) & spyder and python 2.7.2. I suspect my questions are mostly basic to python, and not specific to Spyder or iPython. Note: Up until now, I mainly used MATLAB, and thus need to de-program myself appropriately. I use Win7-64. I wrote the following .py file: ----------------- #! # Filename: newbie00.py if __name__ == '__main__': print 'This program was called from the \ system command line.' print __name__ + '.py' else: print 'This program was imported on the \ Python command line.' print __name__ + '.py' ----------------- If I run from the system (win cmd) command, I get: C:\engineer\engruser\python>python newbie00.py This program was called from the system command line. __main__.py ----------------- If I hit the run button in Sypder, I get (in the iPython command console): In [70]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: \engineer\engruser\python') This program was called from the system command line. __main__.py ----------------- If I import on the iPython command, I get: In [71]: import newbie00 This program was imported on the Python command line. newbie00.py ----------------- If I import *again* on the iPython command, I get: In [72]: import newbie00 In [73]: ----------------- If I hit the run button (again) in Sypder, I get (in the iPython command console): In [73]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: \engineer\engruser\python') UMD has deleted: newbie00 This program was called from the system command line. __main__.py ----------------------------------- Some questions: 1. If running from the system command line, or the Sypder "run" button, "__name__" is "__main__" rather than "newbie00", as seen above. So, how would I get the file name newbie00.py in these two noted cases? I mean, what other function do I use to get it? (This functionality is something that occasionally came in handy back in my m-file writing days. Perhaps I am wrong in anticipating such an occasional need, but I would not know that yet.) 2. In python, there seems to be a distinction between running something as if it is a system command of "C:\...>python myPyFile.py" compared to simply entering that same ".py" file name directly on the python console command line. In fact, the latter does not work unless the somewhat lengthy ">>> runfile(r'C:\... wdir=r'C:\...) stuff is entered (in iPython). (I mean, my old MATLAB habit of simply entering ">> mfilename" on the command line seems to be quite wrong in python.) Is there a shortened syntax of running a .py from the python command prompt, if not using a Spyder "run" button? Or should I always run as if from the system prompt? That is, dispense with the MATLAB-like "run from MATLAB/python command line" bias I may be holding. 3. In injecting my old MATLAB bias of running via the command line ">> mfilename", I tried a tweak of ">>>import newbie00". That "sort of" worked, but only the first time. Why did the subsequent run of ">>>import newbie00" print nothing? I'm just trying to understand how python works. 4. The final case shown of hitting the Spyder run button included this: UMD has deleted: newbie00 What does that mean? I noted that after this "automatic" deletion, I could do the ">>>import newbie00" once again and get the print. (I did not show that above.) 5. I think #4 implies an import can be removed. (Yes/No?) I am not sure why that would be desired, but I will ask how to remove an import, or to "refresh" the run, of that is the appropriate question. I think I saw someplace where a .pyc file is created on an initial run and subsequently run instead of the .py. I'm not sure if that applies here, but if related, I guess an auxiliary question is how to easily force the .py to run rather than the .pyc? 6. Perhaps peripherally related to getting a running script/function/ module name, is getting a "call listing" of all the functions (and modules) called by a .py program. How would I get that? I only ask as it comes in handy if one distributes a program. I mean, you only give people what they actually need. ----------- Advance thanks to any one who answers any of my questions. I am sure they appear from misguided to rudimentary in character. I'm don't claim to be a programmer; I did okay with MATLAB. I'm trying to bootstrap here, and appreciate any help. Thanks! Greg From rmorgan466 at gmail.com Wed May 16 22:16:59 2012 From: rmorgan466 at gmail.com (Rita) Date: Wed, 16 May 2012 22:16:59 -0400 Subject: bash/shell to python Message-ID: Hello, I currently build a lot of interfaces/wrappers to other applications using bash/shell. One short coming for it is it lacks a good method to handle arguments so I switched to python a while ago to use 'argparse' module. Its a great complement to subprocess module. I was wondering if there is a generic framework people follow to build python scripts which are replacing shell scripts? Is there a guide or a template to follow? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From markrrivet at aol.com Wed May 16 23:02:50 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Wed, 16 May 2012 23:02:50 -0400 Subject: Where is the most recent Tkinter information Message-ID: It seems like all the info on tkinter is around the 2000 time frame. Is tkinter still being developed/supported? From tjreedy at udel.edu Wed May 16 23:36:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 May 2012 23:36:12 -0400 Subject: Where is the most recent Tkinter information In-Reply-To: References: Message-ID: On 5/16/2012 11:02 PM, Mark R Rivet wrote: > It seems like all the info on tkinter is around the 2000 time frame. > Is tkinter still being developed/supported? tkinter is CPython's tk interface. tcl/tk is still being developed at Active State. The Windows release for Py 3.3 will come with 8.5.11, released a couple of months ago. tkinter does not change much because tk does not change much. But bugs are fixed as reported. A fix for an obscure bug affecting certain *nix systems was committed just today. The docs do need improving. -- Terry Jan Reedy From markrrivet at aol.com Wed May 16 23:49:57 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Wed, 16 May 2012 23:49:57 -0400 Subject: Are there any instrumentation widgets for wxpython or tkinter? References: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> Message-ID: On Sat, 12 May 2012 12:40:28 -0700 (PDT), Sverre wrote: >I searched for widgets used for PLC automation or lab instrumentation >like gauges, led's etc. in the net, but didn't found anything because >of those massive link spam sites. In the case there isn't any >solution, with which toolkit would it be easiest to build gauges? I just skimmed through the book "Python and Tkinter" by John E. Grayson. This book goes through everything I think you will need for instrumentation type widgets. It even shows how to create your own new widgets. A lot of information in this book. Its dated, but there isn't any other book available. But try some of the code, see how it works. I know I'm going to. From markrrivet at aol.com Wed May 16 23:55:29 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Wed, 16 May 2012 23:55:29 -0400 Subject: Python and Tkinter by John E Grayson Message-ID: I have a copy of this book and was wondering how relevant the content is considering the publish date is 2000. Are people still using this information? Anyone have any experience with this book? I guess what I mean, is, any of the code in this book deprecated? or does it still contain information used today the same as then. I mean, I guess some things don't change right? For instance, the derivative of x^2 is 2x now and in the 1800's. From simoncropper at fossworkflowguides.com Thu May 17 00:04:32 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Thu, 17 May 2012 14:04:32 +1000 Subject: Where is the most recent Tkinter information In-Reply-To: References: Message-ID: <4FB478D0.2010009@fossworkflowguides.com> On 17/05/12 13:02, Mark R Rivet wrote: > It seems like all the info on tkinter is around the 2000 time frame. > Is tkinter still being developed/supported? The main page of the python 3.2.3 documentation for tkinter can be found here... http://docs.python.org/py3k/library/tkinter.html?highlight=tkinter#tkinter it is dated 2012. This seems to be duplicated from the ActiveState site here... http://docs.activestate.com/activepython/3.1/python/library/tkinter.html also dated 2012. Here are some other resources I have stumbled on... http://www.tutorialspoint.com/python/python_gui_programming.htm http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://www.tkdocs.com/tutorial/index.html http://www.ibm.com/developerworks/linux/library/l-tkprg/ -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From tjreedy at udel.edu Thu May 17 00:17:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 May 2012 00:17:25 -0400 Subject: Newbie questions on import & cmd line run In-Reply-To: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Message-ID: On 5/16/2012 9:45 PM, gwhite wrote: > Hi, > > I am a newbie running the latest pythonxy (2.7.2.1)& spyder and > python 2.7.2. I suspect my questions are mostly basic to python, and > not specific to Spyder or iPython. > > Note: Up until now, I mainly used MATLAB, and thus need to de-program > myself appropriately. > > I use Win7-64. > > I wrote the following .py file: > > ----------------- > #! > # Filename: newbie00.py > > if __name__ == '__main__': > print 'This program was called from the \ > system command line.' > print __name__ + '.py' > else: > print 'This program was imported on the \ > Python command line.' > print __name__ + '.py' > > ----------------- > > If I run from the system (win cmd) command, I get: > > C:\engineer\engruser\python>python newbie00.py > > This program was called from the system command line. > __main__.py > > ----------------- > If I hit the run button in Sypder, I get (in the iPython command > console): > > In [70]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: > \engineer\engruser\python') > This program was called from the system command line. > __main__.py > > > ----------------- > If I import on the iPython command, I get: > > In [71]: import newbie00 > This program was imported on the Python command line. > newbie00.py > > ----------------- > If I import *again* on the iPython command, I get: > > In [72]: import newbie00 > > In [73]: > > Read the doc for the import command. It only runs code when needed to create the module to import. When you import again, you re-import the existing module. > If I hit the run button (again) in Sypder, I get (in the iPython > command console): > > In [73]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: > \engineer\engruser\python') > UMD has deleted: newbie00 This output is Spyder specific. When you run from an Idle window, it prints ========================== RESTART ============================ which means that the user main namespace is reset. Idle usually does this by starting a new user subprocess (and terminating the old one), but the alternative would be to try to clean the existing subprocess by reversing and resetting everything that was done. Wiping out everything and restarting is easier ;-). > 1. If running from the system command line, or the Sypder "run" > button, "__name__" is "__main__" rather than "newbie00", as seen > above. [how to get latter] # Running in 3.3 Idle from edit window: tem.py print(dir()) print(__file__) # output in shell window ['__builtins__', '__doc__', '__file__', '__name__', '__package__'] F:\Python\mypy\tem.py os.path.something() can isolate the last part in a cross-platform manner. > 2. In python, there seems to be a distinction between running > something as if it is a system command of "C:\...>python myPyFile.py" You use dos syntax in the dos command prompt window. > compared to simply entering that same ".py" file name directly on the > python console command line. You use python syntax in the interactive python console. The Idle Shell closes simulates that. Other shells add extra syntax that only works in the specific shell. > In fact, the latter does not work unless > the somewhat lengthy ">>> runfile(r'C:\... wdir=r'C:\...) stuff is > entered (in iPython). (I mean, my old MATLAB habit of simply entering > ">> mfilename" on the command line seems to be quite wrong in python.) I believe runfile is ipython (?) specific. >>> exec(open("F:\\Python\\mypy\\tem.py").read()) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__warningregistry__'] F:\Python\mypy\tem.py It is relatively unusual to run a file in the main space rather than importing it. > 5. I think #4 implies an import can be removed. (Yes/No?) Yes, but it is not a newbie thing to do, and it often does not do what people expect or want. My advice: forget about it. > I think I saw someplace where a .pyc file is created on an initial run > and subsequently run instead of the .py. A .pyc file is only generated when the .py is imported. But this is unreleated to the above and a CPython-specific behind-the-scenes time optimization you should not worry about. > here, but if related, I guess an auxiliary question is how to easily > force the .py to run rather than the .pyc? You do not want to do that. If the .py is changed, the .pyc is regenerated on the next import. > 6. Perhaps peripherally related to getting a running script/function/ > module name, is getting a "call listing" of all the functions (and > modules) called by a .py program. How would I get that? I only ask > as it comes in handy if one distributes a program. I mean, you only > give people what they actually need. Look at the trace module. Of course, you distribute files, not functions. There are various packaging programs that do a module import trace rather than function call trace. -- Terry Jan Reedy From antti.ylikoski at aalto.fi Thu May 17 00:27:09 2012 From: antti.ylikoski at aalto.fi (Antti J Ylikoski) Date: Thu, 17 May 2012 07:27:09 +0300 Subject: Algorithms in Python, #n+1 Message-ID: I have continued my research in literature algorithms in Python. The algorithms in Knuth's volumes 1 -- 3 either have been incorporated into Python, or they can be easily implemented with Python. Quite as John Nagle said here. However, the Fascicles in Vol. 4 to my opinion contain nontrivially useful material. And, Vol. 2 has something interesting, however -- e. g. the statistical tests on random number generators. I have included in this entry a working Python program which carries out the chi squared test on different random number generators. It demonstrates the paradigm of building Knuth's equations directly into one's Python program, instead of the DFA/FSA approach. Moreover, someone over there may wish to test his/her random number generators. Therefore, I feel that it is relevant to show this program (which is about two pages long) in this context. I have carried out the chi squared test on Python's own random number generator, which to my knowledge is based on the Mersenne twister: http://en.wikipedia.org/wiki/Mersenne_twister and Knuth's (old) Linear Congruential method: http://en.wikipedia.org/wiki/Linear_congruential_generator If you run the program (with Python 3) you will see that the both generators will pass the chi squared test. ------------------------------------------------------------------------ # Random number generation and analysis after D. E. Knuth. # # See The Art of Computer Programming, VOL 2, Seminumerical Algorithms, # 3rd Edition, pp. 1 -- # # AJY 05-16-2012. import math, random # First do the MIX simulator. # AJY 05-16-2012. # --------------------------------------------------------------------- # Python based MIX simulator. # # Written in the object oriented manner. # # AJY 05-16-2012. # # Do as follows: # # MIX_computer = MIXSIM(memory_size, word_size) # A, X = MIX_computer.MUL(A, X) # # etc etc. in the same vein. # This constitutes just a maximally simple demo. class MIXSIM(object): """ Maximally simple object oriented MIX simulator. """ def __init__(self, mem_size, word_size): self.mem_size = mem_size self.word_size = word_size self.w = 10**word_size # Assume a base 10 computer, after Knuth. # No other methods in this class. I said it only constitutes a demo. # ---------------------------------------------------------------------- class LCRNG(object): """ The Linear Congruential Random Number Generator. AJY 05-16-2012. """ def __init__(self, modulus, multiplier, increment, seed): self.modulus = modulus # Modulus == m in Knuth's text. self.multiplier = multiplier # Multiplier == a in Knuth's text. self.increment = increment # Increment == c in Knuth. # Seed == X0 in Knuth. self.reg_X = seed # Initial value X0 to Register X. self.MIX = MIXSIM(5000, 12) # Demo sample MIX computer. def rand(self): # See Knuth VOL 2 on p. 12. # Following calculate the next pseudo random integer: self.reg_A = (self.multiplier * self.reg_X) % (self.MIX.w + 1) # Transfer A to X for the next round. self.reg_X = self.reg_A # And now return a floating point number x such that 0 <= x < 1. return float(self.reg_A) / float (self.modulus) class chi_squared_test(object): """ Instances are chi squared tests of random number generators. """ def __init__(self, generator_f, buckets, iterations, name): self.generator_f = generator_f # The function to be tested. self.buckets = buckets # How many discrete buckets are used self.iterations = iterations # The # of random numbers generated. self.name = name # name of this test. self.B = [0] * self.buckets # initially all buckets are empty def run_test(self): """ Generate random numbers and place them in buckets. """ for i in range(self.iterations): random_nr = self.generator_f() # Random number, in interval [0, 1) ind_bucket = int(self.buckets * random_nr) # Index, 0 .. #buckets-1 self.B[ind_bucket] += 1 def chi2test(self): """ Carry out the chi squared test of the material generated. """ # Calculate the chi squared statistics value. See Knuth VOL 2 # on Page 43. Vsum = 0 for i in range(self.buckets): Vsum += (self.B[i] - self.iterations * (1.0 / float(self.buckets)))**2 \ / (self.iterations * (1.0 / float(self.buckets))) V = Vsum print("\n Chi squared test. Name = ", self.name) print("\n Chi squared value V = ", V) print("\n Degrees of freedom: ", self.buckets - 1) chi2_1 = (self.buckets - 1) + math.sqrt(2.0 * self.buckets) \ * -2.33 + (2.0/3.0)*(-2.33)**2 - (2.0/3.0) chi2_99 = (self.buckets - 1) + math.sqrt(2.0 * self.buckets) \ * 2.33 + (2.0/3.0)*(2.33)**2 - (2.0/3.0) print("\nValue of chi squared at the 1% level: ", chi2_1) print("\nValue of chi squared at the 99% level: ", chi2_99) # Main code. # if __name__ == "__main__": sd = 77755533311 # The seed. rand_x = LCRNG(10**12, 200200341, 0, sd) chi2_Mersenne = chi_squared_test(random.random, 1000, 1000000, "Mersenne") chi2_Linear = chi_squared_test(rand_x.rand, 1000, 1000000, "Linear") chi2_Mersenne.run_test() chi2_Linear.run_test() chi2_Mersenne.chi2test() chi2_Linear.chi2test() ----------------------------------------------------------------------------------------------- yours and V/R, Antti J Ylikoski Helsinki, Finland, the E.U. From clp2 at rebertia.com Thu May 17 00:29:59 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 16 May 2012 21:29:59 -0700 Subject: Newbie questions on import & cmd line run In-Reply-To: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Message-ID: On Wed, May 16, 2012 at 6:45 PM, gwhite wrote: > Hi, > > I am a newbie running the latest pythonxy (2.7.2.1) & spyder and > python 2.7.2. ? I suspect my questions are mostly basic to python, and > not specific to Spyder or iPython. > > Note: Up until now, I mainly used MATLAB, and thus need to de-program > myself appropriately. > > I use Win7-64. > > I wrote the following .py file: > > ----------------- > #! That's a shebang line. See http://en.wikipedia.org/wiki/Shebang_(Unix) It's doesn't matter at all since you're on Windows. On Unix-like systems, one typically writes: #!/usr/bin/env python > # Filename: newbie00.py > > if __name__ == '__main__': Cheers, Chris From steve+comp.lang.python at pearwood.info Thu May 17 00:33:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2012 04:33:15 GMT Subject: Newbie questions on import & cmd line run References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Message-ID: <4fb47f8a$0$29975$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 May 2012 18:45:39 -0700, gwhite wrote: > #! > # Filename: newbie00.py "Supposed to"? Nothing -- it is completely optional. #! ("hash-bang") lines currently do nothing on Windows machines, they are just comments. However, on Unix and Linux machines (and Macintosh?) they are interpreted by the shell (equivalent to cmd.exe or command.com), in order to tell the shell what interpreter to use to execute the program if you run it directly. It is common to use something like: #!/usr/bin/env python but I stress that this is completely optional, and doesn't do anything on Windows. > if __name__ == '__main__': > print 'This program was called from the \ > system command line.' > print __name__ + '.py' > else: > print 'This program was imported on the \ > Python command line.' > print __name__ + '.py' > > ----------------- > > If I run from the system (win cmd) command, I get: > > C:\engineer\engruser\python>python newbie00.py > > This program was called from the system command line. __main__.py The magic variable "__name__" is special in Python. When you run a Python module as a script from the command line, it gets set to "__main__". Note that there is no such file "__main__.py" (unless you have happened to create one yourself). When you import a module, rather than run it, __name__ gets set to the actual filename of the module, minus the file extension. > ----------------- > If I hit the run button in Sypder, I get (in the iPython command > console): > > In [70]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: > \engineer\engruser\python') > This program was called from the system command line. __main__.py I'm not sure what Spyder is. Is it part of iPython? You may need to consult the iPython or Spyder docs to find out exactly what tricks it plays in its interactive console. > ----------------- > If I import on the iPython command, I get: > > In [71]: import newbie00 > This program was imported on the Python command line. newbie00.py In this case, __name__ is set to the module name (the file name less the file extension). Your script adds the .py at the end. > ----------------- > If I import *again* on the iPython command, I get: > > In [72]: import newbie00 > > In [73]: > > That is correct. Python modules are only executed *once*, the first time they are imported. From then on, additional imports refer back to a cached module object. When you say "import newbie00", the (highly simplified!) process is this: * Python looks in sys.modules for the name "newbie00". If it finds something in the cache (usually a module object), it fetches that thing and assigns it to the variable "newbie00", and the import process is complete. * But if it doesn't find anything in the cache, Python searches the locations listed in sys.path for a module, package, or library. That could mean any of: - newbie00.py (source code) - newbie00.pyc (compiled byte-code) - newbie00.pyo (compiled optimized byte-code) - newbie00.pyw (Windows only) - newbie00.dll (Windows only C library) - newbie00.so (Linux and Unix C library) as well as others (e.g. packages). * If no module is found, Python raises an error, otherwise the first found module is used. * If a compiled module (e.g. newbie00.pyc) is found, and is no older than the source code (newbie00.py), then Python uses the pre-compiled file. (If the compiled module is older than the source module, it is ignored.) * Otherwise Python parses the newbie00.py source code, compiles it to byte-code, and writes it to the file newbie00.pyc so that the next time the import will be faster. * At this point, Python now has a compiled chunk of Python byte-code. It then sets the special global variable __name__ to the file name (less extension), and executes that code. * If no fatal error occurs, Python now bundles the results of the executed code (any functions, classes, variables, etc.) into a module object, stores the module object in the cache sys.modules for next time, and finally assigns it to the name "newbie00". There is a *lot* that goes on the first time you import a module, which is why Python tries really hard to avoid running modules unless you explicitly ask it to. So "import newbie00" only *executes* the code once per Python session. Subsequent imports use the cached version. The process is quite different when you run a Python module as a script. In this case, the .pyc file (if any) is ignored, the script is parsed and compiled from scratch every single time, the magic variable __name__ is set to "__main__", and the script is executed every single time. [...] > Some questions: > > 1. If running from the system command line, or the Sypder "run" button, > "__name__" is "__main__" rather than "newbie00", as seen above. > > So, how would I get the file name newbie00.py in these two noted cases? The special variable "__file__" is set to the filename: >>> import string >>> string.__file__ '/usr/lib/python2.6/string.pyc' Note that __file__ will usually be set to the full path of the file. To extract just the file name: >>> import os >>> os.path.basename(string.__file__) 'string.pyc' To ignore the file extension, use this: >>> os.path.splitext(os.path.basename(string.__file__)) ('string', '.pyc') [...] > 2. In python, there seems to be a distinction between running something > as if it is a system command of "C:\...>python myPyFile.py" compared to > simply entering that same ".py" file name directly on the python console > command line. In fact, the latter does not work unless the somewhat > lengthy ">>> runfile(r'C:\... wdir=r'C:\...) stuff is entered (in > iPython). (I mean, my old MATLAB habit of simply entering ">> > mfilename" on the command line seems to be quite wrong in python.) That is correct. The Python interactive interpreter is not intended to be a full-blown shell. iPython is, so I wouldn't be surprised if there is a shorter version of the runfile(full pathname) stuff, but I don't know what it is. > Is there a shortened syntax of running a .py from the python command > prompt, if not using a Spyder "run" button? Or should I always run as > if from the system prompt? That is, dispense with the MATLAB-like "run > from MATLAB/python command line" bias I may be holding. Normally I would say "always run it from the system prompt", but that may be because I don't know iPython and/or Spyder. Another alternative is to write a "main function" in your script: # Filename newbie01.py def main(): print("Doing stuff here...") if __name__ == '__main__': main() else: print("importing here") Then you can do this: >>> import newbie01 importing here >>> newbie01.main() Doing stuff here... >>> newbie01.main() Doing stuff here... That would be my preference. Your mileage may vary. > 3. In injecting my old MATLAB bias of running via the command line ">> > mfilename", I tried a tweak of ">>>import newbie00". That "sort of" > worked, but only the first time. > > Why did the subsequent run of ">>>import newbie00" print nothing? I'm > just trying to understand how python works. Because modules are executed only the first time they are imported. See above. > 4. The final case shown of hitting the Spyder run button included this: > > UMD has deleted: newbie00 > > What does that mean? I noted that after this "automatic" deletion, I > could do the ">>>import newbie00" once again and get the print. (I did > not show that above.) That looks like a trick specific to Spyder and/or iPython. > 5. I think #4 implies an import can be removed. (Yes/No?) I am not > sure why that would be desired, but I will ask how to remove an import, > or to "refresh" the run, of that is the appropriate question. Hmmm. Well, yes, technically they can, but my recommendation is that you don't, because doing so can lead to some ... interesting ... hard-to- debug problems. But now that you have chosen to ignore me *wink*, you can delete the module so as to allow it to be refreshed like this: del newbie00 # delete the version you are using import sys # only needed once del sys.modules['newbie00'] # delete it from the cache Now, as far as Python is concerned, newbie00 has never been imported. Probably. Another way is with the built-in reload() function: import newbie00 # ... make some edits to the newbie00 source file reload(newbie00) # ... now the changes will show up but be warned that there are some traps to using reload(), so much so that in Python 3 it has been relegated to the "imp" (short for "import") module, where it is less tempting to newbies. > I think I saw someplace where a .pyc file is created on an initial run > and subsequently run instead of the .py. I'm not sure if that applies > here, but if related, I guess an auxiliary question is how to easily > force the .py to run rather than the .pyc? No, see above: .pyc files are only created when you *import* a module, and they are never used when you *run* a module. > 6. Perhaps peripherally related to getting a running script/function/ > module name, is getting a "call listing" of all the functions (and > modules) called by a .py program. How would I get that? I only ask as > it comes in handy if one distributes a program. I mean, you only give > people what they actually need. I'm not quite sure I understand what you mean. Can you explain in more detail? Welcome on board with Python, I hope you have fun! -- Steven From wuwei23 at gmail.com Thu May 17 00:54:37 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 16 May 2012 21:54:37 -0700 (PDT) Subject: Newbie questions on import & cmd line run References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Message-ID: <7bb04805-4849-4d63-860a-0daf66ac7a42@ri8g2000pbc.googlegroups.com> On May 17, 11:45?am, gwhite wrote: > 1. ?If running from the system command line, or the Sypder "run" > button, "__name__" is "__main__" rather than "newbie00", as seen > above. > > So, how would I get the file name newbie00.py in these two noted > cases? You can get it from the file name: import os.path name = os.path.split(__file__)[-1] However, you might find it better in the long term to always separate your code into import-only modules and execute-only scripts. It avoids this issue and others. > 2. ?Is there a shortened syntax of running a .py from the python command > prompt, if not using a Spyder "run" button? ?Or should I always run as > if from the system prompt? ?That is, dispense with the MATLAB-like > "run from MATLAB/python command line" bias I may be holding. Generally, the correct way of running Python code from the interpreter is 'import '. You might find this pattern useful: In your module: def main(): # code goes here if __name__ == '__main__': main() Then from the interpreter: import mymodule; mymodule.main() > 3. ?In injecting my old MATLAB bias of running via the command line > ">> mfilename", I tried a tweak of ?">>>import newbie00". ?That "sort > of" worked, but only the first time. > > Why did the subsequent run of ">>>import newbie00" print nothing? ?I'm > just trying to understand how python works. The import mechanism only imports a module once, as all files use the same module instance (they're effectively singletons). This happens with repeated imports in one module as well as across various modules during a single execution. So re-importing a module does nothing; to force a re-import, you can use the reload() function, although that doesn't guarantee updating all references. For example: import mymodule from mymodule import myfunc # modify myfunc code externally reload(mymodule) myfunc() # original reference mymodule.myfunc() # newly modified function I don't think that only-one-import is true for scripts that are run from the command line, though. They can exist as both '__main__' and their actual name in the module table. (Someone please correct me if this understanding is wrong...) > 4. ?The final case shown of hitting the Spyder run button included > this: > > UMD has deleted: newbie00 > > What does that mean? ?I noted that after this "automatic" deletion, I > could do the ">>>import newbie00" once again and get the print. ?(I > did not show that above.) Spyder provides a convenience feature to force the reimport of user- defined modules, like your newbie00. After execution, it appears to drop all references to your module, forcing a garbage collection. As its no longer loaded, a subsequent import works. > 5. ?I think #4 implies an import can be removed. ?(Yes/No?) ?I am not > sure why that would be desired, but I will ask how to remove an > import, or to "refresh" the run, of that is the appropriate question. reload() However, the only way to guarantee you've updated all references correctly is to close the interpreter and re-start it. For this kind of development process of modifying code and seeing the changes, it's probably better to look into writing tests instead. These will always be run in isolation, so you're guaranteed of having the correct environment each time. > I think I saw someplace where a .pyc file is created on an initial run > and subsequently run instead of the .py. ?I'm not sure if that applies > here, but if related, I guess an auxiliary question is how to easily > force the .py to run rather than the .pyc? A .pyc file won't be created for .py files that are run directly, only for those that are imported. You really shouldn't need to worry about this, though. It's an implementation detail that isn't influencing the issues you're seeing. However, if you do ever need to do it, you can stop .pyc files by passing the -B flag to the interpreter, or by setting the environment variable PYTHONDONTWRITEBYTECODE. > 6. ?Perhaps peripherally related to getting a running script/function/ > module name, is getting a "call listing" of all the functions (and > modules) called by a .py program. ?How would I get that? ?I only ask > as it comes in handy if one distributes a program. ?I mean, you only > give people what they actually need. Perhaps this might be of use: http://pycallgraph.slowchop.com/ Hope this helps. From eearlcirri at yahoo.com Thu May 17 02:57:45 2012 From: eearlcirri at yahoo.com (EdmundBuffey) Date: Wed, 16 May 2012 23:57:45 -0700 (PDT) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign In-Reply-To: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> Message-ID: <1337237865866-4974894.post@n6.nabble.com> I have some more info from a company that makes under-cabinet http://www.ledstrips8.com/outdoor-led-lighting-c-11.html led outdoor lighting . From looking at some of these posts and seeing some of the pricing, I know they are better http://www.ledstrips8.com/flexible-led-strip-lighting-c-32.html led strip lights 12v looking, probably better priced, and all 12 V. http://www.ledlight-mall.com/ LED Bulbs Wholesale -- View this message in context: http://python.6.n6.nabble.com/How-to-convert-simple-B-W-graphic-to-the-dot-matrix-for-the-LED-display-sign-tp4544790p4974894.html Sent from the Python - python-list mailing list archive at Nabble.com. From marco_u at nsgmail.com Thu May 17 03:58:48 2012 From: marco_u at nsgmail.com (Marco) Date: Thu, 17 May 2012 09:58:48 +0200 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 References: <4fb4431d$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/17/2012 02:15 AM, Steven D'Aprano wrote: > the Fine Manual has more detail, although I admit it isn't *entirely* > clear what it is talking about if you're not a Unicode expert: > > > http://docs.python.org/py3k/library/stdtypes.html#str.isdecimal You are right, that is clear, thanks :) > Examples: > > py> c = '\u2155' > py> print(c) > ? > py> c.isdecimal(), c.isdigit(), c.isnumeric() > (False, False, True) > py> import unicodedata > py> unicodedata.numeric(c) > 0.2 > > py> c = '\u00B2' > py> print(c) > ? > py> c.isdecimal(), c.isdigit(), c.isnumeric() > (False, True, True) > py> unicodedata.numeric(c) > 2.0 Perfect explanation, thanks again, Marco From jeanpierreda at gmail.com Thu May 17 04:23:50 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 17 May 2012 04:23:50 -0400 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: <1370342.Eu8Q8A6FV8@PointedEars.de> References: <1370342.Eu8Q8A6FV8@PointedEars.de> Message-ID: On Wed, May 16, 2012 at 5:07 PM, Thomas 'PointedEars' Lahn wrote: > RTFM. > > $ python3 -c 'print("42".isdecimal.__doc__ + "\n"); > print("42".isdigit.__doc__)' Heh, don't print docstrings. Use pydoc. $ ( export PAGER=cat && pydoc3 str.isdecimal && pydoc3 str.isdigit ) Help on method_descriptor in str: str.isdecimal = isdecimal(...) S.isdecimal() -> bool Return True if there are only decimal characters in S, False otherwise. Help on method_descriptor in str: str.isdigit = isdigit(...) S.isdigit() -> bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. --- Although pydoc is still really bad compared to the web/reST documentation. (This has been noted by others.) --- By the way, is it worth filing a bug report on the wording of str.isdecimal()? It seems to imply that ''.isdecimal() should be true. (It isn't.) Especially when compared like that to isdigit, which makes a point of noting this particular edge case. -- Devin From jeanpierreda at gmail.com Thu May 17 04:39:46 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 17 May 2012 04:39:46 -0400 Subject: Where is the most recent Tkinter information In-Reply-To: <4FB478D0.2010009@fossworkflowguides.com> References: <4FB478D0.2010009@fossworkflowguides.com> Message-ID: On Thu, May 17, 2012 at 12:04 AM, Simon Cropper wrote: > The main page of the python 3.2.3 documentation for tkinter can be found > here... > http://docs.python.org/py3k/library/tkinter.html?highlight=tkinter#tkinter > it is dated 2012. > > This seems to be duplicated from the ActiveState site here... > http://docs.activestate.com/activepython/3.1/python/library/tkinter.html > also dated 2012. That is just a smallish tutorial. It's when you look for reference material that you encounter stuff from ages past. The reference pages it links to (by Fred Lundh and New Mexico Tech) were last updated in 1999 and 2004 respectively. It links to no other online reference. It does, however, link to a book published in 2000. And of course it's dated 2012 -- the docs are automatically regenerated. The issue is when the last time they were updated, which is only a few weeks ago. And that's a stronger claim anyway. ;) > Here are some other resources I have stumbled on... > [...] > http://www.tkdocs.com/tutorial/index.html This looks really good. Thanks. -- Devin From rosuav at gmail.com Thu May 17 04:52:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 May 2012 18:52:59 +1000 Subject: bash/shell to python In-Reply-To: References: Message-ID: On Thu, May 17, 2012 at 12:16 PM, Rita wrote: > Hello, > > I currently build a lot of interfaces/wrappers to other applications using > bash/shell. One short coming for it is it lacks a good method to handle > arguments so I switched to python a while ago to use 'argparse' module. Its > a great complement to subprocess module. I was wondering if there is a > generic framework people follow to build python scripts which are replacing > shell scripts? Is there a guide or a template to follow? It's generally accepted that it's easier to port a shell than a shell script. That said, though, Python does have some good "shell-like" functionality - look at the shutil module (along with subprocess which you've already seen). To create optimal Python code, though, you're going to have to look through the shell script, understand what it's actually doing, and rewrite that logic in Python. chrisA From d at davea.name Thu May 17 04:53:24 2012 From: d at davea.name (Dave Angel) Date: Thu, 17 May 2012 04:53:24 -0400 Subject: Newbie questions on import & cmd line run In-Reply-To: <7bb04805-4849-4d63-860a-0daf66ac7a42@ri8g2000pbc.googlegroups.com> References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> <7bb04805-4849-4d63-860a-0daf66ac7a42@ri8g2000pbc.googlegroups.com> Message-ID: <4FB4BC84.50306@davea.name> On 05/17/2012 12:54 AM, alex23 wrote: > On May 17, 11:45 am, gwhite wrote: > > I don't think that only-one-import is true for scripts that are run > from the command line, though. They can exist as both '__main__' and > their actual name in the module table. (Someone please correct me if > this understanding is wrong...) You're basically right, and this is the source of many bugs. Importing the file that was the original script can cause many subtle bugs, much worse than the general "circular imports" problem, because it's not obvious that there are two complete instances of the code and data. There have been many lengthy threads triggered by such a bug, and the cure is always to eliminate the circle. If you find you need to reference back to the original script's objects by module namespace, then it ought to be refactored. The script would then consist of something as simple as import realcode if __name__ == "__main__": realcode.main() else: print "Don't import this file, it's not a module" At this point, other modules could also import realcode, and use its functions and global data. -- DaveA From iainking at gmail.com Thu May 17 05:06:16 2012 From: iainking at gmail.com (Iain King) Date: Thu, 17 May 2012 02:06:16 -0700 (PDT) Subject: tiny script has memory leak In-Reply-To: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> References: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> Message-ID: <10922635.2189.1337245576482.JavaMail.geo-discussion-forums@vbws2> On Friday, 11 May 2012 22:29:39 UTC+1, gry wrote: > sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 > [gcc-4_3-branch revision 141291]] > I thought this script would be very lean and fast, but with a large > value for n (like 150000), it uses 26G of virtural memory, and things > start to crumble. > > #!/usr/bin/env python > '''write a file of random integers. args are: file-name how-many''' > import sys, random > > f = open(sys.argv[1], 'w') > n = int(sys.argv[2]) > for i in xrange(n): > print >>f, random.randint(0, sys.maxint) > f.close() > > What's using so much memory? > What would be a better way to do this? (aside from checking arg > values and types, I know...) Ran OK for me, python 2.4.1 on Windows 7 Iain From clp2 at rebertia.com Thu May 17 05:08:26 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 17 May 2012 02:08:26 -0700 Subject: bash/shell to python In-Reply-To: References: Message-ID: On Wed, May 16, 2012 at 7:16 PM, Rita wrote: > Hello, > > I currently build a lot of interfaces/wrappers to other applications using > bash/shell. One short coming for it is it lacks a good method to handle > arguments so I switched to python a while ago to use 'argparse' module. Its > a great complement to subprocess module. I was wondering if there is a > generic framework people follow to build python scripts which are replacing > shell scripts? Is there a guide or a template to follow? Not really. The new Plumbum library looks pretty awesome though: http://plumbum.readthedocs.org/en/latest/index.html There are also a few 3rd-party wrapper libraries for the `subprocess` module available to make using it more convenient (e.g. `envoy`). Cheers, Chris From ironfroggy at gmail.com Thu May 17 05:20:07 2012 From: ironfroggy at gmail.com (Calvin Spealman) Date: Thu, 17 May 2012 05:20:07 -0400 Subject: ANN: straight.command 0.1a1 - A command framework with a plugin architecture Message-ID: I'd like to announce a new project, based on straight.plugin, a command framework that provides a declarative way to define command-line options, sub-commands, and allows plugins from third-parties to expand commands. This is all very early, I'm calling this version 0.1a1 and lots of things are missing, but here is an example (which works) of a small todo application built with this. #!/usr/bin/env python from __future__ import print_function import sys from straight.command import Command, Option, SubCommand class List(Command): def run_default(self, **extra): for line in open(self.parent.args['filename']): print(line.strip('\n')) class Add(Command): new_todo = Option(dest='new_todo', action='append') def run_default(self, new_todo, **extra): with open(self.parent.args['filename'], 'a') as f: for one_todo in new_todo: print(one_todo.strip('\n'), file=f) class Todo(Command): filename = Option(dest='filename', action='store') list = SubCommand('list', List) add = SubCommand('add', Add) if __name__ == '__main__': Todo().run(sys.argv[1:]) And a sample of the result of this little script: $ ./todo.py todo.txt add "Write an example tool" $ ./todo.py todo.txt add "Get the documentation cleaned up and on readthedocs" $ ./todo.py todo.txt add "Blog about the project" $ ./todo.py todo.txt list Write an example tool Get the documentation cleaned up and on readthedocs Blog about the project The documentation and source are both available now. docs: http://straightcommand.readthedocs.org/ source: https://github.com/ironfroggy/straight.command announcement: http://techblog.ironfroggy.com/2012/05/ann-straightcommand-01a1-command.html -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy From alain at dpt-info.u-strasbg.fr Thu May 17 05:50:28 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 17 May 2012 11:50:28 +0200 Subject: tiny script has memory leak References: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> Message-ID: <87y5or2l23.fsf@dpt-info.u-strasbg.fr> gry writes: > sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 > [gcc-4_3-branch revision 141291]] > I thought this script would be very lean and fast, but with a large > value for n (like 150000), it uses 26G of virtural memory, and things > start to crumble. > > #!/usr/bin/env python > '''write a file of random integers. args are: file-name how-many''' > import sys, random > > f = open(sys.argv[1], 'w') > n = int(sys.argv[2]) > for i in xrange(n): > print >>f, random.randint(0, sys.maxint) > f.close() sys.version is '2.6.6 (r266:84292, Sep 15 2010, 16:22:56) \n[GCC 4.4.5]' here, and your script works like a charm. BTW, I would use f.write() instead of print >> f (which I think is deprecated). -- Alain. From steve+comp.lang.python at pearwood.info Thu May 17 05:53:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 May 2012 09:53:40 GMT Subject: Python and Tkinter by John E Grayson References: Message-ID: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 May 2012 23:55:29 -0400, Mark R Rivet wrote: > I have a copy of this book and was wondering how relevant the content is > considering the publish date is 2000. Are people still using this > information? Anyone have any experience with this book? I guess what I > mean, is, any of the code in this book deprecated? or does it still > contain information used today the same as then. I mean, I guess some > things don't change right? For instance, the derivative of x^2 is 2x > now and in the 1800's. A book written in 2000 will probably be targeting Python 1.5, which is seriously outdated. Most of the code will probably still work, but it will not be the "best" way to do things, and there will probably be a few minor things which act differently. If you already know Python, and just want to learn Tkinter, then using such an old book is probably acceptable, in my opinion. -- Steven From fayaz.yusuf.khan at gmail.com Thu May 17 06:07:10 2012 From: fayaz.yusuf.khan at gmail.com (Fayaz Yusuf Khan) Date: Thu, 17 May 2012 15:37:10 +0530 Subject: Wish: Allow all log Handlers to accept the level argument Message-ID: ***TRIVIAL ISSUE***, but this has been irking me for a while now. The main logging.Handler class' __init__ accepts a level argument while none of its children do. The poor minions seem to be stuck with the setLevel method which considerably lengthens the code. In short: Let's do this: root.addHandler(FileHandler('debug.log', level=DEBUG) Instead of this: debug_file_handler = FileHandler('debug.log') debug_file_handler.setLevel(DEBUG) root.addHandler(debug_file_handler) Python 2.7 -- Cloud architect, Dexetra SS, Kochi, India fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com +91-9746-830-823 From markrrivet at aol.com Thu May 17 07:48:50 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Thu, 17 May 2012 07:48:50 -0400 Subject: Python and Tkinter by John E Grayson References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3bp9r7pgc88f2960lpeajvktt6cj1i4iu5@4ax.com> On 17 May 2012 09:53:40 GMT, Steven D'Aprano wrote: >On Wed, 16 May 2012 23:55:29 -0400, Mark R Rivet wrote: > >> I have a copy of this book and was wondering how relevant the content is >> considering the publish date is 2000. Are people still using this >> information? Anyone have any experience with this book? I guess what I >> mean, is, any of the code in this book deprecated? or does it still >> contain information used today the same as then. I mean, I guess some >> things don't change right? For instance, the derivative of x^2 is 2x >> now and in the 1800's. > >A book written in 2000 will probably be targeting Python 1.5, which is >seriously outdated. Most of the code will probably still work, but it >will not be the "best" way to do things, and there will probably be a few >minor things which act differently. > >If you already know Python, and just want to learn Tkinter, then using >such an old book is probably acceptable, in my opinion. I am in the process of learning python, and want to learn tkinter for GUI stuff. Is tkinter what people are using for GUI? From bahamutzero8825 at gmail.com Thu May 17 08:01:07 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 17 May 2012 07:01:07 -0500 Subject: Python and Tkinter by John E Grayson In-Reply-To: <3bp9r7pgc88f2960lpeajvktt6cj1i4iu5@4ax.com> References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> <3bp9r7pgc88f2960lpeajvktt6cj1i4iu5@4ax.com> Message-ID: <4FB4E883.4080909@gmail.com> On 5/17/2012 6:48 AM, Mark R Rivet wrote: > I am in the process of learning python, and want to learn tkinter for > GUI stuff. Is tkinter what people are using for GUI? tkinter is one of several GUI toolkits that can be used with Python. IIRC, most people use PyGTK or PyQt for serious projects. http://wiki.python.org/moin/GuiProgramming -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From shooshx at gmail.com Thu May 17 08:08:12 2012 From: shooshx at gmail.com (shooshx) Date: Thu, 17 May 2012 05:08:12 -0700 (PDT) Subject: Right way to initialize python embedded in a multi-threaded application Message-ID: <19ed5abe-7283-4dad-bd8f-b5209b3d974b@3g2000vbx.googlegroups.com> I'm embedding python in a multi-threaded C application. I've taken care to wrap every call to the Python C API with gstate = PyGILState_Ensure(); // call python code PyGILState_Release(gstate); But I'm stumped with what to do in the initialization. Right after the call to Py_IsInitialized() I've added a call: PyEval_InitThreads(); The docs say that this function leaves the GIL locked when it returns. I do some more initializations like importing modules and then I call PyEval_ReleaseLock(); This seems to cause a problem since not long after a call to PyGILState_Release(gstate) that's made in a different thread crashes. with "Fatal Python error: This thread state must be current when releasing" If I don't do the call to PyEval_ReleaseLock() in the main thread right after initialization, the GIL seems to be released after the first PyGILState_Ensure() - PyGILState_Release() pair. So what am I doing wrong here? What is the correct way of initializing a multi-threaded application? From kw at codebykevin.com Thu May 17 09:07:18 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 17 May 2012 09:07:18 -0400 Subject: Python and Tkinter by John E Grayson In-Reply-To: References: Message-ID: On 5/16/12 11:55 PM, Mark R Rivet wrote: > I have a copy of this book and was wondering how relevant the content > is considering the publish date is 2000. Are people still using this > information? Anyone have any experience with this book? I guess what I > mean, is, any of the code in this book deprecated? or does it still > contain information used today the same as then. I mean, I guess some > things don't change right? For instance, the derivative of x^2 is 2x > now and in the 1800's. Mark Lutz' "Programming Python" has extensive coverage of Tkinter (it's a huge book and devotes several chapters to Tkinter), and has been updated at regular intervals, most recently in the last year or two; I've found it a very helpful reference and guide to Tkinter programming. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tjreedy at udel.edu Thu May 17 09:32:24 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 May 2012 09:32:24 -0400 Subject: Difference between str.isdigit() and str.isdecimal() in Python 3 In-Reply-To: References: <1370342.Eu8Q8A6FV8@PointedEars.de> Message-ID: On 5/17/2012 4:23 AM, Devin Jeanpierre wrote: > str.isdecimal = isdecimal(...) > S.isdecimal() -> bool > > Return True if there are only decimal characters in S, > False otherwise. > > Help on method_descriptor in str: > > str.isdigit = isdigit(...) > S.isdigit() -> bool > > Return True if all characters in S are digits > and there is at least one character in S, False otherwise. > By the way, is it worth filing a bug report on the wording of > str.isdecimal()? It seems to imply that ''.isdecimal() should be true. > (It isn't.) Especially when compared like that to isdigit, which makes > a point of noting this particular edge case. I think both should read (choosing either decimals or digits) Return True if S has at least one character and all are decimals/digits, False otherwise. Feel free to submit an issue. -- Terry Jan Reedy From tjreedy at udel.edu Thu May 17 09:42:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 May 2012 09:42:00 -0400 Subject: tiny script has memory leak In-Reply-To: <87y5or2l23.fsf@dpt-info.u-strasbg.fr> References: <39d45bf7-661d-489c-a25a-00a3b509b342@f14g2000yqe.googlegroups.com> <87y5or2l23.fsf@dpt-info.u-strasbg.fr> Message-ID: On 5/17/2012 5:50 AM, Alain Ketterlin wrote: > gry writes: > >> sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 >> [gcc-4_3-branch revision 141291]] > >> I thought this script would be very lean and fast, but with a large >> value for n (like 150000), it uses 26G of virtural memory, and things >> start to crumble. >> >> #!/usr/bin/env python >> '''write a file of random integers. args are: file-name how-many''' >> import sys, random >> >> f = open(sys.argv[1], 'w') >> n = int(sys.argv[2]) >> for i in xrange(n): >> print>>f, random.randint(0, sys.maxint) >> f.close() > > sys.version is '2.6.6 (r266:84292, Sep 15 2010, 16:22:56) \n[GCC 4.4.5]' > here, and your script works like a charm. BTW, I would use f.write() That would have to be f.write(str(random.randint(0, sys.maxint))+end) where above end would be '\n'. > instead of print>> f (which I think is deprecated). In the sense that in Py3, print is a function with a file parameter: print(random.randint(0, sys.maxint), file=f) The idiosyncratic ugliness of >>file was one reason for the change. Adding the option to specify separator and terminator was another. -- Terry Jan Reedy From subscriptions at cagttraining.com Thu May 17 09:44:56 2012 From: subscriptions at cagttraining.com (Bill Felton) Date: Thu, 17 May 2012 09:44:56 -0400 Subject: Python and Tkinter by John E Grayson In-Reply-To: References: Message-ID: <53D94017-2CE0-48E9-9337-B0B008E8611B@cagttraining.com> On May 17, 2012, at 9:07 AM, Kevin Walzer wrote: > On 5/16/12 11:55 PM, Mark R Rivet wrote: >> I have a copy of this book and was wondering how relevant the content >> is considering the publish date is 2000. Are people still using this >> information? Anyone have any experience with this book? I guess what I >> mean, is, any of the code in this book deprecated? or does it still >> contain information used today the same as then. I mean, I guess some >> things don't change right? For instance, the derivative of x^2 is 2x >> now and in the 1800's. > > Mark Lutz' "Programming Python" has extensive coverage of Tkinter (it's a huge book and devotes several chapters to Tkinter), and has been updated at regular intervals, most recently in the last year or two; I've found it a very helpful reference and guide to Tkinter programming. I agree with Kevin's recommendation. I've just come off of a large GUI development effort using tkinter. In addition to Lutz' book, I highly recommend the 'google is your friend' approach -- there are quite a few decent or better references available, especially at the 'detailed topic' level. E.g., google 'tkinter listbox' and at least one of the top 3 or 4 hits will likely provide you whatever you need. Lutz will give you the grounding/overview and may have enough detail for what you want. Where and as not, do a google search and you should be good to go. FWIW, I picked up the book originally referenced and didn't find it particularly useful, especially given Lutz and the web. YMMV. cheers, Bill From nibinvm at gmail.com Thu May 17 09:52:09 2012 From: nibinvm at gmail.com (Nibin V M) Date: Thu, 17 May 2012 19:22:09 +0530 Subject: print XML Message-ID: Hello, I have the following code, which will assign XML data to a variable! What is the best method to write the contents of the variable to a file? ======= doc = minidom.parse(sys.stdin) ======= Any help will be highly appreciated! Thank you, -- Regards.... Nibin. http://TechsWare.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu May 17 09:52:58 2012 From: python at bdurham.com (python at bdurham.com) Date: Thu, 17 May 2012 09:52:58 -0400 Subject: Python and Tkinter by John E Grayson In-Reply-To: References: Message-ID: <1337262778.25727.140661076791837.3B94D9E6@webmail.messagingengine.com> > Mark Lutz' "Programming Python" has extensive coverage of Tkinter (it's a huge book and devotes several chapters to Tkinter), and has been updated at regular intervals, most recently in the last year or two; I've found it a very helpful reference and guide to Tkinter programming. +1 I highly recommend Mark's book. An excellent resource on not only Tkinter, but many other Python topics as well. Malcolm From breamoreboy at yahoo.co.uk Thu May 17 09:53:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 17 May 2012 14:53:02 +0100 Subject: Newbie questions on import & cmd line run In-Reply-To: References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> Message-ID: On 17/05/2012 05:29, Chris Rebert wrote: > On Wed, May 16, 2012 at 6:45 PM, gwhite wrote: >> #! > > That's a shebang line. See http://en.wikipedia.org/wiki/Shebang_(Unix) > It's doesn't matter at all since you're on Windows. On Unix-like > systems, one typically writes: > #!/usr/bin/env python > >> # Filename: newbie00.py >> >> if __name__ == '__main__': > > Cheers, > Chris For the record quoting from http://www.python.org/dev/peps/pep-0397/ "As Python 3.x scripts are often syntactically incompatible with Python 2.x scripts, a different strategy must be used to allow files with a '.py' extension to use a different executable based on the Python version the script targets. This will be done by borrowing the existing practices of another operating system - scripts will be able to nominate the version of Python they need by way of a "shebang" line, as described below." -- Cheers. Mark Lawrence. From news at idlcoyote.com Thu May 17 11:05:48 2012 From: news at idlcoyote.com (David Fanning) Date: Thu, 17 May 2012 09:05:48 -0600 Subject: Pan/Zoom Line Plot in Coyote Graphics Message-ID: Folks, At my new job, we had a need to be able to zoom into a lot of data very quickly and then pan around the data to see what points are in the immediate vicinity. Python has a rudimentary capability like we wanted, but it's just a bit clunky and slow. You can pan IDL 8.1 graphics (sometimes even when you don't want to!), but you can easily pan your plot off the face of the Earth and good luck writing or modifying one of *those* programs! So, to make a long story short, I had to un-retire for a day to write what we wanted in Coyote Graphics. It's pretty darn slick, even if I say so myself. :-) I have added it to the Coyote Library this morning: http://www.idlcoyote.com/programs/cgzplot.pro It is written as an object (although called like a procedure), and is a subclass of a new cgGraphicsKeywords object which handles graphics keywords. You will need this program, too. http://www.idlcoyote.com/programs/cggraphicskeywords__define.pro Basically, the program is an interactive wrapper to cgPlot and is called *exactly* like cgPlot, with all of cgPlot's keywords, etc. IDL> cgZPlot, cgDemodata(1), PSym=2, Color='red' The operations are simple. Zoom with the LEFT mouse button and pan with the RIGHT mouse button. If you click inside the plot with the LEFT mouse button, you can draw a rubberband zoom box to make your initial zoom selection. You can tweak your zoom by clicking the LEFT mouse button outside of the plot boundaries. Clicking at the top or bottom of the plot will zoom in or out, respectively, of the X axis. Clicking to the right or left of the plot will do the same with the Y axis. To restore the plot to its original dimensions, simply click and release inside the plot without moving the mouse. Complete directions are in the documentation. If a plot is zoomed, you can use the RIGHT mouse button to pan the plot in the graphics window. Panning and zooming are incredibly fast and smooth, even with a full size window on my display. Since I am retired, I figure I am done holding everyone's hand, so if you want nice looking file output, you will have to install ImageMagick and GhostScript (for PDF output). I figure most Coyote Library users will have these installed by now. If not, there is no hope for them anyway. :-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Thu May 17 11:13:50 2012 From: news at idlcoyote.com (David Fanning) Date: Thu, 17 May 2012 09:13:50 -0600 Subject: Pan/Zoom Line Plot in Coyote Graphics References: Message-ID: David Fanning writes: > At my new job, we had a need to be able to zoom into a > lot of data very quickly and then pan around the data > to see what points are in the immediate vicinity. Aahhh! Darn it. I keep sending this to the wrong news group! Old fingers are hard to train, I guess. Sorry. I'll keep working on this. :-( David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From ppearson at nowhere.invalid Thu May 17 11:59:41 2012 From: ppearson at nowhere.invalid (Peter Pearson) Date: 17 May 2012 15:59:41 GMT Subject: Python and Tkinter by John E Grayson References: Message-ID: On Wed, 16 May 2012 23:55:29 -0400, Mark R Rivet wrote: > I have a copy of this book and was wondering how relevant the content > is considering the publish date is 2000. Are people still using this > information? Anyone have any experience with this book? I bought the book years ago, hoping to learn about Tkinter. I was greatly disappointed: it seems to me that it's a book about Pmw. -- To email me, substitute nowhere->spamcop, invalid->net. From ssawyer at stephensawyer.com Thu May 17 12:01:34 2012 From: ssawyer at stephensawyer.com (Steve Sawyer) Date: Thu, 17 May 2012 12:01:34 -0400 Subject: Extracting DB schema (newbie Q) References: <28618981.415.1337012886784.JavaMail.geo-discussion-forums@vbez18> Message-ID: <638ar7lq88r3u16phdtn2hdevbbnuq04m9@4ax.com> Thanks, James, but John Gordon identified my usage error so I'm good to go now. On Mon, 14 May 2012 09:28:06 -0700 (PDT), james hedley wrote: >On Monday, 14 May 2012 17:01:49 UTC+1, Steve Sawyer wrote: >> Brand-new to Python (that's a warning, folks) >> >> Trying to write a routine to import a CSV file into a SQL Server >> table. To ensure that I convert the data from the CSV appropriately, >> I"m executing a query that gives me the schema (data column names, >> data types and sizes) from the target table. >> >> What I think I want to do is to construct a dictionary using the >> column names as the index value, and a list containing the various >> attributes (data type, lenghth, precision). >> >> If this is NOT a good approach (or if there is a better approach), >> please issue a dope-slap, ignore the rest of this post and set me >> straight. >> >> If this is a good approach, I ran into a problem populating the >> dictionary as I couldn't seem to figure out how to make the update() >> method work by passing the name property of the row object; I kept >> getting a "keyword can't be an expression" error. >> >> What I was able to make work was to construct the command as a string >> and run exec( >> ), but seems there shoudl be a more >> direct way of updating the dictionary. >> >> TIA. > >Could you provide some demo code? Something minimal but runnable, which results in the error you're getting would be best. --Steve-- From ppearson at nowhere.invalid Thu May 17 12:03:16 2012 From: ppearson at nowhere.invalid (Peter Pearson) Date: 17 May 2012 16:03:16 GMT Subject: Python and Tkinter by John E Grayson References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> <3bp9r7pgc88f2960lpeajvktt6cj1i4iu5@4ax.com> Message-ID: On Thu, 17 May 2012 07:48:50 -0400, Mark R Rivet wrote: > > I am in the process of learning python, and want to learn tkinter for > GUI stuff. Is tkinter what people are using for GUI? Tkinter is one option. PyGUI is another. More suggestions will probably accrete on this thread. -- To email me, substitute nowhere->spamcop, invalid->net. From rridge at csclub.uwaterloo.ca Thu May 17 12:58:27 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 17 May 2012 12:58:27 -0400 Subject: Newbie questions on import & cmd line run References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> <4fb47f8a$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >#! ("hash-bang") lines currently do nothing on Windows machines, they are >just comments. However, on Unix and Linux machines (and Macintosh?) they >are interpreted by the shell (equivalent to cmd.exe or command.com), in >order to tell the shell what interpreter to use to execute the program if >you run it directly. They're actually interpreted by the kernel so that they'll work when run from any program. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From abhishek.vit at gmail.com Thu May 17 13:32:55 2012 From: abhishek.vit at gmail.com (Abhishek Pratap) Date: Thu, 17 May 2012 10:32:55 -0700 Subject: multiprocessing : farming out python functions to a cluster Message-ID: Hey Guys I am wondering if I can execute/run python functions through multiprocessing package on a grid/cluster rather than on the same local machine. It will help me create 100's of jobs on which same function has to be used and farm them out to our local cluster through DRMAA. I am not sure if this is possible or makes sense to do with child processes/forks. Any example or advice would be helpful. Thanks! -Abhi -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidgshi at yahoo.co.uk Thu May 17 13:46:11 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 17 May 2012 18:46:11 +0100 (BST) Subject: Looking for Python script for Vector Map simplification, preserving shape and topology Message-ID: <1337276771.10595.YahooMailNeo@web171605.mail.ir2.yahoo.com> Dear All, I am looking for Python script for Vector Map simplification, preserving shape and topology. Please get in touch with davidgshi at yahoo.co.uk??? Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco_u at nsgmail.com Thu May 17 15:32:29 2012 From: marco_u at nsgmail.com (Marco) Date: Thu, 17 May 2012 21:32:29 +0200 Subject: str.isnumeric and Cuneiforms Message-ID: Is it normal the str.isnumeric() returns False for these Cuneiforms? '\U00012456' '\U00012457' '\U00012432' '\U00012433' They are all in the Nl category. Marco From peter.milliken at gmail.com Thu May 17 16:57:42 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 17 May 2012 13:57:42 -0700 (PDT) Subject: Python and Tkinter by John E Grayson In-Reply-To: References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> <3bp9r7pgc88f2960lpeajvktt6cj1i4iu5@4ax.com> Message-ID: <791395.514.1337288262046.JavaMail.geo-discussion-forums@pbad7> I have used Grayson's book - purchased and read many years ago now though. I am only an occasional GUI programmer, but have recently moved away from Tkinter and ttk towards wxPython - mainly because I am very dissatisfied with the lack of widgets to choose from. (new from 2.7 on) ttk supposedly added to the basic TkInter kit but is extremely difficult to work out due to lack of documentation i.e. I quickly wanted to use styles and finding some easy documentation that explained how all that worked was impossible - despite searching the Internet for hours (perhaps I was just unlucky? :-)). For learning wxPython I am using "wxPython in Action" by Noel Rappin and Robin Dunn. Neither book is about learning Python though - they are both aimed at users who have at least a basic Python background and want to learn about the particular GUI toolkit in question. Even though I am on my first wxPython GUI, I am extremely happy that I made the switch - I am already using basic wxPython widgets that were just not available under TkInter/ttk, creating a much more intuitive interface (IMO :-)) for my users. Best of luck in your choices, Peter From peter.milliken at gmail.com Thu May 17 17:00:58 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 17 May 2012 14:00:58 -0700 (PDT) Subject: Are there any instrumentation widgets for wxpython or tkinter? In-Reply-To: References: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> Message-ID: <31480388.444.1337288458787.JavaMail.geo-discussion-forums@pbcqs6> Or wxPython is another good alternative. Download the demo and have a look at the widgets people have already used/created. I think there are some good choices for instrumentation (from memory). From miki.tebeka at gmail.com Thu May 17 17:26:50 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 17 May 2012 14:26:50 -0700 (PDT) Subject: argparse - option with optional value Message-ID: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> Greetings, I'd like to have an --edit option in my program. That if not specified will not open editor. If specified without value will open default editor ($EDITOR) and if specified with value, assume this value is the editor program to run. The way I'm doing it currently is: ... no_edit = 'no-edit' parser.add_argument('-e', '--edit', help='open editor on log', nargs='?', default=no_edit) ... if args.edit != no_edit: editor = args.edit or environ.get('EDITOR', 'vim') However I get a feeling there's a better way to do that. Any ideas? Thanks, -- Miki From simoncropper at fossworkflowguides.com Thu May 17 19:17:23 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Fri, 18 May 2012 09:17:23 +1000 Subject: Looking for Python script for Vector Map simplification, preserving shape and topology In-Reply-To: <1337276771.10595.YahooMailNeo@web171605.mail.ir2.yahoo.com> References: <1337276771.10595.YahooMailNeo@web171605.mail.ir2.yahoo.com> Message-ID: <4FB58703.10004@fossworkflowguides.com> On 18/05/12 03:46, David Shi wrote: > Dear All, > > I am looking for Python script for Vector Map simplification, preserving > shape and topology. > > Please get in touch with davidgshi at yahoo.co.uk > > Regards. > > David > > David, You really need to provide more information to get a specific answer; what sort of vector file? What do you mean by simplify? etc. Of course, most likely most people python-gis bent would say check out the GDAL libraries -- http://pypi.python.org/pypi/GDAL/ -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From diego.uribe.gamez at gmail.com Thu May 17 19:21:40 2012 From: diego.uribe.gamez at gmail.com (Diego Uribe Gamez) Date: Thu, 17 May 2012 18:21:40 -0500 Subject: Browse model UserProfile -> ManyToManyField -> (OneToOneField -> Item) Message-ID: The problem is I can not navigate this model who believes has in particular that the user assigned to some entries, the model is using ManyToManyField to another model and this model by entering a OneToOneField assigned to another model. Model - a model ManyToManyField - until the last OneToOneField model and data. I need the data. the idea is to get all data from all entries, please see the example: --------------------------------------------------------------------------------------------------- class User # a standard django.contrib.auth user model class UserProfile(models.Model): # my AUTH_PROFILE_MODULE for django-profiles user = models.ForeignKey(User, unique=True) instance = models.ManyToManyField(Instance1) class Instance1(models.Model): user = models.ForeignKey(User) element1 = models.CharField(max_length=12) instance2 = models.OneToOneField(Instance2) element1 = 'letter%s' % (X) class Instance2(models.Model): element2 = models.CharField(max_length=12) element2 = 'number%s' % (X) X = X + 1 user = request.user Instance1 - element1 - letter1 - letter2 - letter3 Instance2 - element2 - number1 - number2 - number3 as I can get the letters and all numbers using profile and placed in a variable to render in the template all the ManyToManyField -> (OneToOneField -> Items) ? -- *Diego Alonso Uribe Gamez* ------------------------------ *Desarrollador web* Twitter: @DiegoUG Google+: http://gplus.to/diegoug ------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu May 17 19:42:19 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 May 2012 09:42:19 +1000 Subject: Python and Tkinter by John E Grayson References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ehqi8jdw.fsf@benfinney.id.au> Steven D'Aprano writes: > If you already know Python, and just want to learn Tkinter, then using > such an old book is probably acceptable, in my opinion. There are much more current resources though, which is important because not only Python but especially Tk has gone through some dramatic improvements since that time. One which has seen a lot of love is . -- \ ?Without cultural sanction, most or all of our religious | `\ beliefs and rituals would fall into the domain of mental | _o__) disturbance.? ?John F. Schumaker | Ben Finney From ben+python at benfinney.id.au Thu May 17 20:08:44 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 May 2012 10:08:44 +1000 Subject: argparse - option with optional value References: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> Message-ID: <878vgq8i5v.fsf@benfinney.id.au> Miki Tebeka writes: > I'd like to have an --edit option in my program. That if not specified > will not open editor. If specified without value will open default > editor ($EDITOR) and if specified with value, assume this value is the > editor program to run. So, two rather separate tasks: handle the command-line option, and start the editor. > The way I'm doing it currently is: > ... > no_edit = 'no-edit' > parser.add_argument('-e', '--edit', help='open editor on log', nargs='?', > default=no_edit) There is a built-in ?no value specified? value in Python: the None singleton. The ?argparse? library uses this for the argument default already, so you don't need to fuss with your own special handling . So the above becomes:: parser.add_argument('-e', '--edit', help='open editor on log', nargs='?') > ... > if args.edit != no_edit: and this test becomes the familiar test against None:: if args.edit is not None: > editor = args.edit or environ.get('EDITOR', 'vim') This will work fine, AFAICT. -- \ ?But it is permissible to make a judgment after you have | `\ examined the evidence. In some circles it is even encouraged.? | _o__) ?Carl Sagan, _The Burden of Skepticism_, 1987 | Ben Finney From python.list at tim.thechases.com Thu May 17 20:32:18 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 17 May 2012 19:32:18 -0500 Subject: SocketServer.BaseRequestHandler and __init__/super() Message-ID: <4FB59892.40900@tim.thechases.com> Sparring with a little sandbox/test code (in 2.6, FWIW), I'm trying to set up some instance variables in my __init__ but keep hitting my head against the wall. Initially, I had something of the form class MyServer(SocketServer.BaseRequestHandler): def __init__(self, *args, **kwargs): self.foo = "some default" super(MyServer, self).__init__(*args, **kwargs) but, because SocketServer.BaseRequestHandler is an old-style class, it barfed with the classic "TypeError: super() argument 1 must be type, not classobj" So I tossed in "object" to the class hierarchy: class MyServer(object, SocketServer.BaseRequestHandler): def __init__(self, *args, **kwargs): self.foo = "some default" super(MyServer, self).__init__(*args, **kwargs) but now because it tries to pass *args/**kwargs into object.__init__ I get a "TypeError: object.__init__() takes no parameters" I know I can just force it with class MyServer(SocketServer.BaseRequestHandler): def __init__(self, *args, **kwargs): self.foo = "some default" SocketServer.BaseRequestHandler.__init__(self, *args, **kwargs) but I want to be sure there's not some more pythonicly proper way to go about it. Any thoughts on this? (other than "SocketServer should have inherited from object which is a 2.x best-practice") -tkc From steve+comp.lang.python at pearwood.info Thu May 17 20:50:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 May 2012 00:50:09 GMT Subject: str.isnumeric and Cuneiforms References: Message-ID: <4fb59cc1$0$29984$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 May 2012 21:32:29 +0200, Marco wrote: > Is it normal the str.isnumeric() returns False for these Cuneiforms? > > '\U00012456' > '\U00012457' > '\U00012432' > '\U00012433' > > They are all in the Nl category. Are you sure about that? Do you have a reference? It seems to me that they are not: py> c = '\U00012456' py> import unicodedata py> unicodedata.numeric(c) Traceback (most recent call last): File "", line 1, in ValueError: not a numeric character Although it is possible that unicodedata is buggy, or perhaps just doesn't support the multilingual plane characters. -- Steven From simoncropper at fossworkflowguides.com Thu May 17 20:52:07 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Fri, 18 May 2012 10:52:07 +1000 Subject: GUI toolkits and dynamic table browser widget Message-ID: <4FB59D37.1020709@fossworkflowguides.com> Hi, There has been some discussion on this list regarding GUI toolkits and it reinvigorated my search for one to meet my needs. I would like to create windows with grids (AKA rows and column of a table like excel). Do any of the GUI interfaces have these types of widgets? i have looked but can't find any and I have not stumbled on program that presents data in this way so I can see how they do it. Specifically I would like to run a SQL command and have the returned list passed to a widget with little or no manipulation and that widget present the data, allow the user to scroll through that data and preferably allow edits to occur. These edits could then be passed back via a string to the program for inclusion in a sql-update command. Any ideas? -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From skippy.hammond at gmail.com Thu May 17 21:25:23 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 18 May 2012 11:25:23 +1000 Subject: Right way to initialize python embedded in a multi-threaded application In-Reply-To: <19ed5abe-7283-4dad-bd8f-b5209b3d974b@3g2000vbx.googlegroups.com> References: <19ed5abe-7283-4dad-bd8f-b5209b3d974b@3g2000vbx.googlegroups.com> Message-ID: <4FB5A503.6030705@gmail.com> On 17/05/2012 10:08 PM, shooshx wrote: > I'm embedding python in a multi-threaded C application. > I've taken care to wrap every call to the Python C API with > > gstate = PyGILState_Ensure(); > // call python code > PyGILState_Release(gstate); > > But I'm stumped with what to do in the initialization. > Right after the call to Py_IsInitialized() I've added a call: > > PyEval_InitThreads(); > > The docs say that this function leaves the GIL locked when it returns. > I do some more initializations like importing modules and then I call > > PyEval_ReleaseLock(); > > This seems to cause a problem since not long after a call to > PyGILState_Release(gstate) that's made in a different thread crashes. > with > > "Fatal Python error: This thread state must be current when releasing" > > If I don't do the call to PyEval_ReleaseLock() in the main thread > right after initialization, the GIL seems to be released > after the first PyGILState_Ensure() - PyGILState_Release() pair. > > So what am I doing wrong here? > What is the correct way of initializing a multi-threaded application? Try replacing the PyEval_ReleaseLock() call with PyEval_SaveThread(); - that works for pythoncom, which has the same basic requirement - see http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/raw-file/b8c62cf04c5a/com/win32com/src/dllmain.cpp for how it works. HTH, Mark > > From tjreedy at udel.edu Thu May 17 21:58:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 May 2012 21:58:18 -0400 Subject: str.isnumeric and Cuneiforms In-Reply-To: <4fb59cc1$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <4fb59cc1$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5/17/2012 8:50 PM, Steven D'Aprano wrote: > On Thu, 17 May 2012 21:32:29 +0200, Marco wrote: > >> Is it normal the str.isnumeric() returns False for these Cuneiforms? >> >> '\U00012456' >> '\U00012457' >> '\U00012432' >> '\U00012433' >> >> They are all in the Nl category. > > Are you sure about that? Do you have a reference? > > It seems to me that they are not: > > > py> c = '\U00012456' > py> import unicodedata > py> unicodedata.numeric(c) > Traceback (most recent call last): > File "", line 1, in > ValueError: not a numeric character > > > Although it is possible that unicodedata is buggy, or perhaps just > doesn't support the multilingual plane characters. Neither. It appears that these 'letter-like numeric characters' do not have specific numeric values, at least not in UCD 6.1.0 http://www.unicode.org/Public/6.1.0/ucd/UnicodeData.txt ... 12432;CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS DISH;Nl;0;L;;;;;N;;;;; 12433;CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS MIN;Nl;0;L;;;;;N;;;;; ... 12456;CUNEIFORM NUMERIC SIGN NIGIDAMIN;Nl;0;L;;;;;N;;;;; 12457;CUNEIFORM NUMERIC SIGN NIGIDAESH;Nl;0;L;;;;;N;;;;; 12458;CUNEIFORM NUMERIC SIGN ONE ESHE3;Nl;0;L;;;;1;N;;;;; 12459;CUNEIFORM NUMERIC SIGN TWO ESHE3;Nl;0;L;;;;2;N;;;;; 1245A;CUNEIFORM NUMERIC SIGN ONE THIRD DISH;Nl;0;L;;;;1/3;N;;;;; 1245B;CUNEIFORM NUMERIC SIGN TWO THIRDS DISH;Nl;0;L;;;;2/3;N;;;;; When there is a value, it comes just before the last 'N'. The last regular character is 2FA1D;CJK COMPATIBILITY IDEOGRAPH-2FA1D;Lo;0;L;2A600;;;;N;;;;; -- Terry Jan Reedy From research at johnohagan.com Thu May 17 23:06:07 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 18 May 2012 13:06:07 +1000 Subject: argparse - option with optional value In-Reply-To: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> References: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> Message-ID: <20120518130607.d6c01fcee3295bd9b098eb16@johnohagan.com> On Thu, 17 May 2012 14:26:50 -0700 (PDT) Miki Tebeka wrote: > Greetings, > > I'd like to have an --edit option in my program. That if not specified will > not open editor. If specified without value will open default editor > ($EDITOR) and if specified with value, assume this value is the editor > program to run. This looks like a job for 'const': parser.add_argument('-e', '--edit', help='open editor on log', nargs='?', const="$EDITOR") I think that does what you want. HTH, John From vincent.vandevyvre at swing.be Fri May 18 00:00:25 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 18 May 2012 06:00:25 +0200 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: <4FB59D37.1020709@fossworkflowguides.com> References: <4FB59D37.1020709@fossworkflowguides.com> Message-ID: <4FB5C959.4020404@swing.be> On 18/05/12 02:52, Simon Cropper wrote: > Hi, > > There has been some discussion on this list regarding GUI toolkits and > it reinvigorated my search for one to meet my needs. > > I would like to create windows with grids (AKA rows and column of a > table like excel). Do any of the GUI interfaces have these types of > widgets? i have looked but can't find any and I have not stumbled on > program that presents data in this way so I can see how they do it. > > Specifically I would like to run a SQL command and have the returned > list passed to a widget with little or no manipulation and that widget > present the data, allow the user to scroll through that data and > preferably allow edits to occur. These edits could then be passed back > via a string to the program for inclusion in a sql-update command. > > Any ideas? > Have a look at PyQt [1], specially QTableView [2] and QtSql [3] [1] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/index.html [2] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtableview.html [3] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsql.html -- Vincent V.V. Oqapy . Qarte+7 . PaQager From jason at powerpull.net Fri May 18 00:36:17 2012 From: jason at powerpull.net (Jason Friedman) Date: Thu, 17 May 2012 22:36:17 -0600 Subject: Sharing Data in Python In-Reply-To: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> References: <9370220.1818.1336765291816.JavaMail.geo-discussion-forums@vbep19> Message-ID: > I have some Pickled data, which is stored on disk, and it is about 100 MB in size. > > When my python program is executed, the picked data is loaded using the cPickle module, and all that works fine. > > If I execute the python multiple times using python main.py for example, each python process will load the same data multiple times, which is the correct behaviour. > > How can I make it so, all new python process share this data, so it is only loaded a single time into memory? > > asked the same question on SO, but could not get any constructive responses.. http://stackoverflow.com/questions/10550870/sharing-data-in-python/10551845 If I was running this code on somewhat new hardware I'm not sure I would do anything. Your OS or disk subsystem, possibly both, are probably already caching this data. From rosuav at gmail.com Fri May 18 01:32:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 May 2012 15:32:37 +1000 Subject: SocketServer.BaseRequestHandler and __init__/super() In-Reply-To: <4FB59892.40900@tim.thechases.com> References: <4FB59892.40900@tim.thechases.com> Message-ID: On Fri, May 18, 2012 at 10:32 AM, Tim Chase wrote: > Any thoughts on this? (other than "SocketServer should > have inherited from object which is a 2.x best-practice") Well, Python 3 dodges the issue by making all classes inherit from object. That might be a solution :) ChrisA From simoncropper at fossworkflowguides.com Fri May 18 01:47:45 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Fri, 18 May 2012 15:47:45 +1000 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: <4FB5C959.4020404@swing.be> References: <4FB59D37.1020709@fossworkflowguides.com> <4FB5C959.4020404@swing.be> Message-ID: <4FB5E281.7000800@fossworkflowguides.com> On 18/05/12 14:00, Vincent Vande Vyvre wrote: > On 18/05/12 02:52, Simon Cropper wrote: >> Hi, >> >> There has been some discussion on this list regarding GUI toolkits and >> it reinvigorated my search for one to meet my needs. >> >> I would like to create windows with grids (AKA rows and column of a >> table like excel). Do any of the GUI interfaces have these types of >> widgets? i have looked but can't find any and I have not stumbled on >> program that presents data in this way so I can see how they do it. >> >> Specifically I would like to run a SQL command and have the returned >> list passed to a widget with little or no manipulation and that widget >> present the data, allow the user to scroll through that data and >> preferably allow edits to occur. These edits could then be passed back >> via a string to the program for inclusion in a sql-update command. >> >> Any ideas? >> > Have a look at PyQt [1], specially QTableView [2] and QtSql [3] > > [1] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/index.html > [2] > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtableview.html > [3] http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsql.html > Vincent, That looks very promising... do you understand the licensing though? GPL to GPL is obvious but would development of an in-house system be commercial or GPL licensing? -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From tymoteusz.jankowski at gmail.com Fri May 18 04:22:26 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 18 May 2012 01:22:26 -0700 (PDT) Subject: How to hide console with Popen on Windows? Message-ID: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> Like the topic, more details in followed links.. http://stackoverflow.com/questions/10637450/how-to-hide-console-with-popen-on-windows http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/?c=14452 Please help :( Any hint i would appreciate From rosuav at gmail.com Fri May 18 04:48:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 May 2012 18:48:59 +1000 Subject: How to hide console with Popen on Windows? In-Reply-To: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> Message-ID: On Fri, May 18, 2012 at 6:22 PM, xliiv wrote: > Like the topic, more details in followed links.. > > > http://stackoverflow.com/questions/10637450/how-to-hide-console-with-popen-on-windows As you've already been advised, the way to avoid a console is to use pythonw.exe (which is a windowed Python as opposed to a console Python). If you don't have it, you may need to install an actual Python instead of depending on what Open Office provides. ChrisA From wxjmfauth at gmail.com Fri May 18 05:24:52 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 18 May 2012 02:24:52 -0700 (PDT) Subject: str.isnumeric and Cuneiforms References: Message-ID: On 17 mai, 21:32, Marco wrote: > Is it normal the str.isnumeric() returns False for these Cuneiforms? > > '\U00012456' > '\U00012457' > '\U00012432' > '\U00012433' > > They are all in the Nl category. Indeed there are, but Unicode (ver. 5.0.0) does not assign numeric values to these code points. Do not ask me, why? jmf From motoom at xs4all.nl Fri May 18 05:49:58 2012 From: motoom at xs4all.nl (Michiel Overtoom) Date: Fri, 18 May 2012 11:49:58 +0200 Subject: Looking for video/slides from PyCon 2011... In-Reply-To: References: Message-ID: On May 16, 2012, at 08:24, Monte Milanuk wrote: >>> >>> http://us.pycon.org/2011/schedule/presentations/207/ > > Unless its buried in one of the lightning talk vids, I'm not seein' it. Me neither. But that page show that it was a workshop, not necessarily videotaped. That's a pity, it seems interesting to me. Greetings, -- Test your knowledge of flowers! http://www.learn-the-flowers.com or http://www.leer-de-bloemen.nl for the Dutch version. Test je kennis van bloemen! http://www.leer-de-bloemen.nl of http://www.learn-the-flowers.com voor de Engelse versie. From rmorgan466 at gmail.com Fri May 18 06:53:48 2012 From: rmorgan466 at gmail.com (Rita) Date: Fri, 18 May 2012 06:53:48 -0400 Subject: standard module xpath Message-ID: Hello, Does python ship with xpath query language support? Certainly, I can use lxml but I prefer something in the standard modules list. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Fri May 18 07:09:02 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 18 May 2012 07:09:02 -0400 Subject: How to hide console with Popen on Windows? In-Reply-To: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> Message-ID: On 5/18/12 4:22 AM, xliiv wrote: > Like the topic, more details in followed links.. > > > http://stackoverflow.com/questions/10637450/how-to-hide-console-with-popen-on-windows > > http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/?c=14452 > > Please help :( > Any hint i would appreciate There are some Windows-specific flags in the subprocess module that you can set to control the display of a console window. I use something like this: self.pscmd=os.path.join(execdir, 'pstools-1.1/txt2ps.exe') startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW txtps = self.pscmd + ' -o ' + tempfile.gettempdir() + '\\whois.ps' + ' ' + tmpfile subprocess.check_output(txtps, startupinfo = startupinfo) Hope this helps. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From dfnsonfsduifb at gmx.de Fri May 18 08:14:33 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 18 May 2012 14:14:33 +0200 Subject: Binding first parameter of method to constant value Message-ID: Hi group, I'm trying to dynamically add methods to a class at runtime. What I would like to do is have them all delegated to one common function which is called with the name of the function as first parameter. I.e.: class Foo(): def __init__(self): # Some magic missing here setattr(self, "foometh", types.MethodType(self._dispatcher, self)) setattr(self, "barmeth", types.MethodType(self._dispatcher, self)) def _dispatcher(self, caller, *args): # Dispatcher called with caller == "foometh" # or caller == "barmeth", depending on which one was called with the effect that f = Foo() f.foometh(1, 2, 3) # -> this should be equivaent to Foo._dispatcher(f, "foometh", 1, 2, 3) f.barmeth() # -> this should be equivaent to Foo._dispatcher(f, "barmeth") I'm kind of stuck. Can you please give me hints? Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From dpalao.python at gmail.com Fri May 18 09:04:12 2012 From: dpalao.python at gmail.com (DPalao) Date: Fri, 18 May 2012 15:04:12 +0200 Subject: Binding first parameter of method to constant value In-Reply-To: References: Message-ID: <3623473.E2ZJ9yZbU0@twisted> On Viernes mayo 18 2012 14:14:33 Johannes Bauer escribi?: > Hi group, > > I'm trying to dynamically add methods to a class at runtime. What I > would like to do is have them all delegated to one common function which > is called with the name of the function as first parameter. I.e.: > > class Foo(): > def __init__(self): > # Some magic missing here > setattr(self, "foometh", types.MethodType(self._dispatcher, self)) > setattr(self, "barmeth", types.MethodType(self._dispatcher, self)) > > def _dispatcher(self, caller, *args): > # Dispatcher called with caller == "foometh" > # or caller == "barmeth", depending on which one was called > > > with the effect that > > f = Foo() > f.foometh(1, 2, 3) > # -> this should be equivaent to Foo._dispatcher(f, "foometh", 1, 2, 3) > > f.barmeth() > # -> this should be equivaent to Foo._dispatcher(f, "barmeth") > > I'm kind of stuck. Can you please give me hints? > > Best regards, > Joe > > >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > > > > Zumindest nicht ?ffentlich! > > Ah, der neueste und bis heute genialste Streich unsere gro?en > Kosmologen: Die Geheim-Vorhersage. > - Karl Kaos ?ber R?diger Thomas in dsa Hi Johannes, If I understood well your question, for specific attributes I recommend you to have a look at properties and descriptors (I love them). For a general way to deal with attributes: the __getattr__ (to handle undefined attributes), __getattribute__ (to handle *every* attribute; be careful with loops), and __setattr__ (to catch *every* attribute assignmet, same warning concerning loops). Hope it helps. BR, DPalao From steve+comp.lang.python at pearwood.info Fri May 18 09:10:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 May 2012 13:10:23 GMT Subject: Binding first parameter of method to constant value References: Message-ID: <4fb64a3f$0$29984$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 May 2012 14:14:33 +0200, Johannes Bauer wrote: > Hi group, > > I'm trying to dynamically add methods to a class at runtime. What I > would like to do is have them all delegated to one common function which > is called with the name of the function as first parameter. I.e.: [...] Here's one way: import types class K(object): def _dispatcher(self, name, *args): print "called from", name, args def __init__(self): setattr(self, 'foometh', types.MethodType( lambda self, *args: self._dispatcher('foometh', *args), self, self.__class__) ) setattr(self, 'barmeth', types.MethodType( lambda self, *args: self._dispatcher('barmeth', *args), self, self.__class__) ) -- Steven From dfnsonfsduifb at gmx.de Fri May 18 09:28:46 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 18 May 2012 15:28:46 +0200 Subject: Binding first parameter of method to constant value In-Reply-To: <4fb64a3f$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <4fb64a3f$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18.05.2012 15:10, Steven D'Aprano wrote: > Here's one way: > > import types > class K(object): > def _dispatcher(self, name, *args): > print "called from", name, args > def __init__(self): > setattr(self, 'foometh', > types.MethodType( > lambda self, *args: self._dispatcher('foometh', *args), > self, self.__class__) > ) > setattr(self, 'barmeth', > types.MethodType( > lambda self, *args: self._dispatcher('barmeth', *args), > self, self.__class__) > ) Aaaah, amazingly beautiful! Thank you very much. Didn't know that lambda functions could have a variable number of arguments in Python (never tried that before). Learned something about Python again. No words to describe how much I love the language :-)) Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From miki.tebeka at gmail.com Fri May 18 09:55:32 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 18 May 2012 06:55:32 -0700 (PDT) Subject: argparse - option with optional value In-Reply-To: <878vgq8i5v.fsf@benfinney.id.au> References: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> <878vgq8i5v.fsf@benfinney.id.au> Message-ID: <8ec96f9d-d2b2-489e-9874-e84719ccf8dd@googlegroups.com> > There is a built-in ?no value specified? value in Python: the None > singleton. The ?argparse? library uses this for the argument default > already, so you don't need to fuss with your own special handling > . The problem with this approach is that in both cases of not specifying -e and with -e with no argument the value of args.edit is None. From name.surname at gmail.com Fri May 18 09:56:12 2012 From: name.surname at gmail.com (Marco Buttu) Date: Fri, 18 May 2012 15:56:12 +0200 Subject: str.isnumeric and Cuneiforms References: <4fb59cc1$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/18/2012 02:50 AM, Steven D'Aprano wrote: >> Is it normal the str.isnumeric() returns False for these Cuneiforms? >> > >> > '\U00012456' >> > '\U00012457' >> > '\U00012432' >> > '\U00012433' >> > >> > They are all in the Nl category. > Are you sure about that? Do you have a reference? I I was just playing with Unicode on Python 3.3a: >>> from unicodedata import category, name >>> from sys import maxunicode >>> nl = [chr(c) for c in range(maxunicode + 1) \ ... if category(chr(c)).startswith('Nl')] >>> numerics = [chr(c) for c in range(maxunicode + 1) \ ... if chr(c).isnumeric()] >>> for c in set(nl) - set(numerics): ... print(hex(ord(c)), category(c), unicodedata.name(c)) ... 0x12432 Nl CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS DISH 0x12433 Nl CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS MIN 0x12456 Nl CUNEIFORM NUMERIC SIGN NIGIDAMIN 0x12457 Nl CUNEIFORM NUMERIC SIGN NIGIDAESH So they are in the Nl category but are not "numerics", and that sounds strange because other Cuneiforms are "numerics": >>> '\U00012455'.isnumeric(), '\U00012456'.isnumeric() (True, False) > It seems to me that they are not: > > > py> c = '\U00012456' > py> import unicodedata > py> unicodedata.numeric(c) > Traceback (most recent call last): > File "", line 1, in > ValueError: not a numeric character Exactly, as I wrote above, is that right? -- Marco From name.surname at gmail.com Fri May 18 10:06:12 2012 From: name.surname at gmail.com (Marco Buttu) Date: Fri, 18 May 2012 16:06:12 +0200 Subject: str.isnumeric and Cuneiforms References: Message-ID: On 05/18/2012 11:24 AM, jmfauth wrote: >> Is it normal the str.isnumeric() returns False for these Cuneiforms? >> > >> > '\U00012456' >> > '\U00012457' >> > '\U00012432' >> > '\U00012433' >> > >> > They are all in the Nl category. > Indeed there are, but Unicode (ver. 5.0.0) does not assign numeric > values to these code points. help(unicodedata) says Python 3.3a refers to Unicode 6.0.0 -- Marco From name.surname at gmail.com Fri May 18 11:08:08 2012 From: name.surname at gmail.com (Marco Buttu) Date: Fri, 18 May 2012 17:08:08 +0200 Subject: str.isnumeric and Cuneiforms References: Message-ID: On 05/17/2012 09:32 PM, Marco wrote: > Is it normal the str.isnumeric() returns False for these Cuneiforms? > > '\U00012456' > '\U00012457' > '\U00012432' > '\U00012433' > > They are all in the Nl category. > > Marco It's ok, I found that they don't have a number assigned in the ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt database. -- Marco From wxjmfauth at gmail.com Fri May 18 11:34:50 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 18 May 2012 08:34:50 -0700 (PDT) Subject: str.isnumeric and Cuneiforms References: Message-ID: <2223c11e-6c82-405e-8418-437d583e5fe6@v10g2000vbe.googlegroups.com> On 18 mai, 17:08, Marco Buttu wrote: > On 05/17/2012 09:32 PM, Marco wrote: > > > Is it normal the str.isnumeric() returns False for these Cuneiforms? > > > '\U00012456' > > '\U00012457' > > '\U00012432' > > '\U00012433' > > > They are all in the Nl category. > > > Marco > > It's ok, I found that they don't have a number assigned in theftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txtdatabase. > -- > Marco Good. I was about to send this information. I have all this (not updated) stuff locally on my hd. From wxjmfauth at gmail.com Fri May 18 11:42:28 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 18 May 2012 08:42:28 -0700 (PDT) Subject: str.isnumeric and Cuneiforms References: Message-ID: <19e5d559-ca6a-4832-84c1-3019ae798e06@w10g2000vbc.googlegroups.com> On 18 mai, 17:08, Marco Buttu wrote: > On 05/17/2012 09:32 PM, Marco wrote: > > > Is it normal the str.isnumeric() returns False for these Cuneiforms? > > > '\U00012456' > > '\U00012457' > > '\U00012432' > > '\U00012433' > > > They are all in the Nl category. > > > Marco > > It's ok, I found that they don't have a number assigned in theftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txtdatabase. > -- > Marco Non official but really practical: http://www.fileformat.info/info/unicode/index.htm From charleshixsn at earthlink.net Fri May 18 12:53:32 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Fri, 18 May 2012 09:53:32 -0700 Subject: Questions on __slots__ Message-ID: <4FB67E8C.802@earthlink.net> Does __slots__ make access to variables more efficient? If one uses property() to create a few read-only pseudo-variables, does that negate the efficiency advantages of using __slots__? (Somehow I feel the documentation needs a bit of improvement.) -- Charles Hixson From name.surname at gmail.com Fri May 18 13:06:31 2012 From: name.surname at gmail.com (Marco Buttu) Date: Fri, 18 May 2012 19:06:31 +0200 Subject: str.isnumeric and Cuneiforms References: <19e5d559-ca6a-4832-84c1-3019ae798e06@w10g2000vbc.googlegroups.com> Message-ID: On 05/18/2012 05:42 PM, jmfauth wrote: > Non official but really practical: > > http://www.fileformat.info/info/unicode/index.htm Very well ordered, thanks -- Marco From memilanuk at gmail.com Fri May 18 16:09:43 2012 From: memilanuk at gmail.com (memilanuk) Date: Fri, 18 May 2012 13:09:43 -0700 (PDT) Subject: Are there any instrumentation widgets for wxpython or tkinter? In-Reply-To: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> References: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> Message-ID: PyQt4 has built-in widgets for things like digital counters & dials... kind of surprising there aren't more instrument related widgets out there... From gwhite at ti.com Fri May 18 17:26:49 2012 From: gwhite at ti.com (gwhite) Date: Fri, 18 May 2012 14:26:49 -0700 (PDT) Subject: Newbie questions on import & cmd line run References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> <4fb47f8a$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On May 16, 9:33?pm, Steven D'Aprano wrote: > On Wed, 16 May 2012 18:45:39 -0700, gwhite wrote: > > #! > > # Filename: newbie00.py > > "Supposed to"? Nothing -- it is completely optional. > > #! ("hash-bang") lines currently do nothing on Windows machines, they are > just comments. However, on Unix and Linux machines (and Macintosh?) they > are interpreted by the shell (equivalent to cmd.exe or command.com), in > order to tell the shell what interpreter to use to execute the program if > you run it directly. It is common to use something like: > > #!/usr/bin/env python > > but I stress that this is completely optional, and doesn't do anything on > Windows. > > > if __name__ == '__main__': > > ? ? print 'This program was called from the \ > > system command line.' > > ? ? print __name__ + '.py' > > else: > > ? ? print 'This program was imported on the \ > > Python command line.' > > ? ? print __name__ + '.py' > > > ----------------- > > > If I run from the system (win cmd) command, I get: > > > C:\engineer\engruser\python>python ?newbie00.py > > > This program was called from the system command line. __main__.py > > The magic variable "__name__" is special in Python. When you run a Python > module as a script from the command line, it gets set to "__main__". Note > that there is no such file "__main__.py" (unless you have happened to > create one yourself). > > When you import a module, rather than run it, __name__ gets set to the > actual filename of the module, minus the file extension. > > > ----------------- > > If I hit the run button in Sypder, I get (in the iPython command > > console): > > > In [70]: runfile(r'C:\engineer\engruser\python\newbie00.py', wdir=r'C: > > \engineer\engruser\python') > > This program was called from the system command line. __main__.py > > I'm not sure what Spyder is. Is it part of iPython? You may need to > consult the iPython or Spyder docs to find out exactly what tricks it > plays in its interactive console. Sypder is the IDE for pythonxy. Since some other newbies here at my office decided to go down the pythonxy route, I wanted to be on the same page with them. All of us were MATLAB users. We're engineers, not programmers. > > ----------------- > > If I import on the iPython command, I get: > > > In [71]: import newbie00 > > This program was imported on the Python command line. newbie00.py > > In this case, __name__ is set to the module name (the file name less the > file extension). Your script adds the .py at the end. > > > ----------------- > > If I import *again* on the iPython command, I get: > > > In [72]: import newbie00 > > > In [73]: > > > > > That is correct. Python modules are only executed *once*, the first time > they are imported. From then on, additional imports refer back to a > cached module object. > > When you say "import newbie00", the (highly simplified!) process is this: > > * Python looks in sys.modules for the name "newbie00". If it finds > ? something in the cache (usually a module object), it fetches that thing > ? and assigns it to the variable "newbie00", and the import process is > ? complete. > > * But if it doesn't find anything in the cache, Python searches the > ? locations listed in sys.path for a module, package, or library. That > ? could mean any of: > > ? - newbie00.py ? (source code) > ? - newbie00.pyc ?(compiled byte-code) > ? - newbie00.pyo ?(compiled optimized byte-code) > ? - newbie00.pyw ?(Windows only) > ? - newbie00.dll ?(Windows only C library) > ? - newbie00.so ? (Linux and Unix C library) > > ? as well as others (e.g. packages). > > * If no module is found, Python raises an error, otherwise the first > ? found module is used. > > * If a compiled module (e.g. newbie00.pyc) is found, and is no older than > ? the source code (newbie00.py), then Python uses the pre-compiled file. > > ? (If the compiled module is older than the source module, it is ignored.) > > * Otherwise Python parses the newbie00.py source code, compiles it to > ? byte-code, and writes it to the file newbie00.pyc so that the next time > ? the import will be faster. > > * At this point, Python now has a compiled chunk of Python byte-code. > ? It then sets the special global variable __name__ to the file name (less > ? extension), and executes that code. > > * If no fatal error occurs, Python now bundles the results of the > ? executed code (any functions, classes, variables, etc.) into a module > ? object, stores the module object in the cache sys.modules for next time, > ? and finally assigns it to the name "newbie00". > > There is a *lot* that goes on the first time you import a module, which > is why Python tries really hard to avoid running modules unless you > explicitly ask it to. So "import newbie00" only *executes* the code once > per Python session. Subsequent imports use the cached version. okay. > The process is quite different when you run a Python module as a script. > In this case, the .pyc file (if any) is ignored, the script is parsed and > compiled from scratch every single time, the magic variable __name__ is > set to "__main__", and the script is executed every single time. > > [...] > > > Some questions: > > > 1. ?If running from the system command line, or the Sypder "run" button, > > "__name__" is "__main__" rather than "newbie00", as seen above. > > > So, how would I get the file name newbie00.py in these two noted cases? > > The special variable "__file__" is set to the filename: > > >>> import string > >>> string.__file__ > > '/usr/lib/python2.6/string.pyc' > > Note that __file__ will usually be set to the full path of the file. To > extract just the file name: > > >>> import os > >>> os.path.basename(string.__file__) > > 'string.pyc' > > To ignore the file extension, use this: > > >>> os.path.splitext(os.path.basename(string.__file__)) > > ('string', '.pyc') > > [...] Thanks. > > 2. ?In python, there seems to be a distinction between running something > > as if it is a system command of "C:\...>python myPyFile.py" compared to > > simply entering that same ".py" file name directly on the python console > > command line. ?In fact, the latter does not work unless the somewhat > > lengthy ">>> runfile(r'C:\... wdir=r'C:\...) stuff is entered (in > > iPython). ?(I mean, my old MATLAB habit of simply entering ">> > > mfilename" on the command line seems to be quite wrong in python.) > > That is correct. The Python interactive interpreter is not intended to be > a full-blown shell. iPython is, so I wouldn't be surprised if there is a > shorter version of the runfile(full pathname) stuff, but I don't know > what it is. Thanks for the note that iPython is a "full-blown shell." > > Is there a shortened syntax of running a .py from the python command > > prompt, if not using a Spyder "run" button? ?Or should I always run as > > if from the system prompt? ?That is, dispense with the MATLAB-like "run > > from MATLAB/python command line" bias I may be holding. > > Normally I would say "always run it from the system prompt", but that may > be because I don't know iPython and/or Spyder. Sure. I actually think it is better upon some reflection. I need to un-MATLAB myself. > Another alternative is to write a "main function" in your script: > > # Filename newbie01.py > def main(): > ? ? print("Doing stuff here...") > > if __name__ == '__main__': > ? ? main() > else: > ? ? print("importing here") > > Then you can do this: > > >>> import newbie01 > importing here > >>> newbie01.main() > > Doing stuff here...>>> newbie01.main() > > Doing stuff here... > > That would be my preference. Your mileage may vary. Neat. I'll try that for case's I think it makes sense for. I'll play with it some. > > 3. ?In injecting my old MATLAB bias of running via the command line ">> > > mfilename", I tried a tweak of ?">>>import newbie00". ?That "sort of" > > worked, but only the first time. > > > Why did the subsequent run of ">>>import newbie00" print nothing? ?I'm > > just trying to understand how python works. > > Because modules are executed only the first time they are imported. See > above. > > > 4. ?The final case shown of hitting the Spyder run button included this: > > > UMD has deleted: newbie00 > > > What does that mean? ?I noted that after this "automatic" deletion, I > > could do the ">>>import newbie00" once again and get the print. ?(I did > > not show that above.) > > That looks like a trick specific to Spyder and/or iPython. It happens when I have previously done the import on the iPython cmd line. After that is cleared out, iPython does not give that message again. It must be doing this to make sure the version in the Spyder editor window is the one being executed, or something like that. Incidentally, it makes no difference if I delete the .pyc file made by the import newbie00 command before running via Spyder/iPython. Maybe that means the import version in compiled and in memory (or maybe what you called "cached module object"). I just don't know. But I think it makes some kind of sense to clear things out. > > 5. ?I think #4 implies an import can be removed. ?(Yes/No?) ?I am not > > sure why that would be desired, but I will ask how to remove an import, > > or to "refresh" the run, of that is the appropriate question. > > Hmmm. Well, yes, technically they can, but my recommendation is that you > don't, because doing so can lead to some ... interesting ... hard-to- > debug problems. > > But now that you have chosen to ignore me *wink*, you can delete the > module so as to allow it to be refreshed like this: > > del newbie00 ?# delete the version you are using > import sys ?# only needed once > del sys.modules['newbie00'] ?# delete it from the cache > > Now, as far as Python is concerned, newbie00 has never been imported. > Probably. > > Another way is with the built-in reload() function: > > import newbie00 > ? # ... make some edits to the newbie00 source file > reload(newbie00) > ? # ... now the changes will show up > > but be warned that there are some traps to using reload(), so much so > that in Python 3 it has been relegated to the "imp" (short for "import") > module, where it is less tempting to newbies. > > > I think I saw someplace where a .pyc file is created on an initial run > > and subsequently run instead of the .py. ?I'm not sure if that applies > > here, but if related, I guess an auxiliary question is how to easily > > force the .py to run rather than the .pyc? > > No, see above: .pyc files are only created when you *import* a module, > and they are never used when you *run* a module. > > > 6. ?Perhaps peripherally related to getting a running script/function/ > > module name, is getting a "call listing" of all the functions (and > > modules) called by a .py program. ?How would I get that? ?I only ask as > > it comes in handy if one distributes a program. ?I mean, you only give > > people what they actually need. > > I'm not quite sure I understand what you mean. Can you explain in more > detail? Oh, on reflection, I think I am MATLAB biasing again. The rudimentary method is that there there is an "m-file per function." Those are then called as inline commands. They are not "imported." Basically, it might be a pain to know for sure every one of the functions you called. In MATLAB, if I want to send someone a "program," I also need to know all the functions it calls outside the "standard package." It isn't obvious given that they don't need to be "imported." But I think the import method with python may make things much more obvious. So I can relax a bit. I was meaning like this: http://www.mathworks.com/help/techdoc/ref/depfun.html > Welcome on board with Python, I hope you have fun! Thanks, Steven! Thank you for spending your valuable time explaining things to me. From ronDOTeggler at tscheemail.com Fri May 18 17:53:21 2012 From: ronDOTeggler at tscheemail.com (Ron Eggler) Date: Fri, 18 May 2012 14:53:21 -0700 Subject: serial module Message-ID: Hoi, I'm trying to connect to a serial port and always get the error "serial.serialutil.SerialException: Port is already open." whcih is untrue. I have no serial port open yet, my code looks like this: #!/usr/bin/python import time import serial # configure the serial connections (the parameters differs on the device # you are connecting to) ser = serial.Serial( port='/dev/ttyUSB0', baudrate=19200, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) ser.open() Why do I get this error? Thank you, Ron --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From gwhite at ti.com Fri May 18 17:55:55 2012 From: gwhite at ti.com (gwhite) Date: Fri, 18 May 2012 14:55:55 -0700 (PDT) Subject: Newbie questions on import & cmd line run References: <6130ac73-1bf2-4257-a918-81894116fad8@d6g2000vbe.googlegroups.com> <7bb04805-4849-4d63-860a-0daf66ac7a42@ri8g2000pbc.googlegroups.com> Message-ID: On May 16, 9:54?pm, alex23 wrote: > On May 17, 11:45?am, gwhite wrote: > > > 1. ?If running from the system command line, or the Sypder "run" > > button, "__name__" is "__main__" rather than "newbie00", as seen > > above. > > > So, how would I get the file name newbie00.py in these two noted > > cases? > > You can get it from the file name: > > ? ? import os.path > ? ? name = os.path.split(__file__)[-1] > > However, you might find it better in the long term to always separate > your code into import-only modules and execute-only scripts. It avoids > this issue and others. Thanks, and yes, I am starting to see your point. > > 2. ?Is there a shortened syntax of running a .py from the python command > > prompt, if not using a Spyder "run" button? ?Or should I always run as > > if from the system prompt? ?That is, dispense with the MATLAB-like > > "run from MATLAB/python command line" bias I may be holding. > > Generally, the correct way of running Python code from the interpreter > is 'import '. You might find this pattern useful: > > In your module: > > ? ? def main(): # code goes here > > ? ? if __name__ == '__main__': main() > > Then from the interpreter: > > ? ? import mymodule; mymodule.main() I am going to play with the idea. > > 3. ?In injecting my old MATLAB bias of running via the command line > > ">> mfilename", I tried a tweak of ?">>>import newbie00". ?That "sort > > of" worked, but only the first time. > > > Why did the subsequent run of ">>>import newbie00" print nothing? ?I'm > > just trying to understand how python works. > > The import mechanism only imports a module once, as all files use the > same module instance (they're effectively singletons). This happens > with repeated imports in one module as well as across various modules > during a single execution. So re-importing a module does nothing; to > force a re-import, you can use the reload() function, although that > doesn't guarantee updating all references. For example: > > ? ? import mymodule > ? ? from mymodule import myfunc > > ? ? # modify myfunc code externally > > ? ? reload(mymodule) > ? ? myfunc() # original reference > ? ? mymodule.myfunc() ?# newly modified function > > I don't think that only-one-import is true for scripts that are run > from the command line, though. They can exist as both '__main__' and > their actual name in the module table. (Someone please correct me if > this understanding is wrong...) > > > 4. ?The final case shown of hitting the Spyder run button included > > this: > > > UMD has deleted: newbie00 > > > What does that mean? ?I noted that after this "automatic" deletion, I > > could do the ">>>import newbie00" once again and get the print. ?(I > > did not show that above.) > > Spyder provides a convenience feature to force the reimport of user- > defined modules, like your newbie00. After execution, it appears to > drop all references to your module, forcing a garbage collection. As > its no longer loaded, a subsequent import works. > > > 5. ?I think #4 implies an import can be removed. ?(Yes/No?) ?I am not > > sure why that would be desired, but I will ask how to remove an > > import, or to "refresh" the run, of that is the appropriate question. > > reload() > > However, the only way to guarantee you've updated all references > correctly is to close the interpreter and re-start it. For this kind > of development process of modifying code and seeing the changes, it's > probably better to look into writing tests instead. These will always > be run in isolation, so you're guaranteed of having the correct > environment each time. I think I mostly need to revise my tact. Some of these questions came from my MATLAB-centric way of thinking, and I am unlearning that. > > I think I saw someplace where a .pyc file is created on an initial run > > and subsequently run instead of the .py. ?I'm not sure if that applies > > here, but if related, I guess an auxiliary question is how to easily > > force the .py to run rather than the .pyc? > > A .pyc file won't be created for .py files that are run directly, only > for those that are imported. You really shouldn't need to worry about > this, though. It's an implementation detail that isn't influencing the > issues you're seeing. However, if you do ever need to do it, you can > stop .pyc files by passing the -B flag to the interpreter, or by > setting the environment variable PYTHONDONTWRITEBYTECODE. > > > 6. ?Perhaps peripherally related to getting a running script/function/ > > module name, is getting a "call listing" of all the functions (and > > modules) called by a .py program. ?How would I get that? ?I only ask > > as it comes in handy if one distributes a program. ?I mean, you only > > give people what they actually need. > > Perhaps this might be of use:http://pycallgraph.slowchop.com/ I was thinking along the lines of this, should you remotely care: http://www.mathworks.com/help/techdoc/ref/depfun.html But the more I think of it, the difference between scripts/programs, and modules/functions in python make this much less of an issue than I had thought. In MATLAB, there is no important distinction between them, so I was probably misguided with the concern/question. As I examine it, the nature of python sort makes this one take care of itself to a large degree. I mean to say, "imports" in python are obvious. There is no "import" corollary in MATLAB. Let the unlearning begin. > Hope this helps. It does. Thanks for your help, Alex. It is much appreciated. From clp2 at rebertia.com Fri May 18 18:15:08 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 18 May 2012 15:15:08 -0700 Subject: serial module In-Reply-To: References: Message-ID: On Fri, May 18, 2012 at 2:53 PM, Ron Eggler wrote: > Hoi, > > I'm trying to connect to a serial port and always get the error > "serial.serialutil.SerialException: Port is already open." whcih is untrue. > I have no serial port open yet, my code looks like this: > #!/usr/bin/python > import time > import serial > > # configure the serial connections (the parameters differs on the device > # you are connecting to) > ser = serial.Serial( > ? ? ? ?port='/dev/ttyUSB0', > ? ? ? ?baudrate=19200, > ? ? ? ?parity=serial.PARITY_ODD, > ? ? ? ?stopbits=serial.STOPBITS_TWO, > ? ? ? ?bytesize=serial.SEVENBITS > ) > > ser.open() > > Why do I get this error? Read the fine documentation. http://pyserial.sourceforge.net/pyserial_api.html#serial.Serial.__init__ (emphasis added): "The port is **immediately opened** on object creation, when a port is given. It is not opened when port is None and a successive call to open() will be needed." So the port is indeed already open since you specified port='/dev/ttyUSB0'; thus, your .open() call is redundant. Cheers, Chris From psimon at sonic.net Fri May 18 21:37:33 2012 From: psimon at sonic.net (Paul Simon) Date: Fri, 18 May 2012 18:37:33 -0700 Subject: serial module References: Message-ID: <4fb6f977$0$87637$742ec2ed@news.sonic.net> Sounds like you may be using this on a Windows machine. the code is functional, it is best practice to close the port first before openiing it. If due to an error, usually not syntax, the port will stay stuck open until the program is closed and reopened. I have used the Python serial port (serial.py?) with good results. Paul Simon "Ron Eggler" wrote in message news:jp6gcj$1rij$1 at adenine.netfront.net... > Hoi, > > I'm trying to connect to a serial port and always get the error > "serial.serialutil.SerialException: Port is already open." whcih is > untrue. > I have no serial port open yet, my code looks like this: > #!/usr/bin/python > import time > import serial > > # configure the serial connections (the parameters differs on the device > # you are connecting to) > ser = serial.Serial( > port='/dev/ttyUSB0', > baudrate=19200, > parity=serial.PARITY_ODD, > stopbits=serial.STOPBITS_TWO, > bytesize=serial.SEVENBITS > ) > > ser.open() > > Why do I get this error? > > Thank you, > Ron > > --- Posted via news://freenews.netfront.net/ - Complaints to > news at netfront.net --- From ben+python at benfinney.id.au Fri May 18 21:59:14 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 May 2012 11:59:14 +1000 Subject: argparse - option with optional value References: <05f459dd-5fdc-47c9-824c-84b7933a3cf2@googlegroups.com> <878vgq8i5v.fsf@benfinney.id.au> Message-ID: <87zk956idp.fsf@benfinney.id.au> Ben Finney writes: > Miki Tebeka writes: > > The way I'm doing it currently is: > > ... > > no_edit = 'no-edit' > > parser.add_argument('-e', '--edit', help='open editor on log', nargs='?', > > default=no_edit) > > There is a built-in ?no value specified? value in Python: the None > singleton. The ?argparse? library uses this for the argument default > already, so you don't need to fuss with your own special handling > . Miki Tebeka writes: > The problem with this approach is that in both cases of not specifying > -e and with -e with no argument the value of args.edit is None. Okay. Then instead of a string, which has a chance of being used as the actual value, I recommend you instead, make a guaranteed-unique sentinel value:: NO_EDITOR = object() parser.add_argument( '-e', '--edit', help='open editor on log', nargs='?', default=NO_EDITOR) # ? if args.edit is not NO_EDITOR: # start the editor -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From steve+comp.lang.python at pearwood.info Fri May 18 21:59:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 May 2012 01:59:59 GMT Subject: Plot a function with matplotlib? Message-ID: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> I have matplotlib and iPython, and want to plot a function over an equally-spaced range of points. That is to say, I want to say something like this: plot(func, start, end) rather than generating the X and Y values by hand, and plotting a scatter graph. All the examples I've seen look something like this: from pylab import * import numpy as np t = arange(0.0, 2.0+0.01, 0.01) # generate x-values s = sin(t*pi) # and y-values plot(t, s) show() which is fine for what it is, but I'm looking for an interface closer to what my HP graphing calculator would use, i.e. something like this: plot(lambda x: sin(x*pi), # function or expression to plot, start=0.0, end=2.0, ) and have step size taken either from some default, or better still, automatically calculated so one point is calculated per pixel. Is there a way to do this in iPython or matplotlib? -- Steven From simoncropper at fossworkflowguides.com Fri May 18 22:05:44 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Sat, 19 May 2012 12:05:44 +1000 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: References: <4FB59D37.1020709@fossworkflowguides.com> Message-ID: <4FB6FFF8.6070307@fossworkflowguides.com> On 19/05/12 01:09, Dennis Lee Bieber wrote: > On Fri, 18 May 2012 10:52:07 +1000, Simon Cropper > declaimed the following in > gmane.comp.python.general: > >> Hi, >> >> There has been some discussion on this list regarding GUI toolkits and >> it reinvigorated my search for one to meet my needs. >> >> I would like to create windows with grids (AKA rows and column of a >> table like excel). Do any of the GUI interfaces have these types of >> widgets? i have looked but can't find any and I have not stumbled on >> program that presents data in this way so I can see how they do it. >> > Page 426 of "wxPython in Action" starts a chapter on using a grid > view (and a "gridtable" which uses a linked data structure for > populating the grid).. > >> Specifically I would like to run a SQL command and have the returned >> list passed to a widget with little or no manipulation and that widget >> present the data, allow the user to scroll through that data and >> preferably allow edits to occur. These edits could then be passed back >> via a string to the program for inclusion in a sql-update command. >> > Don't know if it has a direct link to SQL data sources; however, the > "gridtable" is probably closest. Dennis, Thanks for you feedback. Sometimes it just knowing the name of what you are looking for you to be able to find the data. Googling gridtable allowed me to find my way to the wxGrid Manual which seems to be what I was asking for... http://wiki.wxpython.org/wxGrid%20Manual wxPyGridTableBase, a particular class associated with wxGrid appears to be what I need. The blurb states "The wxPyGridTableBase class is the interface between the wxGrid and your application-specific data sources" http://wiki.wxpython.org/wxPyGridTableBase -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From vito.detullio at gmail.com Sat May 19 01:11:49 2012 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 19 May 2012 07:11:49 +0200 Subject: GUI toolkits and dynamic table browser widget References: <4FB59D37.1020709@fossworkflowguides.com> <4FB5C959.4020404@swing.be> <4FB5E281.7000800@fossworkflowguides.com> Message-ID: Simon Cropper wrote: >>> I would like to create windows with grids (AKA rows and column of a >>> table like excel). Do any of the GUI interfaces have these types of >>> widgets? i have looked but can't find any and I have not stumbled on >>> program that presents data in this way so I can see how they do it. >>> >>> Specifically I would like to run a SQL command and have the returned >>> list passed to a widget with little or no manipulation and that widget >>> present the data, allow the user to scroll through that data and >>> preferably allow edits to occur. These edits could then be passed back >>> via a string to the program for inclusion in a sql-update command. >> Have a look at PyQt [1], specially QTableView [2] and QtSql [3] > That looks very promising... do you understand the licensing though? > > GPL to GPL is obvious but would development of an in-house system be > commercial or GPL licensing? If you're so scared of GPL, you should look at pyside: http://www.pyside.org/docs/pyside/PySide/QtGui/QTableView.html -- ZeD From research at johnohagan.com Sat May 19 01:23:37 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 19 May 2012 15:23:37 +1000 Subject: How to generate only rotationally-unique permutations? Message-ID: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> To revisit a question which I'm sure none of you remember from when I posted it a year or so ago - there were no takers at the time - I'd like to try again with a more concise statement of the problem: How to generate only the distinct permutations of a sequence which are not rotationally equivalent to any others? More precisely, to generate only the most "left-packed" of each group of rotationally equivalent permutations, such that for each permutation p: p == min(p[i:] + p[:i] for i in range(len(p)) if p[i - 1] == max(p)) At the moment I'm generating all the distinct permutations and filtering the ones which fail this test, but the inefficiency bothers me and slows down the program I'm feeding the results to.. Below is some code which removes the maxima from a sequence, permutes it using some permuting function, and tries to reinsert the maxima in such a way as to comply with the above requirement: from itertools import combinations_with_replacement as cwr def rot_uniq_perms(seq, permfunc): ma = max(seq) maxnum = seq.count(ma) - 1 nonmax = [i for i in seq if i != ma] if nonmax: for perm in permfunc(nonmax): perm = perm + [ma] if maxnum: inserts = [i for i in range(1, len(perm)) if perm[i] >= perm[0]] insert_combs = cwr(inserts, maxnum) for points in insert_combs: result = perm[:] for point in reversed(points): result.insert(point, ma) if result[:point + 1] > result[point + 1:]: break else: yield result else: yield perm else: yield seq This is the most success I've had so far, but unfortunately still generates 2-3% false positives. I'm also trying a similar approach using the minima instead, which is intended to generates only the minimum of each rotationally equivalent group such that: p == min(p[i:] + p[:i] for i in range(len(p))) but so far, despite seeming simpler, I've had difficulty getting my head around it, and it performs far worse than the above code. I'm looking for any method which would guarantee rotational uniqueness. I also get the feeling I'm barking up the wrong tree. Any suggestion? Thanks, -- John From arnodel at gmail.com Sat May 19 04:15:39 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 19 May 2012 09:15:39 +0100 Subject: How to generate only rotationally-unique permutations? In-Reply-To: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> References: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> Message-ID: On 19 May 2012 06:23, John O'Hagan wrote: > To revisit a question which I'm sure none of you remember from when I posted it > a year or so ago - there were no takers at the time - I'd like to try again with > a more concise statement of the problem: > > How to generate only the distinct permutations of a sequence which are not > rotationally equivalent to any others? More precisely, to generate only the most > "left-packed" of each group of rotationally equivalent permutations, such that > for each permutation p: This makes me think of Lyndon words. A Lyndon word is a word which is the only lexicographical minimum of all its rotations. There is a very effective way of generating Lyndon words of length <= n. It may be possible to adapt it to what you want (obviously as Lyndon words are aperiodic you'd have to generate Lyndon word of length d | n when suitable). -- Arnaud From schesis at gmail.com Sat May 19 04:21:35 2012 From: schesis at gmail.com (Zero Piraeus) Date: Sat, 19 May 2012 04:21:35 -0400 Subject: How to generate only rotationally-unique permutations? In-Reply-To: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> References: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> Message-ID: : On 19 May 2012 01:23, John O'Hagan wrote: > How to generate only the distinct permutations of a sequence which are not > rotationally equivalent to any others? More precisely, to generate only the most > "left-packed" of each group of rotationally equivalent permutations, such that > for each permutation p: It's late and I'm tired (and the solution below isn't a generator), but ... itertools.permutations() generates results in lexicographic order [1], so if you reverse-sort the sequence before processing it, when you get a sequence back whose first item isn't the maximum, you'll know that you've got all the sequences whose first item *is* the maximum - which means you can bail at that point. Wow, that's a nasty sentence. As I said, tired. Anyway - you'll get dupes if there are non-unique items in the rest of the sequence, so some form of filtering is required, but you could use a set to handle that. Something like: from itertools import permutations def rot_uniq_perms(seq): result = set() seq = sorted(seq, reverse=True) maximum = seq[0] for x in permutations(seq): if x[0] != maximum: break else: result.add(x[::-1]) return result No idea how this performs compared to your existing solution, but it might be a starting point. [1] http://docs.python.org/library/itertools.html#itertools.permutations -[]z. From dfnsonfsduifb at gmx.de Sat May 19 05:30:46 2012 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 19 May 2012 11:30:46 +0200 Subject: ctype C library call always returns 0 with Python3 Message-ID: Hi group, I'm playing with ctypes and using it to do regressions on some C code that I compile as a shared library. Python is the testing framework. This works nicely as long as I do not need the return value (i.e. calling works as expected and parameters are passed correctly). The return value of all functions is always zero in my case, however. Even the example in the standard library fails: import ctypes libc = ctypes.cdll.LoadLibrary("/lib64/libc-2.14.1.so") print(libc.strchr("abcdef", ord("d"))) Always returns "0". I'm working on a x86-64 Gentoo Linux and can reproduce this behavior with Python 3.1.4 and Python 3.2.3. On Python 2.7.3 and Python 2.6.6 the example works fine on my system. Since I'd like to use Python3, I'm curious to know what changed in the behavior and how I can get this to run. Any help is greatly appreciated. Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From colin.mcphail at talktalk.net Sat May 19 07:07:28 2012 From: colin.mcphail at talktalk.net (Colin McPhail) Date: Sat, 19 May 2012 12:07:28 +0100 Subject: ctype C library call always returns 0 with Python3 In-Reply-To: References: Message-ID: On 19/05/2012 10:30, Johannes Bauer wrote: > Even the example in the standard library fails: > > import ctypes > libc = ctypes.cdll.LoadLibrary("/lib64/libc-2.14.1.so") > print(libc.strchr("abcdef", ord("d"))) > > Always returns "0". I think there may be two problems with this code: (1) You are using a 64-bit system but, in the absence of a function prototype for strchr, ctypes will be passing and returning 32-bit types. To add prototype information put something like: libc.strchr.restype = ctypes.c_char_p libc.strchr.argtypes = [ctypes.c_char_p, c_int] before the call of strchr(). (2) In Python3 strings are not plain sequences of bytes by default. In your example try passing b"abcdef" instead of "abcdef". -- CMcP From nobody at nowhere.com Sat May 19 07:20:24 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 19 May 2012 12:20:24 +0100 Subject: ctype C library call always returns 0 with Python3 References: Message-ID: On Sat, 19 May 2012 11:30:46 +0200, Johannes Bauer wrote: > import ctypes > libc = ctypes.cdll.LoadLibrary("/lib64/libc-2.14.1.so") > print(libc.strchr("abcdef", ord("d"))) In 3.x, a string will be passed as a wchar_t*, not a char*. IOW, the memory pointed to by the first argument to strchr() will consist mostly of NUL bytes. Either use a "bytes" instead of a string: > print(libc.strchr(b"abcdef", ord("d"))) 1984444291 or specify the argument types to force a conversion: > libc.strchr.argtypes = [c_char_p, c_int] > print(libc.strchr("abcdef", ord("d"))) 1984755787 From vlastimil.brom at gmail.com Sat May 19 07:45:06 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 19 May 2012 13:45:06 +0200 Subject: Plot a function with matplotlib? In-Reply-To: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2012/5/19 Steven D'Aprano : > I have matplotlib and iPython, and want to plot a function over an > equally-spaced range of points. > > That is to say, I want to say something like this: > > plot(func, start, end) > > rather than generating the X and Y values by hand, and plotting a scatter > graph. All the examples I've seen look something like this: > > from pylab import * > import numpy as np > t = arange(0.0, 2.0+0.01, 0.01) ?# generate x-values > s = sin(t*pi) ?# and y-values > plot(t, s) > show() > > > which is fine for what it is, but I'm looking for an interface closer to > what my HP graphing calculator would use, i.e. something like this: > > > plot(lambda x: sin(x*pi), # function or expression to plot, > ? ? start=0.0, > ? ? end=2.0, > ? ?) > > and have step size taken either from some default, or better still, > automatically calculated so one point is calculated per pixel. > > Is there a way to do this in iPython or matplotlib? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list Hi, would a mpmath solution be acceptable? http://code.google.com/p/mpmath/ http://mpmath.googlecode.com/svn/trunk/doc/build/plotting.html#mpmath.plot """ mpmath.plot(ctx, f, xlim=[-5, 5], ylim=None, points=200, file=None, dpi=None, singularities=[], axes=None) Shows a simple 2D plot of a function ... or list of functions ... over a given interval specified by xlim. ... """ >>> import mpmath >>> mpmath.plot(lambda x: mpmath.sin(x*mpmath.pi), xlim=[0.0, 2.0]) hth, vbr From cjw at ncf.ca Sat May 19 07:54:18 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 19 May 2012 07:54:18 -0400 Subject: .py to .pyc In-Reply-To: <1qOdnUeu_tXdRCvSnZ2dnUVZ8nSdnZ2d@giganews.com> References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> <1qOdnUeu_tXdRCvSnZ2dnUVZ8nSdnZ2d@giganews.com> Message-ID: On 18/05/2012 7:20 PM, Tony the Tiger wrote: > On Sun, 13 May 2012 23:36:02 +0200, Irmen de Jong wrote: > >> Why do you care anyway? > > Wanna hide his code...? > > /Grrr Curiosity. Perhaps there are stack-based processors out there which could use the .pyc code more directly. Colin W. From WolfgangMeiners01 at web.de Sat May 19 09:25:30 2012 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Sat, 19 May 2012 15:25:30 +0200 Subject: sqlalchemy: delete() on m:n-relationship Message-ID: <4fb79f4b$0$6563$9b4e6d93@newsspool4.arcor-online.net> Hi all, i dont understand, how sqlalchemy deletes from m:n relationships. Maybe, someone can explain to me, how to delete in the following program: (pyhton3, sqlalchemy 0.7.0) ===================================================================== > #!/usr/bin/env python3 > # -*- coding: utf-8 -*- > > ''' > Created on 19.05.2012 > > @author: wolfgang > > ''' > > from sqlalchemy import * > > from sqlalchemy.orm.session import sessionmaker > from sqlalchemy.orm import relationship, backref > from sqlalchemy.ext.declarative import declarative_base > > > Base = declarative_base() > > class Book(Base): > __tablename__='books' > > def __init__(self, title, authors): > # here authors is a list of items of type Autor > self.title = title > for author in authors: > self.authors.append(author) > > bid = Column(Integer, primary_key=True) > title = Column(String, index=True) > > authors = relationship('Author', secondary='author_book', > backref=backref('books', order_by='Book.title', cascade='all, delete'), > cascade='all, delete') > > class Author(Base): > __tablename__ = 'authors' > > def __init__(self, name): > self.name = name > > aid = Column(Integer, primary_key=True) > name = Column(String, index=True) > > > # Association table between authors and books: > author_book = Table('author_book', Base.metadata, > Column('aid', Integer, ForeignKey('authors.aid'), primary_key=True), > Column('bid', Integer, ForeignKey('books.bid'), primary_key=True)) > > > class DB: > def __init__(self, dbname=None, echo=False): > self.dbname = dbname if dbname else ':memory:' > self.dbfile = 'sqlite:///{db}'.format(db=self.dbname) > self.engine = create_engine(self.dbfile) > Base.metadata.create_all(self.engine) > self.Session = sessionmaker(self.engine) > > def find_or_create_author(session, name): > qauthor = session.query(Author).filter_by(name=name) > if qauthor.count() == 0: > session.add(Author(name=name)) > return qauthor.one() > > if __name__ == '__main__': > > db = DB(dbname='booksdb.sqlite', echo=True) > session = db.Session() > > # insert 4 books into db > session.add_all([Book(title='Title a', > authors=[find_or_create_author(session, name='Author 1'), > find_or_create_author(session, name='Author 2')]), > Book(title='Title b', > authors=[find_or_create_author(session, name='Author 1'), > find_or_create_author(session, name='Author 2')]), > Book(title='Title c', > authors=[find_or_create_author(session, name='Author 3'), > find_or_create_author(session, name='Author 4')]), > Book(title='Title d', > authors=[find_or_create_author(session, name='Author 3'), > find_or_create_author(session, name='Author 4')])]) > > session.commit() > > # At this point there are 4 book in db, the first 2 written by Author 1 and Author 2, > # the last 2 written by Author 3 and Author 4. > # Now, i delete books with bid == 1 and bid == 3: > > book1 = session.query(Book).filter_by(bid=1).one() > session.delete(book1) > > session.query(Book).filter_by(bid=3).delete() > > session.commit() > > # The first query deletes to much: Title b is related to Author 1 and Author 2 > # this relation has dissapeared from the db > > # The last query deletes to less: There is no Title 3, but the entries > # of this book remain in the associationtable. > > # How is this done right? ========================================================================================== after i run this program, the contents of booksdb.sqlite has the following data: $ sqlite3 booksdb.sqlite SQLite version 3.6.12 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> select * from author_book; 3|3 4|3 3|4 4|4 sqlite> select * from ...> books natural inner join author_book ...> natural inner join authors; 4|Title d|3|Author 3 4|Title d|4|Author 4 which means, association between Title b and ist authors is lost, information on Title c is still in author_book table. Thank you for any help Wolfgang From awilliam at whitemice.org Sat May 19 09:31:32 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 19 May 2012 09:31:32 -0400 Subject: cPython, IronPython, Jython, and PyPy (Oh my!) In-Reply-To: References: <4FB41D35.3010904@stoneleaf.us> <4FB431CD.6080707@stoneleaf.us> Message-ID: <1337434292.10794.2.camel@linux-nysu.site> On Thu, 2012-05-17 at 11:13 +1000, Chris Angelico wrote: > On Thu, May 17, 2012 at 9:01 AM, Ethan Furman wrote: > > A record is an interesting critter -- it is given life either from the user > > or from the disk-bound data; its fields can then change, but those changes > > are not reflected on disk until .write_record() is called; I do this > > because I am frequently moving data from one table to another, making > > changes to the old record contents before creating the new record with the > > changes -- since I do not call .write_record() on the old record those > > changes do not get backed up to disk. > I strongly recommend being more explicit about usage and when it gets > written and re-read, You need to define a 'session' that tracks records and manages flushing. Potentially it can hold a pool of weak references to record objects that have been read from disk. Record what records are 'dirty' and flush those to disk explicitly or drop all records ('essentially rollback'). That is the only sane way to manage this. > rather than relying on garbage collection. +1 +1 Do *not* rely on implementation details as features. Sooner or later doing so will always blow-up. > Databasing should not be tied to a language's garbage collection. > Imagine you were to reimplement the equivalent logic in some other > language - could you describe it clearly? If so, then that's your > algorithm. If not, you have a problem. -------------- 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 amvds at xs4all.nl Sat May 19 09:35:39 2012 From: amvds at xs4all.nl (Alex van der Spek) Date: 19 May 2012 13:35:39 GMT Subject: Plot a function with matplotlib? References: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fb7a1ab$0$6942$e4fe514c@news2.news.xs4all.nl> On Sat, 19 May 2012 01:59:59 +0000, Steven D'Aprano wrote: > I have matplotlib and iPython, and want to plot a function over an > equally-spaced range of points. > > That is to say, I want to say something like this: > > plot(func, start, end) > > rather than generating the X and Y values by hand, and plotting a > scatter graph. All the examples I've seen look something like this: > > from pylab import * > import numpy as np > t = arange(0.0, 2.0+0.01, 0.01) # generate x-values s = sin(t*pi) # > and y-values > plot(t, s) > show() > > > which is fine for what it is, but I'm looking for an interface closer to > what my HP graphing calculator would use, i.e. something like this: > > > plot(lambda x: sin(x*pi), # function or expression to plot, > start=0.0, > end=2.0, > ) > > and have step size taken either from some default, or better still, > automatically calculated so one point is calculated per pixel. > > Is there a way to do this in iPython or matplotlib? Not to my knowledge unless you code it yourself. However in gnuplot (www.gnuplot.info) gnuplot>>> set xrange[start:end] gnuplot>>> foo(x)=mycomplicatedfunction(x) gnuplot>>> plot foo(x) or shorter still gnuplot>>> plot [start:end] foo(x) without the need to set the xrange in advance. From awilliam at whitemice.org Sat May 19 09:39:19 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 19 May 2012 09:39:19 -0400 Subject: Questions on __slots__ In-Reply-To: <4FB67E8C.802@earthlink.net> References: <4FB67E8C.802@earthlink.net> Message-ID: <1337434759.10794.4.camel@linux-nysu.site> On Fri, 2012-05-18 at 09:53 -0700, Charles Hixson wrote: > Does __slots__ make access to variables more efficient? Absolutely, yes. > If one uses property() to create a few read-only pseudo-variables, does > that negate the efficiency advantages of using __slots__? > (Somehow I feel the documentation needs a bit of improvement.) If you are tempted to use property, setattr, etc... then do not use __slots__. __slots__ should really only be used for Fly Weight pattern type work, or at least for objects with a limited scope and will not be inherited from. -------------- 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 miki.tebeka at gmail.com Sat May 19 10:22:17 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 19 May 2012 07:22:17 -0700 (PDT) Subject: Plot a function with matplotlib? In-Reply-To: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: > I'm looking for an interface closer to > what my HP graphing calculator would use, i.e. something like this: > > > plot(lambda x: sin(x*pi), # function or expression to plot, > start=0.0, > end=2.0, > ) > > and have step size taken either from some default, or better still, > automatically calculated so one point is calculated per pixel. > > Is there a way to do this in iPython or matplotlib? I don't think there is, but using range and list comprehension you can write a little utility function that does that: HTH -- Miki Tebeka http://pythonwise.blogspot.com def simplot(fn, start, end): xs = range(start, end+1) plot(xs, [fn(x) for x in xs)]) From torriem at gmail.com Sat May 19 10:27:45 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 19 May 2012 08:27:45 -0600 Subject: bash/shell to python In-Reply-To: References: Message-ID: <4FB7ADE1.9020707@gmail.com> On 05/16/2012 08:16 PM, Rita wrote: > I currently build a lot of interfaces/wrappers to other applications > using bash/shell. One short coming for it is it lacks a good method > to handle arguments so I switched to python a while ago to use > 'argparse' module. Actually there is a great way of parsing command line options in bash, using the GNU "getopt" program. See: http://www.manpagez.com/man/1/getopt/ This command is available on all Linux systems, and most BSD systems. There's also freegetopt, a BSD implementation for unix, MSDOS, or Windows. > Its a great complement to subprocess module. I was wondering if there > is a generic framework people follow to build python scripts which > are replacing shell scripts? Is there a guide or a template to > follow? Besides the advice given by the other posters in this thread, here is a very good document on some unique aspects of python that are well suited to doing system programming or shell scripting in python: http://www.dabeaz.com/generators/ This describes how generators can be used to replace pipes with something that is quite efficient and very pythonic. See the presentation pdf first. From hansmu at xs4all.nl Sat May 19 12:23:36 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 19 May 2012 18:23:36 +0200 Subject: ctype C library call always returns 0 with Python3 In-Reply-To: References: Message-ID: <4fb7c90a$0$6880$e4fe514c@news2.news.xs4all.nl> On 19/05/12 13:20:24, Nobody wrote: > On Sat, 19 May 2012 11:30:46 +0200, Johannes Bauer wrote: > >> import ctypes >> libc = ctypes.cdll.LoadLibrary("/lib64/libc-2.14.1.so") >> print(libc.strchr("abcdef", ord("d"))) > > In 3.x, a string will be passed as a wchar_t*, not a char*. IOW, the > memory pointed to by the first argument to strchr() will consist mostly of > NUL bytes. > > Either use a "bytes" instead of a string: > > > print(libc.strchr(b"abcdef", ord("d"))) > 1984444291 > > or specify the argument types to force a conversion: > > > libc.strchr.argtypes = [c_char_p, c_int] > > print(libc.strchr("abcdef", ord("d"))) > 1984755787 You'll also want to specify the return type: >>> libc.strchr.argtypes = [c_char_p, c_int] >>> print(libc.strchr(b"abcdef", ord("d"))) 7224211 >>> libc.strchr.restype = c_char_p >>> print(libc.strchr(b"abcdef", ord("d"))) b'def' Hope this helps, -- HansM From guido at python.org Sat May 19 12:31:29 2012 From: guido at python.org (Guido van Rossum) Date: Sat, 19 May 2012 09:31:29 -0700 Subject: Jython 2.7 alpha1 is out! In-Reply-To: References: Message-ID: Congrats Frank! I reposted this on my G+ account and got some interesting comments. https://plus.google.com/u/0/115212051037621986145/posts/ifyqW3JBd3a There's got to be a way for you to make money off the Oracle connection! (PS: It would have been nice if there was an announcement page on the Jython website/wiki instead of having to link to a mailing list archive page. :-) --Guido On Thu, May 17, 2012 at 1:56 PM, fwierzbicki at gmail.com wrote: > On behalf of the Jython development team, I'm pleased to announce that > Jython 2.7 alpha1 is available for download here: > http://sourceforge.net/projects/jython/files/jython-dev/2.7.0a1/jython_installer-2.7a1.jar/downloaddownload. > See the installation instructions here: > http://wiki.python.org/jython/InstallationInstructions > > I'd like to thank Adconion Media Group for sponsoring my work on > Jython 2.7. I'd also like to thank the many contributors to Jython. > > Jython 2.7 alpha1 implements much of the functionality introduced by > CPython 2.6 and 2.7. There are still some missing features, in > particular bytearray and the io system are currently incomplete. > > Please report any bugs here: http://bugs.jython.org/ Thanks! > > -Frank > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > ? ? ? ?Support the Python Software Foundation: > ? ? ? ?http://www.python.org/psf/donations/ -- --Guido van Rossum (python.org/~guido) From research at johnohagan.com Sat May 19 12:31:41 2012 From: research at johnohagan.com (John O'Hagan) Date: Sun, 20 May 2012 02:31:41 +1000 Subject: How to generate only rotationally-unique permutations? In-Reply-To: References: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> Message-ID: <20120520023141.f67a504dc197a863aa74a974@johnohagan.com> On Sat, 19 May 2012 09:15:39 +0100 Arnaud Delobelle wrote: > On 19 May 2012 06:23, John O'Hagan wrote: [...] > > > > How to generate only the distinct permutations of a sequence which are not > > rotationally equivalent to any others? More precisely, to generate only the > > most "left-packed" of each group of rotationally equivalent permutations, > > such that for each permutation p: > > This makes me think of Lyndon words. A Lyndon word is a word which is > the only lexicographical minimum of all its rotations. There is a > very effective way of generating Lyndon words of length <= n. It may > be possible to adapt it to what you want (obviously as Lyndon words > are aperiodic you'd have to generate Lyndon word of length d | n when > suitable). > Thanks for your suggestion. The Lyndon word generators I found were not quite what I was after as they didn't guarantee giving sequences with the same elements. but your suggestion led me to necklaces: http://en.wikipedia.org/wiki/Necklace_ (combinatorics) of which Lyndon words represent a special aperiodic case. I found these algorithms for generating necklaces: http://www.sagenb.org/src/combinat/necklace.py which seems to be exactly what I want. Thanks! Regards, -- John From charleshixsn at earthlink.net Sat May 19 12:49:26 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sat, 19 May 2012 09:49:26 -0700 Subject: Questions on __slots__ In-Reply-To: <1337434759.10794.4.camel@linux-nysu.site> References: <4FB67E8C.802@earthlink.net> <1337434759.10794.4.camel@linux-nysu.site> Message-ID: <4FB7CF16.4070900@earthlink.net> On 05/19/2012 06:39 AM, Adam Tauno Williams wrote: > On Fri, 2012-05-18 at 09:53 -0700, Charles Hixson wrote: > >> Does __slots__ make access to variables more efficient? >> > Absolutely, yes. > > >> If one uses property() to create a few read-only pseudo-variables, does >> that negate the efficiency advantages of using __slots__? >> (Somehow I feel the documentation needs a bit of improvement.) >> > If you are tempted to use property, setattr, etc... then do not use > __slots__. __slots__ should really only be used for Fly Weight pattern > type work, or at least for objects with a limited scope and will not be > inherited from. > Thank you. What I really wanted was a "named list", sort of like a "named tuple", only modifiable, but since the only way to do it was to create a class, I started thinking of reasonable operations for it to perform (data hiding, etc.) Sounds like I should go back to the "named list" idea. -- Charles Hixson From research at johnohagan.com Sat May 19 13:02:32 2012 From: research at johnohagan.com (John O'Hagan) Date: Sun, 20 May 2012 03:02:32 +1000 Subject: How to generate only rotationally-unique permutations? In-Reply-To: References: <20120519152337.faf6872c327bfe33e609ccd3@johnohagan.com> Message-ID: <20120520030232.b7545b2f379381ae01db69f4@johnohagan.com> On Sat, 19 May 2012 04:21:35 -0400 Zero Piraeus wrote: > : > > On 19 May 2012 01:23, John O'Hagan wrote: > > How to generate only the distinct permutations of a sequence which are not > > rotationally equivalent to any others? More precisely, to generate only the > > most "left-packed" of each group of rotationally equivalent permutations, > > such that for each permutation p: > > It's late and I'm tired (and the solution below isn't a generator), but ... > > itertools.permutations() generates results in lexicographic order [1], > so if you reverse-sort the sequence before processing it, when you get > a sequence back whose first item isn't the maximum, you'll know that > you've got all the sequences whose first item *is* the maximum - which > means you can bail at that point. > > Wow, that's a nasty sentence. As I said, tired. Anyway - you'll get > dupes if there are non-unique items in the rest of the sequence, so > some form of filtering is required, but you could use a set to handle > that. Something like: > > from itertools import permutations > > def rot_uniq_perms(seq): > result = set() > seq = sorted(seq, reverse=True) > maximum = seq[0] > for x in permutations(seq): > if x[0] != maximum: > break > else: > result.add(x[::-1]) > return result > > No idea how this performs compared to your existing solution, but it > might be a starting point. Thanks for your reply, but I can't profitably use itertools.permutations, as my sequences have repeated elements, so I was using a python implementation of the next_permutation algorithm, which yields only distinct permutations. Your trick of bailing when x[0] != maximum is, I think, another version of what my attempt did, that is, remove the maximum, permute the rest, then replace it. But the problem remains of what to do if there are several maxima. That is obviated by a solution suggested by another reply, of using a necklace generator. Thanks again, -- John From g.rodola at gmail.com Sat May 19 13:23:53 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Sat, 19 May 2012 19:23:53 +0200 Subject: Advantages of logging vs. print() Message-ID: Hi all, I'm currently working on 1.0.0 release of pyftpdlib module. This new release will introduce some backward incompatible changes in that certain APIs will no longer accept bytes but unicode. While I'm at it, as part of this breackage I was contemplating the possibility to rewrite my logging functions, which currently use the print statement, and use the logging module instead. As of right now pyftpdlib delegates the logging to 3 functions: def log(s): """Log messages intended for the end user.""" print s def logline(s): """Log commands and responses passing through the command channel.""" print s def logerror(s): """Log traceback outputs occurring in case of errors.""" print >> sys.stderr, s The user willing to customize logs (e.g. write them to a file) is supposed to just overwrite these 3 functions as in: >>> from pyftpdlib import ftpserver >>> def log2file(s): ... open(''ftpd.log', 'a').write(s) ... >>> ftpserver.log = ftpserver.logline = ftpserver.logerror = log2file Now I'm asking: what benefits would imply to get rid of this approach and use logging module instead? >From a module vendor perspective, how exactly am I supposed to use/provide logging in my module? Am I supposed to do this: import logging logger = logging.getLogger("pyftpdlib") ...and state in my doc that "logger" is the object which is supposed to be used in case the user wants to customize how logs behave? Is logging substantially slower compared to print()? Thanks in advance --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From peterx.mcevoy at gmail.com Sat May 19 15:44:03 2012 From: peterx.mcevoy at gmail.com (pete McEvoy) Date: Sat, 19 May 2012 12:44:03 -0700 (PDT) Subject: setdefault behaviour question Message-ID: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> I am confused by some of the dictionary setdefault behaviour, I think I am probably missing the obvious here. def someOtherFunct(): print "in someOtherFunct" return 42 def someFunct(): myDict = {1: 2} if myDict.has_key(1): print "myDict has key 1" x = myDict.setdefault(1, someOtherFunct()) # <<<<< I didn't expect someOtherFunct to get called here print "x", x y = myDict.setdefault(5, someOtherFunct()) print "y", y +++++++++++++++++++++ if I call someFunct() I get the following output myDict has key 1 in someOtherFunct x 2 in someOtherFunct y 42 For the second use of setdefault I do expect a call as the dictionary does not the key. Will the function, someOtherFunct, in setdefault always be called anyway and it is just that the dictionary will not be updated in any way? From python at mrabarnett.plus.com Sat May 19 16:01:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 19 May 2012 21:01:28 +0100 Subject: setdefault behaviour question In-Reply-To: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> References: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> Message-ID: <4FB7FC18.3060305@mrabarnett.plus.com> On 19/05/2012 20:44, pete McEvoy wrote: > I am confused by some of the dictionary setdefault behaviour, I think > I am probably missing the obvious here. > > def someOtherFunct(): > print "in someOtherFunct" > return 42 > > def someFunct(): > myDict = {1: 2} > if myDict.has_key(1): > print "myDict has key 1" > x = myDict.setdefault(1, someOtherFunct()) #<<<<< I didn't > expect someOtherFunct to get called here > print "x", x > y = myDict.setdefault(5, someOtherFunct()) > print "y", y > > > +++++++++++++++++++++ > > if I call someFunct() I get the following output > > myDict has key 1 > in someOtherFunct > x 2 > in someOtherFunct > y 42 > > > For the second use of setdefault I do expect a call as the dictionary > does not the key. Will the function, someOtherFunct, in setdefault > always be called anyway and it is just that the dictionary will not be > updated in any way? The answer is yes. someOtherFunct() is called and then 1 and the result of someOtherFunct() are passed as arguments to myDict.setdefault(...). From peterx.mcevoy at gmail.com Sat May 19 16:44:07 2012 From: peterx.mcevoy at gmail.com (pete McEvoy) Date: Sat, 19 May 2012 13:44:07 -0700 (PDT) Subject: setdefault behaviour question References: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> Message-ID: Ah - I have checked some previous posts (sorry, should have done this first) and I now can see that the lazy style evaluation approach would not be good. I can see the reasons it behaves this way. many thanks anyway. From breamoreboy at yahoo.co.uk Sat May 19 19:22:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 20 May 2012 00:22:04 +0100 Subject: Plot a function with matplotlib? In-Reply-To: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <4fb6fe9f$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/05/2012 02:59, Steven D'Aprano wrote: > I have matplotlib and iPython, and want to plot a function over an > equally-spaced range of points. > > That is to say, I want to say something like this: > > plot(func, start, end) > > rather than generating the X and Y values by hand, and plotting a scatter > graph. All the examples I've seen look something like this: > > from pylab import * > import numpy as np > t = arange(0.0, 2.0+0.01, 0.01) # generate x-values > s = sin(t*pi) # and y-values > plot(t, s) > show() > > > which is fine for what it is, but I'm looking for an interface closer to > what my HP graphing calculator would use, i.e. something like this: > > > plot(lambda x: sin(x*pi), # function or expression to plot, > start=0.0, > end=2.0, > ) > > and have step size taken either from some default, or better still, > automatically calculated so one point is calculated per pixel. > > Is there a way to do this in iPython or matplotlib? > > Sorry don't know but wouldn't it make sense to ask on the matplotlib users mailing lst, cos like most python users the're extremely friendly? -- Cheers. Mark Lawrence. From zahlman at gmail.com Sat May 19 19:32:46 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Sat, 19 May 2012 19:32:46 -0400 Subject: print XML In-Reply-To: References: Message-ID: What do you want the contents of the file to look like? Why are you parsing the XML in the first place? (What do you want to happen if the data on `sys.stdin` isn't actually valid XML?) On Thu, May 17, 2012 at 9:52 AM, Nibin V M wrote: > Hello, > > I have the following code, which will assign ?XML data to a variable! What > is the best method to write the contents of the variable to a file? > > ======= > doc = minidom.parse(sys.stdin) > ======= > > Any help will be highly appreciated! > > Thank you, > -- > Regards.... > > Nibin. > > http://TechsWare.in > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~Zahlman {:> From rosuav at gmail.com Sat May 19 19:49:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 May 2012 09:49:25 +1000 Subject: setdefault behaviour question In-Reply-To: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> References: <4f984fe2-5229-4132-acb1-d34a3f95faf8@w13g2000vbc.googlegroups.com> Message-ID: On Sun, May 20, 2012 at 5:44 AM, pete McEvoy wrote: > I am confused by some of the dictionary setdefault behaviour, I think > I am probably missing the obvious here. > > def someOtherFunct(): > ? ?print "in someOtherFunct" > ? ?return 42 > > ? ?x = myDict.setdefault(1, someOtherFunct()) ? # <<<<< I didn't > expect someOtherFunct to get called here Python doesn't have lazy evaluation as such, but if what you want is a dictionary that calls a function of yours whenever a value isn't found, check out collections.defaultdict: >>> import collections >>> a=collections.defaultdict() >>> def func(): print("Generating a default!") return 42 >>> a.default_factory=func >>> x = a[1] Generating a default! >>> x = a[1] Tested in 3.2, but should work fine in 2.5 and newer. ChrisA From neolo12 at yandex.ru Sun May 20 02:29:55 2012 From: neolo12 at yandex.ru (jimmy970) Date: Sat, 19 May 2012 23:29:55 -0700 (PDT) Subject: http://porn-extreme.2304310.n4.nabble.com/ In-Reply-To: <1337147972283-4974741.post@n6.nabble.com> References: <1334515222183-4884289.post@n6.nabble.com> <1334655385567-4889606.post@n6.nabble.com> <1334907134743-4901176.post@n6.nabble.com> <1335001127779-4904646.post@n6.nabble.com> <1335369266792-4917074.post@n6.nabble.com> <1335623703913-4936643.post@n6.nabble.com> <1335847182281-4942868.post@n6.nabble.com> <1335955532204-4945863.post@n6.nabble.com> <1336893271019-4974351.post@n6.nabble.com> <1337147972283-4974741.post@n6.nabble.com> Message-ID: <1337495395130-4975250.post@n6.nabble.com> http://porn-extreme.2304310.n4.nabble.com/ -- View this message in context: http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4975250.html Sent from the Python - python-list mailing list archive at Nabble.com. From real-not-anti-spam-address at apple-juice.co.uk Sun May 20 09:51:28 2012 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Sun, 20 May 2012 14:51:28 +0100 Subject: DjangoCon Europe 2012 Message-ID: <1kkedey.8pxue31bp7h05N%real-not-anti-spam-address@apple-juice.co.uk> DjangoCon Europe, the community's biggest European event this year, is only two weeks away now. The packed schedule of talks has been posted, the site has been updated with useful information about Z?rich , and the conference now has its own social networking presence courtesy of hyperweek. On top of that, the programme's second keynote speaker has been announced. Jessica McKellar is a Python Software Foundation board member and a maintainer of several important open source Python projects. Tickets are still available. Sign up, join in and enjoy everything that the event has to offer. Daniele From dihedral88888 at googlemail.com Sun May 20 09:55:10 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 20 May 2012 06:55:10 -0700 (PDT) Subject: .py to .pyc In-Reply-To: References: <4fb02943$0$6861$e4fe514c@news2.news.xs4all.nl> <1qOdnUeu_tXdRCvSnZ2dnUVZ8nSdnZ2d@giganews.com> Message-ID: <85325f21-d067-4564-bf4d-a763437e5412@googlegroups.com> On Saturday, May 19, 2012 7:54:18 PM UTC+8, Colin J. Williams wrote: > On 18/05/2012 7:20 PM, Tony the Tiger wrote: > > On Sun, 13 May 2012 23:36:02 +0200, Irmen de Jong wrote: > > > >> Why do you care anyway? > > > > Wanna hide his code...? > > > > /Grrr > Curiosity. Perhaps there are st ack-based processors out there which > could use the .pyc code more directly. > > Colin W. Uhn, don't forget the famous Z-80, and forth CPU which were stack based. But I am trained in the register based C as my favorite low level language higher than any assembly. From python at bdurham.com Sun May 20 10:42:26 2012 From: python at bdurham.com (python at bdurham.com) Date: Sun, 20 May 2012 10:42:26 -0400 Subject: Python and Tkinter by John E Grayson In-Reply-To: <87ehqi8jdw.fsf@benfinney.id.au> References: <4fb4caa4$0$29975$c3e8da3$5496439d@news.astraweb.com> <87ehqi8jdw.fsf@benfinney.id.au> Message-ID: <1337524946.8698.140661078075957.503155DF@webmail.messagingengine.com> > Tk has gone through some dramatic improvements since that time. > One which has seen a lot of love is . I agree with Ben. Tkinter (with ttk) is now a viable GUI framework. Key benefits of Tkinter/ttk to consider when evaluating other tool kits: 1. Tkinter/ttk is bundled with Python meaning distribution is almost painless. 2. Tkinter/ttk are very light weight in terms of the size they add to a distribution. Malcolm From steve+comp.lang.python at pearwood.info Sun May 20 11:55:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 May 2012 15:55:52 GMT Subject: Doctest documentation? Message-ID: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> Is this a bug in the doctest documentation, or is my browser broken? On this page: http://docs.python.org/library/doctest.html#option-flags-and-directives scroll down to the examples showing the doctest directives, e.g: [quote] For example, this test passes: >>> print range(20) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] Likewise for the Python 3 version: http://docs.python.org/py3k/library/doctest.html Seems to me that the actual directives are missing. I can't see them in the raw HTML either. Can anyone else confirm that they are missing? -- Steven From vincent.vandevyvre at swing.be Sun May 20 12:33:51 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 20 May 2012 18:33:51 +0200 Subject: Doctest documentation? In-Reply-To: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FB91CEF.6020506@swing.be> On 20/05/12 17:55, Steven D'Aprano wrote: > Is this a bug in the doctest documentation, or is my browser broken? > > On this page: > > http://docs.python.org/library/doctest.html#option-flags-and-directives > > scroll down to the examples showing the doctest directives, e.g: > > [quote] > For example, this test passes: > > >>> print range(20) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, > 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] > > Likewise for the Python 3 version: > > http://docs.python.org/py3k/library/doctest.html > > Seems to me that the actual directives are missing. I can't see them in > the raw HTML either. Can anyone else confirm that they are missing? > > No, this paragraph exists. Copied from source of http://docs.python.org/py3k/library/doctest.html: An example's doctest directives modify doctest's behavior for that single example. Use ``+`` to enable the named behavior, or ``-`` to disable it. For example, this test passes:: >>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] -- Vincent V.V. Oqapy . Qarte+7 . PaQager From mgbg25171 at blueyonder.co.uk Sun May 20 12:52:11 2012 From: mgbg25171 at blueyonder.co.uk (e-mail mgbg25171) Date: Sun, 20 May 2012 17:52:11 +0100 Subject: what do these mean Message-ID: There's a little forth program written in python here #http://openbookproject.net/py4fun/forth/forth.py I'm struggling to understand what these lines mean. def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()] def rJz (cod,p) : return (p+1,cod[p])[ds.pop()==0] Specifically I'm stuck on what (code[p], followed by p+1 does inside the brackets and also what [ds.pop()] abd [ds.pop==0] does afterwards I do know that p is an integer cod[p] is one of a list of functions that are stored in cod ds.pop() is popping the top of the ds list and ds.pop() == 0 either means that the result popped is 0 or that there are no items left in list ds[] Any help much appreciated -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun May 20 13:05:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 May 2012 03:05:52 +1000 Subject: what do these mean In-Reply-To: References: Message-ID: On Mon, May 21, 2012 at 2:52 AM, e-mail mgbg25171 wrote: > def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()] > def rJz? (cod,p) : return (p+1,cod[p])[ds.pop()==0] > > Specifically I'm stuck on what (code[p], followed by p+1 does inside the > brackets (cod[p],p+1) is a two-item tuple with [0] equal to cod[p] and [1] equal to p+1. It takes the next element off the list ds and indexes that little tuple with it. It's like this: def rJnz (cod,p): if ds.pop()==1: return p+1 return cod[p] def rJz? (cod,p): if ds.pop()==0: return cod[p] return p+1 > ds.pop() == 0 either means that the result popped is 0 or that there are no > items left in list ds[] If there are no items left. pop() will raise an exception. ChrisA From ian.g.kelly at gmail.com Sun May 20 13:16:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 20 May 2012 11:16:19 -0600 Subject: what do these mean In-Reply-To: References: Message-ID: On Sun, May 20, 2012 at 10:52 AM, e-mail mgbg25171 wrote: > There's a little forth program written in python here > #http://openbookproject.net/py4fun/forth/forth.py > I'm struggling to understand what these lines mean. > > def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()] > def rJz? (cod,p) : return (p+1,cod[p])[ds.pop()==0] rJz is the jump-if-zero instruction used by the If and Until constructs. It creates a tuple containing the next instruction and the instruction to jump to. Which element of the tuple to return is determined by the expression "ds.pop()==0", which is True (i.e. 1) if the top of the stack is 0, or False (i.e. 0) if it is not. rJnz appears to be a complementary jump-if-nonzero instruction that is never actually used by the program and appears to be buggy in any case. It has the order of the tuple backwards, and the "ds.pop()" expression makes the false assumption that the item at the top of the stack is already 0 or 1 and not something else. From tjreedy at udel.edu Sun May 20 14:15:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 May 2012 14:15:32 -0400 Subject: Doctest documentation? In-Reply-To: <4FB91CEF.6020506@swing.be> References: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> <4FB91CEF.6020506@swing.be> Message-ID: On 5/20/2012 12:33 PM, Vincent Vande Vyvre wrote: > On 20/05/12 17:55, Steven D'Aprano wrote: >> Is this a bug in the doctest documentation, or is my browser broken? >> >> On this page: >> >> http://docs.python.org/library/doctest.html#option-flags-and-directives >> >> scroll down to the examples showing the doctest directives, e.g: >> >> [quote] >> For example, this test passes: >> >> >>> print range(20) >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, >> 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >> >> Likewise for the Python 3 version: >> >> http://docs.python.org/py3k/library/doctest.html >> >> Seems to me that the actual directives are missing. I can't see them in >> the raw HTML either. Can anyone else confirm that they are missing? > No, this paragraph exists. > > Copied from source of http://docs.python.org/py3k/library/doctest.html: > > An example's doctest directives modify doctest's behavior for that single > example. Use ``+`` to enable the named behavior, or ``-`` to disable it. > > For example, this test passes:: > > >>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, > 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] The directives may be in the source, but they seem to be getting removed when the docs are built. They are also missing from the Windows help version. I suspect that sphinx now uses the directives itself for doctest testing examples, and does not know to leave them. I opened an issue. http://bugs.python.org/issue14865 I determined that the removing bug first happened with 3.2.0 and then 2.7.3 (but not 2.7.2, released 4 months after 3.2.0). -- Terry Jan Reedy From tjreedy at udel.edu Sun May 20 14:38:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 May 2012 14:38:25 -0400 Subject: what do these mean In-Reply-To: References: Message-ID: On 5/20/2012 1:16 PM, Ian Kelly wrote: > On Sun, May 20, 2012 at 10:52 AM, e-mail mgbg25171 > wrote: >> There's a little forth program written in python here >> #http://openbookproject.net/py4fun/forth/forth.py >> I'm struggling to understand what these lines mean. >> >> def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()] >> def rJz (cod,p) : return (p+1,cod[p])[ds.pop()==0] > > rJz is the jump-if-zero instruction used by the If and Until > constructs. It creates a tuple containing the next instruction and > the instruction to jump to. Which element of the tuple to return is > determined by the expression "ds.pop()==0", which is True (i.e. 1) if > the top of the stack is 0, or False (i.e. 0) if it is not. > > rJnz appears to be a complementary jump-if-nonzero instruction that is > never actually used by the program and appears to be buggy in any > case. It has the order of the tuple backwards, and the "ds.pop()" > expression makes the false assumption that the item at the top of the > stack is already 0 or 1 and not something else. Would not the order be correct if 'ds.pop()' became 'ds.pop == 0'? Admittedly, (p+1,cod[p])[ds.pop()!=0] would more clearly be jump if not 0. If course, this just goes to show what code should be unit-tested. It is so easy to mis-type and not notice even when the code in ones head is correct and even pretty trivial. -- Terry Jan Reedy From jeanpierreda at gmail.com Sun May 20 15:36:01 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 20 May 2012 15:36:01 -0400 Subject: Doctest documentation? In-Reply-To: References: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> <4FB91CEF.6020506@swing.be> Message-ID: This was previously reported as http://bugs.python.org/issue12947 -- Devin From cmpython at gmail.com Sun May 20 22:07:19 2012 From: cmpython at gmail.com (CM) Date: Sun, 20 May 2012 19:07:19 -0700 (PDT) Subject: Are there any instrumentation widgets for wxpython or tkinter? References: <32231be1-d4ec-4193-8608-6e101614e180@l17g2000vbj.googlegroups.com> <31480388.444.1337288458787.JavaMail.geo-discussion-forums@pbcqs6> Message-ID: <6cc2ea67-36b1-4b34-bdeb-7adf0fe21d3c@h10g2000yqn.googlegroups.com> On May 17, 5:00?pm, Peter wrote: > Or wxPython is another good alternative. Download the demo and have a look at the widgets people have already used/created. I think there are some good choices for instrumentation (from memory). Yes, wxPython has some that are applicable: LEDNumberCtrl PeakMeter SpeedMeter KnobCtrl wxGauge wxSpinCtrl Slider And probably others. From nkwerk at gmail.com Sun May 20 23:01:21 2012 From: nkwerk at gmail.com (.) Date: Sun, 20 May 2012 20:01:21 -0700 (PDT) Subject: Django: metaWeblog: dir() doesn't show methods Message-ID: <7cf3c49d-9125-44d6-a040-5d53de904be8@w13g2000vbc.googlegroups.com> Hello, I'm using Django and metaWeblog. s = xmlrpclib.Server("http://localhost:8000/xmlrpc/") # Let's call a method s.metaWeblog.test() "Test" # It works #But it won't output available methods if I try to use dir() for this purpose dir(s.metaWeblog) ['_Method__name', '_Method__send', '__call__', '__doc__', '__getattr__', '__init__', '__module__'] # It doesn't contain my test method Is this a bug or some sort of encapsulation? Regards From angeljanai at gmail.com Sun May 20 23:33:56 2012 From: angeljanai at gmail.com (angeljanai at gmail.com) Date: Sun, 20 May 2012 20:33:56 -0700 (PDT) Subject: 2.x,3.x iOS static build: Fatal Python error: exceptions bootstrapping error. Message-ID: <43d26adf-647a-4ffd-89de-7753cb0514e5@googlegroups.com> Hello! I'm trying to embed a part of python (core+some modules) in my iOS application for internal scripting. I started from compiling original unmodified Python source. Tried both 2.7.3 and 3.x latest source code. As I found no easy way to configure it, just tried to run configure from Mac OS X(10.7) and it was successful. After that I created XCode project and added all necessary files from after-configure source. There were some minor problems, but compilation and link errors were fixed very quickly. Finally I tried to create a test program, which has just this: ... Py_NoSiteFlag=1; Py_Initialize(); Py_Finalize(); ... When I run it I getting "Fatal Python error: exceptions bootstrapping error." Call stack is: #0 0x300cba1c in __pthread_kill () #1 0x362e43ba in pthread_kill () #2 0x362dcbfe in abort () #3 0x00127d96 in Py_FatalError at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:2169 #4 0x00155328 in _PyExc_Init at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Objects/exceptions.c:2042 #5 0x00127ad4 in Py_InitializeEx at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:272 #6 0x0012846a in Py_Initialize at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:332 #7 0x000d6242 in testpython at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/testmac.c:15 #8 0x000d618e in -[ViewController viewDidLoad] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/ViewController.m:23 #9 0x3283ff0e in -[UIViewController view] () #10 0x3283e2b4 in -[UIWindow addRootViewControllerViewIfPossible] () #11 0x3283a332 in -[UIWindow _setHidden:forced:] () #12 0x3283e28e in -[UIWindow _orderFrontWithoutMakingKey] () #13 0x3284cc60 in -[UIWindow makeKeyAndVisible] () #14 0x000d5ffe in -[AppDelegate application:didFinishLaunchingWithOptions:] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/AppDelegate.m:35 #15 0x3283e820 in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] () #16 0x32838b64 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] () #17 0x3280d7d6 in -[UIApplication handleEvent:withNewEvent:] () #18 0x3280d214 in -[UIApplication sendEvent:] () #19 0x3280cc52 in _UIApplicationHandleEvent () #20 0x322b7e76 in PurpleEventCallback () #21 0x3113ba96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ () #22 0x3113d83e in __CFRunLoopDoSource1 () XCode version is 4.3.2. I tried to debug, and unfortunately I don't understand why this error is occured. Also tried source from here: http://stackoverflow.com/a/4177748/1337666. But no luck, same problem. Porting Python core will be very helpful for my iOS application. Any hint will be appreciated. Best Regards From cs at zip.com.au Sun May 20 23:39:10 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 21 May 2012 13:39:10 +1000 Subject: bash/shell to python In-Reply-To: <4FB7ADE1.9020707@gmail.com> References: <4FB7ADE1.9020707@gmail.com> Message-ID: <20120521033910.GA10053@cskk.homeip.net> On 19May2012 08:27, Michael Torrie wrote: | On 05/16/2012 08:16 PM, Rita wrote: | > I currently build a lot of interfaces/wrappers to other applications | > using bash/shell. One short coming for it is it lacks a good method | > to handle arguments so I switched to python a while ago to use | > 'argparse' module. | | Actually there is a great way of parsing command line options in | bash, using the GNU "getopt" program. See: | http://www.manpagez.com/man/1/getopt/ | | This command is available on all Linux systems, and most BSD systems. | There's also freegetopt, a BSD implementation for unix, MSDOS, or Windows. And if you don't want to do option bundling it's easy enough to write a simple option parser without getopt at all. My standard option parsing looks somewhat like this: # some things to control via the options the_file= doit=1 trace= # badness? badopts= while [ $# -gt 0 ] do case $1 in -f) the_file=$2; shift ;; -n) doit= ;; -x) trace=1 ;; --) shift; break ;; -?*) echo "$0: unrecognised option: $1" >&2 badopts=1 ;; *) break ;; esac shift done # ... parse non-option arguments ... [ $badopts ] && { echo "$usage" >&2; exit 2; } # ... rest of program ... There's nothing hard there. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Any profit should go to Arnie's `get the daemon carved on Mount Rushmore' fund. - Marty Albini, DOD0550, martya at sdd.hp.com From wuwei23 at gmail.com Mon May 21 00:38:34 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 May 2012 21:38:34 -0700 (PDT) Subject: How to hide console with Popen on Windows? References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> Message-ID: On May 18, 6:22?pm, xliiv wrote: > Like the topic, more details in followed links.. > http://stackoverflow.com/questions/10637450/how-to-hide-console-with-... Try replacing all of your code with something simple, a 'pass' op will do. Run the script again. Does the console still open? Then it's not subprocess that you're struggling with. If I put your code into a .py file and execute it under Windows via a double-click, I get a console: the one in which the .py file is executing. Unless you're able to make the file a .pyw file - which you are apparently not as you're using OpenOffice - then executing the code that uses Popen is what is displaying a console, not the call to Popen itself. From jonathan.beer at gmail.com Mon May 21 01:08:21 2012 From: jonathan.beer at gmail.com (Jonathan) Date: Sun, 20 May 2012 22:08:21 -0700 (PDT) Subject: calling a simple PyQt application more than once In-Reply-To: References: Message-ID: <1337576901334-4975385.post@n6.nabble.com> Hello Jabba, Did you ever find a solution to the problem? If so, can you please post it? Thanks, Jonathan -- View this message in context: http://python.6.n6.nabble.com/calling-a-simple-PyQt-application-more-than-once-tp4335946p4975385.html Sent from the Python - python-list mailing list archive at Nabble.com. From wuwei23 at gmail.com Mon May 21 01:13:39 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 May 2012 22:13:39 -0700 (PDT) Subject: Django: metaWeblog: dir() doesn't show methods References: <7cf3c49d-9125-44d6-a040-5d53de904be8@w13g2000vbc.googlegroups.com> Message-ID: <2375fd42-4d5a-414c-9847-db596a03175a@l5g2000pbo.googlegroups.com> On May 21, 1:01?pm, "." wrote: > Is this a bug or some sort of encapsulation? More or less the latter. What you have is a server proxy, something that passes data back & forth between your app and the XMLRPC-providing server. So when you dir() it, it's showing you the methods of the proxy, not of the RPC server. You should be able to do s.system.listMethods() to pull back all available methods. Or to just give you the ones relevant to metaWeblog: [m for m in s.system.listMethods() if 'metaWeblog' in m] From tjreedy at udel.edu Mon May 21 01:59:34 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 May 2012 01:59:34 -0400 Subject: 2.x, 3.x iOS static build: Fatal Python error: exceptions bootstrapping error. In-Reply-To: <43d26adf-647a-4ffd-89de-7753cb0514e5@googlegroups.com> References: <43d26adf-647a-4ffd-89de-7753cb0514e5@googlegroups.com> Message-ID: On 5/20/2012 11:33 PM, angeljanai at gmail.com wrote: > I'm trying to embed a part of python (core+some modules) in my iOS application for internal scripting. I have not read that anyone has run under iOS yet ;-). Good luck. I started from compiling original unmodified Python source. Tried both 2.7.3 and 3.x latest source code. As I found no easy way to configure it, just tried to run configure from Mac OS X(10.7) and it was successful. > After that I created XCode project and added all necessary files from after-configure source. There were some minor problems, but compilation and link errors were fixed very quickly. > Finally I tried to create a test program, which has just this: > ... > Py_NoSiteFlag=1; > Py_Initialize(); > Py_Finalize(); > ... > When I run it I getting "Fatal Python error: exceptions bootstrapping error." > Call stack is: [opposite order from Python tracebacks] > #0 0x300cba1c in __pthread_kill () > #1 0x362e43ba in pthread_kill () > #2 0x362dcbfe in abort () > #3 0x00127d96 in Py_FatalError at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:2169 > #4 0x00155328 in _PyExc_Init at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Objects/exceptions.c:2042 You said you tried to debug. What have you done? Message above is from one of these locations in exceptions.c or pythonrun.c. > #5 0x00127ad4 in Py_InitializeEx at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:272 > #6 0x0012846a in Py_Initialize at /Users/mac_user/Downloads/Python-3.2.3/IOS/pythoncore/../../Python/pythonrun.c:332 > #7 0x000d6242 in testpython at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/testmac.c:15 > #8 0x000d618e in -[ViewController viewDidLoad] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/ViewController.m:23 > #9 0x3283ff0e in -[UIViewController view] () > #10 0x3283e2b4 in -[UIWindow addRootViewControllerViewIfPossible] () > #11 0x3283a332 in -[UIWindow _setHidden:forced:] () > #12 0x3283e28e in -[UIWindow _orderFrontWithoutMakingKey] () > #13 0x3284cc60 in -[UIWindow makeKeyAndVisible] () > #14 0x000d5ffe in -[AppDelegate application:didFinishLaunchingWithOptions:] at /Users/mac_user/Downloads/Python-3.2.3/IOS/test/test/AppDelegate.m:35 > #15 0x3283e820 in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] () > #16 0x32838b64 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] () > #17 0x3280d7d6 in -[UIApplication handleEvent:withNewEvent:] () > #18 0x3280d214 in -[UIApplication sendEvent:] () > #19 0x3280cc52 in _UIApplicationHandleEvent () > #20 0x322b7e76 in PurpleEventCallback () > #21 0x3113ba96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ () > #22 0x3113d83e in __CFRunLoopDoSource1 () > > XCode version is 4.3.2. > I tried to debug, and unfortunately I don't understand why this error is occured. > Also tried source from here: http://stackoverflow.com/a/4177748/1337666. > But no luck, same problem. > Porting Python core will be very helpful for my iOS application. > Any hint will be appreciated. > Best Regards -- Terry Jan Reedy From hansmu at xs4all.nl Mon May 21 02:29:04 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 21 May 2012 08:29:04 +0200 Subject: Doctest documentation? In-Reply-To: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4fb91407$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fb9e0b0$0$6850$e4fe514c@news2.news.xs4all.nl> On 20/05/12 17:55:52, Steven D'Aprano wrote: > Is this a bug in the doctest documentation, or is my browser broken? > > On this page: > > http://docs.python.org/library/doctest.html#option-flags-and-directives > > scroll down to the examples showing the doctest directives, e.g: > > [quote] > For example, this test passes: > > >>> print range(20) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, > 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] > > Likewise for the Python 3 version: > > http://docs.python.org/py3k/library/doctest.html > > Seems to me that the actual directives are missing. I can't see them in > the raw HTML either. Can anyone else confirm that they are missing? I don't see them either. -- HansM From roy at panix.com Mon May 21 08:37:29 2012 From: roy at panix.com (Roy Smith) Date: Mon, 21 May 2012 08:37:29 -0400 Subject: A question of style (finding item in list of tuples) Message-ID: I've got this code in a django app: CHOICES = [ ('NONE', 'No experience required'), ('SAIL', 'Sailing experience, new to racing'), ('RACE', 'General racing experience'), ('GOOD', 'Experienced racer'), ('ROCK', 'Rock star'), ] def experience_text(self): for code, text in self.CHOICES: if code == self.level: return text return "????" Calling experience_text("ROCK") should return "Rock star". Annoyingly, django handles this for you automatically inside a form, but if you also need it in your application code, you have to roll your own. The above code works, but it occurs to me that I could use the much shorter: def experience_text(self): return dict(CHOICES).get("self.level", "???") So, the question is, purely as a matter of readability, which would you find easier to understand when reading some new code? Assume the list of choices is short enough that the cost of building a temporary dict on each call is negligible. I'm just after style and readability here. From rosuav at gmail.com Mon May 21 09:04:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 May 2012 23:04:03 +1000 Subject: A question of style (finding item in list of tuples) In-Reply-To: References: Message-ID: On Mon, May 21, 2012 at 10:37 PM, Roy Smith wrote: > The above code works, but it occurs to me that I could use the much > shorter: > > ? ?def experience_text(self): > ? ? ? ?return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you > find easier to understand when reading some new code? ?Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. ?I'm just after style and readability here. Is there a reason not to keep the dictionary around? That would surely be the most logical thing to do. (With, of course, no quotes around self.level.) But out of your two options, I'd go with the loop. It's clear what you're doing and doesn't fiddle around with multiple translations. Chris Angelico From dave at lambsys.com Mon May 21 09:10:08 2012 From: dave at lambsys.com (David Lambert) Date: Mon, 21 May 2012 08:10:08 -0500 Subject: A question of style (finding item in list of tuples) In-Reply-To: References: Message-ID: <4FBA3EB0.90006@lambsys.com> One suggestion is to construct the dictionary first: CHOICES = dict( NONE = 'No experience required', SAIL = 'Sailing experience, new to racing', RACE = 'General racing experience', GOOD = 'Experienced racer', ROCK = 'Rock star' ) def experience_text(self): try: return CHOICES[self] except: return "????" On 05/21/2012 07:37 AM, Roy Smith wrote: > I've got this code in a django app: > > CHOICES = [ > ('NONE', 'No experience required'), > ('SAIL', 'Sailing experience, new to racing'), > ('RACE', 'General racing experience'), > ('GOOD', 'Experienced racer'), > ('ROCK', 'Rock star'), > ] > > def experience_text(self): > for code, text in self.CHOICES: > if code == self.level: > return text > return "????" > > Calling experience_text("ROCK") should return "Rock star". Annoyingly, > django handles this for you automatically inside a form, but if you also > need it in your application code, you have to roll your own. > > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you > find easier to understand when reading some new code? Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. I'm just after style and readability here. From steve+comp.lang.python at pearwood.info Mon May 21 09:10:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 May 2012 13:10:32 GMT Subject: A question of style (finding item in list of tuples) References: Message-ID: <4fba3ec7$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: [...] > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you > find easier to understand when reading some new code? Definitely the dictionary lookup. Rather than convert list CHOICES to a dict every time, you might convert it to a dict *once*, then just write: return CHOICES.get(self.level, "???") > Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. Negligible or not, why bother? Not that it really matters -- if you have a good reason for CHOICES to remain a list, still stick with the dict lookup rather than a explicit loop. -- Steven From python.list at tim.thechases.com Mon May 21 09:34:11 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 21 May 2012 08:34:11 -0500 Subject: A question of style (finding item in list of tuples) In-Reply-To: <4fba3ec7$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4fba3ec7$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FBA4453.8070103@tim.thechases.com> On 05/21/12 08:10, Steven D'Aprano wrote: > On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: > > [...] >> The above code works, but it occurs to me that I could use the much >> shorter: >> >> def experience_text(self): >> return dict(CHOICES).get("self.level", "???") >> >> So, the question is, purely as a matter of readability, which would you >> find easier to understand when reading some new code? > > Definitely the dictionary lookup. > > Rather than convert list CHOICES to a dict every time, you might convert > it to a dict *once*, then just write: > > return CHOICES.get(self.level, "???") While I back Steven's suggestion, I'd keep *both* around. The dictionary isn't inherently ordered, so presenting it to the user may come out with a differing orders depending on how code gets hit. So I'd do CHOICES = [ ("NONE", "No experience required"), ... ] CHOICE_DICT = dict(CHOICES) once at setup, and then use Steven's suggestion of return CHOICES_DICT.get(self.level, "???") then you get the best of both worlds: You can specify the order for presentation using CHOICES, and get O(1) lookups and defaulting via CHOICE_DICT. -tkc From joncle at googlemail.com Mon May 21 09:39:59 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 21 May 2012 06:39:59 -0700 (PDT) Subject: A question of style (finding item in list of tuples) In-Reply-To: References: Message-ID: On Monday, 21 May 2012 13:37:29 UTC+1, Roy Smith wrote: > I've got this code in a django app: > > CHOICES = [ > ('NONE', 'No experience required'), > ('SAIL', 'Sailing experience, new to racing'), > ('RACE', 'General racing experience'), > ('GOOD', 'Experienced racer'), > ('ROCK', 'Rock star'), > ] > > def experience_text(self): > for code, text in self.CHOICES: > if code == self.level: > return text > return "????" > > Calling experience_text("ROCK") should return "Rock star". Annoyingly, > django handles this for you automatically inside a form, but if you also > need it in your application code, you have to roll your own. > > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you > find easier to understand when reading some new code? Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. I'm just after style and readability here. Haven't used django in a while, but doesn't the model provide a get_experience_display() method which you could use... Failing that, if order isn't important, you can not bother with tuples and have CHOICES be a dict, then pass choices=CHOICES.iteritems() as I believe it takes any iterable, and maybe plug an ordereddict if order is important. hth Jon. From ironfroggy at gmail.com Mon May 21 10:51:33 2012 From: ironfroggy at gmail.com (Calvin Spealman) Date: Mon, 21 May 2012 10:51:33 -0400 Subject: PyCarolinas 2012 Call For Proposals Message-ID: PyCarolinas 2012 Call For Proposals PyCarolinas 2012, the first Python conference held in the carolinas, is now accepting proposals! We?re looking for proposals for talks you can present to this great and growing Python community. PyCarolinas will be held in October in Chapel Hill, NC. The exact location and dates of the two-day conference will be announced shortly. The proposal deadline is July 20, 2011. Please submit your proposals to talks at pycarolinas.org. About PyCarolinas 2012 PyCarolinas 2012 is the first Python Conference held in the carolinas and will be located in Chapel Hill, NC this October. The specific date and location will be announced shortly. It is a two day conference, with one day of talks and one day or sprinting. Who should submit a proposal? Anyone! We?re looking for as broad a cross-section of the Python community as possible. We?re looking for both experienced conference speakers and people new to technical conferences; industry professionals and hobbyists; entrepreneurs, researchers, and system administrators. You?ve probably learned something that other Python users could benefit from, so come toPyCarolinas and share your story. Maybe you?ve written the next great data mining package, or you have a case study to share, or you?ve learned something about how to start a Python users? group, or you just want to help novices learn how to choose a Python web framework. If you have something to tell your fellow Python programmers, this is your chance. You don?t have to be a professional speaker to give a talk at PyCarolinas. Presenters can be volunteers from all walks of life and all levels of experience. From hardcore hackers to educators to hobbyists, anyone with something to say and the desire to say it is welcome. If you have a topic idea but you?re not sure exactly how to turn it into a killer session, let us know! The program committee is happy to work with you to help your session shine. What kind of sessions can I give? PyCarolinas 2012, as a small event, is acceptingonly traditional sessions during the main conference. We are looking for sessions at 30 and 45 minutes. All levels of talks from from novice-level overviews to advanced topics are welcome. Conference registration and travel PyCarolinas is entirely volunteer-organized and run, and must keep costs as low as possible. We are unable to provide assistance or compensation for speakers traveling to and staying near the conference for the duration of the event. Timeline and deadlines Please don?t delay! The proposal window is long, but the sooner you submit a proposal, the more time we?ll have to help you put forward the best proposal. The program committee will officially begin reviewing proposals and giving feedback as soon as the CFP closes, but the team will attempt to begin reviewing and discussing proposals prior to the close of the Call for Proposals to assist authors. Proposals for talks will be accepted until July 20th. The list of selected talks and tutorials will be finalized by the end of August. Thank you! Submit your proposal to talks at pycarolinas.org and thanks for helping us make the first ever PyCarolinas great! From ironfroggy at gmail.com Mon May 21 11:02:13 2012 From: ironfroggy at gmail.com (Calvin Spealman) Date: Mon, 21 May 2012 11:02:13 -0400 Subject: PyCarolinas 2012 Call For Proposals In-Reply-To: References: Message-ID: CORRECTION The proposal deadline is July 20, 2012 Not 2011, obviously. On Mon, May 21, 2012 at 10:51 AM, Calvin Spealman wrote: > PyCarolinas 2012 Call For Proposals > > PyCarolinas 2012, the first Python conference held in the carolinas, > is now accepting proposals! We?re looking for proposals for talks you > can present to this great and growing Python community. > > PyCarolinas will be held in October in Chapel Hill, NC. The exact > location and dates of the two-day conference will be announced > shortly. > > The proposal deadline is July 20, 2011. Please submit your proposals > to talks at pycarolinas.org. > About PyCarolinas 2012 > > PyCarolinas 2012 is the first Python Conference held in the carolinas > and will be located in Chapel Hill, NC this October. The specific date > and location will be announced shortly. It is a two day conference, > with one day of talks and one day or sprinting. > Who should submit a proposal? > > Anyone! We?re looking for as broad a cross-section of the Python > community as possible. > > We?re looking for both experienced conference speakers and people new > to technical conferences; industry professionals and hobbyists; > entrepreneurs, researchers, and system administrators. You?ve probably > learned something that other Python users could benefit from, so come > toPyCarolinas and share your story. Maybe you?ve written the next > great data mining package, or you have a case study to share, or > you?ve learned something about how to start a Python users? group, or > you just want to help novices learn how to choose a Python web > framework. > > If you have something to tell your fellow Python programmers, this is > your chance. > > You don?t have to be a professional speaker to give a talk at > PyCarolinas. Presenters can be volunteers from all walks of life and > all levels of experience. From hardcore hackers to educators to > hobbyists, anyone with something to say and the desire to say it is > welcome. > > If you have a topic idea but you?re not sure exactly how to turn it > into a killer session, let us know! The program committee is happy to > work with you to help your session shine. > What kind of sessions can I give? > > PyCarolinas 2012, as a small event, is acceptingonly traditional > sessions during the main conference. We are looking for sessions at 30 > and 45 minutes. All levels of talks from from novice-level overviews > to advanced topics are welcome. > Conference registration and travel > > PyCarolinas is entirely volunteer-organized and run, and must keep > costs as low as possible. We are unable to provide assistance or > compensation for speakers traveling to and staying near the conference > for the duration of the event. > Timeline and deadlines > > Please don?t delay! The proposal window is long, but the sooner you > submit a proposal, the more time we?ll have to help you put forward > the best proposal. The program committee will officially begin > reviewing proposals and giving feedback as soon as the CFP closes, but > the team will attempt to begin reviewing and discussing proposals > prior to the close of the Call for Proposals to assist authors. > > Proposals for talks will be accepted until July 20th. The list of > selected talks and tutorials will be finalized by the end of August. > > Thank you! > > Submit your proposal to talks at pycarolinas.org and thanks for helping > us make the first ever PyCarolinas great! -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy From charleshixsn at earthlink.net Mon May 21 11:29:28 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 21 May 2012 08:29:28 -0700 Subject: Unexpected exception thrown in __del__ Message-ID: <4FBA5F58.7060800@earthlink.net> message excerpt: flush: sql = insert or replace into persists (id, name, data, rdCnt, rdTim, wrCnt, wrTim, deprecation) values (?, ?, ?, ?, ?, ?, ?, ?) Exception TypeError: "'NoneType' object is not callable" in > ignored flush is being called from within __del__. I've narrowed it down to: print ("flush: sql = ", sql) curTim = nowI() print ("flush: curTim = ", curTim) nowI() is a function defined at the top of the file, and before the class, thus: def nowI(): t = int (time() * 100) return t All I can guess is that there's some reason that an external to the class function shouldn't be called during a __del__. Is this correct? -- Charles Hixson From roy at panix.com Mon May 21 11:31:41 2012 From: roy at panix.com (Roy Smith) Date: Mon, 21 May 2012 08:31:41 -0700 (PDT) Subject: A question of style (finding item in list of tuples) In-Reply-To: References: Message-ID: On Monday, May 21, 2012 9:39:59 AM UTC-4, Jon Clements wrote: > > def experience_text(self): > > return dict(CHOICES).get("self.level", "???") > Haven't used django in a while, but doesn't the model provide a get_experience_display() method which you could use... Duh, I totally missed seeing that! Yeah, that's exactly what I want. Thanks. Hmmm, looking at the source, I see they went the dict().get() route: def _get_FIELD_display(self, field): value = getattr(self, field.attname) return force_unicode(dict(field.flatchoices).get(value, value), strings_only=True) From charleshixsn at earthlink.net Mon May 21 11:55:09 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 21 May 2012 08:55:09 -0700 Subject: Unexpected exception thrown in __del__ In-Reply-To: <4FBA5F58.7060800@earthlink.net> References: <4FBA5F58.7060800@earthlink.net> Message-ID: <4FBA655D.3010703@earthlink.net> On 05/21/2012 08:29 AM, Charles Hixson wrote: > message excerpt: > flush: sql = insert or replace into persists (id, name, data, rdCnt, > rdTim, wrCnt, wrTim, deprecation) values (?, ?, ?, ?, ?, ?, ?, ?) > Exception TypeError: "'NoneType' object is not callable" in method Shelve2.__del__ of <__main__.Shelve2 object at 0x7ff4c0513f90>> > ignored > > flush is being called from within __del__. I've narrowed it down to: > print ("flush: sql = ", sql) > curTim = nowI() > print ("flush: curTim = ", curTim) > > nowI() is a function defined at the top of the file, and before the > class, thus: > def nowI(): > t = int (time() * 100) > return t > > All I can guess is that there's some reason that an external to the > class function shouldn't be called during a __del__. Is this correct? > That seems to be the answer, as replacing the call to nowI() in flush() with: curTim = int (time() * 100) fixes the problem. Rereading the documentation, I guess that this should have been expected, but if nowI() were a static method of the class, would that have avoided the problem? A class method? -- Charles Hixson From stutzbach at google.com Mon May 21 12:46:32 2012 From: stutzbach at google.com (Daniel Stutzbach) Date: Mon, 21 May 2012 09:46:32 -0700 Subject: Good data structure for finding date intervals including a given date In-Reply-To: References: Message-ID: On Wed, May 16, 2012 at 5:38 AM, Jean-Daniel wrote: > On Sun, May 13, 2012 at 2:29 PM, Alec Taylor > wrote: > > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. > > Ordered dict are useful, but they only remember the ordered in which > they were added, you can not order them a on key. > For what it's worth, my blist package (mentioned earlier in the thread) also provides sortedlist and sorteddict classes which efficiently keep items in sorted order. I don't think those are enough on their own to create a efficient solution, but they might be useful parts of an efficient solution. More information: http://pypi.python.org/pypi/blist http://stutzbachenterprises.com/blist/ -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From tymoteusz.jankowski at gmail.com Mon May 21 13:00:26 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Mon, 21 May 2012 10:00:26 -0700 (PDT) Subject: How to hide console with Popen on Windows? In-Reply-To: References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> Message-ID: <4dfb44cf-b5dc-47d0-895a-9de6f942ec23@googlegroups.com> On Monday, May 21, 2012 6:38:34 AM UTC+2, alex23 wrote: > On May 18, 6:22?pm, xliiv wrote: > > Like the topic, more details in followed links.. > > http://stackoverflow.com/questions/10637450/how-to-hide-console-with-... > > Try replacing all of your code with something simple, a 'pass' op will > do. Run the script again. Does the console still open? Then it's not > subprocess that you're struggling with. > > If I put your code into a .py file and execute it under Windows via a > double-click, I get a console: the one in which the .py file is > executing. Unless you're able to make the file a .pyw file - which you > are apparently not as you're using OpenOffice - then executing the > code that uses Popen is what is displaying a console, not the call to > Popen itself. Ok, thanks for explanation. Now I know that my 'solution' is not a solution and problem still bugs me. Any ideas how to deal with it? From nulla.epistola at web.de Mon May 21 15:35:05 2012 From: nulla.epistola at web.de (Sibylle Koczian) Date: Mon, 21 May 2012 21:35:05 +0200 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: <4FB6FFF8.6070307@fossworkflowguides.com> References: <4FB59D37.1020709@fossworkflowguides.com> <4FB6FFF8.6070307@fossworkflowguides.com> Message-ID: Am 19.05.2012 04:05, schrieb Simon Cropper: > Googling gridtable allowed me to find my way to the wxGrid Manual which > seems to be what I was asking for... > > http://wiki.wxpython.org/wxGrid%20Manual > > wxPyGridTableBase, a particular class associated with wxGrid appears to > be what I need. The blurb states "The wxPyGridTableBase class is the > interface between the wxGrid and your application-specific data sources" > > http://wiki.wxpython.org/wxPyGridTableBase > So I suppose you're using Python 2 or that's acceptable for you at least. In this case I'd take a long look at Dabo: http://www.dabodev.com/ That's based on wxPython but easier to use and explicitly made for database applications. Developers and mailing list are especially helpful and friendly. HTH Sibylle From python at bdurham.com Mon May 21 20:01:59 2012 From: python at bdurham.com (python at bdurham.com) Date: Mon, 21 May 2012 20:01:59 -0400 Subject: DIR reports file timestamp and size, but os.path.getctime(), os.path.getsize() raise WindowsError [Error 5] Access is denied Message-ID: <1337644919.6007.140661078814021.0B9599BF@webmail.messagingengine.com> Wondering if any of you have stumbled across the following behavior: I'm doing a recursive directory listing of my Windows folder and I can access the timestamps and file sizes of all files except the following 6 files: In the \windows\microsoft.net\framework\v2.0.50727\config folder: enterprisesec.config.cch.6824.14057640 security.config.cch.6824.14057640 In the \windows\\microsoft.net\framework64\v2.0.50727\config folder: \enterprisesec.config.cch.4412.14151427 enterprisesec.config.cch.6912.14056844 security.config.cch.4412.14151427 security.config.cch.6912.14056844 When I attempt to do any of the following on the above files, a WindowsError exception is raised with a value of "[Error 5] Access is denied: ...". os.path.getctime() os.path.getatime() os.path.getmtime() os.path.getsize() What's strange is that the DIR command from a cmd prompt returns timestamps and file sizes for the above files. Background; 64-bit Windows 7; 32-bit Python 2.7.2 Any ideas on how I can retrieve timestamps and file sizes like DIR without raising exceptions? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Mon May 21 20:45:11 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 21 May 2012 17:45:11 -0700 (PDT) Subject: How to hide console with Popen on Windows? References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> <4dfb44cf-b5dc-47d0-895a-9de6f942ec23@googlegroups.com> Message-ID: <670eb456-eba6-4acc-8ed2-f1742e0d8ddc@pa10g2000pbc.googlegroups.com> On May 22, 3:00?am, xliiv wrote: > Now I know that my 'solution' is not a solution and problem still bugs me. > Any ideas how to deal with it? I haven't tried it but this thread talks about being able to use a standard install of Python with OpenOffice: http://user.services.openoffice.org/en/forum/viewtopic.php?t=26877 From drsalists at gmail.com Mon May 21 21:31:41 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 21 May 2012 18:31:41 -0700 Subject: bash/shell to python In-Reply-To: References: Message-ID: FWIW, I do manual argument parsing, because pylint understands how to detect typos with manual argument parsing, but not the highly dynamic modules that parse arguments. On Wed, May 16, 2012 at 7:16 PM, Rita wrote: > Hello, > > I currently build a lot of interfaces/wrappers to other applications using > bash/shell. One short coming for it is it lacks a good method to handle > arguments so I switched to python a while ago to use 'argparse' module. Its > a great complement to subprocess module. I was wondering if there is a > generic framework people follow to build python scripts which are replacing > shell scripts? Is there a guide or a template to follow? > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From simoncropper at fossworkflowguides.com Mon May 21 22:37:05 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 22 May 2012 12:37:05 +1000 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: References: <4FB59D37.1020709@fossworkflowguides.com> <4FB6FFF8.6070307@fossworkflowguides.com> Message-ID: <4FBAFBD1.1080300@fossworkflowguides.com> On 22/05/12 05:35, Sibylle Koczian wrote: > So I suppose you're using Python 2 or that's acceptable for you at > least. In this case I'd take a long look at Dabo: http://www.dabodev.com/ > That's based on wxPython but easier to use and explicitly made for > database applications. Developers and mailing list are especially > helpful and friendly. I have investigated Dabo. Dabo is OK but is like a big wizard. You fix you underlying data structure then it creates basic menus, data entry screens, etc. The basic stuff is OK but you need change the underlying code to customize the screens and you are bound to use the classes created by the developers (you can create you own but all sorts of interactions can happen apparently, and although it can be done, care needs to be taken to avoid conflicts -- the recommendation by the developers to is use the existing classes whenever possible). On top of this the project is not being developed any more. What is there, is what is there. The developers occasionally jump on the forums to propose a solution to an interesting problem but state that no further development will be happening. The community is still active however and there are a number of devotees. Personally, when I reviewed it, I wanted to develop a different dialog screen and database model than what Dabo is designed to address, which meant that I required to butcher their code and classes to achieve what I wanted. In my mind you are better starting from scratch using a maintained library/toolkit, rather than creating a hybrid system with a unmaintained project (that is unless you want to fork the project). -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From angeljanai at gmail.com Tue May 22 01:20:08 2012 From: angeljanai at gmail.com (angeljanai at gmail.com) Date: Mon, 21 May 2012 22:20:08 -0700 (PDT) Subject: 2.x,3.x iOS static build: Fatal Python error: exceptions bootstrapping error. In-Reply-To: <43d26adf-647a-4ffd-89de-7753cb0514e5@googlegroups.com> References: <43d26adf-647a-4ffd-89de-7753cb0514e5@googlegroups.com> Message-ID: well, I dont tested all, but at least error above was fixed by using build script from https://github.com/cobbal/python-for-iphone and patch from http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html From rustompmody at gmail.com Tue May 22 01:59:31 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 21 May 2012 22:59:31 -0700 (PDT) Subject: escaping/encoding/formatting in python References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> <0e358c78-fb71-4b28-a737-f9e6468cf2bc@a8g2000pbe.googlegroups.com> Message-ID: On Apr 6, 10:13?am, Steve Howell wrote: > On Apr 5, 9:59?pm,rusi wrote: > > > On Apr 6, 6:56?am,SteveHowell wrote: > > > > One of the biggest nuisances for programmers, just beneath date/time > > > APIs in the pantheon of annoyances, is that we are constantly dealing > > > with escaping/encoding/formatting issues. > > > [OT for this list] > > If you run > > $ find /usr/share/emacs/23.3/lisp/ -name '*.gz'|xargs zgrep '\\\\\\\\\\ > > \\\\\\' > > you can get quite a few results. > > > [Suitable assumptions: linux box with emacs installed] > > You've one-upped me with 2-to-the-N backslash escaping. ?I've written > useful scripts before with "\\\\\\\\" (scripts that went through > three > levels of interpretation), but four is setting a new bar. ?My use of > three exponentially increasing levels of backslashes back in the day > was like Beamon's jump in the Mexico City Olympics. ?An amazing feat > for its time, but every record > eventually gets broken. ?Well done. On a (somewhat distantly) related note, found this old fortune: Wouldn't the sentence 'I want to put a hyphen between the words Fish and And and And and Chips in my Fish-And-Chips sign' have been clearer if quotation marks had been placed before Fish, and between Fish and and, and and and And, and And and and, and and and And, and And and and, and and and Chips, as well as after Chips? From Rosie at omniumit.com Tue May 22 05:30:28 2012 From: Rosie at omniumit.com (Python Recruiter) Date: Tue, 22 May 2012 02:30:28 -0700 (PDT) Subject: Recruiting for Python Developer - Perm Message-ID: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> Can any one help? I am looking for a Senior Python Developer - Linux, AppScript, Adobe Illustrator - Bradford, Yorkshire - ?45,000 Our marketing and design client is looking to recruit an experienced Python developer for a senior position within their expanding organisation. Working independently, you will need a good background of developing Python on Linux, be an experienced software developer, have skills in C, SQL and any experience in Adobe Illustrator and Photoshop would also be beneficial. Our client has a number of blue- chip customers and your role will be to work on the packaging and branding of their products. Due to the nature of this role any additional experience in AppScript or Adobe Illustrator would be very beneficial - as long as you have a good understanding of client's requirements and can work to their needs though then these are not essential. Key skills required for this role are: 1. Python Development on Linux 2. Experienced Software Developer Desirable: 1. AppScript 2. Adobe Illustrator If any one can recommend, I will pay a ?100 recom fee for any successful placements. From mail at timgolden.me.uk Tue May 22 05:44:08 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 22 May 2012 10:44:08 +0100 Subject: Recruiting for Python Developer - Perm In-Reply-To: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> Message-ID: <4FBB5FE8.5090603@timgolden.me.uk> Someone will soon pop up and tell you that job ads are unwelcome on this list and that you should post to the Python Jobs board --> http://www.python.org/community/jobs/ However, the python-uk list is probably a better place for UK-focused jobs, as long as you have something which is definitely Python and definitely in the UK: http://mail.python.org/mailman/listinfo/python-uk TJG From jkn_gg at nicorp.f9.co.uk Tue May 22 06:50:16 2012 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 22 May 2012 03:50:16 -0700 (PDT) Subject: Recruiting for Python Developer - Perm References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> Message-ID: On May 22, 10:30?am, Python Recruiter wrote: > If any one can recommend, I will pay a ?100 recom fee for any > successful placements. aHaHaHaHaHa... And what percentage will you be charging your client? 15 percent? 25 percent? Even if you were to offer 15% of your (say) 15% commission you should be offering over a grand. I might well fit your profile, and know & like the Bradford area. I also use recruitment agencies when hiring. You're certainly off my list... Try doing a bit of research beforehand. There is a Python Jobs listing where you can make your paltry offer. J^n From jeanmichel at sequans.com Tue May 22 06:56:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 22 May 2012 12:56:26 +0200 Subject: Unexpected exception thrown in __del__ In-Reply-To: <4FBA655D.3010703@earthlink.net> References: <4FBA5F58.7060800@earthlink.net> <4FBA655D.3010703@earthlink.net> Message-ID: <4FBB70DA.6090703@sequans.com> Charles Hixson wrote: > On 05/21/2012 08:29 AM, Charles Hixson wrote: >> message excerpt: >> flush: sql = insert or replace into persists (id, name, data, rdCnt, >> rdTim, wrCnt, wrTim, deprecation) values (?, ?, ?, ?, ?, ?, ?, ?) >> Exception TypeError: "'NoneType' object is not callable" in > method Shelve2.__del__ of <__main__.Shelve2 object at >> 0x7ff4c0513f90>> ignored >> >> flush is being called from within __del__. I've narrowed it down to: >> print ("flush: sql = ", sql) >> curTim = nowI() >> print ("flush: curTim = ", curTim) >> >> nowI() is a function defined at the top of the file, and before the >> class, thus: >> def nowI(): >> t = int (time() * 100) >> return t >> >> All I can guess is that there's some reason that an external to the >> class function shouldn't be called during a __del__. Is this correct? >> > That seems to be the answer, as replacing the call to nowI() in > flush() with: > curTim = int (time() * 100) > fixes the problem. > > Rereading the documentation, I guess that this should have been > expected, but if nowI() were a static method of the class, would that > have avoided the problem? A class method? > > I may be stating somthing you already know, sorry if it happends. __del__ is *not* executed upon a del statement, so I hope you don't have any del(obj) assuming __del__ will be called. That is not true. __del__ is called when there's no reference to an object any more, *AND* when the python implementation feels in the mood for it, which is specific to that implemenation. There's a chance that a class method won't fix anything, if it does, it's not reliable anyway. Cheers, JM From jeanmichel at sequans.com Tue May 22 07:24:52 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 22 May 2012 13:24:52 +0200 Subject: Advantages of logging vs. print() In-Reply-To: References: Message-ID: <4FBB7784.9030802@sequans.com> Giampaolo Rodol? wrote: > Hi all, > I'm currently working on 1.0.0 release of pyftpdlib module. > This new release will introduce some backward incompatible changes in > that certain APIs will no longer accept bytes but unicode. > While I'm at it, as part of this breackage I was contemplating the > possibility to rewrite my logging functions, which currently use the > print statement, and use the logging module instead. > > As of right now pyftpdlib delegates the logging to 3 functions: > > def log(s): > """Log messages intended for the end user.""" > print s > > def logline(s): > """Log commands and responses passing through the command channel.""" > print s > > def logerror(s): > """Log traceback outputs occurring in case of errors.""" > print >> sys.stderr, s > > > The user willing to customize logs (e.g. write them to a file) is > supposed to just overwrite these 3 functions as in: > > > >>>> from pyftpdlib import ftpserver >>>> def log2file(s): >>>> > ... open(''ftpd.log', 'a').write(s) > ... > >>>> ftpserver.log = ftpserver.logline = ftpserver.logerror = log2file >>>> > > > Now I'm asking: what benefits would imply to get rid of this approach > and use logging module instead? > >From a module vendor perspective, how exactly am I supposed to > use/provide logging in my module? > Am I supposed to do this: > > import logging > logger = logging.getLogger("pyftpdlib") > > ...and state in my doc that "logger" is the object which is supposed > to be used in case the user wants to customize how logs behave? > Is logging substantially slower compared to print()? > > > Thanks in advance > > --- Giampaolo > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ > Well, getting all the features of the standard logging modules without writing a line is one huge benefit. It has among many other things : - Handlers: ability to handle logs in a different way, logging on stdout, on a file, on the network ... - Filters: ability to filter logs, depending on their severity, content or whatsoever - Thread safe - fully integrated with any other application using the logging module - configuration file - it's standard If you plan to release your module to the python community, using the logging module is something you should consider. Only by stating that your module is using the standard logging module will allow any user to configure it as they se fit. btw The code is usually the following: import logging logger = logging.getLogger(__name__) JM From kw at codebykevin.com Tue May 22 09:25:51 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 22 May 2012 09:25:51 -0400 Subject: Recruiting for Python Developer - Perm In-Reply-To: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> Message-ID: On 5/22/12 5:30 AM, Python Recruiter wrote: > Key skills required for this role are: > 1. Python Development on Linux > 2. Experienced Software Developer > > Desirable: > 1. AppScript > 2. Adobe Illustrator I'm in the U.S. so would not be applying for your position, but one thing your post neglects to mention is that competence on Mac OS X may also be required here. appscript is a Mac-specific technology (Python interface to Apple Event framework), and can be used to script Adobe Illustrator, which, of course, does not run on Linux. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From jeanmichel at sequans.com Tue May 22 09:31:52 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 22 May 2012 15:31:52 +0200 Subject: Wish: Allow all log Handlers to accept the level argument In-Reply-To: References: Message-ID: <4FBB9548.6000607@sequans.com> Fayaz Yusuf Khan wrote: > ***TRIVIAL ISSUE***, but this has been irking me for a while now. > The main logging.Handler class' __init__ accepts a level argument while none > of its children do. The poor minions seem to be stuck with the setLevel > method which considerably lengthens the code. > > In short: > Let's do this: > root.addHandler(FileHandler('debug.log', level=DEBUG) > Instead of this: > debug_file_handler = FileHandler('debug.log') > debug_file_handler.setLevel(DEBUG) > root.addHandler(debug_file_handler) > > Python 2.7 > -- > Cloud architect, Dexetra SS, Kochi, India > fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com > +91-9746-830-823 > > > Meanwhile you can shorten the code this way: root.addHandler(FileHandler('debug.log')) root.handlers[-1].setLevel(DEBUG) JM From emile at fenx.com Tue May 22 11:26:50 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 22 May 2012 08:26:50 -0700 Subject: DIR reports file timestamp and size, but os.path.getctime(), os.path.getsize() raise WindowsError [Error 5] Access is denied In-Reply-To: <1337644919.6007.140661078814021.0B9599BF@webmail.messagingengine.com> References: <1337644919.6007.140661078814021.0B9599BF@webmail.messagingengine.com> Message-ID: On 5/21/2012 5:01 PM python at bdurham.com said... > Wondering if any of you have stumbled across the following behavior: > Any ideas on how I can retrieve timestamps and file sizes like DIR > without raising exceptions? Beyond the obvious trap the error and use the commands module to run DIR directly? Emile From invalid at invalid.invalid Tue May 22 11:42:15 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 22 May 2012 15:42:15 +0000 (UTC) Subject: serial module References: Message-ID: On 2012-05-22, Albert van der Horst wrote: >># configure the serial connections (the parameters differs on the device >># you are connecting to) >>ser = serial.Serial( >> port='/dev/ttyUSB0', >> baudrate=19200, >> parity=serial.PARITY_ODD, >> stopbits=serial.STOPBITS_TWO, >> bytesize=serial.SEVENBITS >>) >> >>ser.open() >> >>Why do I get this error? > > You realize that these parameters relate to RS232 ports? /dev/ttyUSB0 is a serial port. In all likelyhood an RS-232 port, but it could be RS-485 or RS-422 or some other physical layer. In anycase it works just like a "normal" serial port such as /dev/ttyS0. > It is anybody's guess what they do in USB. They do exactly what they're supposed to regardless of what sort of bus is used to connect the CPU and the UART (ISA, PCI, PCI-express, USB, Ethernet, etc.). > The best answers is probably that it depends on the whim of whoever > implements the usb device. It does not depend on anybody's whim. The meaning of those parameters is well-defined. > Certainly this stuff is system dependant, No, it isn't. > so please start with stating which version kernel etc. of Linux you > run, and the output of lsusb --verbose. There's very probably no need for that. The drivers for the various USB-attached serial ports all work pretty much exactly like the normal ISA/PCI-attached drivers. The main things you'll notice are differences in buffer/fifo sizes and the timing of things like commands to set/clear modem control lines. -- Grant Edwards grant.b.edwards Yow! I didn't order any at WOO-WOO ... Maybe a YUBBA gmail.com ... But no WOO-WOO! From invalid at invalid.invalid Tue May 22 11:50:44 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 22 May 2012 15:50:44 +0000 (UTC) Subject: serial module References: Message-ID: On 2012-05-18, Ron Eggler wrote: > I'm trying to connect to a serial port and always get the error > "serial.serialutil.SerialException: Port is already open." which is > untrue. It is true. > I have no serial port open yet, my code looks like this: > #!/usr/bin/python > import time > import serial > > # configure the serial connections (the parameters differs on the device > # you are connecting to) > ser = serial.Serial( > port='/dev/ttyUSB0', > baudrate=19200, > parity=serial.PARITY_ODD, > stopbits=serial.STOPBITS_TWO, > bytesize=serial.SEVENBITS > ) The call above opened the port. Please see the pySerial documentation: http://pyserial.sourceforge.net/shortintro.html#opening-serial-ports Particularly the first example: Open port 0 at "9600,8,N,1" no timeout: >>> import serial >>> ser = serial.Serial(0) # open first serial port >>> print ser.portstr # check which port was really used >>> ser.write("hello") # write a string >>> ser.close() # close port And here to try to open and already-opened port: > ser.open() > > Why do I get this error? Becaue the port is already opened. :) -- Grant Edwards grant.b.edwards Yow! Sign my PETITION. at gmail.com From invalid at invalid.invalid Tue May 22 11:51:57 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 22 May 2012 15:51:57 +0000 (UTC) Subject: serial module References: <4fb6f977$0$87637$742ec2ed@news.sonic.net> Message-ID: On 2012-05-19, Paul Simon wrote: > "Ron Eggler" wrote: >> [...] my code looks like this: >> #!/usr/bin/python [...] >> port='/dev/ttyUSB0', > Sounds like you may be using this on a Windows machine. I don't think so. :) -- Grant Edwards grant.b.edwards Yow! Hello? Enema Bondage? at I'm calling because I want gmail.com to be happy, I guess ... From tymoteusz.jankowski at gmail.com Tue May 22 11:59:04 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Tue, 22 May 2012 08:59:04 -0700 (PDT) Subject: How to hide console with Popen on Windows? In-Reply-To: <670eb456-eba6-4acc-8ed2-f1742e0d8ddc@pa10g2000pbc.googlegroups.com> References: <5d9fbba0-f6a4-4afc-b49a-28608d70d351@googlegroups.com> <4dfb44cf-b5dc-47d0-895a-9de6f942ec23@googlegroups.com> <670eb456-eba6-4acc-8ed2-f1742e0d8ddc@pa10g2000pbc.googlegroups.com> Message-ID: <7d713089-9137-4911-b89d-6a779e932f72@googlegroups.com> On Tuesday, May 22, 2012 2:45:11 AM UTC+2, alex23 wrote: > On May 22, 3:00?am, xliiv wrote: > > Now I know that my 'solution' is not a solution and problem still bugs me. > > Any ideas how to deal with it? > > I haven't tried it but this thread talks about being able to use a > standard install of Python with OpenOffice: > > http://user.services.openoffice.org/en/forum/viewtopic.php?t=26877 On Tuesday, May 22, 2012 2:45:11 AM UTC+2, alex23 wrote: > On May 22, 3:00?am, xliiv wrote: > > Now I know that my 'solution' is not a solution and problem still bugs me. > > Any ideas how to deal with it? > > I haven't tried it but this thread talks about being able to use a > standard install of Python with OpenOffice: > > http://user.services.openoffice.org/en/forum/viewtopic.php?t=26877 On Tuesday, May 22, 2012 2:45:11 AM UTC+2, alex23 wrote: > On May 22, 3:00?am, xliiv wrote: > > Now I know that my 'solution' is not a solution and problem still bugs me. > > Any ideas how to deal with it? > > I haven't tried it but this thread talks about being able to use a > standard install of Python with OpenOffice: > > http://user.services.openoffice.org/en/forum/viewtopic.php?t=26877 On Tuesday, May 22, 2012 2:45:11 AM UTC+2, alex23 wrote: > On May 22, 3:00?am, xliiv wrote: > > Now I know that my 'solution' is not a solution and problem still bugs me. > > Any ideas how to deal with it? > > I haven't tried it but this thread talks about being able to use a > standard install of Python with OpenOffice: > > http://user.services.openoffice.org/en/forum/viewtopic.php?t=26877 Thx for the link It's useful especially that: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=26149 for my walkaround of the problem. From albert at spenarnc.xs4all.nl Tue May 22 12:28:00 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 May 2012 16:28:00 GMT Subject: serial module References: Message-ID: In article , Ron Eggler wrote: >Hoi, > >I'm trying to connect to a serial port and always get the error >"serial.serialutil.SerialException: Port is already open." whcih is untrue. >I have no serial port open yet, my code looks like this: >#!/usr/bin/python >import time >import serial > ># configure the serial connections (the parameters differs on the device ># you are connecting to) >ser = serial.Serial( > port='/dev/ttyUSB0', > baudrate=19200, > parity=serial.PARITY_ODD, > stopbits=serial.STOPBITS_TWO, > bytesize=serial.SEVENBITS >) > >ser.open() > >Why do I get this error? You realize that these parameters relate to RS232 ports? It is anybody's guess what they do in USB. The best answers is probably that it depends on the whim of whoever implements the usb device. Certainly this stuff is system dependant, so please start with stating which version kernel etc. of Linux you run, and the output of lsusb --verbose. > >Thank you, >Ron 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 imail at kuzzzya.ru Tue May 22 12:42:04 2012 From: imail at kuzzzya.ru (=?KOI8-R?B?6dfBziDn0s/Nz9c=?=) Date: Tue, 22 May 2012 20:42:04 +0400 Subject: Compiling debug Python 2.7 on Windows Message-ID: Hi, I'm trying to compile a debug version of Python 2.7 on Windows, but I've encountered some problems while creating a distribution.\ When I run PCbuild\python.exe setup.py bdist_wininst I get an error error: pyconfig.h: No such file or directory As far as I understand, I need to run something similar to ./configure on Linux, but I haven't found any information what the command should be. GnuWin32 autoconf also fails with errors. What is the correct way to build Python distribuiton from source on Windows? -- Best regards, Ivan Gromov -------------- next part -------------- An HTML attachment was scrubbed... URL: From shilparani9030 at gmail.com Tue May 22 13:15:41 2012 From: shilparani9030 at gmail.com (SHILPA) Date: Tue, 22 May 2012 10:15:41 -0700 (PDT) Subject: NEW HOT PHOTOS & VIDEOS Message-ID: <7886b79e-5c10-4f31-ad61-554cda0e8617@oe8g2000pbb.googlegroups.com> ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From k.sahithi2862 at gmail.com Tue May 22 13:17:25 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 22 May 2012 10:17:25 -0700 (PDT) Subject: NEW HOT PHOTOS & VIDEOS Message-ID: ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From ronDOTeggler at tscheemail.com Tue May 22 16:24:59 2012 From: ronDOTeggler at tscheemail.com (Ron Eggler) Date: Tue, 22 May 2012 13:24:59 -0700 Subject: serial module References: <4fb6f977$0$87637$742ec2ed@news.sonic.net> Message-ID: Grant Edwards wrote: > On 2012-05-19, Paul Simon wrote: >> "Ron Eggler" wrote: > >>> [...] my code looks like this: > >>> #!/usr/bin/python > [...] >>> port='/dev/ttyUSB0', > >> Sounds like you may be using this on a Windows machine. > > I don't think so. :) Nope it's Linmux but nevermind. I'm writing a C app instead. That's more in my line of fire too... :) Thanks, Ron --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From nagle at animats.com Tue May 22 16:47:35 2012 From: nagle at animats.com (John Nagle) Date: Tue, 22 May 2012 13:47:35 -0700 Subject: serial module In-Reply-To: References: Message-ID: On 5/22/2012 8:42 AM, Grant Edwards wrote: > On 2012-05-22, Albert van der Horst wrote: >> It is anybody's guess what they do in USB. > > They do exactly what they're supposed to regardless of what sort of > bus is used to connect the CPU and the UART (ISA, PCI, PCI-express, > USB, Ethernet, etc.). If a device is registered as /dev/ttyUSBnn, one would hope that the Linux USB insertion event handler, which assigns that name, determined that the device was a serial port emulator. Unfortunately, the USB standard device classes (http://www.usb.org/developers/defined_class) don't have "serial port emulator" as a standardized device. So there's more variation in this area than in keyboards, mice, or storage devices. > >> The best answers is probably that it depends on the whim of whoever >> implements the usb device. > > It does not depend on anybody's whim. The meaning of those parameters > is well-defined. > >> Certainly this stuff is system dependant, > > No, it isn't. It is, a little. There's a problem with the way Linux does serial ports. The only speeds allowed are the ones nailed into the kernel as named constants. This is a holdover from UNIX, which is a holdover from DEC PDP-11 serial hardware circa mid 1970s, which had 14 standard baud rates encoded in 4 bits. Really. In the Windows world, the actual baud rate is passed to the driver. Serial ports on the original IBM PC were loaded with a clock rate, so DOS worked that way. This only matters if you need non-standard baud rates. I've had to deal with that twice, for a SICK LMS LIDAR, (1,000,000 baud) and 1930s Teletype machines (45.45 baud). If you need non-standard speeds, see this: http://www.aetherltd.com/connectingusb.html If 19,200 baud is enough for you, don't worry about it. John Nagle From no.email at nospam.invalid Tue May 22 17:07:45 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 22 May 2012 14:07:45 -0700 Subject: serial module References: Message-ID: <7xy5ojrkke.fsf@ruckus.brouhaha.com> John Nagle writes: > If a device is registered as /dev/ttyUSBnn, one would hope that > the Linux USB insertion event handler, which assigns that name, > determined that the device was a serial port emulator. Unfortunately, > the USB standard device classes > (http://www.usb.org/developers/defined_class) don't have "serial port > emulator" as a standardized device. So there's more variation in this > area than in keyboards, mice, or storage devices. Hmm, I've been using USB-to-serial adapters and so far they've worked just fine. I plug the USB end of adapter into a Ubuntu box, see /dev/ttyUSB* appear, plug the serial end into the external serial device, and just use pyserial like with an actual serial port. I didn't realize there were issues with this. From nkwerk at gmail.com Tue May 22 17:10:37 2012 From: nkwerk at gmail.com (.) Date: Tue, 22 May 2012 14:10:37 -0700 (PDT) Subject: Django: metaWeblog: dir() doesn't show methods References: <7cf3c49d-9125-44d6-a040-5d53de904be8@w13g2000vbc.googlegroups.com> <2375fd42-4d5a-414c-9847-db596a03175a@l5g2000pbo.googlegroups.com> Message-ID: Thanks. From nagle at animats.com Tue May 22 17:24:08 2012 From: nagle at animats.com (John Nagle) Date: Tue, 22 May 2012 14:24:08 -0700 Subject: serial module In-Reply-To: <7xy5ojrkke.fsf@ruckus.brouhaha.com> References: <7xy5ojrkke.fsf@ruckus.brouhaha.com> Message-ID: On 5/22/2012 2:07 PM, Paul Rubin wrote: > John Nagle writes: >> If a device is registered as /dev/ttyUSBnn, one would hope that >> the Linux USB insertion event handler, which assigns that name, >> determined that the device was a serial port emulator. Unfortunately, >> the USB standard device classes >> (http://www.usb.org/developers/defined_class) don't have "serial port >> emulator" as a standardized device. So there's more variation in this >> area than in keyboards, mice, or storage devices. > > Hmm, I've been using USB-to-serial adapters and so far they've worked > just fine. I plug the USB end of adapter into a Ubuntu box, see > /dev/ttyUSB* appear, plug the serial end into the external serial > device, and just use pyserial like with an actual serial port. I didn't > realize there were issues with this. There are. See "http://wiki.debian.org/usbserial". Because there's no standard USB class for such devices, the specific vendor ID/product ID pair has to be known to the OS. In Linux, there's a file of these, but not all USB to serial adapters are in it. In Windows, there tends to be a vendor-provided driver for each brand of USB to serial converter. This all would have been much simpler if the USB Consortium had defined a USB class for these devices, as they did for keyboards, mice, etc. However, this is not the original poster's problem. John Nagle From invalid at invalid.invalid Tue May 22 17:58:58 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 22 May 2012 21:58:58 +0000 (UTC) Subject: serial module References: Message-ID: On 2012-05-22, John Nagle wrote: > On 5/22/2012 8:42 AM, Grant Edwards wrote: >> On 2012-05-22, Albert van der Horst wrote: > >>> It is anybody's guess what they do in USB. >> >> They do exactly what they're supposed to regardless of what sort of >> bus is used to connect the CPU and the UART (ISA, PCI, PCI-express, >> USB, Ethernet, etc.). > > If a device is registered as /dev/ttyUSBnn, one would hope that the > Linux USB insertion event handler, which assigns that name, > determined that the device was a serial port emulator. The fact that it shows up as /dev/tty means that the driver registered the port as a tty (serial) device. > Unfortunately, the USB standard device classes > (http://www.usb.org/developers/defined_class) don't have "serial port > emulator" as a standardized device. So there's more variation in > this area than in keyboards, mice, or storage devices. I've used a log of USB connected serial devices, and they all worked fine. Some show up as /dev/ttyUSBn and some as /dev/ttyACMn, but the standard tty APIs all worked fine. What sorts of vartiations have you seen? >>> The best answers is probably that it depends on the whim of whoever >>> implements the usb device. >> >> It does not depend on anybody's whim. The meaning of those >> parameters is well-defined. >> >>> Certainly this stuff is system dependant, >> >> No, it isn't. > > It is, a little. There's a problem with the way Linux does serial > ports. The only speeds allowed are the ones nailed into the kernel > as named constants. That hasn't been true for years. The termios2 structure allows arbitrary baud rates. I don't know if all low-level serial drivers support that API, but I believe all the in-kernel ones do (and I know the out-of-kernel one's I maintain do). The UART hardware may have limits in the buad-clock divider chains that limit the number of baud rates that can be generated, but that's a different problem. > In the Windows world, the actual baud rate is passed to the driver. That's also how it works with a modern Linux serial driver. You use "struct termios2" instead of "struct termios" TCGETS2 et al instead of TCGETS et al. Here's source code for a command-line utility to set a Linux serial port to an arbitrary baud rate: http://www.panix.com/~grante/files/arbitrary-baud.c That said, the POSIX APIs in the libc implementations I know about (glibc, uClibc) unfortunately haven't caught up yet. :) > Serial ports on the original IBM PC were loaded with a clock rate, so > DOS worked that way. > > This only matters if you need non-standard baud rates. I've had to > deal with that twice, for a SICK LMS LIDAR, (1,000,000 baud) and > 1930s Teletype machines (45.45 baud). We run our Sick LMS units at 500,000 baud, and bog-standard Linux kernels support that just fine. -- Grant Edwards grant.b.edwards Yow! I'm having a BIG BANG at THEORY!! gmail.com From invalid at invalid.invalid Tue May 22 18:00:22 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 22 May 2012 22:00:22 +0000 (UTC) Subject: serial module References: <7xy5ojrkke.fsf@ruckus.brouhaha.com> Message-ID: On 2012-05-22, Paul Rubin wrote: > John Nagle writes: >> If a device is registered as /dev/ttyUSBnn, one would hope that >> the Linux USB insertion event handler, which assigns that name, >> determined that the device was a serial port emulator. Unfortunately, >> the USB standard device classes >> (http://www.usb.org/developers/defined_class) don't have "serial port >> emulator" as a standardized device. So there's more variation in this >> area than in keyboards, mice, or storage devices. > > Hmm, I've been using USB-to-serial adapters and so far they've worked > just fine. I plug the USB end of adapter into a Ubuntu box, see > /dev/ttyUSB* appear, plug the serial end into the external serial > device, and just use pyserial like with an actual serial port. I didn't > realize there were issues with this. I've used probably a dozen different ones. I've read about some people having odd problems with them, but I've never seen any of the those problems. They've all "just worked" for me. -- Grant Edwards grant.b.edwards Yow! He is the MELBA-BEING at ... the ANGEL CAKE gmail.com ... XEROX him ... XEROX him -- From ben+python at benfinney.id.au Tue May 22 18:20:51 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 23 May 2012 08:20:51 +1000 Subject: Please use the Python Job Board for recruiting (was: Recruiting for Python Developer - Perm) References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> Message-ID: <87mx4z7t8c.fsf@benfinney.id.au> Python Recruiter writes: > Can any one help? I am looking for a Senior Python Developer Yes, please use the Python Job Board for this purpose instead . Good hunting! -- \ ?Probably the earliest flyswatters were nothing more than some | `\ sort of striking surface attached to the end of a long stick.? | _o__) ?Jack Handey | Ben Finney From drsalists at gmail.com Tue May 22 19:34:54 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 22 May 2012 16:34:54 -0700 Subject: Please use the Python Job Board for recruiting (was: Recruiting for Python Developer - Perm) In-Reply-To: <87mx4z7t8c.fsf@benfinney.id.au> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> Message-ID: On Tue, May 22, 2012 at 3:20 PM, Ben Finney wrote: > Python Recruiter writes: > > > Can any one help? I am looking for a Senior Python Developer > > Yes, please use the Python Job Board for this purpose instead > . > > Good hunting! I find it more than a little disappointing that the Python Job Board doesn't do latitude and longitude. It's a big missed opportunity. Yes, it's not an identical process from nation to nation, but it's still important. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Tue May 22 19:39:50 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 23 May 2012 01:39:50 +0200 Subject: virtualenv and jython on Ubuntu 12.04 Message-ID: Hi, I wanted to do some first experiments with Jython (which should now be able to run django apps) Thus I wanted to create a virtualenv setup for jython with following command: virtualenv -p jython --no-site-packages ~/mypy However this fails with following output: > Running virtualenv with interpreter /usr/bin/jython > The --no-site-packages flag is deprecated; it is now the default behavior. > Cannot find file /usr/share/jython/cachedir (bad symlink) > New jython executable in /home/gelonida/mypy/bin/jython > ERROR: The executable /home/gelonida/mypy/bin/jython is not functioning > ERROR: It thinks sys.prefix is u'/usr/share/jython' (should be u'/home/gelonida/mypy') > ERROR: virtualenv is not compatible with this system or executable > > The jython version is: > jython -V > Jython 2.5.1+ virtualenv version is What would the best way to start with a clean jython setup? Or can I avoid virtualenv and have other means of trying to install Django for jython on Ubuntu 12.04? From gelonida at gmail.com Tue May 22 19:44:24 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 23 May 2012 01:44:24 +0200 Subject: Install python 2.6 and python 2.7 on Windows Message-ID: I'd like to install python 2.6 and 2.7 on Windows? In fact I have already 2.6 installed and would like to additionally install 2.7 When clicking on .py file I'd like to execute it with python 2.6 If I really wanted to run 2.7 I'd call the code with %SystemDrive%\Python27\Python program.py Thanks in advance for tips. From gelonida at gmail.com Tue May 22 19:47:26 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 23 May 2012 01:47:26 +0200 Subject: install python 2.6 on Ubuntu 12.04 Message-ID: Hi, On Ubuntu 12.04 python 2.7 is the default version I'd like to install python 2.6 parallel to 2.7 and create a virtualenv for it. The reason is, that I have to write some code, that will be executed under 2.6 and I want to be sure, that I don't accidentally write code, that would no more run on 2.6. What would be the recommended way to install (compile) 2.6 on 12.04? From drsalists at gmail.com Tue May 22 20:09:15 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 22 May 2012 17:09:15 -0700 Subject: install python 2.6 on Ubuntu 12.04 In-Reply-To: References: Message-ID: If the pythons you require are in synaptic (sudo to root and run synaptic), you probably can just use them. If not, then you, for each release, need to: 1) download a tarball using a browser or whatever 2) extract the tarball: tar xvfp foo.tar.bz2 3) cd into the newly created, top-level directory, and run ./configure --prefix /usr/local/cpython-2.6 (or similar) 4) Run "make", optionally with parallelism; I often use number_of_cores+1, so for a quad core system, I might use "make -j 5". This speeds up the build. 5) Run /usr/local/cpython-2.6/bin/python - just to make sure it gives a prompt. control-d to exit. 6) Try running your script with one of your new python builds: /usr/local/cpython-2.6/bin/python my-script I've done this for 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and the 3.3 preview stuff. They cooperate with each other well. Actually, I scripted out the build so that I'd get all 7 built automatically with cython and pylint in them. On Tue, May 22, 2012 at 4:47 PM, Gelonida N wrote: > Hi, > > On Ubuntu 12.04 python 2.7 is the default version > > I'd like to install python 2.6 parallel to 2.7 and create a virtualenv for > it. > > The reason is, that I have to write some code, that will be executed under > 2.6 and I want to be sure, that I don't accidentally write code, that would > no more run on 2.6. > > What would be the recommended way to install (compile) 2.6 on 12.04? > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Tue May 22 20:28:00 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 22 May 2012 19:28:00 -0500 Subject: Install python 2.6 and python 2.7 on Windows In-Reply-To: References: Message-ID: <4FBC2F10.6030606@gmail.com> On 5/22/2012 6:44 PM, Gelonida N wrote: > I'd like to install python 2.6 and 2.7 on Windows? > > > In fact I have already 2.6 installed and would like to additionally > install 2.7 > > > > When clicking on .py file I'd like to execute it with python 2.6 There is an checkbox for an option to associate the newly installed Python with .py/.pyw files that you can uncheck during installation... -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From benjamin.kaplan at case.edu Tue May 22 20:51:44 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 22 May 2012 20:51:44 -0400 Subject: install python 2.6 on Ubuntu 12.04 In-Reply-To: References: Message-ID: On Tue, May 22, 2012 at 8:09 PM, Dan Stromberg wrote: > > If the pythons you require are in synaptic (sudo to root and run synaptic), > you probably can just use them. > > If not, then you, for each release, need to: > 1) download a tarball using a browser or whatever > 2) extract the tarball: tar xvfp foo.tar.bz2 > 3) cd into the newly created, top-level directory, and run ./configure > --prefix /usr/local/cpython-2.6 (or similar) > 4) Run "make", optionally with parallelism; I often use number_of_cores+1, > so for a quad core system, I might use "make -j 5".? This speeds up the > build. > 5) Run /usr/local/cpython-2.6/bin/python - just to make sure it gives a > prompt.? control-d to exit. > 6) Try running your script with one of your new python builds: > /usr/local/cpython-2.6/bin/python my-script > > I've done this for 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and the 3.3 preview stuff. > They cooperate with each other well.? Actually, I scripted out the build so > that I'd get all 7 built automatically with cython and pylint in them. > > Even easier: ./configure make sudo make altinstall If I recall correctly, that will install it in /usr/local/lib/python2.6 and it will create /usr/local/bin/python2.6 but it will not create /usr/local/bin/python so it won't clobber the system python. From sdouche at gmail.com Tue May 22 21:00:53 2012 From: sdouche at gmail.com (Sebastien Douche) Date: Wed, 23 May 2012 03:00:53 +0200 Subject: install python 2.6 on Ubuntu 12.04 In-Reply-To: References: Message-ID: On Wed, May 23, 2012 at 1:47 AM, Gelonida N wrote: > What would be the recommended way to install (compile) 2.6 on 12.04? Hi, I manage my own Python interpreters with Pythonbrew (I don't use the global Python): http://pypi.python.org/pypi/pythonbrew/ -- Sebastien Douche Twitter: @sdouche / G+: +sdouche From skippy.hammond at gmail.com Wed May 23 00:45:43 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 23 May 2012 14:45:43 +1000 Subject: Compiling debug Python 2.7 on Windows In-Reply-To: References: Message-ID: <4FBC6B77.5080106@gmail.com> On 23/05/2012 2:42 AM, ???? ?????? wrote: > Hi, > > I'm trying to compile a debug version of Python 2.7 on Windows, but I've > encountered some problems while creating a distribution.\ > When I run > PCbuild\python.exe setup.py bdist_wininst > I get an error > error: pyconfig.h: No such file or directory > As far as I understand, I need to run something similar to ./configure on Linux, > but I haven't found any information what the command should be. GnuWin32 > autoconf also fails with errors. What is the correct way to build Python > distribuiton from source on Windows? I believe the correct way is still to load the PCBuild/PCBuild.sln file as a project in MS Visual Studio 2008. Cheers, Mark > > -- > Best regards, Ivan Gromov > > > From michele.simionato at gmail.com Wed May 23 02:21:35 2012 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 22 May 2012 23:21:35 -0700 (PDT) Subject: A better contextlib.contextmanager Message-ID: Python 3.2 enhanced contextlib.contextmanager so that it is possible to use a context manager as a decorator. For instance, given the contextmanager factory below @contextmanager def before_after(): print(before) yield print(after) it is possibile to use it to generate decorators: @before_after() def hello(user): print('hello', user) This is equivalent to the more traditional def hello(user): with before_after(): print('hello', user) but it has the advantage of saving a level of indentation and we all know that flat is better than nested. Cool, but there are three issues: 1. I am using Python 2.7, not Python 3.2, so contextmanager has not such feature 2. The contextmanager decorator is losing the signature of the before_after factory: >>> help(before_after) Help on function before_after in module __main__: before_after(*args, **kwds) 3. before_after() decorators do not preserve the signature of the decorated function either. Since I am the author of the decorator module I have easily found out a recipe to solve both issues. Here it is: from decorator import decorator, FunctionMaker from contextlib import GeneratorContextManager class GeneratorCM(GeneratorContextManager): def __call__(self, func): return FunctionMaker.create( func, "with _cm_: return _func_(%(shortsignature)s)", dict(_cm_=self, _func_=func), __wrapped__=func) @decorator def contextmanager(func, *args, **kwds): return GeneratorCM(func(*args, **kwds)) before_after() objects obtained by using this version of contextmanager become signature-preserving decorators. I am not going to explain how FunctionMaker performs its magic (hint: it uses eval), but I am asking a question instead: should I add this feature to the next release of the decorator module? Do people use the context-manager-as-decorator functionality? It is quite handy in unit tests and actually I think it came from the unittest2 module. But I am reluctant to complicate the API of the module, which currently is really really small and such has been for many years. From lists at cheimes.de Wed May 23 03:40:53 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 23 May 2012 09:40:53 +0200 Subject: install python 2.6 on Ubuntu 12.04 In-Reply-To: References: Message-ID: Am 23.05.2012 02:51, schrieb Benjamin Kaplan: > Even easier: > > ./configure > make > sudo make altinstall > > If I recall correctly, that will install it in > /usr/local/lib/python2.6 and it will create /usr/local/bin/python2.6 > but it will not create /usr/local/bin/python so it won't clobber the > system python. You recall correctly. That's the recommended and correct way to install Python 2.6 on a recent machine, with one exception. You must compile it with the option MACHDEP=linux2, otherwise sys.platform will contain the string "linux3" [1]. You also must set LDFLAGS and some other flags because Python 2.6 doesn't support multiarch systems. [2] It's all in my blog. My default settings are: export arch=$(dpkg-architecture -qDEB_HOST_MULTIARCH) export LDFLAGS="-L/usr/lib/$arch -L/lib/$arch" export CFLAGS="-I/usr/include/$arch" export CPPFLAGS="-I/usr/include/$arch" ./configure --enable-shared --enable-unicode=ucs4 --config-cache make MACHDEP=linux2 -j3 sudo make altinstall Christian [1] http://lipyrary.blogspot.de/2011/09/python-and-linux-kernel-30-sysplatform.html [2] http://lipyrary.blogspot.de/2011/05/how-to-compile-python-on-ubuntu-1104.html From lists at cheimes.de Wed May 23 03:49:23 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 23 May 2012 09:49:23 +0200 Subject: install python 2.6 on Ubuntu 12.04 In-Reply-To: References: Message-ID: Am 23.05.2012 09:40, schrieb Christian Heimes: > You recall correctly. That's the recommended and correct way to install > Python 2.6 on a recent machine, with one exception. You must compile it > with the option MACHDEP=linux2, otherwise sys.platform will contain the > string "linux3" [1]. You also must set LDFLAGS and some other flags > because Python 2.6 doesn't support multiarch systems. [2] It's all in my > blog. I almost forgot, you have to patch the _ssl module, too. diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -302,8 +302,10 @@ self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */ else if (proto_version == PY_SSL_VERSION_SSL3) self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */ +#ifndef OPENSSL_NO_SSL2 else if (proto_version == PY_SSL_VERSION_SSL2) self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */ +#endif else if (proto_version == PY_SSL_VERSION_SSL23) self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ PySSL_END_ALLOW_THREADS From jeanmichel at sequans.com Wed May 23 05:27:28 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 23 May 2012 11:27:28 +0200 Subject: Please use the Python Job Board for recruiting In-Reply-To: References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> Message-ID: <4FBCAD80.903@sequans.com> Dan Stromberg wrote: > > On Tue, May 22, 2012 at 3:20 PM, Ben Finney > > wrote: > > Python Recruiter > > writes: > > > Can any one help? I am looking for a Senior Python Developer > > Yes, please use the Python Job Board for this purpose instead > . > > Good hunting! > > > I find it more than a little disappointing that the Python Job Board > doesn't do latitude and longitude. It's a big missed opportunity. > Yes, it's not an identical process from nation to nation, but it's > still important. > > > Sorry for asking but what do you mean by "doing latitude and longitude". I tried dictionaries + google and didn't find how these geographical terms apply to job boards. Since you said it's important... JM From astromantic3 at gmail.com Wed May 23 05:30:20 2012 From: astromantic3 at gmail.com (20_feet_tall) Date: Wed, 23 May 2012 02:30:20 -0700 (PDT) Subject: Korean fonts on Python 2.6 (MacOsX) Message-ID: <34dbf7bf-5d87-4f4f-ada2-a92fc1f166bf@oe8g2000pbb.googlegroups.com> I have a problem with the visualization of korean fonts on Python. When I try to type in the characters only squares come out. I have tried to install the CJK codec, the hangul 1.0 codec but still no result. Hoep someone can help me out. From rosuav at gmail.com Wed May 23 05:44:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 May 2012 19:44:29 +1000 Subject: Please use the Python Job Board for recruiting In-Reply-To: <4FBCAD80.903@sequans.com> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> <4FBCAD80.903@sequans.com> Message-ID: On Wed, May 23, 2012 at 7:27 PM, Jean-Michel Pichavant wrote: > Sorry for asking but what do you mean by "doing latitude and longitude". I > tried dictionaries + google and didn't find how these geographical terms > apply to job boards. Since you said it's important... My understanding of that is to distinguish UK postings from US, etc. It's not much use finding out about a job in Buxton when you don't know whether that's in Victoria or Derbyshire. (And yes, I'm aware that some won't know where either of those areas would be. Suffice it to say that they're approximately as far apart as two places can be while sharing this planet.) ChrisA From chris at python.org Wed May 23 06:30:58 2012 From: chris at python.org (Chris Withers) Date: Wed, 23 May 2012 11:30:58 +0100 Subject: Please use the Python Job Board for recruiting In-Reply-To: References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> Message-ID: <4FBCBC62.5080506@python.org> On 23/05/2012 00:34, Dan Stromberg wrote: > > I find it more than a little disappointing that the Python Job Board > doesn't do latitude and longitude. It's a big missed opportunity. Yes, > it's not an identical process from nation to nation, but it's still > important. If you had experience of how incompetent the majority of recruiters are, you'd realise that this is a pretty futile hope ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From franck at ditter.org Wed May 23 08:04:44 2012 From: franck at ditter.org (Franck Ditter) Date: Wed, 23 May 2012 14:04:44 +0200 Subject: How to launch idle -n on windows ? Message-ID: I have some problems with Python 3.2 on Windows. I want to use the turtle package, works fine, but I can't close the turtle windows. On MacOS-X, I launch idle -n and it's fine. How can I do that on Windows ? Thanks, fd From 1248283536 at qq.com Wed May 23 08:23:10 2012 From: 1248283536 at qq.com (=?gb18030?B?y66+ssH3ye4=?=) Date: Wed, 23 May 2012 20:23:10 +0800 Subject: append method Message-ID: >>> s=[1,2,3] >>> s.append(5) >>> s [1, 2, 3, 5] >>> s=s.append(5) >>> s >>> print s None why can't s=s.append(5) ,what is the reason? -------------- next part -------------- An HTML attachment was scrubbed... URL: From nulla.epistola at web.de Wed May 23 09:54:31 2012 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 23 May 2012 15:54:31 +0200 Subject: GUI toolkits and dynamic table browser widget In-Reply-To: <4FBAFBD1.1080300@fossworkflowguides.com> References: <4FB59D37.1020709@fossworkflowguides.com> <4FB6FFF8.6070307@fossworkflowguides.com> <4FBAFBD1.1080300@fossworkflowguides.com> Message-ID: Am 22.05.2012 04:37, schrieb Simon Cropper: > On 22/05/12 05:35, Sibylle Koczian wrote: >> So I suppose you're using Python 2 or that's acceptable for you at >> least. In this case I'd take a long look at Dabo: http://www.dabodev.com/ >> That's based on wxPython but easier to use and explicitly made for >> database applications. Developers and mailing list are especially >> helpful and friendly. > > I have investigated Dabo. > > Dabo is OK but is like a big wizard. > > You fix you underlying data structure then it creates basic menus, > data entry screens, etc. The basic stuff is OK but you need change the > underlying code to customize the screens and you are bound to use the > classes created by the developers (you can create you own but all sorts > of interactions can happen apparently, and although it can be done, care > needs to be taken to avoid conflicts -- the recommendation by the > developers to is use the existing classes whenever possible). > > On top of this the project is not being developed any more. What is > there, is what is there. The developers occasionally jump on the forums > to propose a solution to an interesting problem but state that no > further development will be happening. The community is still active > however and there are a number of devotees. > This looks to me more like a description of the Dabo Application wizard which is just one possible way to start your Dabo application - not the only way and not the preferred way. And as far as I can see from change log and mailing list it isn't true that Dabo isn't developed any more. But it really can be difficult to do non standard things in a Dabo application, that's quite right. On the other hand no GUI programming in Python is exactly easy, is it? Sibylle From jeanmichel at sequans.com Wed May 23 10:26:25 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 23 May 2012 16:26:25 +0200 Subject: append method In-Reply-To: References: Message-ID: <4FBCF391.1040003@sequans.com> ???? wrote: > >>> s=[1,2,3] > >>> s.append(5) > >>> s > [1, 2, 3, 5] > >>> s=s.append(5) > >>> s > >>> print s > None > > why can't s=s.append(5) ,what is the reason? Because the append method returns None, not the object. It modifies the object in place, and does not create any copy. You can still write s = s + [5] if you really want to, but what's the point ? JM From seededfromstars at gmail.com Wed May 23 13:14:24 2012 From: seededfromstars at gmail.com (seededfromstars at gmail.com) Date: Wed, 23 May 2012 10:14:24 -0700 (PDT) Subject: Fallen Angels, Originators of Evil on Planet Earth? In-Reply-To: References: Message-ID: I don't believe that angels originated evil. Take a look at this book http://www.amazon.com/The-Change-Freiderici-Ms/dp/147508076X/ref=sr_1_1?ie=UTF8&qid=1337792796&sr=8-1 From nagle at animats.com Wed May 23 14:19:55 2012 From: nagle at animats.com (John Nagle) Date: Wed, 23 May 2012 11:19:55 -0700 Subject: escaping/encoding/formatting in python In-Reply-To: References: <437faa74-07a3-4062-abfa-8135c0710f3e@n5g2000pbg.googlegroups.com> Message-ID: On 4/5/2012 10:10 PM, Steve Howell wrote: > On Apr 5, 9:59 pm, rusi wrote: >> On Apr 6, 6:56 am, Steve Howell wrote: > You've one-upped me with 2-to-the-N backspace escaping. Early attempts at UNIX word processing, "nroff" and "troff", suffered from that problem, due to a badly designed macro system. A question in language design is whether to escape or quote. Do you write "X = %d" % (n,)) or "X = " + str(n) In general, for anything but output formatting, the second scales better. Regular expressions have a bad case of the first. For a quoted alternative to regular expression syntax, see SNOBOL or Icon. SNOBOL allows naming patterns, and those patterns can then be used as components of other patterns. SNOBOL is obsolete, but that approach produced much more readable code. John Nagle From zahlman at gmail.com Wed May 23 15:10:08 2012 From: zahlman at gmail.com (Karl Knechtel) Date: Wed, 23 May 2012 15:10:08 -0400 Subject: append method In-Reply-To: References: Message-ID: On Wed, May 23, 2012 at 8:23 AM, ???? <1248283536 at qq.com> wrote: >>>> s=[1,2,3] >>>> s.append(5) >>>> s > [1, 2, 3, 5] >>>> s=s.append(5) >>>> s >>>> print s > None > > why can't? s=s.append(5)? ,what is the reason? For the same reason that you don't see `[1, 2, 3, 5]` immediately after doing `s.append(5)` the first time around, but must instead check `s`: because the value is not returned from the function. `s` is modified in-place, and nothing is returned. This was a deliberate design decision made a long time ago that is very well documented; try Googling for `python why doesn't list.append return the value` for example. -- ~Zahlman {:> From emile at fenx.com Wed May 23 15:13:19 2012 From: emile at fenx.com (Emile van Sebille) Date: Wed, 23 May 2012 12:13:19 -0700 Subject: append method In-Reply-To: References: Message-ID: On 5/23/2012 5:23 AM ???? said... > >>> s=[1,2,3] > >>> s.append(5) > >>> s > [1, 2, 3, 5] > >>> s=s.append(5) > >>> s > >>> print s > None > > why can't s=s.append(5) It could, but it doesn't. > ,what is the reason? A design decision -- there's currently a mix of methods that return themselves and not. Mostly is appears to me that mutables modify in place without returning self and immutables return the new value. But that's simply my observation. Emile From d at davea.name Wed May 23 15:42:55 2012 From: d at davea.name (Dave Angel) Date: Wed, 23 May 2012 15:42:55 -0400 Subject: append method In-Reply-To: References: Message-ID: <4FBD3DBF.5090604@davea.name> On 05/23/2012 03:13 PM, Emile van Sebille wrote: > On 5/23/2012 5:23 AM ???? said... >> >>> s=[1,2,3] >> >>> s.append(5) >> >>> s >> [1, 2, 3, 5] >> >>> s=s.append(5) >> >>> s >> >>> print s >> None >> >> why can't s=s.append(5) > > It could, but it doesn't. > > >> ,what is the reason? > > > A design decision -- there's currently a mix of methods that return > themselves and not. Mostly is appears to me that mutables modify in > place without returning self and immutables return the new value. > > But that's simply my observation. > > Emile > > It's simpler than that. Methods/functions either modify the object (or one of their arguments), or return the results, but generally not both. So sorted() returns a sorted list without modifying the input. And the sort() method modifies the list, but does not return it. So you're right that methods on non-mutables must return the new value, since they can't modify the object. -- DaveA From wanderer at dialup4less.com Wed May 23 16:06:40 2012 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 23 May 2012 13:06:40 -0700 (PDT) Subject: PyDev IPython Confusion Message-ID: I have two versions of Python and Ipython; Python 2.6.6 with Ipython 0.11 and Python 2.7.3 with Ipython 0.12. When I run the Eclipse PyDev console for the Python 2.7.3 it says it is using Ipython 0.11 as the interpreter. Ipython 0.11 should not be in the Path for Python 2.7.3. Is this a bug in Ipython 0.12? Is there a command to check the Ipython version to verify it is Ipython 0.11 and not Ipython 0.12? Could this be something in the Windows registry that Ipython 0.11 is the 'registered' version of Ipython? Thanks From ckaynor at zindagigames.com Wed May 23 16:31:32 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 23 May 2012 13:31:32 -0700 Subject: append method In-Reply-To: <4FBD3DBF.5090604@davea.name> References: <4FBD3DBF.5090604@davea.name> Message-ID: On Wed, May 23, 2012 at 12:42 PM, Dave Angel wrote: > On 05/23/2012 03:13 PM, Emile van Sebille wrote: >> A design decision -- there's currently a mix of methods that return >> themselves and not. ?Mostly is appears to me that mutables modify in >> place without returning self and immutables return the new value. >> > > It's simpler than that. ?Methods/functions either modify the object (or > one of their arguments), or return the results, but generally not both. > So sorted() returns a sorted list without modifying the input. ?And the > sort() method modifies the list, but does not return it. ?So you're > right that methods on non-mutables must return the new value, since they > can't modify the object. While this is true, its also important to keep in mind that, mostly due to magic methods, what appears to be a single function call my be multiple, and as such there are cases which appear to do both. Consider sorted on a generator. It returns the result, but the magic method __iter__ is implicitly called by sorted, and mutates the generator. Aside from those cases, the only cases I can think of in the Python standard library are cases where the code is only intended to be used directly in the interpreter, and not scripted, namely debugging aids such as pstats, where the convenience of having both outweighs the potential of confusion. From kevin.s.anthony at gmail.com Wed May 23 16:36:59 2012 From: kevin.s.anthony at gmail.com (Kevin Anthony) Date: Wed, 23 May 2012 16:36:59 -0400 Subject: Question about argparse and namespace Message-ID: the documentation says argparse.prase_args creates a new empty namespace, but if i pass it a existing namespace, it seems to append the arguments to the existing namespace An example is if it's part of a class, calling parser.parse_args(namespace=self) doesn't seem to have any ill effects. Is this a good idea? is there a better way of doing this? -- Thanks Kevin Anthony Do you use Banshee? Download the Community Extensions: http://banshee.fm/download/extensions/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed May 23 16:45:47 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 23 May 2012 15:45:47 -0500 Subject: Install python 2.6 and python 2.7 on Windows In-Reply-To: <4FBD47B3.2070006@gmail.com> References: <4FBC2F10.6030606@gmail.com> <4FBD47B3.2070006@gmail.com> Message-ID: <4FBD4C7B.7020709@gmail.com> On 5/23/2012 3:25 PM, Gelonida N wrote: > So I just install 2.7 and uncheck this box and I'll keep 2.6 right? Different versions are installed in different locations by default, and if you uncheck that box, the installer will leave file associations alone. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From no1.woot at gmail.com Wed May 23 17:10:19 2012 From: no1.woot at gmail.com (no1) Date: Wed, 23 May 2012 14:10:19 -0700 (PDT) Subject: problem loading matlab data with ompc and python Message-ID: <82406634-ca5d-419d-807f-d065623fb20e@googlegroups.com> Hi, we're investigating transitioning our company from matlab to python. We found OMPC as a MATLAB m-file-to Python translator, but we're encountering a problem using the translated code to import MATLAB data structures into Python. For example, when we save data within MATLAB this way: x.a = 5; x.b = 6; save -v6 test x this saves data in test.mat, with MATLAB version 6 compatibility (OMPC says it's not compatible with the latest versions of MATLAB). The code to read in data in MATLAB is just load test and when we run it through OMPC we get load(mstring('test.mat')) but when we run it we get the error message File "ompclib\ompclib_numpy.py", line 1496, in load KeyError: "[('a', '|O4'), ('b', '|O4')]" Reading in simpler data (up to arrays) does not have this problem. To get other people in the company to transition, we were hoping that the translation process could be done in one step or on the fly. We could read in MATLAB data using I/O functions imported from scipy, but then the transition isn't seamless any more. Is there a simple fix to using OMPC? Or a similar alternative that would work better? Thanks From hsaziz at gmail.com Wed May 23 19:45:05 2012 From: hsaziz at gmail.com (hsaziz at gmail.com) Date: Wed, 23 May 2012 16:45:05 -0700 (PDT) Subject: Python Book for a C Programmer? Message-ID: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. From breamoreboy at yahoo.co.uk Wed May 23 20:11:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 24 May 2012 01:11:38 +0100 Subject: Install python 2.6 and python 2.7 on Windows In-Reply-To: <4FBD4C7B.7020709@gmail.com> References: <4FBC2F10.6030606@gmail.com> <4FBD47B3.2070006@gmail.com> <4FBD4C7B.7020709@gmail.com> Message-ID: On 23/05/2012 21:45, Andrew Berg wrote: > On 5/23/2012 3:25 PM, Gelonida N wrote: >> So I just install 2.7 and uncheck this box and I'll keep 2.6 right? > Different versions are installed in different locations by default, and > if you uncheck that box, the installer will leave file associations alone. > I find it amazing that this doesn't come up more often http://www.python.org/dev/peps/pep-0397/ -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed May 23 20:19:36 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 24 May 2012 01:19:36 +0100 Subject: Please use the Python Job Board for recruiting In-Reply-To: <4FBCBC62.5080506@python.org> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> <4FBCBC62.5080506@python.org> Message-ID: On 23/05/2012 11:30, Chris Withers wrote: > On 23/05/2012 00:34, Dan Stromberg wrote: >> >> I find it more than a little disappointing that the Python Job Board >> doesn't do latitude and longitude. It's a big missed opportunity. Yes, >> it's not an identical process from nation to nation, but it's still >> important. > > If you had experience of how incompetent the majority of recruiters are, > you'd realise that this is a pretty futile hope ;-) > > Chris > I believe that that the eleventh commandment is "Thou shalt not extract the urine". How could you be so rude to recruiters? You are a cruel, hard and absolutely correct man :) -- Cheers. Mark Lawrence. From drsalists at gmail.com Wed May 23 21:03:56 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 23 May 2012 18:03:56 -0700 Subject: Please use the Python Job Board for recruiting In-Reply-To: <4FBCAD80.903@sequans.com> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> <4FBCAD80.903@sequans.com> Message-ID: On Wed, May 23, 2012 at 2:27 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Dan Stromberg wrote: > >> >> On Tue, May 22, 2012 at 3:20 PM, Ben Finney > ben+python at benfinney.**id.au >> wrote: >> >> Python Recruiter > >> writes: >> >> > Can any one help? I am looking for a Senior Python Developer >> >> Yes, please use the Python Job Board for this purpose instead >> >> >. >> >> Good hunting! >> >> I find it more than a little disappointing that the Python Job Board >> doesn't do latitude and longitude. It's a big missed opportunity. Yes, >> it's not an identical process from nation to nation, but it's still >> important. >> >> >> >> Sorry for asking but what do you mean by "doing latitude and longitude". > I tried dictionaries + google and didn't find how these geographical terms > apply to job boards. Since you said it's important... > Latitude and longitude are kind of the earth-wide way of describing a position on the surface of the earth. If you have them, you can figure out how many miles there are between your domicile, and your place of employment (or candidate employment). Latitude and longitude are getting easier to find with the popularity of GPS units and cell phones with GPS, but there are ways of converting things like a USA zip code to latitude and longitude as well. Personally, I don't want to relocate, so the _place_ an employer resides tends to matter quite a bit to me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed May 23 21:22:35 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 23 May 2012 18:22:35 -0700 Subject: Please use the Python Job Board for recruiting In-Reply-To: <4FBCBC62.5080506@python.org> References: <717a8369-dda8-4a2c-8f8d-4e22d0da7511@v10g2000vbe.googlegroups.com> <87mx4z7t8c.fsf@benfinney.id.au> <4FBCBC62.5080506@python.org> Message-ID: On Wed, May 23, 2012 at 3:30 AM, Chris Withers wrote: > On 23/05/2012 00:34, Dan Stromberg wrote: > >> >> I find it more than a little disappointing that the Python Job Board >> doesn't do latitude and longitude. It's a big missed opportunity. Yes, >> it's not an identical process from nation to nation, but it's still >> important. >> > > If you had experience of how incompetent the majority of recruiters are, > you'd realise that this is a pretty futile hope ;-) > Recruiter skill aside, the best user interface would probably ask for a zip code or something analogous (this probably varies a lot country by country), and convert that to something universal like latitude and longitude internally prior to doing math on the locations. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at rhubarbfizz.com Wed May 23 23:24:10 2012 From: astan.chee at rhubarbfizz.com (Astan) Date: Wed, 23 May 2012 20:24:10 -0700 (PDT) Subject: Applying a patch from a diff in python (if possible) Message-ID: Hi, I'm trying to synch up two databases that are very far from each other using diff and patch. Currently, what happens is a mysqldump on database A (which is linux) which is sent over to database B and over time the diff of this mysql is sent over to database B. The database B lives on a NAS server without any linux machines available (all of them are windows 7s) to apply the patch to the diff. I've been looking into the python diff modules and it seems that most can't deal with files (these .diff files are large and binary since the data in the database is all sorts of binary). Also I've had a look at the patch.exe program for windows which also complains about the file being binary (or something. i've tried all sorts of flags and they don't seem to work). Are there any patch modules out there that I'm missing? The diff_patch_match module doesn't seem to like the diffs with angle brackets Thanks for any help From astan.chee at rhubarbfizz.com Wed May 23 23:42:17 2012 From: astan.chee at rhubarbfizz.com (Astan) Date: Wed, 23 May 2012 20:42:17 -0700 (PDT) Subject: Applying a patch from a diff in python (if possible) References: Message-ID: On May 24, 1:24?pm, Astan wrote: > Hi, > I'm trying to synch up two databases that are very far from each other > using diff and patch. Currently, what happens is a mysqldump on > database A (which is linux) which is sent over to database B and over > time the diff of this mysql is sent over to database B. The database B > lives on a NAS server without any linux machines available (all of > them are windows 7s) to apply the patch to the diff. I've been looking > into the python diff modules and it seems that most can't deal with > files (these .diff files are large and binary since the data in the > database is all sorts of binary). Also I've had a look at the > patch.exe program for windows which also complains about the file > being binary (or something. i've tried all sorts of flags and they > don't seem to work). Are there any patch modules out there that I'm > missing? The diff_patch_match module doesn't seem to like the diffs > with angle brackets > Thanks for any help Ignore me. I just figured out cygwin. From fayaz.yusuf.khan at gmail.com Thu May 24 01:24:51 2012 From: fayaz.yusuf.khan at gmail.com (Fayaz Yusuf Khan) Date: Thu, 24 May 2012 10:54:51 +0530 Subject: Wish: Allow all log Handlers to accept the level argument References: <4FBB9548.6000607@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Meanwhile you can shorten the code this way: > > root.addHandler(FileHandler('debug.log')) > root.handlers[-1].setLevel(DEBUG) > Eh? Readability was the aim. -- Fayaz Yusuf Khan Cloud architect, Dexetra SS, India fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com +91-9746-830-823 From ethan at stoneleaf.us Thu May 24 01:57:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 23 May 2012 22:57:39 -0700 Subject: A better contextlib.contextmanager In-Reply-To: References: Message-ID: <4FBDCDD3.7080604@stoneleaf.us> Michele Simionato wrote: > but I am asking a question instead: should I add this feature to the > next release of the decorator module? I think it would be an excellent addition to your module. ~Ethan~ From michael.poeltl at univie.ac.at Thu May 24 02:45:17 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Thu, 24 May 2012 08:45:17 +0200 Subject: Python Book for a C Programmer? In-Reply-To: References: Message-ID: <20120524064517.GK5468@terra.cms.at> hi, take 'Pro Python' (by Marty Alchin) regards Michael * hsaziz at gmail.com [2012-05-24 07:54]: > I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From ulrich.eckhardt at dominolaser.com Thu May 24 02:58:30 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 24 May 2012 08:58:30 +0200 Subject: Python Book for a C Programmer? In-Reply-To: References: Message-ID: Am 24.05.2012 01:45, schrieb hsaziz at gmail.com: > I am trying to join an online class that uses python. I need to brush > up on the language quickly. Is there a good book or resource that > covers it well but does not have to explain what an if..then..else > statement is? First thing to check first is whether the online course uses Python 2 or Python 3. For Python 2, try starting at docs.python.org. There you will find library documentation, language specifications and also tutorials. Uli From __peter__ at web.de Thu May 24 03:22:49 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 May 2012 09:22:49 +0200 Subject: Wish: Allow all log Handlers to accept the level argument References: Message-ID: Fayaz Yusuf Khan wrote: > ***TRIVIAL ISSUE***, but this has been irking me for a while now. > The main logging.Handler class' __init__ accepts a level argument while > none of its children do. The poor minions seem to be stuck with the > setLevel method which considerably lengthens the code. > > In short: > Let's do this: > root.addHandler(FileHandler('debug.log', level=DEBUG) > Instead of this: > debug_file_handler = FileHandler('debug.log') > debug_file_handler.setLevel(DEBUG) > root.addHandler(debug_file_handler) > > Python 2.7 Your suggestion comes too late for Python 2 for which only bugfixes are accepted. For Python 3.3 you could write a patch and make a feature request on http://bugs.python.org/ . From merwin.irc at gmail.com Thu May 24 03:31:40 2012 From: merwin.irc at gmail.com (Thibaut DIRLIK) Date: Thu, 24 May 2012 09:31:40 +0200 Subject: Working with dates : complex problem Message-ID: Hi, I've a list of python objects with dates attributes. This list is ordered by one of these date. Elements mandatory follow each other : Element #1 Element #2 Element #3 |-------------------------|--------------|--------------------------| Now, I want to "insert" an element in this timeline. This imply that I will have to resize some elements : Element #1 Element #2 Element #3 |-------------------------|--------------|--------------------------| New element |----------------------| And after resize : Element #1 New element Element #2 Element #3 |---------|----------------------|---------|--------------------------| |----------------------| My question is the following : how can I know (easily) which elements my "New element" is "over", which, in my example would have returned ['Element #1', 'Element #2']. Elements objets are simple Python objects with dates : obj.begin = datetime() obj.end = datetime() I'm looking for the more Pythonic way to handle this problem, thanks ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu May 24 04:50:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 May 2012 08:50:59 GMT Subject: Namespace hack Message-ID: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> >From the Zen of Python ("import this"): Namespaces are one honking great idea -- let's do more of those! Inspired by this, I have a decorator that abuses function closures to create a namespace type with the following properties: - all methods are static methods that do not take a "self" parameter; - methods can see "class variables"; - external callers can see selected methods and attributes. An example may make this clearer. In a regular class: class C: x = 42 def spam(self, y): return self.x + y def ham(self, z): return self.spam(z+1) Notice that the class attribute x is visible to the outside caller, but methods spam and ham cannot see it except by prefixing it with a reference to "self". Here's an example using my namespace hack example: @namespace def C(): # Abuse nested functions to make this work. x = 42 def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) # Need an explicit return to make methods visible. However, class attribute x is not exposed. You may consider this a feature, rather than a bug. To expose a class attribute, define it in the outer function argument list: @namespace def C(x=42): def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) And in use: >>> C.x 42 >>> C.spam(100) 142 >>> C.ham(999) 1042 Here's the namespace decorator: import inspect def namespace(func): spec = inspect.getargspec(func) ns = {'__doc__': func.__doc__} for name, value in zip(spec.args, spec.defaults or ()): ns[name] = value function = type(lambda: None) exported = func() or () try: len(exported) except TypeError: exported = (exported,) for obj in exported: if isinstance(obj, function): ns[obj.__name__] = staticmethod(obj) else: raise TypeError('bad export') Namespace = type(func.__name__, (), ns) return Namespace() Have fun! -- Steven From __peter__ at web.de Thu May 24 05:04:55 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 May 2012 11:04:55 +0200 Subject: Working with dates : complex problem References: Message-ID: Thibaut DIRLIK wrote: > Hi, > > I've a list of python objects with dates attributes. This list is ordered > by one of these date. Elements mandatory follow each other : > > Element #1 Element #2 Element #3 > |-------------------------|--------------|--------------------------| > > Now, I want to "insert" an element in this timeline. This imply that I > will have to resize some elements : > > Element #1 Element #2 Element #3 > |-------------------------|--------------|--------------------------| > New element > |----------------------| > > And after resize : > > Element #1 New element Element #2 Element #3 > |---------|----------------------|---------|--------------------------| > > |----------------------| > > My question is the following : how can I know (easily) which elements my > "New element" is "over", which, > in my example would have returned ['Element #1', 'Element #2']. > > Elements objets are simple Python objects with dates : > > obj.begin = datetime() > obj.end = datetime() > > I'm looking for the more Pythonic way to handle this problem, thanks ! Untested: def insert(timeline, interval): keys = [item.begin for item in timeline] where = bisect.bisect(keys, interval.begin) if where > 0: # adjust previous interval to avoid a gap or an intersection timeline[where-1].end = interval.begin # remove intervals covered by the new interval while where < len(timeline) and timeline[where].end < interval.end: del timeline[where] if where < len(timeline): # adjust subsequent interval to avoid gap or intersection timeline[where].begin = interval.end timeline.insert(where, interval) If you implement comparison for your interval type you won't need the intermediate keys list. The functools.total_ordering decorator may help you with that. From ulrich.eckhardt at dominolaser.com Thu May 24 05:09:57 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 24 May 2012 11:09:57 +0200 Subject: Korean fonts on Python 2.6 (MacOsX) In-Reply-To: <34dbf7bf-5d87-4f4f-ada2-a92fc1f166bf@oe8g2000pbb.googlegroups.com> References: <34dbf7bf-5d87-4f4f-ada2-a92fc1f166bf@oe8g2000pbb.googlegroups.com> Message-ID: <5ga199-3j5.ln1@satorlaser.homedns.org> Am 23.05.2012 11:30, schrieb 20_feet_tall: > I have a problem with the visualization of korean fonts on Python. > When I try to type in the characters only squares come out. > I have tried to install the CJK codec, the hangul 1.0 codec but still > no result. What exactly do you mean with "visualization"? Python itself doesn't do any visualization, all it does is to manage data. This data can be bytes exchanged with e.g. a terminal window or a file. If the file uses encoding A for some text, but Python interprets the bytes according to encoding B, no good will come of it. Similarly, if the console window expects Python to output one encoding and Python uses a different encoding, bad things happen. Further, but that now has almost nothing to do with Python directly, if the console window tries to render a character that is not contained in the current font, it will fail. The typical behaviour then is to fall back to some placeholder char, like the square you describe. Summary: It's not clear enough what you did, so it's impossible to tell what went wrong. It could also help if you told us what you wanted to achieve. That said, Python 2.7 has been out for a while, and I'd consider upgrading. Uli From jeanmichel at sequans.com Thu May 24 05:38:34 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 24 May 2012 11:38:34 +0200 Subject: Wish: Allow all log Handlers to accept the level argument In-Reply-To: References: <4FBB9548.6000607@sequans.com> Message-ID: <4FBE019A.9030603@sequans.com> Fayaz Yusuf Khan wrote: > Jean-Michel Pichavant wrote: > >> Meanwhile you can shorten the code this way: >> >> root.addHandler(FileHandler('debug.log')) >> root.handlers[-1].setLevel(DEBUG) >> >> > Eh? Readability was the aim. > I fail to see how it's not readable, code is short and no magic is involved provided you know about slicing list items. Anyway, to answer your question on why addHandler do not return the handler, I'll quote Dave Angel from a recent thread about "why s.append(5) does not return s": "It's simpler than that. Methods/functions either modify the object (or one of their arguments), or return the results, but generally not both. So sorted() returns a sorted list without modifying the input. And the sort() method modifies the list, but does not return it. So you're right that methods on non-mutables must return the new value, since they can't modify the object." JM From __peter__ at web.de Thu May 24 06:23:15 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 May 2012 12:23:15 +0200 Subject: Wish: Allow all log Handlers to accept the level argument References: <4FBB9548.6000607@sequans.com> <4FBE019A.9030603@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Fayaz Yusuf Khan wrote: >> Jean-Michel Pichavant wrote: >> >>> Meanwhile you can shorten the code this way: >>> >>> root.addHandler(FileHandler('debug.log')) >>> root.handlers[-1].setLevel(DEBUG) >>> >>> >> Eh? Readability was the aim. >> > I fail to see how it's not readable, code is short and no magic is > involved provided you know about slicing list items. Anyway, to answer You have to know or verify that .addHandler() appends to the .handlers list, you have to check if or under which conditions h = SomeHandler() root.addHandler(h) assert h is root.handlers[-1] can fail. In short, if I see such a hack my trust in the author of that code is significantly lowered. From jeanmichel at sequans.com Thu May 24 06:48:17 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 24 May 2012 12:48:17 +0200 Subject: Wish: Allow all log Handlers to accept the level argument In-Reply-To: References: <4FBB9548.6000607@sequans.com> <4FBE019A.9030603@sequans.com> Message-ID: <4FBE11F1.3070001@sequans.com> Peter Otten wrote: > Jean-Michel Pichavant wrote: > > >> Fayaz Yusuf Khan wrote: >> >>> Jean-Michel Pichavant wrote: >>> >>> >>>> Meanwhile you can shorten the code this way: >>>> >>>> root.addHandler(FileHandler('debug.log')) >>>> root.handlers[-1].setLevel(DEBUG) >>>> >>>> >>>> >>> Eh? Readability was the aim. >>> >>> >> I fail to see how it's not readable, code is short and no magic is >> involved provided you know about slicing list items. Anyway, to answer >> > > You have to know or verify that .addHandler() appends to the .handlers list, > you have to check if or under which conditions > > h = SomeHandler() > root.addHandler(h) > assert h is root.handlers[-1] > > can fail. In short, if I see such a hack my trust in the author of that code > is significantly lowered. > > I now fail to see how it's a hack. handlers is a public attribute of loggers. FYI def addHandler(self, hdlr): """ Add the specified handler to this logger. """ if not (hdlr in self.handlers): self.handlers.append(hdlr) Cheers, JM From __peter__ at web.de Thu May 24 07:13:43 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 May 2012 13:13:43 +0200 Subject: Wish: Allow all log Handlers to accept the level argument References: <4FBB9548.6000607@sequans.com> <4FBE019A.9030603@sequans.com> <4FBE11F1.3070001@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Peter Otten wrote: >> Jean-Michel Pichavant wrote: >> >> >>> Fayaz Yusuf Khan wrote: >>> >>>> Jean-Michel Pichavant wrote: >>>> >>>> >>>>> Meanwhile you can shorten the code this way: >>>>> >>>>> root.addHandler(FileHandler('debug.log')) >>>>> root.handlers[-1].setLevel(DEBUG) >>>>> >>>>> >>>>> >>>> Eh? Readability was the aim. >>>> >>>> >>> I fail to see how it's not readable, code is short and no magic is >>> involved provided you know about slicing list items. Anyway, to answer >>> >> >> You have to know or verify that .addHandler() appends to the .handlers >> list, you have to check if or under which conditions >> >> h = SomeHandler() >> root.addHandler(h) >> assert h is root.handlers[-1] >> >> can fail. In short, if I see such a hack my trust in the author of that >> code is significantly lowered. >> >> > I now fail to see how it's a hack. handlers is a public attribute of > loggers. Can you come up with a setup that makes the above assertion fail? I can think of three: - adding a handler twice - adding a singleton handler - adding handlers from multiple threads > FYI > > def addHandler(self, hdlr): > """ > Add the specified handler to this logger. > """ Subject to change. I think in current Python > if not (hdlr in self.handlers): > self.handlers.append(hdlr) is protected by a lock. From wrw at mac.com Thu May 24 07:50:13 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Thu, 24 May 2012 07:50:13 -0400 Subject: Python Book for a C Programmer? In-Reply-To: References: Message-ID: On May 23, 2012, at 7:45 PM, hsaziz at gmail.com wrote: > I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list My preference is "Python Essential Reference" by Beazley. You can find it and several reviews here: http://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786/ref=sr_1_1?s=books&ie=UTF8&qid=1337859988&sr=1-1 -Bill From rmorgan466 at gmail.com Thu May 24 07:58:49 2012 From: rmorgan466 at gmail.com (Rita) Date: Thu, 24 May 2012 07:58:49 -0400 Subject: other languages API to python Message-ID: Hello, A vendor provided a C, C++ and Java API for a application. They dont support python so I would like to create a library for it. My question is, how hard/easy would it be to create something like this? Is there a simple HOWTO or examples I can follow? Can someone shed home light on this? TIA -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjandacw at cox.net Thu May 24 08:06:41 2012 From: tjandacw at cox.net (Tim Williams) Date: Thu, 24 May 2012 05:06:41 -0700 (PDT) Subject: problem loading matlab data with ompc and python References: <82406634-ca5d-419d-807f-d065623fb20e@googlegroups.com> Message-ID: <30be053a-2c34-4652-8bf6-79b7e61f29a3@h10g2000yqn.googlegroups.com> On May 23, 5:10?pm, no1 wrote: > Hi, we're investigating transitioning our company from matlab to python. We found OMPC as a MATLAB m-file-to Python translator, but we're encountering a problem using the translated code to import MATLAB data structures into Python. For example, when we save data within MATLAB this way: > > x.a = 5; > x.b = 6; > save -v6 test x > > this saves data in test.mat, with MATLAB version 6 compatibility (OMPC says it's not compatible with the latest versions of MATLAB). The code to read in data in MATLAB is just > > load test > > and when we run it through OMPC we get > > load(mstring('test.mat')) > > but when we run it we get the error message > > File "ompclib\ompclib_numpy.py", line 1496, in load > KeyError: "[('a', '|O4'), ('b', '|O4')]" > > Reading in simpler data (up to arrays) does not have this problem. > > To get other people in the company to transition, we were hoping that the translation process could be done in one step or on the fly. We could read in MATLAB data using I/O functions imported from scipy, but then the transition isn't seamless any more. > > Is there a simple fix to using OMPC? Or a similar alternative that would work better? > > Thanks Have you tried using loadmat from the scipy.io module? http://docs.scipy.org/doc/scipy/reference/io.html From rosuav at gmail.com Thu May 24 08:25:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 May 2012 22:25:09 +1000 Subject: other languages API to python In-Reply-To: References: Message-ID: On Thu, May 24, 2012 at 9:58 PM, Rita wrote: > Hello, > > A vendor provided a C, C++ and Java API for a application. They dont support > python so I would like to create a library for it. My question is, how > hard/easy would it be to create something like this? Is there a simple HOWTO > or examples I can follow? Can someone shed home light on this? The best way would be to write something in C that exposes the API to Python. Check out the docs on "Extending and Embedding Python": For Python 2.x: http://docs.python.org/extending/ For Python 3.x: http://docs.python.org/py3k/extending/ You'll need to learn Python's own API, of course, but if you're a competent C programmer, you should find it fairly straightforward. There's an alternative, too, though I haven't personally used it. The ctypes module allows you to directly call a variety of C-provided functions. http://docs.python.org/library/ctypes.html http://docs.python.org/py3k/library/ctypes.html The resulting code isn't nearly as Pythonic as it could be if you write a proper wrapper, but you save the work of writing C code. Chris Angelico From nikunjparmar.it at gmail.com Thu May 24 08:32:16 2012 From: nikunjparmar.it at gmail.com (niks) Date: Thu, 24 May 2012 05:32:16 -0700 (PDT) Subject: Email Id Verification Message-ID: Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Can anyone tell me how to use this and what is the meaning of this \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* From rosuav at gmail.com Thu May 24 08:41:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 24 May 2012 22:41:41 +1000 Subject: Email Id Verification In-Reply-To: References: Message-ID: On Thu, May 24, 2012 at 10:32 PM, niks wrote: > Hello everyone.. > I am new to asp.net... > I want to use Regular Expression validator in Email id verification.. > Can anyone tell me how to use this and what is the meaning of > this > \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* This is a mailing list about Python, not ASP, and not regular expressions. Every regex library is different, some more than others, so your best bet is to find documentation on the actual function/library you'll be using. But I would strongly recommend NOT using a regex to validate an email address. It's prone to false positives and false negatives. There are, unfortunately, many systems around which do not accept legal addresses (for instance, "this.is.valid+1 at rosuav.com" is, as the name suggests, quite valid - as is "fred_foobar@[203.214.67.43]"); part of the blame can be laid on PHP's inbuilt validation functions, but I know that several are implemented using a fairly simple and brutally wrong check. Validate the domain part (the bit after the @) with a DNS lookup, nothing more and nothing less. If you absolutely must do a syntactic/charset check, read the appropriate RFCs and figure out what really is and isn't legal. You will be surprised. (For instance, "foo at localhost" is a perfectly valid address, because "localhost" is a top-level domain.) Chris Angelico From alister.ware at ntlworld.com Thu May 24 08:54:51 2012 From: alister.ware at ntlworld.com (alister) Date: Thu, 24 May 2012 12:54:51 GMT Subject: Email Id Verification References: Message-ID: On Thu, 24 May 2012 05:32:16 -0700, niks wrote: > Hello everyone.. > I am new to asp.net... > I want to use Regular Expression validator in Email id verification.. > Can anyone tell me how to use this and what is the meaning of this > \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* this is not really a python question. I would suggest you locate a good regular expression tutorial & then try to break it down otherwise you could try asking in an asp.net forum -- Sometimes when presented with a problem you will think "I know I will use regular expressions" Now you have two problems. From alister.ware at ntlworld.com Thu May 24 08:56:25 2012 From: alister.ware at ntlworld.com (alister) Date: Thu, 24 May 2012 12:56:25 GMT Subject: Python Book for a C Programmer? References: Message-ID: On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: > I am trying to join an online class that uses python. I need to brush up > on the language quickly. Is there a good book or resource that covers it > well but does not have to explain what an if..then..else statement is? > > Thanks. Dive into python seems to be quite popular & can be read online fro free -- If life gives you lemons, make lemonade. From fetchinson at googlemail.com Thu May 24 09:04:34 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 24 May 2012 15:04:34 +0200 Subject: Namespace hack In-Reply-To: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> Message-ID: > >From the Zen of Python ("import this"): > > Namespaces are one honking great idea -- let's do more of those! > > > Inspired by this, I have a decorator that abuses function closures to > create a namespace type with the following properties: > > - all methods are static methods that do not take a "self" parameter; > > - methods can see "class variables"; > > - external callers can see selected methods and attributes. > > > An example may make this clearer. > > In a regular class: > > class C: > x = 42 > def spam(self, y): > return self.x + y > def ham(self, z): > return self.spam(z+1) > > > Notice that the class attribute x is visible to the outside caller, but > methods spam and ham cannot see it except by prefixing it with a > reference to "self". > > Here's an example using my namespace hack example: > > @namespace > def C(): # Abuse nested functions to make this work. > x = 42 > def spam(y): > return x + y > def ham(z): > return spam(z+1) > return (spam, ham) # Need an explicit return to make methods visible. > > However, class attribute x is not exposed. You may consider this a > feature, rather than a bug. To expose a class attribute, define it in the > outer function argument list: > > @namespace > def C(x=42): > def spam(y): > return x + y > def ham(z): > return spam(z+1) > return (spam, ham) > > > > And in use: > >>>> C.x > 42 >>>> C.spam(100) > 142 >>>> C.ham(999) > 1042 > > > > Here's the namespace decorator: > > import inspect > > def namespace(func): > spec = inspect.getargspec(func) > ns = {'__doc__': func.__doc__} > for name, value in zip(spec.args, spec.defaults or ()): > ns[name] = value > function = type(lambda: None) > exported = func() or () > try: > len(exported) > except TypeError: > exported = (exported,) > for obj in exported: > if isinstance(obj, function): > ns[obj.__name__] = staticmethod(obj) > else: > raise TypeError('bad export') > Namespace = type(func.__name__, (), ns) > return Namespace() > > > Have fun! Funny, you got to the last line of "import this" but apparently skipped the second line: Explicit is better than implicit. And you didn't even post your message on April 1 so no, I can't laugh even though I'd like to. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jstitch at invernalia.homelinux.net Thu May 24 09:28:49 2012 From: jstitch at invernalia.homelinux.net (Javier Novoa C.) Date: Thu, 24 May 2012 13:28:49 +0000 (UTC) Subject: Python Book for a C Programmer? References: Message-ID: On 2012-05-24, alister wrote: > On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: > >> I am trying to join an online class that uses python. I need to brush up >> on the language quickly. Is there a good book or resource that covers it >> well but does not have to explain what an if..then..else statement is? >> >> Thanks. > > Dive into python seems to be quite popular & can be read online fro free > > Learning Python by Mark Lutz, from O'Reilly is a good one, I've been reading it and it also enforces a comparison between C programming and Python. However, it's focused on Python 2, but it also mentions Python 3 things in the text... -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to news at netfront.net --- From robertvstepp at gmail.com Thu May 24 09:34:24 2012 From: robertvstepp at gmail.com (boB Stepp) Date: Thu, 24 May 2012 08:34:24 -0500 Subject: Python Book for a C Programmer? In-Reply-To: References: Message-ID: On Thu, May 24, 2012 at 8:28 AM, Javier Novoa C. wrote: > On 2012-05-24, alister wrote: >> On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: >> >>> I am trying to join an online class that uses python. I need to brush up >>> on the language quickly. Is there a good book or resource that covers it >>> well but does not have to explain what an if..then..else statement is? >>> >>> Thanks. >> >> Dive into python seems to be quite popular & can be read online fro free >> >> > > Learning Python by Mark Lutz, from O'Reilly is a good one, I've been > reading it and it also enforces a comparison between C programming and > Python. However, it's focused on Python 2, but it also mentions Python > 3 things in the text... > There is a new edition out, copyright 2010 if I recall correctly, that updates its coverage to Python 3.x, which is the book's primary focus, though it points out where 3.x syntax does not work in version 2.x. Cheers! boB From mlangenhoven at gmail.com Thu May 24 10:14:18 2012 From: mlangenhoven at gmail.com (mlangenhoven at gmail.com) Date: Thu, 24 May 2012 07:14:18 -0700 (PDT) Subject: Dynamic comparison operators Message-ID: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> I would like to pass something like this into a function test(val1,val2,'>=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? From phil.le.bienheureux at gmail.com Thu May 24 10:32:11 2012 From: phil.le.bienheureux at gmail.com (Phil Le Bienheureux) Date: Thu, 24 May 2012 16:32:11 +0200 Subject: Dynamic comparison operators In-Reply-To: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> References: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> Message-ID: Hello, You can pass an operator as an argument to your function. See : http://docs.python.org/library/operator.html Regards, ---------- Forwarded message ---------- From: Date: 2012/5/24 Subject: Dynamic comparison operators To: python-list at python.org I would like to pass something like this into a function test(val1,val2,'>=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Thu May 24 10:37:03 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 24 May 2012 16:37:03 +0200 Subject: Dynamic comparison operators References: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> Message-ID: <87ehq9wsq8.fsf@dpt-info.u-strasbg.fr> mlangenhoven at gmail.com writes: > I would like to pass something like this into a function > test(val1,val2,'>=') > > and it should come back with True or False. def test(x,y,c): return c(x,y) Call with: test(v1,v2, lambda x,y:x<=y ). A bit noisy imho. If you have a finite number of comparison operators, put them in a dict: compares = dict([ ("<",lambda x,y:x References: Message-ID: On 05/23/2012 07:45 PM, hsaziz at gmail.com wrote: > I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? > > Thanks. My opinion: Martelli's "Python in a Nutshell" is the K&R of Python. Alas, it does discuss if statements, but it doesn't slap you silly with them. From no1.woot at gmail.com Thu May 24 15:47:18 2012 From: no1.woot at gmail.com (no1) Date: Thu, 24 May 2012 12:47:18 -0700 (PDT) Subject: problem loading matlab data with ompc and python In-Reply-To: <30be053a-2c34-4652-8bf6-79b7e61f29a3@h10g2000yqn.googlegroups.com> References: <82406634-ca5d-419d-807f-d065623fb20e@googlegroups.com> <30be053a-2c34-4652-8bf6-79b7e61f29a3@h10g2000yqn.googlegroups.com> Message-ID: <6ef9449e-6a8a-4bc2-a325-63f59ea055c7@googlegroups.com> On Thursday, May 24, 2012 5:06:41 AM UTC-7, Tim Williams wrote: > On May 23, 5:10?pm, no1 wrote: > > Hi, we're investigating transitioning our company from matlab to python. We found OMPC as a MATLAB m-file-to Python translator, but we're encountering a problem using the translated code to import MATLAB data structures into Python. For example, when we save data within MATLAB this way: > > > > x.a = 5; > > x.b = 6; > > save -v6 test x > > > > this saves data in test.mat, with MATLAB version 6 compatibility (OMPC says it's not compatible with the latest versions of MATLAB). The code to read in data in MATLAB is just > > > > load test > > > > and when we run it through OMPC we get > > > > load(mstring('test.mat')) > > > > but when we run it we get the error message > > > > File "ompclib\ompclib_numpy.py", line 1496, in load > > KeyError: "[('a', '|O4'), ('b', '|O4')]" > > > > Reading in simpler data (up to arrays) does not have this problem. > > > > To get other people in the company to transition, we were hoping that the translation process could be done in one step or on the fly. We could read in MATLAB data using I/O functions imported from scipy, but then the transition isn't seamless any more. > > > > Is there a simple fix to using OMPC? Or a similar alternative that would work better? > > > > Thanks > > Have you tried using loadmat from the scipy.io module? > > http://docs.scipy.org/doc/scipy/reference/io.html Yes (I mentioned the scipi I/O module near the end of my original post) but we were hoping not to have to require the users to learn any Python to start. The simpler the process, the less resistance to using the "new" Python methodology; we were hoping the use of a single "black box" like translator (OMPC) would be enough. We'd really like to avoid any additional steps for the user, like rewriting code, otherwise the users are going to resist the transition. From scott.siegler at gmail.com Thu May 24 16:22:43 2012 From: scott.siegler at gmail.com (Scott Siegler) Date: Thu, 24 May 2012 13:22:43 -0700 (PDT) Subject: Help doing it the "python way" Message-ID: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Hello, I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more "C" style syntax. I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? thanks! From duncan.booth at invalid.invalid Thu May 24 16:53:46 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 May 2012 20:53:46 GMT Subject: Help doing it the "python way" References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: Scott Siegler wrote: > Hello, > > I am an experienced programmer but a beginner to python. As such, I > can figure out a way to code most algorithms using more "C" style > syntax. > > I am doing something now that I am sure is a more python way but i > can't quite get it right. I was hoping someone might help. > > So I have a list of grid coordinates (x, y). From that list, I want > to create a new list that for each coordinate, I add the coordinate > just above and just below (x,y+1) and (x,y-1) > > right now I am using a for loop to go through all the coordinates and > then separate append statements to add the top and bottom. > > is there a way to do something like: [(x,y-1), (x,y+1) for zzz in > coord_list] or something along those lines? > > thanks! > def vertical_neighbours(coords): for x, y in coords: yield x, y-1 yield x, y+1 new_coords = list(vertical_neighbours(coords)) -- Duncan Booth http://kupuguy.blogspot.com From no.email at nospam.invalid Thu May 24 16:55:04 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 24 May 2012 13:55:04 -0700 Subject: Help doing it the "python way" References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: <7xzk8xfgev.fsf@ruckus.brouhaha.com> Scott Siegler writes: > is there a way to do something like: > [(x,y-1), (x,y+1) for zzz in coord_list] > or something along those lines? You should read the docs of the itertools module on general principles, since they are very enlightening in many ways. Your particular problem can be handled with itertools.chain: from itertools import chain new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) You can alternatively write an iterative loop: def gen_expand(coord_list): for x,y in coord_list: yield (x-1,y) yield (x+1, y) new_list = list(gen_expand(coord_list)) From d at davea.name Thu May 24 17:12:16 2012 From: d at davea.name (Dave Angel) Date: Thu, 24 May 2012 17:12:16 -0400 Subject: Help doing it the "python way" In-Reply-To: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: <4FBEA430.1000705@davea.name> On 05/24/2012 04:22 PM, Scott Siegler wrote: > Hello, > > I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more "C" style syntax. > > I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. > > So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) > > right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. > > is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? > > thanks! So, where's the code that works? That you want optimized, or "pythonified" ? Your algorithm description is sufficiently confusing that I'm going to have make some wild guesses about what you're after. Apparently you have a list of tuples, and you want to create a second list that's related to the first in the sense that each item (i) of list2 is the sum of the items (i-1) and (i+1) of list1. Presumably you mean sum as in vector sum, where we add the x and y values, respectively. Easiest way to handle edge conditions is to stick an extra (0,0) at both the beginning and end of the list. list1 = [ (3,7), (2,2), (944, -2), (12, 12) ] def sumtuple(mytuple1, mytuple2): return ( mytuple1[0] + mytuple2[0] , mytuple1[1] + mytuple2[1]) def makesum(list1): list2 = [] list1a = [(0, 0)] + list1 + [(0, 0)] for item1, item2 in zip(list1a, list1a[2:]): list2.append( sumtuple(item1, item2) ) return list2 print makesum(list1) output: [(2, 2), (947, 5), (14, 14), (944, -2)] Now, that undoubtedly isn't what you wanted, but perhaps you could clarify the algorithm, so we could refine it. No point in making it more compact till it solves the problem you're actually interested in. -- DaveA From no.email at nospam.invalid Thu May 24 17:30:58 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 24 May 2012 14:30:58 -0700 Subject: Help doing it the "python way" References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> <7xzk8xfgev.fsf@ruckus.brouhaha.com> Message-ID: <7x4nr5e06l.fsf@ruckus.brouhaha.com> Paul Rubin writes: > new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) Sorry: new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) From ben+python at benfinney.id.au Thu May 24 18:07:47 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 25 May 2012 08:07:47 +1000 Subject: Email Id Verification References: Message-ID: <87txz55j2k.fsf@benfinney.id.au> John Nagle writes: > It matches anything that looks like a mail user name followed by > an @ followed by anything that looks more or less like a domain name. > The domain name must contain at least one ".", and cannot end with > a ".", which is not strictly correct but usually works. It will reject many valid email addresses. For better guidance on verifying email address values, see the official recommendations in RFC 3696 . In short: don't bother validating email addresses, the email system is best placed to do that. Just try using them and catch the failures when they happen. -- \ ?He was the mildest-mannered man / That ever scuttled ship or | `\ cut a throat.? ??Lord? George Gordon Noel Byron, _Don Juan_ | _o__) | Ben Finney From cs at zip.com.au Thu May 24 18:53:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 May 2012 08:53:14 +1000 Subject: Wish: Allow all log Handlers to accept the level argument In-Reply-To: <4FBE11F1.3070001@sequans.com> References: <4FBE11F1.3070001@sequans.com> Message-ID: <20120524225314.GA8607@cskk.homeip.net> On 24May2012 12:48, Jean-Michel Pichavant wrote: | Peter Otten wrote: | > Jean-Michel Pichavant wrote: | >> Fayaz Yusuf Khan wrote: | >>> Jean-Michel Pichavant wrote: | >>>> Meanwhile you can shorten the code this way: | >>>> root.addHandler(FileHandler('debug.log')) | >>>> root.handlers[-1].setLevel(DEBUG) | >>>> | >>> Eh? Readability was the aim. | >>> | >> I fail to see how it's not readable, code is short and no magic is | >> involved provided you know about slicing list items. Anyway, to answer | > | > You have to know or verify that .addHandler() appends to the .handlers list, | > you have to check if or under which conditions | > | > h = SomeHandler() | > root.addHandler(h) | > assert h is root.handlers[-1] | > | > can fail. In short, if I see such a hack my trust in the author of that code | > is significantly lowered. | | I now fail to see how it's a hack. handlers is a public attribute of | loggers. | | FYI | | def addHandler(self, hdlr): | """ | Add the specified handler to this logger. | """ | if not (hdlr in self.handlers): | self.handlers.append(hdlr) Nothing there says handlers is a list. (Nothing in the docs says that the .handlers even exists, AFAICS.) Might be a set or something more esoteric. Particularly, if I wanted to add and remove handlers a lot I might well expect (or at least imagine) it to be a set. So I too find: root.handlers[-1] a risky thing to say, and harder to read because it assumes something I would not want to rely on. Versus the original proposal that avoids all need to know how logging tracks its handler internally. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The reason that God was able to create the world in seven days is that he didn't have to worry about the installed base. - Enzo Torresi From cs at zip.com.au Thu May 24 19:00:55 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 May 2012 09:00:55 +1000 Subject: Email Id Verification In-Reply-To: References: Message-ID: <20120524230054.GA9528@cskk.homeip.net> On 25May2012 01:20, Chris Angelico wrote: | On Thu, May 24, 2012 at 11:45 PM, Dennis Lee Bieber | wrote: | > ? ? ? ?And maybe follow-up with a review of this monster: | > http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html | | That is.... awesome. Epic. Eyeball-bleeding. +1 !! I hope someone's validated that regexp before using it to validate email addresses:-) I'm amazed. (And amazed that the sheer code smell doesn't drive the author away from suggesting it.) The mere presence of nesting comments in RFC2822 addresses prevents using a single regexp to parse them. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ "It's state-of-the-art" "But it doesn't work!" "That is the state-of-the-art". From cs at zip.com.au Thu May 24 19:03:36 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 May 2012 09:03:36 +1000 Subject: Email Id Verification In-Reply-To: References: Message-ID: <20120524230336.GA9816@cskk.homeip.net> On 24May2012 05:32, niks wrote: | Hello everyone.. | I am new to asp.net... Time to run away fast before you're commited then:-) You're aware this is a _python_ list/group, yes? | I want to use Regular Expression validator in Email id verification.. You can't. Valid addresses including nesting comments. Regexps don't do recursion. | Can anyone tell me how to use this and what is the meaning of | this | \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* If you don't understand it, DON'T use it. And in any case, it is simplistic (== wrong). As pointed out by others in this thread. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Men are four: He who knows and knows that he knows; he is wise, follow him. He who knows and knows not that he knows; he is asleep, wake him. He who knows not and knows that he knows not; he is ignorant, teach him. He who knows not and knows not that he knows not; he is a fool, spurn him! From emile at fenx.com Thu May 24 19:12:34 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 24 May 2012 16:12:34 -0700 Subject: Help doing it the "python way" In-Reply-To: <7x4nr5e06l.fsf@ruckus.brouhaha.com> References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> <7xzk8xfgev.fsf@ruckus.brouhaha.com> <7x4nr5e06l.fsf@ruckus.brouhaha.com> Message-ID: On 5/24/2012 2:30 PM Paul Rubin said... > Paul Rubin writes: >> new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) > > Sorry: > > new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) >>> from itertools import chain >>> coord_list = zip(range(20,30),range(30,40)) >>> a = [((x,y-1),(x,y+1)) for x,y in coord_list] >>> b = list(chain(((x,y-1),(x,y+1)) for x,y in coord_list)) >>> a == b True >>> So, why use chain? Is it a premature optimization? Similar to the practice of using "".join(targets) vs targeta+targetb+...+targetn? Emile From rosuav at gmail.com Thu May 24 19:48:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 May 2012 09:48:05 +1000 Subject: Email Id Verification In-Reply-To: <20120524230336.GA9816@cskk.homeip.net> References: <20120524230336.GA9816@cskk.homeip.net> Message-ID: On Fri, May 25, 2012 at 9:03 AM, Cameron Simpson wrote: > On 24May2012 05:32, niks wrote: > | Hello everyone.. > | I am new to asp.net... > > Time to run away fast before you're commited then:-) > You're aware this is a _python_ list/group, yes? Committed to an asylum or to source control? Python is an asylum. Ruled by a Benevolent Inmate For Life. And yes, it's a life sentence. ChrisA From steve+comp.lang.python at pearwood.info Thu May 24 20:46:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2012 00:46:50 GMT Subject: Email Id Verification References: Message-ID: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 May 2012 05:32:16 -0700, niks wrote: > Hello everyone.. > I am new to asp.net... > I want to use Regular Expression validator in Email id verification.. Why do you want to write buggy code that makes your users hate your program? Don't do it! Write good code, useful code! Validating email addresses is the wrong thing to do. The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. That is all. Just because an address is syntactically valid doesn't mean it is deliverable. You can't validate postal addresses. How would you even try? Even if you could, you wouldn't use a regex for it. That's the post office's job to decide whether mail can be delivered, not yours. Who are you to say that some address in Russia or Bolivia or Kuwait is "invalid"? Email addresses are no different. It is the job of the mail server to decide whether email can be delivered, not yours. http://northernplanets.blogspot.com.au/2007/03/how-not-to-validate-email-addresses.html http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx http://haacked.com/archive/2007/08/26/dont-be-a-validation-nazi.aspx -- Steven From python at mrabarnett.plus.com Thu May 24 20:48:45 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 25 May 2012 01:48:45 +0100 Subject: Email Id Verification In-Reply-To: <20120524230336.GA9816@cskk.homeip.net> References: <20120524230336.GA9816@cskk.homeip.net> Message-ID: <4FBED6ED.1090103@mrabarnett.plus.com> On 25/05/2012 00:03, Cameron Simpson wrote: > On 24May2012 05:32, niks wrote: > | Hello everyone.. > | I am new to asp.net... > > Time to run away fast before you're commited then:-) > You're aware this is a _python_ list/group, yes? > > | I want to use Regular Expression validator in Email id verification.. > > You can't. Valid addresses including nesting comments. Regexps don't do > recursion. > Some regex implementations _can_ do recursion. > | Can anyone tell me how to use this and what is the meaning of > | this > | \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* > > If you don't understand it, DON'T use it. And in any case, it is > simplistic (== wrong). As pointed out by others in this thread. True, it's the wrong tool for the job. From steve+comp.lang.python at pearwood.info Thu May 24 21:08:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2012 01:08:14 GMT Subject: Dynamic comparison operators References: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> Message-ID: <4fbedb7e$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 May 2012 11:22:37 -0400, Colin J. Williams wrote: > On 24/05/2012 10:14 AM, mlangenhoven at gmail.com wrote: >> I would like to pass something like this into a function >> test(val1,val2,'>=') >> >> and it should come back with True or False. >> >> Is there a way to dynamically compare 2 values like this or will I have >> to code each operator individually? > > Would something like the following meet your need? > > Yes, it would be nice if there were a b.__name__ constant. What is "a b.__name__ constant", and how will it be useful? As for your solution using eval, please, please, PLEASE do not encourage newbies to write slow, insecure, dangerous code. There are enough security holes in software without you encouraging people to create more. * eval is slow. * eval is dangerous. * eval is using a 200lb sledgehammer to crack a peanut. Any time you find yourself thinking that you want to use eval to solve a problem, take a long, cold shower until the urge goes away. If you have to ask why eval is dangerous, then you don't know enough about programming to use it safely. Scrub it out of your life until you have learned about code injection attacks, data sanitation, trusted and untrusted input. Then you can come back to eval and use it safely and appropriately. Today, your "test" function using eval is used only by yourself, at the interactive interpreter. Tomorrow, it ends up in a web application, and random hackers in China and script-kiddies in Bulgaria now have total control of your server. Any time you hear about some piece of malware or some virus infecting people's systems when they look at a PDF file, chances are high that it is a code injection attack. To learn more, you can start here: http://cwe.mitre.org/top25/index.html Two of the top three most common vulnerabilities are code injection attacks, similar to the improper use of eval. Here is the "eval injection" vulnerability: http://cwe.mitre.org/data/definitions/95.html Also google on "code injection" for many more examples. -- Steven From sherjilozair at gmail.com Thu May 24 21:23:18 2012 From: sherjilozair at gmail.com (SherjilOzair) Date: Thu, 24 May 2012 18:23:18 -0700 (PDT) Subject: Scoping Issues Message-ID: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. From no.email at nospam.invalid Thu May 24 21:35:21 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 24 May 2012 18:35:21 -0700 Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xsjep9h5y.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Why do you want to write buggy code that makes your users hate your > program? ... > The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO > IT. Of course spamming people will make them hate you even more. Insisting that people give you a valid email address (unless you have a demonstrably legitimate use for it) is a variant of that. From no.email at nospam.invalid Thu May 24 21:36:57 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 24 May 2012 18:36:57 -0700 Subject: Dynamic comparison operators References: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> Message-ID: <7xobpd9h3a.fsf@ruckus.brouhaha.com> mlangenhoven at gmail.com writes: > I would like to pass something like this into a function > test(val1,val2,'>=') > > and it should come back with True or False. import operator test(val1, val2, operator.ge) From steve+comp.lang.python at pearwood.info Thu May 24 21:50:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2012 01:50:15 GMT Subject: Scoping Issues References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> Message-ID: <4fbee557$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 May 2012 18:23:18 -0700, SherjilOzair wrote: > def adder(): > s = 0 > def a(x): > s += x > return sum > return a I think you mean "return s", not sum. > This should work, right? Why does it not? No, it shouldn't. When you have an assignment, such as "s += x", Python treats s as a local variable. Since s is local to the inner function a(), it has no initial value, and the += fails. In Python 3, you can declare s to be a non-local variable with the nonlocal keyword: def adder(): s = 0 def a(x): nonlocal s s += x return s return a which now works the way you should expect: >>> add = adder() >>> add(1) 1 >>> add(2) 3 >>> add(5) 8 But in Python 2, which you are using, there is no nonlocal keyword and you can only write to globals (declaring them with the global keyword) or locals (with no declaration), not nonlocals. There are a number of work-arounds to this. One is to use a callable class: class Adder: def __init__(self): self.s = 0 def __call__(self, x): self.s += x return self.s Another is to use an extra level of indirection, and a mutable argument. Instead of rebinding the non-local, you simply modify it in place: def adder(): s = [0] def a(x): s[0] += x return s[0] return a -- Steven From steve+comp.lang.python at pearwood.info Thu May 24 21:51:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2012 01:51:49 GMT Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> <7xsjep9h5y.fsf@ruckus.brouhaha.com> Message-ID: <4fbee5b5$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 May 2012 18:35:21 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Why do you want to write buggy code that makes your users hate your >> program? ... >> The only way to validate an email address is to ACTUALLY SEND AN EMAIL >> TO IT. > > Of course spamming people will make them hate you even more. Insisting > that people give you a valid email address (unless you have a > demonstrably legitimate use for it) is a variant of that. Ha, of course. I assumed that the OP actually has a valid reason for requesting an email address from the user. -- Steven From python at mrabarnett.plus.com Thu May 24 21:51:58 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 25 May 2012 02:51:58 +0100 Subject: Scoping Issues In-Reply-To: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> Message-ID: <4FBEE5BE.6030903@mrabarnett.plus.com> On 25/05/2012 02:23, SherjilOzair wrote: > def adder(): > s = 0 > def a(x): > s += x > return sum > return a > > pos, neg = adder(), adder() > for i in range(10): > print pos(i), neg(-2*i) > > This should work, right? Why does it not? > > Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted > to see if python was the same as Go in this regard. Sorry, if I'm being > rude, or anything. If you bind to a name (assign to a variable) in a function, that name is by default local to the function unless it's declared as "global" (which means "in this module's namespace") or "nonlocal" (which means "in the enclosing function's namespace") (Python 3 only). From skippy.hammond at gmail.com Thu May 24 21:53:59 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 25 May 2012 11:53:59 +1000 Subject: Embedding Python27 in C++ on Windows: CRT compatibility issues with VS2010? In-Reply-To: References: Message-ID: <4FBEE637.6030105@gmail.com> On 25/05/2012 2:10 AM, Stephen Lin wrote: > Hello, > > I'm a relative python newbie but I've been tasked to figure out how to > embed calls to a python library in an Excel XLL add-in. > > The Python/C API for doing this seems pretty straightforward, but I > seem to have read somewhere online that it's important that the C++ > program or DLL linking to and embedding Python must be using the same > CRT as what the Python implementation dll is using. Is this true, or > is the Python API written in such a way that there is no dependency on > a common CRT? It depends on the APIs you use. eg, some APIs take a "FILE *" and some may take ownership of memory - such APIs needs to use the same CRT. APIs that don't attempt to share CRT "objects" should be fine. Mark > > If there is a dependency, does that mean that I cannot use VS2010 to > develop this XLL, but should use VS2008 instead, or are there other > workarounds? > > Thanks for the help, > Stephen > From rosuav at gmail.com Thu May 24 21:56:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 May 2012 11:56:40 +1000 Subject: Email Id Verification In-Reply-To: <7xsjep9h5y.fsf@ruckus.brouhaha.com> References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> <7xsjep9h5y.fsf@ruckus.brouhaha.com> Message-ID: On Fri, May 25, 2012 at 11:35 AM, Paul Rubin wrote: > Steven D'Aprano writes: >> Why do you want to write buggy code that makes your users hate your >> program? ... >> The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO >> IT. > > Of course spamming people will make them hate you even more. ?Insisting > that people give you a valid email address (unless you have a > demonstrably legitimate use for it) is a variant of that. But why do you want to validate the email address? That's the question. Usually it's because you're going to be sending emails to that address, in which case you not only want to ensure that it's a real address, you want to ensure that the person who keyed it in is legitimately allowed to do so - the usual implementation of that being "please check your emails for the confirmation code". There are, however, ways of not-quite-sending an email. For instance, you can connect to the domain's MX, give your HELO, MAIL FROM, and RCPT TO commands, and then quit before sending any DATA. That won't give a 100% guarantee, but it'll certainly tell you about a lot of failures (most of them in that first megastep of looking up the domain in DNS to find its MX record, and then attempting a connection). Now, if your goal is to recognize email addresses in plain text (eg to make them clickable), then you probably don't want true validation - you want more of a DWIM setup where common "tails" aren't included [for instance, an email address followed by a close bracket, like foo at bar.com]. That's completely different. ChrisA From clp2 at rebertia.com Thu May 24 21:56:53 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 24 May 2012 18:56:53 -0700 Subject: Scoping Issues In-Reply-To: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> Message-ID: On Thu, May 24, 2012 at 6:23 PM, SherjilOzair wrote: > def adder(): > ? ? ? ?s = 0 > ? ? ? ?def a(x): Add a "nonlocal s" declaration right here. See http://www.python.org/dev/peps/pep-3104/ > ? ? ? ? ? ?s += x > ? ? ? ? ? ?return sum > ? ? ? ?return a > > pos, neg = adder(), adder() > for i in range(10): > ? ? ? ?print pos(i), neg(-2*i) > > This should work, right? Why does it not? Python doesn't have a C-like variable declaration scheme. So without a `global` or `nonlocal` declaration, you can only assign to names which reside in the innermost scope. > Checkout slide no. 37 of a Tour of Go to know inspiration. You mean slide #38 ("And functions are full closures."). > Just wanted to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. I would suggest reading through the Python Language Reference (http://docs.python.org/release/3.1.5/reference/index.html ) prior to asking further questions, as it may well answer them for you. Cheers, Chris From d at davea.name Thu May 24 21:59:50 2012 From: d at davea.name (Dave Angel) Date: Thu, 24 May 2012 21:59:50 -0400 Subject: Scoping Issues In-Reply-To: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> Message-ID: <4FBEE796.1070504@davea.name> On 05/24/2012 09:23 PM, SherjilOzair wrote: > def adder(): > s = 0 > def a(x): > s += x > return sum > return a > > pos, neg = adder(), adder() > for i in range(10): > print pos(i), neg(-2*i) > > This should work, right? Why does it not? > Guess that depends on what you mean by work. First, it gets a syntax error on the print function call, because you omitted the parens. When I fixed that, I got UnboundLocalError: local variable 's' referenced before assignment so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Then I got the output because sum is a built-in function. Presumably you meant to return s, not sum. Here's what I end up with, and it seems to work fine in Python 3.2 on Linux: def adder(): s = 0 def a(x): nonlocal s s += x return s return a pos, neg = adder(), adder() for i in range(10): print (pos(i), neg(-2*i)) ..... Output is: 0 0 1 -2 3 -6 6 -12 10 -20 15 -30 21 -42 28 -56 36 -72 45 -90 -- DaveA From bahamutzero8825 at gmail.com Thu May 24 22:27:31 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 24 May 2012 21:27:31 -0500 Subject: Scoping Issues In-Reply-To: <4FBEE796.1070504@davea.name> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> <4FBEE796.1070504@davea.name> Message-ID: <4FBEEE13.2070801@gmail.com> On 5/24/2012 8:59 PM, Dave Angel wrote: > so I fixed that, and got > inconsistent use of tabs and spaces in indentation > > because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, but tabs are perfectly legal indentation in Python. That exception is raised when the interpreter can't determine how much a line is indented because tabs and spaces are both used. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From steve+comp.lang.python at pearwood.info Thu May 24 22:47:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 May 2012 02:47:11 GMT Subject: Namespace hack References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> Message-ID: <4fbef2af$0$29992$c3e8da3$5496439d@news.astraweb.com> Pardon me for breaking threading, but Daniel's response is not available on my ISP's news server, and I only discovered it by accident. On Thu May 24 15:04:34 CEST 2012, Daniel Fetchinson wrote: > > On Thu, 24 May 2012 08:50:59 +0000, Steven D'Aprano wrote: > > From the Zen of Python ("import this"): > > Namespaces are one honking great idea -- let's do more of those! [...] > Funny, you got to the last line of "import this" but apparently > skipped the second line: > > Explicit is better than implicit. > > And you didn't even post your message on April 1 so no, I can't laugh > even though I'd like to. Do you object to the ability to write standard Python modules? # module.py def spam(obj, n): return len(obj) + n def ham(obj): return spam(obj, 23) By your apparent misunderstanding of the Zen, you think that this should be written with oodles of more explicitness, 'cos explicit is always better, right? keyword.def globals.spam(locals.obj, locals.n): keyword.return builtin.len(locals.obj) + locals.n keyword.def globals.ham(locals.obj): keyword.return globals.spam(locals.obj, 23) Python, like most (all?) non-trivial languages, has scoping rules so that you can refer to names without explicitly specifying which namespace they are in. So long as this is unambiguous, Explicit vs Implicit is irrelevant if not outright wrong. My namespace decorator simply applies a slightly different set of scoping rules to the ones you are already used to in modules. It's no worse than nested functions (hardly a surprise, because it is built on nested functions!) or module-level scoping rules. -- Steven From kevonwang6032 at gmail.com Thu May 24 22:53:48 2012 From: kevonwang6032 at gmail.com (kevon wang) Date: Thu, 24 May 2012 19:53:48 -0700 (PDT) Subject: Is there a custom fields plugin or component of django Message-ID: <5443239a-da22-4ab2-8536-93b5ebd103bc@googlegroups.com> I want to find a plugin of django what it can custom fields in the form. The functions include custom fields in web page and create the fields in database. plugin's flow like these: 1.we can define fields in web page --> 2.create the table in database(table includes all custom fields) --> 3.generate CURD operations in web server --> 4.we can CURD records in web pages. I want to know whether there is a plugin or component of django, If there is please tell me. Maybe there is the other plugin like this as well. From lamialily at cleverpun.com Thu May 24 23:02:05 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 24 May 2012 20:02:05 -0700 Subject: Namespace hack In-Reply-To: <4fbef2af$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> <4fbef2af$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: [Default] On 25 May 2012 02:47:11 GMT, Steven D'Aprano wrote: >Do you object to the ability to write standard Python modules? > ># module.py >def spam(obj, n): > return len(obj) + n > >def ham(obj): > return spam(obj, 23) > > >By your apparent misunderstanding of the Zen, you think that this should >be written with oodles of more explicitness, 'cos explicit is always >better, right? > >keyword.def globals.spam(locals.obj, locals.n): > keyword.return builtin.len(locals.obj) + locals.n > >keyword.def globals.ham(locals.obj): > keyword.return globals.spam(locals.obj, 23) > > >Python, like most (all?) non-trivial languages, has scoping rules so that >you can refer to names without explicitly specifying which namespace they >are in. So long as this is unambiguous, Explicit vs Implicit is >irrelevant if not outright wrong. > >My namespace decorator simply applies a slightly different set of scoping >rules to the ones you are already used to in modules. It's no worse than >nested functions (hardly a surprise, because it is built on nested >functions!) or module-level scoping rules. > > >-- >Steven But then we've got "Simple is better than complex", and "Complex is better than complicated". Of course if we decided to start iterating through the zen of Python's verses and continually modifying the example code to fit, it would get rather silly rather fast. ~Temia -- When on earth, do as the earthlings do. From tjreedy at udel.edu Thu May 24 23:27:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 24 May 2012 23:27:59 -0400 Subject: Help doing it the "python way" In-Reply-To: References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: On 5/24/2012 4:53 PM, Duncan Booth wrote: > Scott Siegler wrote: > >> Hello, >> >> I am an experienced programmer but a beginner to python. As such, I >> can figure out a way to code most algorithms using more "C" style >> syntax. Hi, welcome to Python. I came here from C also. >> I am doing something now that I am sure is a more python way but i >> can't quite get it right. I was hoping someone might help. >> >> So I have a list of grid coordinates (x, y). From that list, I want >> to create a new list that for each coordinate, I add the coordinate >> just above and just below (x,y+1) and (x,y-1) The Python way, especially the Python 3 way, is to not make the new sequence into a concrete list unless you actually need a list to append or sort or otherwise mutate. In many use cases, that is not necessary. >> right now I am using a for loop to go through all the coordinates and >> then separate append statements to add the top and bottom. >> >> is there a way to do something like: [(x,y-1), (x,y+1) for zzz in >> coord_list] or something along those lines? > def vertical_neighbours(coords): > for x, y in coords: > yield x, y-1 > yield x, y+1 > > new_coords = list(vertical_neighbours(coords)) -- Terry Jan Reedy From d at davea.name Thu May 24 23:36:21 2012 From: d at davea.name (Dave Angel) Date: Thu, 24 May 2012 23:36:21 -0400 Subject: Scoping Issues In-Reply-To: <4FBEEE13.2070801@gmail.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> <4FBEE796.1070504@davea.name> <4FBEEE13.2070801@gmail.com> Message-ID: <4FBEFE35.7070608@davea.name> On 05/24/2012 10:27 PM, Andrew Berg wrote: > On 5/24/2012 8:59 PM, Dave Angel wrote: >> so I fixed that, and got >> inconsistent use of tabs and spaces in indentation >> >> because you mistakenly used tabs for indentation. > Not to start another tabs-vs.-spaces discussion, but tabs are perfectly > legal indentation in Python. That exception is raised when the > interpreter can't determine how much a line is indented because tabs and > spaces are both used. > I configure my editor(s) to always use spaces for indentation. So a file that currently uses tabs is unusable to me. You of course are right that tabs are syntactically correct, but until I find another editor that makes tabs visible (like the one I used 20 years ago) they're unacceptable to me. -- DaveA From ben+python at benfinney.id.au Fri May 25 00:02:33 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 25 May 2012 14:02:33 +1000 Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> <7xsjep9h5y.fsf@ruckus.brouhaha.com> Message-ID: <87pq9s6h7q.fsf@benfinney.id.au> Paul Rubin writes: > Steven D'Aprano writes: > > Why do you want to write buggy code that makes your users hate your > > program? ... > > The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO > > IT. > > Of course spamming people will make them hate you even more. Use the email address without spamming, then. The point is that, having collected the email address, it's useless unless one actually uses it *as an email address*, by sending a message to it. Before then, ?validating? it tells you nothing. > Insisting that people give you a valid email address (unless you have > a demonstrably legitimate use for it) is a variant of that. And matching it against a regex is going to either get it wrong (rejecting many valid email addresses), or be useless (accepting just about anything as ?valid?). The test which matters is to use the value as an email address, by sending a message when the time comes to do that. -- \ ?It's my belief we developed language because of our deep inner | `\ need to complain.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From no.email at nospam.invalid Fri May 25 00:27:45 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 24 May 2012 21:27:45 -0700 Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> <7xsjep9h5y.fsf@ruckus.brouhaha.com> <87pq9s6h7q.fsf@benfinney.id.au> Message-ID: <7xobpcyjem.fsf@ruckus.brouhaha.com> Ben Finney writes: > The point is that, having collected the email address, it's useless > unless one actually uses it *as an email address*, by sending a message > to it. Before then, ?validating? it tells you nothing. Right, the only legitimate use of an email address is sending legitimate email to it. An example might be collecting an address so that service staff can respond to a help request. If there is not an up-front, good reason to want to email the address, then collecting it is not legitimate. An example is web sites where users have to supply addresses to register. This is why mailinator.com was invented, but it's annoying even if you use mailinator. From rosuav at gmail.com Fri May 25 00:40:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 May 2012 14:40:30 +1000 Subject: Namespace hack In-Reply-To: References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> <4fbef2af$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 25, 2012 at 1:02 PM, Temia Eszteri wrote: > But then we've got "Simple is better than complex", and "Complex is > better than complicated". Of course if we decided to start iterating > through the zen of Python's verses and continually modifying the > example code to fit, it would get rather silly rather fast. > Silly but amusing. As with all these sorts of documents, the Zen of Python is self-contradictory; it's always left up to an intelligent human to decide when to apply which rule. ChrisA From ulrich.eckhardt at dominolaser.com Fri May 25 04:24:06 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 25 May 2012 10:24:06 +0200 Subject: installing 2 and 3 alongside on MS Windows Message-ID: <66s399-j0c.ln1@satorlaser.homedns.org> Hi! I'm using Python 2.7 for mostly unit testing here. I'm using Boost.Python to wrap C++ code into a module, in another place I'm also embedding Python as interpreter into a test framework. This is the stuff that must work, it's important for production use. I'm running MS Windows XP here and developing C++ with VS2005/VC8. What I'm considering is installing Python 3 alongside, in order to prepare the code for this newer version. What I'd like to know first is whether there are any problems I'm likely to encounter and possible workarounds. Thank you! Uli PS: Dear lazyweb, is there any way to teach VC8 some syntax highlighting for Python? From jeanmichel at sequans.com Fri May 25 05:51:03 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 25 May 2012 11:51:03 +0200 Subject: Scoping Issues In-Reply-To: <4FBEEE13.2070801@gmail.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> <4FBEE796.1070504@davea.name> <4FBEEE13.2070801@gmail.com> Message-ID: <4FBF5607.9070708@sequans.com> Andrew Berg wrote: > On 5/24/2012 8:59 PM, Dave Angel wrote: > >> so I fixed that, and got >> inconsistent use of tabs and spaces in indentation >> >> because you mistakenly used tabs for indentation. >> > Not to start another tabs-vs.-spaces discussion, > Too late, the seeds of war have been planted, we reached to point of no return. The OP mistakenly used spaces with its tabs for indentation. JM From jeanpierreda at gmail.com Fri May 25 07:37:48 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 25 May 2012 07:37:48 -0400 Subject: Namespace hack In-Reply-To: References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> Message-ID: On Thu, May 24, 2012 at 9:04 AM, Daniel Fetchinson wrote: > Funny, you got to the last line of "import this" but apparently > skipped the second line: > > Explicit is better than implicit. > > And you didn't even post your message on April 1 so no, I can't laugh > even though I'd like to. Can you be less condescending? -- Devin From hjgreenberg at gmail.com Fri May 25 09:12:58 2012 From: hjgreenberg at gmail.com (Harvey Greenberg) Date: Fri, 25 May 2012 06:12:58 -0700 (PDT) Subject: getting started Message-ID: elementary ques...I set s.name = ["a","b"] s.value = [3,5] I get error that s is not defined. How do I define s and proceed to give its attributes? From miki.tebeka at gmail.com Fri May 25 09:30:44 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 25 May 2012 06:30:44 -0700 (PDT) Subject: getting started In-Reply-To: References: Message-ID: <31502f32-b9fa-4716-9b60-e66f645444cb@googlegroups.com> > s.name = ["a","b"] > s.value = [3,5] > > I get error that s is not defined. How do I define s and proceed to > give its attributes? Either you create a class and use __init__: class S: def __init__(self, name, value): self.name = name self.value = value or create a generic object and stick attributes to it: class Object(object): pass s = Object() s.name = ["a","b"] s.value = [3,5] I highly recommend going over the tutorial - http://docs.python.org/tutorial/ From invalid at invalid.invalid Fri May 25 09:36:18 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 25 May 2012 13:36:18 +0000 (UTC) Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-05-25, Steven D'Aprano wrote: > On Thu, 24 May 2012 05:32:16 -0700, niks wrote: > >> Hello everyone.. >> I am new to asp.net... >> I want to use Regular Expression validator in Email id verification.. > > Why do you want to write buggy code that makes your users hate your > program? Don't do it! Write good code, useful code! Validating email > addresses is the wrong thing to do. I have to agree with Steven. Nothing will make your users swear at you as certainly as when you refuse to accept the e-mail address at which the reeive e-mail all day every day. -- Grant Edwards grant.b.edwards Yow! I appoint you at ambassador to Fantasy gmail.com Island!!! From d at davea.name Fri May 25 09:37:44 2012 From: d at davea.name (Dave Angel) Date: Fri, 25 May 2012 09:37:44 -0400 Subject: getting started In-Reply-To: References: Message-ID: <4FBF8B28.9070202@davea.name> On 05/25/2012 09:12 AM, Harvey Greenberg wrote: > elementary ques...I set > s.name = ["a","b"] > s.value = [3,5] > > I get error that s is not defined. How do I define s and proceed to > give its attributes? You just have to initialize s as an object that's willing to take those attributes. The most trivial way I can think of to do that would be to create an empty class for the purpose. class MyClass: pass s = MyClass() s.name = ["a","b"] s.value = [3,5] Of course if you told why you want to do it, we might be able to suggest a better type for s. -- DaveA From ethan at stoneleaf.us Fri May 25 11:16:48 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 25 May 2012 08:16:48 -0700 Subject: Scoping Issues In-Reply-To: <4FBEEE13.2070801@gmail.com> References: <7bf4c370-5479-47af-ba0a-7c1985c88365@googlegroups.com> <4FBEE796.1070504@davea.name> <4FBEEE13.2070801@gmail.com> Message-ID: <4FBFA260.2010908@stoneleaf.us> Andrew Berg wrote: > On 5/24/2012 8:59 PM, Dave Angel wrote: >> so I fixed that, and got >> inconsistent use of tabs and spaces in indentation >> >> because you mistakenly used tabs for indentation. > Not to start another tabs-vs.-spaces discussion, but tabs are perfectly > legal indentation in Python. That exception is raised when the > interpreter can't determine how much a line is indented because tabs and > spaces are both used. To be clear: each entire suite must be consistent with its use of either tabs /or/ spaces -- attempting to use both, even on seperate lines, raises `TabError: inconsistent use of tabs and spaces in indentation`. (Python 3, of course. ;) ~Ethan~ From ian.g.kelly at gmail.com Fri May 25 11:31:31 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 May 2012 09:31:31 -0600 Subject: Help doing it the "python way" In-Reply-To: References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> <7xzk8xfgev.fsf@ruckus.brouhaha.com> <7x4nr5e06l.fsf@ruckus.brouhaha.com> Message-ID: On Thu, May 24, 2012 at 5:12 PM, Emile van Sebille wrote: > On 5/24/2012 2:30 PM Paul Rubin said... > >> Paul Rubin ?writes: >>> >>> ? ? new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) >> >> >> Sorry: >> >> ? ?new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) > > > >>>> from itertools import chain >>>> coord_list = zip(range(20,30),range(30,40)) >>>> a = [((x,y-1),(x,y+1)) for x,y in coord_list] >>>> b = list(chain(((x,y-1),(x,y+1)) for x,y in coord_list)) >>>> a == b > True >>>> > > So, why use chain? ?Is it a premature optimization? ?Similar to the practice > of using "".join(targets) vs targeta+targetb+...+targetn? Paul's code is incorrect. It should use chain.from_iterable in place of chain. The difference then is that it creates a single list of coordinates, rather than a list of pairs of coordinates. Cheers, Ian From ppearson at nowhere.invalid Fri May 25 12:25:24 2012 From: ppearson at nowhere.invalid (Peter Pearson) Date: 25 May 2012 16:25:24 GMT Subject: Email Id Verification References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 25 May 2012 13:36:18 +0000 (UTC), Grant Edwards wrote: [snip] > . . . Nothing will make your users swear at > you as certainly as when you refuse to accept the e-mail address at > which the reeive e-mail all day every day. Amusingly, every time I log into Discovercard's web site, I get a red-letter warning that my registered email address is invalid. Inquiring, I was told that the presence of the substring "spam" anywhere in the address (including "@spamcop.net") makes the address invalid in Discovercard's opinion. -- To email me, substitute nowhere->spamcop, invalid->net. From kevin.p.dwyer at gmail.com Fri May 25 12:31:48 2012 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 25 May 2012 17:31:48 +0100 Subject: Is there a custom fields plugin or component of django References: <5443239a-da22-4ab2-8536-93b5ebd103bc@googlegroups.com> Message-ID: kevon wang wrote: > I want to find a plugin of django what it can custom fields in the form. > The functions include custom fields in web page and create the fields in > database. > You might have more luck getting an answer to this question on the django list (django-users at googlegroups.com if you're using Google Groups). Cheers From maxerickson at gmail.com Fri May 25 12:33:01 2012 From: maxerickson at gmail.com (Max Erickson) Date: Fri, 25 May 2012 16:33:01 +0000 (UTC) Subject: installing 2 and 3 alongside on MS Windows References: <66s399-j0c.ln1@satorlaser.homedns.org> Message-ID: Ulrich Eckhardt wrote: > Hi! > > I'm using Python 2.7 for mostly unit testing here. I'm using > Boost.Python to wrap C++ code into a module, in another place I'm > also embedding Python as interpreter into a test framework. This > is the stuff that must work, it's important for production use. > I'm running MS Windows XP here and developing C++ with > VS2005/VC8. > > What I'm considering is installing Python 3 alongside, in order > to prepare the code for this newer version. What I'd like to know > first is whether there are any problems I'm likely to encounter > and possible workarounds. > > Thank you! > > Uli > > PS: Dear lazyweb, is there any way to teach VC8 some syntax > highlighting for Python? > One hassle is that .py files can only be associated with one program. The proposed launcher works fine for me: https://bitbucket.org/vinay.sajip/pylauncher/downloads (I'm not sure that is the most up to date place for the launcher, but that's the one I am using) Max From rosuav at gmail.com Fri May 25 12:33:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 May 2012 02:33:07 +1000 Subject: Email Id Verification In-Reply-To: References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 26, 2012 at 2:25 AM, Peter Pearson wrote: > Amusingly, every time I log into Discovercard's web site, I > get a red-letter warning that my registered email address is > invalid. ?Inquiring, I was told that the presence of the > substring "spam" anywhere in the address (including > "@spamcop.net") makes the address invalid in Discovercard's > opinion. I had no idea it was so easy to prevent spam from getting through. I am in awe, Discovercard! Yet, invalid or not, it apparently works for you? ChrisA From ian.g.kelly at gmail.com Fri May 25 13:04:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 May 2012 11:04:10 -0600 Subject: Email Id Verification In-Reply-To: References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, May 25, 2012 at 10:33 AM, Chris Angelico wrote: > On Sat, May 26, 2012 at 2:25 AM, Peter Pearson wrote: >> Amusingly, every time I log into Discovercard's web site, I >> get a red-letter warning that my registered email address is >> invalid. ?Inquiring, I was told that the presence of the >> substring "spam" anywhere in the address (including >> "@spamcop.net") makes the address invalid in Discovercard's >> opinion. > > I had no idea it was so easy to prevent spam from getting through. I > am in awe, Discovercard! I would think that it is not an anti-spam measure, but simply due to the fact that most addresses containing "spam" tend to be something like "nospam at invalid.net", being either a fake address or a junk inbox that is only checked when an important mail is expected. From rosuav at gmail.com Fri May 25 13:10:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 May 2012 03:10:36 +1000 Subject: Email Id Verification In-Reply-To: References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, May 26, 2012 at 3:04 AM, Ian Kelly wrote: > I would think that it is not an anti-spam measure, but simply due to > the fact that most addresses containing "spam" tend to be something > like "nospam at invalid.net", being either a fake address or a junk inbox > that is only checked when an important mail is expected. If it's fake, you'll find out when you send to it. If it's checked only when important mail is expected, you accept it. I'm not seeing a problem here. I have a @yahoo.com.au address that is used solely in the latter form; it's checked maybe once or twice a month (in comparison to my two primary accounts, which both alert me on incoming mail, one of them in direct response to the SMTP server receiving it); and if any form rejects it, that's flat wrong. DNS lookups aren't particularly expensive. A check for whether the domain has an MX record will catch most forms of fakery without needing any extra effort. ChrisA From gdamjan at gmail.com Fri May 25 15:45:23 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Fri, 25 May 2012 21:45:23 +0200 Subject: PEP 405 vs 370 Message-ID: http://www.python.org/dev/peps/pep-0405/ I don't get what PEP 405 (Python Virtual Environments) brings vs what we already had in PEP 370 since Python 2.6. Obviously 405 has a tool to create virtual environments, but that's trivial for PEP 370 [1], and has support for isolation from the system-wide site patch which could've been added in addition to PEP 370. So maybe I'm missing something? [1] PYTHONUSERBASE=~/my-py-venv pip install --user Whatever will create ~/my-py-venv and everything under it as needed PYTHONUSERBASE=~/my-py-venv python setup.py install --user the same without pip -- damjan From phd at phdru.name Fri May 25 15:45:51 2012 From: phd at phdru.name (Oleg Broytman) Date: Fri, 25 May 2012 23:45:51 +0400 Subject: SQLObject 1.3.1 Message-ID: <20120525194551.GC20997@iskra.aviel.ru> Hello! I'm pleased to announce version 1.3.1, the first bug-fix release of branch 1.3 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.3.1 News and changes: http://sqlobject.org/News.html What's New ========== * Fixed a minor bug in PostgreSQL introspection: VIEWs don't have PRIMARY KEYs - use sqlmeta.idName as the key. * Fixed a bug in cache handling while unpickling. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From ian.g.kelly at gmail.com Fri May 25 16:08:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 May 2012 14:08:58 -0600 Subject: PEP 405 vs 370 In-Reply-To: References: Message-ID: On Fri, May 25, 2012 at 1:45 PM, Damjan Georgievski wrote: > http://www.python.org/dev/peps/pep-0405/ > > I don't get what PEP 405 (Python Virtual Environments) brings vs what we > already had in PEP 370 since Python 2.6. > > Obviously 405 has a tool to create virtual environments, but that's trivial > for PEP 370 [1], and has support for isolation from the system-wide site > patch which could've been added in addition to PEP 370. > > So maybe I'm missing something? Virtual environments entail not just isolation from the system environment, but also the ability to switch between different virtual environments on demand. A single user site-packages directory can't easily support that. The two PEPs are related but geared toward very different purposes. Virtual environments are for setting up a multitude of environments in order to support running scripts with different requirements or configurations on a single platform. The user site-packages directory is for augmenting the static system environment with packages desired by individual users, who can't or simply don't want to install the package for all users of the system. Cheers, Ian From lists at cheimes.de Fri May 25 16:18:25 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 25 May 2012 22:18:25 +0200 Subject: PEP 405 vs 370 In-Reply-To: References: Message-ID: Am 25.05.2012 21:45, schrieb Damjan Georgievski: > http://www.python.org/dev/peps/pep-0405/ > > I don't get what PEP 405 (Python Virtual Environments) brings vs what we > already had in PEP 370 since Python 2.6. My PEP 370 is about installing additional packages as an unprivileged user and for the current user. It's a simplistic approach that just adds one more site-package directory in the user's home directory. PEP 405 is a different beast. It adds support for isolated environment that don't share state with the site wide installation. A user can have multiple virtual envs and install different sets of packages in each env. Christian From cs at zip.com.au Fri May 25 18:26:08 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 26 May 2012 08:26:08 +1000 Subject: Email Id Verification In-Reply-To: References: Message-ID: <20120525222608.GA4133@cskk.homeip.net> On 25May2012 13:36, Grant Edwards wrote: | On 2012-05-25, Steven D'Aprano wrote: | > On Thu, 24 May 2012 05:32:16 -0700, niks wrote: | >> Hello everyone.. | >> I am new to asp.net... | >> I want to use Regular Expression validator in Email id verification.. | > | > Why do you want to write buggy code that makes your users hate your | > program? Don't do it! Write good code, useful code! Validating email | > addresses is the wrong thing to do. | | I have to agree with Steven. Nothing will make your users swear at | you as certainly as when you refuse to accept the e-mail address at | which the reeive e-mail all day every day. And it will get better. If the validation code is sufficiently widespread, the user may be unable to complain or report the issue. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Don't have awk? Use this simple sh emulation: #!/bin/sh echo 'Awk bailing out!' >&2 exit 2 - Tom Horsley From joncle at googlemail.com Fri May 25 18:28:57 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 25 May 2012 15:28:57 -0700 (PDT) Subject: Email Id Verification In-Reply-To: References: <4fbed67a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, 25 May 2012 14:36:18 UTC+1, Grant Edwards wrote: > On 2012-05-25, Steven D'Aprano wrote: > > On Thu, 24 May 2012 05:32:16 -0700, niks wrote: > > > >> Hello everyone.. > >> I am new to asp.net... > >> I want to use Regular Expression validator in Email id verification.. > > > > Why do you want to write buggy code that makes your users hate your > > program? Don't do it! Write good code, useful code! Validating email > > addresses is the wrong thing to do. > > I have to agree with Steven. Nothing will make your users swear at > you as certainly as when you refuse to accept the e-mail address at > which the reeive e-mail all day every day. > > -- > Grant Edwards grant.b.edwards Yow! I appoint you > at ambassador to Fantasy > gmail.com Island!!! Ditto. This would be my public email, but (like most I believe) also have 'private' and work email addresses. For the OP, just trying to check an email is syntactically correct is okay-ish if done properly. Normally as mentioned you just send a confirmation email to said address with some id and link that confirms (normally with an expiry period). Some mail servers support the "does this mailbox exist?" request, but I fear these days due to spam, most will just say no -- so the only option is to send and handle a bounce (and some don't even send back bounces). And a pretty good way for malicious people to make mail servers think you're trying a DoS. Although, what I'm finding useful is an option of "auth'ing" with twitter, facebook, google etc... Doesn't require a huge amount of work, and adds a bit of validity to the request. Jon (who still didn't get any bloody Olympic tickets). From joncle at googlemail.com Fri May 25 18:38:55 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 25 May 2012 15:38:55 -0700 (PDT) Subject: usenet reading Message-ID: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Hi All, Normally use Google Groups but it's becoming absolutely frustrating - not only has the interface changed to be frankly impractical, the posts are somewhat random of what appears, is posted and whatnot. (Ironically posted from GG) Is there a server out there where I can get my news groups? I use to be with an ISP that hosted usenet servers, but alas, it's no longer around... Only really interested in Python groups and C++. Any advice appreciated, Jon. From cs at zip.com.au Fri May 25 18:40:22 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 26 May 2012 08:40:22 +1000 Subject: getting started In-Reply-To: <4FBF8B28.9070202@davea.name> References: <4FBF8B28.9070202@davea.name> Message-ID: <20120525224022.GA4872@cskk.homeip.net> On 25May2012 09:37, Dave Angel wrote: | On 05/25/2012 09:12 AM, Harvey Greenberg wrote: | > elementary ques...I set | > s.name = ["a","b"] | > s.value = [3,5] | > | > I get error that s is not defined. How do I define s and proceed to | > give its attributes? [...] | Of course if you told why you want to do it, we might be able to suggest | a better type for s. If he's just mucking around to get a feel for the language then there probably isn't a better type. So a trite subclass of "object" is the go. Just a brief aside for Harvey: I spent a brief while confused that this doesn't work: o = object() o.x = 1 and that I needed to do this: class O(object): pass o = O() o.x = 1 until I realised that plain "object", the root of all classes, doesn't accept arbitrary attributes. But subclasses do. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ ..And in all of Babylonia there was wailing and gnashing of teeth, till the prophets bade the multitudes get a grip on themselves and shape up. - Woody Allen From joncle at googlemail.com Fri May 25 18:44:42 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 25 May 2012 15:44:42 -0700 (PDT) Subject: Dynamic comparison operators In-Reply-To: <4fbedb7e$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <05bb00e2-763f-4082-a107-65d148718a29@googlegroups.com> <4fbedb7e$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0a8dda19-b6c5-41ed-b273-81e9bd3bb7ca@googlegroups.com> > > Any time you find yourself thinking that you want to use eval to solve a > problem, take a long, cold shower until the urge goes away. > > If you have to ask why eval is dangerous, then you don't know enough > about programming to use it safely. Scrub it out of your life until you > have learned about code injection attacks, data sanitation, trusted and > untrusted input. Then you can come back to eval and use it safely and > appropriately. I would +1 QOTW - but fear might have to cheat and say +1 to 2 paragraphs of the week :) Jon. From memilanuk at gmail.com Fri May 25 20:26:11 2012 From: memilanuk at gmail.com (memilanuk) Date: Fri, 25 May 2012 17:26:11 -0700 (PDT) Subject: usenet reading In-Reply-To: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On Friday, May 25, 2012 3:38:55 PM UTC-7, Jon Clements wrote: > Hi All, > > Normally use Google Groups but it's becoming absolutely frustrating - not only has the interface changed to be frankly impractical, the posts are somewhat random of what appears, is posted and whatnot. (Ironically posted from GG) > > Is there a server out there where I can get my news groups? I use to be with an ISP that hosted usenet servers, but alas, it's no longer around... > > Only really interested in Python groups and C++. > > Any advice appreciated, > > Jon. Have you tried news.gmane.org? They have a Mail2News gateway for many popular mailing lists, as well as some of the traditional usenet hierarchy - including this group. Here is a link to their page for this group, to give you an idea of what kind of reading options they provide. http://dir.gmane.org/gmane.comp.python.general Or you can point your usenet reader @ news.gmane.org and subscribe 'normally'. HTH, Monte From jearl at notengoamigos.org Sat May 26 01:30:24 2012 From: jearl at notengoamigos.org (Jason Earl) Date: Fri, 25 May 2012 23:30:24 -0600 Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: <87r4u7ecgf.fsf@notengoamigos.org> On Fri, May 25 2012, Jon Clements wrote: > Hi All, > > Normally use Google Groups but it's becoming absolutely frustrating - > not only has the interface changed to be frankly impractical, the > posts are somewhat random of what appears, is posted and > whatnot. (Ironically posted from GG) > > Is there a server out there where I can get my news groups? I use to > be with an ISP that hosted usenet servers, but alas, it's no longer > around... > > Only really interested in Python groups and C++. > > Any advice appreciated, > > Jon. I have had good success with news.eternal-september.org . http://www.eternal-september.org/ Jason From lamialily at cleverpun.com Sat May 26 01:52:54 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 25 May 2012 22:52:54 -0700 Subject: usenet reading In-Reply-To: <87r4u7ecgf.fsf@notengoamigos.org> References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> <87r4u7ecgf.fsf@notengoamigos.org> Message-ID: [Default] On Fri, 25 May 2012 23:30:24 -0600, Jason Earl wrote: >On Fri, May 25 2012, Jon Clements wrote: > >> Hi All, >> >> Normally use Google Groups but it's becoming absolutely frustrating - >> not only has the interface changed to be frankly impractical, the >> posts are somewhat random of what appears, is posted and >> whatnot. (Ironically posted from GG) >> >> Is there a server out there where I can get my news groups? I use to >> be with an ISP that hosted usenet servers, but alas, it's no longer >> around... >> >> Only really interested in Python groups and C++. >> >> Any advice appreciated, >> >> Jon. > >I have had good success with news.eternal-september.org . > >http://www.eternal-september.org/ > >Jason I could definitely make use of this. Even though I use Agent, I've mostly just been using the mailing list in lieu of having an actual newsgroup subscription. Now I can turn that habit around! Not the OP, but you have my appreciation regardless! ~Temia -- When on earth, do as the earthlings do. From lamialily at cleverpun.com Sat May 26 04:40:10 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Sat, 26 May 2012 01:40:10 -0700 Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> <87r4u7ecgf.fsf@notengoamigos.org> Message-ID: <5g51s7leeq65ksakudegd2jtddbgp1f3vp@4ax.com> On Fri, 25 May 2012 23:30:24 -0600, Jason Earl wrote: >On Fri, May 25 2012, Jon Clements wrote: > >> Hi All, >> >> Normally use Google Groups but it's becoming absolutely frustrating - >> not only has the interface changed to be frankly impractical, the >> posts are somewhat random of what appears, is posted and >> whatnot. (Ironically posted from GG) >> >> Is there a server out there where I can get my news groups? I use to >> be with an ISP that hosted usenet servers, but alas, it's no longer >> around... >> >> Only really interested in Python groups and C++. >> >> Any advice appreciated, >> >> Jon. > >I have had good success with news.eternal-september.org . > >http://www.eternal-september.org/ > >Jason Not sure if you can even see my original reply to you (I certainly can't), but it seems the Python mailing list (which I've been using rather extensively up until now) has some serious problems syncing to the newsgroup - large amounts of content simply isn't crossing over into Usenet's territory, if the synchronization is anything beyond read-only to begin with. It's a shame, but it looks like I'll have to go back to using the mailing list to read for completeness's sake. :/ Gonna be tricky juggling that for reading and keeping Usenet for writing (so as to not contribute to the information loss), but I'll make do somehow. ~Temia -- When on earth, do as the earthlings do. From irmen.NOSPAM at xs4all.nl Sat May 26 05:14:17 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 26 May 2012 11:14:17 +0200 Subject: installing 2 and 3 alongside on MS Windows In-Reply-To: <66s399-j0c.ln1@satorlaser.homedns.org> References: <66s399-j0c.ln1@satorlaser.homedns.org> Message-ID: <4fc09eea$0$6914$e4fe514c@news2.news.xs4all.nl> On 25-5-2012 10:24, Ulrich Eckhardt wrote: > Hi! > What I'm considering is installing Python 3 alongside, in order to > prepare the code for this newer version. What I'd like to know first is > whether there are any problems I'm likely to encounter and possible > workarounds. What I'm doing myself on Windows is deciding which version of Python I want to be the default, and install that from the msi normally (including "register extensions" options). I then proceed to add its install location to my %PATH%. After which I install additional Python versions but *without* selecting "register extensions" otherwise they will overwrite the registry associations. I have about 5 different versions coexisting peacefully in c:\python26 c:\python27 c:\python27-64, c:\python32 and c:\python33 (with python27 being the default and only c:\python27 added to %PATH%) In the IDE I'm using (PyCharm) you can trivially switch the Python version it will use for your project. > Thank you! > > Uli > > PS: Dear lazyweb, is there any way to teach VC8 some syntax highlighting > for Python? http://pytools.codeplex.com/ perhaps? Irmen. From alec.taylor6 at gmail.com Sat May 26 06:30:16 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 26 May 2012 20:30:16 +1000 Subject: Automatically caching computationally intensive variable values? Message-ID: I am working with a few corpora included in nltk-data with NTLK (http://nltk.org/) to figure out certain algorithms. So my code would generally be something of the style: import re, nltk, random from nltk.corpus import reuters def find_test_and_train_data(): return [fileid for fileid in reuters.fileids() if re.match(r"^training/", fileid)], [fileid for fileid in reuters.fileids() if re.match(r"^test/", fileid)] def generate_random_data(train_and_test_fileids): random.seed(348) ; random.shuffle(train_and_test_fileids[0]) return train_and_test_fileids[0][2000:], train_and_test_fileids[0][:2000] def fileid_words(fileid): return [word.lower() for line in reuters.words(fileid) for word in line.split() if re.match('^[A-Za-z]+$', word)] if __name__ == '__main__': train_fileids, dev_fileids = generate_random_data(find_test_and_train_data()) train_data=fileid_words(train_fileids) dev_data=fileid_words(dev_fileids) So if I run it into an interactive interpreter I can then perform tasks on `train_data`, `dev_data` and their corresponding fileids without repopulating the variables (a very time consuming task, e.g.: this takes 7 minutes to run each time). However, I want to be able to write it into a .py file so that I can save statistically interesting algorithms. I could do this by double-typing, e.g.: when I get a function working in the interpreter I then copy+paste it into the .py file, but this is quite inefficient and I lose out on my IDEs' features. Are there any IDEs or Python modules which can automatically keep the Python script running in memory, or store the value of a variable?such as `test_data`?in a db? Thanks for all suggestions From anfojp at gmail.com Sat May 26 09:31:36 2012 From: anfojp at gmail.com (Mr.T Beppu) Date: Sat, 26 May 2012 22:31:36 +0900 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. Message-ID: I think that I will make a browser in Official Python (not MacPorts Python). What should I do in order to install Webkit for Official Python (not MacPorts Python) ? from tokyo Japan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From barry at barrys-emacs.org Sat May 26 09:40:19 2012 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 26 May 2012 14:40:19 +0100 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. In-Reply-To: References: Message-ID: <74E4E58F-E2A0-4E8D-9D0D-BE191F76F1EA@barrys-emacs.org> On 26 May 2012, at 14:31, Mr.T Beppu wrote: > I think that I will make a browser in Official Python (not MacPorts Python). > What should I do in order to install Webkit for Official Python (not MacPorts Python) ? > from tokyo Japan. > -- > http://mail.python.org/mailman/listinfo/python-list The PyWebKit binding are not maintained and have problems. You will find yourself getting very frustrated trying to get anything but the trivia working. We ended up writing C++ code to use WebKit on Linux rather then our preferred Python. Barry -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Sat May 26 10:09:45 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 26 May 2012 10:09:45 -0400 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. In-Reply-To: References: Message-ID: On Sat, May 26, 2012 at 9:31 AM, Mr.T Beppu wrote: > I think that I will make a browser in Official Python (not MacPorts > Python). > What should I do in order to install Webkit for Official Python (not > MacPorts Python) ? > from tokyo Japan. > You don't just "install WebKit". You need a GUI framework. My suggestion would be to install PySide, which is a QT wrapper that includes a Webkit component. The other option is to use PyObjC to build a Cocoa GUI but then you're restricted to Mac OS X only. From animelovin at gmail.com Sat May 26 10:49:56 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Sat, 26 May 2012 10:49:56 -0400 Subject: Uliweb release 0.1 version In-Reply-To: References: Message-ID: <4FC0ED94.5060003@gthcfoundation.org> Flexible is more English than "flexiable" i guess... :-) Besides the typing errors I look forward in checking this out for new concepts... Cheers and congratulations, Etienne -- Etienne Robillard Occupation: Software Developer Company: Green Tea Hackers Club Email: erob at gthcfoundation.org Website: gthcfoundation.org Skype ID: incidah From buzzard at urubu.freeserve.co.uk Sat May 26 11:05:23 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sat, 26 May 2012 16:05:23 +0100 Subject: usenet reading In-Reply-To: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On 25/05/12 23:38, Jon Clements wrote: > Hi All, > > Normally use Google Groups but it's becoming absolutely frustrating - not only has the interface changed to be frankly impractical, the posts are somewhat random of what appears, is posted and whatnot. (Ironically posted from GG) > > Is there a server out there where I can get my news groups? If you don't mind paying a small fee there are several companies providing usenet access such as http://www.newsdemon.com. (I didn't have much joy trying to track down a reliable free service, so now I pay a few pounds a year.) Duncan From roy at panix.com Sat May 26 11:34:19 2012 From: roy at panix.com (Roy Smith) Date: Sat, 26 May 2012 11:34:19 -0400 Subject: Smallest/cheapest possible Python platform? Message-ID: What's the smallest/cheapest/lowest-power hardware platform I can run Python on today? I'm looking for something to use as a hardware controller in a battery-powered device and want to avoid writing in C for this project. Performance requirements are minimal. I need to monitor a few switches, control a couple of LEDs and relays, and keep time over about a 30 minute period to 1/10th second accuracy. Nice-to-have (but not essential) would be a speech synthesizer with a vocabulary of maybe 50 words. The Rasberry Pi certainly looks attractive, but isn't quite available today. Can you run Python on an Arduino? Things like http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are more than I need, and the $129 price probably busts my budget. From roy at panix.com Sat May 26 11:43:38 2012 From: roy at panix.com (Roy Smith) Date: Sat, 26 May 2012 11:43:38 -0400 Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: In article , duncan smith wrote: > On 25/05/12 23:38, Jon Clements wrote: > > Hi All, > > > > Normally use Google Groups but it's becoming absolutely frustrating - not > > only has the interface changed to be frankly impractical, the posts are > > somewhat random of what appears, is posted and whatnot. (Ironically posted > > from GG) > > > > Is there a server out there where I can get my news groups? > > If you don't mind paying a small fee there are several companies > providing usenet access such as http://www.newsdemon.com. (I didn't have > much joy trying to track down a reliable free service, so now I pay a > few pounds a year.) > > Duncan I use panix.com. For $100/year, I get mail, news, and unix shell access. By some measures, it's an expensive way to get mail access, but I'd much rather give Panix $100 than take advantage of any of the free mail services who does who-knows-what with my mail. Not to mention that I get access to such private newsgroups as panix.nytel.abuse. From rridge at csclub.uwaterloo.ca Sat May 26 12:20:19 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 26 May 2012 12:20:19 -0400 Subject: Smallest/cheapest possible Python platform? References: Message-ID: Roy Smith wrote: >What's the smallest/cheapest/lowest-power hardware platform I can run >Python on today? Not counting the Rasberry Pi, then probably a wireless router or one of those cheap media streaming boxes running custom firmware. >Performance requirements are minimal. I need to monitor a few switches, >control a couple of LEDs and relays, and keep time over about a 30 >minute period to 1/10th second accuracy. Nice-to-have (but not >essential) would be a speech synthesizer with a vocabulary of maybe 50 >words. Unfortunately I don't think any of these devices would have the GPIO pins you'd want for such a project. >The Rasberry Pi certainly looks attractive, but isn't quite available >today. Can you run Python on an Arduino? Things like >http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are >more than I need, and the $129 price probably busts my budget. The Arduino uses an 8-bit micro-controller, so probably not. (The ARM emulator based port of Linux probably doesn't meet your performance requirements.) I think you may need to either wait for the Rasberry Pi to become generally available or increase your budget. You should also consider whether any of these devices have Python bindings to interface with their GPIO pins. If not you'll probably have to end up writing some C code anyways. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From tinnews at isbd.co.uk Sat May 26 12:22:00 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Sat, 26 May 2012 17:22:00 +0100 Subject: Smallest/cheapest possible Python platform? References: Message-ID: <8ic799-gk3.ln1@chris.zbmc.eu> Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. Rasberry Pi is available, some have arrived, mine will arrive on Monday or Tuesday (I'm talking about UK here). I think getting python to run on an arduino device would be quite a lot of effort even if it's possible. You might want to avoid C but the 'sort of C' on the Arduino is very simple indeed, hardly more difficult than Python. -- Chris Green From no.email at nospam.invalid Sat May 26 12:25:17 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 26 May 2012 09:25:17 -0700 Subject: Smallest/cheapest possible Python platform? References: Message-ID: <7xipfirjte.fsf@ruckus.brouhaha.com> Roy Smith writes: > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? No. YOu want a 32-bit platform with an OS and perhaps 1 meg of memory. And by the time you port Python to it unless it's there already, you may as well have just written your application in C. If you want something even cheaper than an Arduino, look at the TI Launchpad. But you can't program that in Python either. There is a standalone interactive Forth for it, if that's of any interest: http://www.somersetweb.com/4E4th/EN.html There are some fairly cheap ARM boards around that could run Python, but they will be battery hungry compared to a Launchpad or Arduino, and again, may not be worth the porting hassle if there's not an already-done Python port. Lua might be another scripting language of interest (www.lua.org). Sort of the same idea as Python, not quite as nice, but smaller and easier to embed. I think it wants around 50-100k of ram, still way out of the Arduino range. From duane.kaufman at gmail.com Sat May 26 12:44:25 2012 From: duane.kaufman at gmail.com (TheSeeker) Date: Sat, 26 May 2012 09:44:25 -0700 (PDT) Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: Message-ID: <16a09324-e78c-4fc2-a2ae-82a724663ee9@googlegroups.com> On Saturday, May 26, 2012 10:34:19 AM UTC-5, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > You might take a look at the work being done by Dean Hall (with others) on the python-on-a-chip project: http://code.google.com/p/python-on-a-chip/ Many platforms have been ported to, including Arduino Mega, RedBee EconoTAG, Teensy++ 2.0, Microchip PIC24/dsPIC, among others This route may be more work than others, but considering budget may be attractive. > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. On Saturday, May 26, 2012 10:34:19 AM UTC-5, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. On Saturday, May 26, 2012 10:34:19 AM UTC-5, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. On Saturday, May 26, 2012 10:34:19 AM UTC-5, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. From nospam at nospam.com Sat May 26 12:49:31 2012 From: nospam at nospam.com (Javier) Date: Sat, 26 May 2012 16:49:31 +0000 (UTC) Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: news.aioe.org nntp.aioe.org http://www.aioe.org/ Aioe.org hosts a public news server, an USENET site that is intentionally kept open for all IP addresses without requiring any kind of authentication both for reading and posting.Each IP address is authorized to post 25 messages per day... From roy at panix.com Sat May 26 13:39:03 2012 From: roy at panix.com (Roy Smith) Date: Sat, 26 May 2012 13:39:03 -0400 Subject: Smallest/cheapest possible Python platform? References: <8ic799-gk3.ln1@chris.zbmc.eu> Message-ID: In article <8ic799-gk3.ln1 at chris.zbmc.eu>, tinnews at isbd.co.uk wrote: > > Rasberry Pi is available, some have arrived, mine will arrive on > Monday or Tuesday (I'm talking about UK here). Interesting. Newark is claiming they'll have 1 piece on June 18th, and no further stock until October. http://www.newark.com/jsp/search/productdetail.jsp?sku=83T1943 From nobody at nowhere.com Sat May 26 14:02:20 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 26 May 2012 19:02:20 +0100 Subject: Help doing it the "python way" References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: On Thu, 24 May 2012 13:22:43 -0700, Scott Siegler wrote: > is there a way to do something like: > [(x,y-1), (x,y+1) for zzz in coord_list] > or something along those lines? [(xx,yy) for x, y in coord_list for xx, yy in [(x,y-1),(x,y+1)]] or: [(x,yy) for x, y in coord_list for yy in [y-1,y+1]] Not to be confused with: [[(xx,yy) for xx, yy in [(x,y-1),(x,y+1)]] for x, y in coord_list] or: [[(x,yy) for yy in (y-1,y+1)] for x, y in coord_list] which will produce the same pairs in the same order but as a list of lists rather than as a single flat list. From nobody at nowhere.com Sat May 26 14:14:54 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 26 May 2012 19:14:54 +0100 Subject: Smallest/cheapest possible Python platform? References: Message-ID: On Sat, 26 May 2012 11:34:19 -0400, Roy Smith wrote: > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. You can't run Python on an Arduino. There are a number of boards with ARM or PIC32 processors which can use Arduino daughter-boards (shields), but all of the ones which I've seen have rather limited RAM. From drobinow at gmail.com Sat May 26 14:33:18 2012 From: drobinow at gmail.com (David Robinow) Date: Sat, 26 May 2012 14:33:18 -0400 Subject: usenet reading In-Reply-To: References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On Sat, May 26, 2012 at 11:43 AM, Roy Smith wrote: > I use panix.com. ?For $100/year, I get mail, news, and unix shell > access. ?By some measures, it's an expensive way to get mail access, but > I'd much rather give Panix $100 than take advantage of any of the free > mail services who does who-knows-what with my mail. ?Not to mention that > I get access to such private newsgroups as panix.nytel.abuse. I'm happy enough with several of the free services and haven't used news in over a decade, but if it works for you, great. I'm curious, though, what makes you think that panix.com protects your privacy more than yahoo, google, or AOL? From no.email at nospam.invalid Sat May 26 15:22:05 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 26 May 2012 12:22:05 -0700 Subject: Smallest/cheapest possible Python platform? References: <8ic799-gk3.ln1@chris.zbmc.eu> Message-ID: <7x1um6928y.fsf@ruckus.brouhaha.com> tinnews at isbd.co.uk writes: > Rasberry Pi is available, some have arrived, mine will arrive on > Monday or Tuesday (I'm talking about UK here). Early orders have been filled, more are being filled, but there is a huge backlong and therefore a long wait if you waited til now to order. If you want one right away, at least as of a week or so ago they were going for $200-ish on ebay. The Raspberry Pi is not really appropriate for a low powered portable application anyway, because of relatively high power requirements compared to an 8 bitter without all that media playback stuff. The Beaglebone (www.beagleboard.org) is slightly higher end than the RPi and runs Python nicely, though it faces the same issues. I think a microcontroller (AVR, MSP430 etc) is a better fit for the OP's application than anything big enough to run Python. If C is really intolerable I know there are some micros that can be programmed in BASIC. From rosuav at gmail.com Sat May 26 15:40:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 May 2012 05:40:35 +1000 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <7x1um6928y.fsf@ruckus.brouhaha.com> References: <8ic799-gk3.ln1@chris.zbmc.eu> <7x1um6928y.fsf@ruckus.brouhaha.com> Message-ID: On Sun, May 27, 2012 at 5:22 AM, Paul Rubin wrote: > If C is really intolerable I know there are some micros that can be > programmed in BASIC. Ugh. Of those, I would strongly recommend going with C. ChrisA From roy at panix.com Sat May 26 15:53:25 2012 From: roy at panix.com (Roy Smith) Date: Sat, 26 May 2012 15:53:25 -0400 Subject: Smallest/cheapest possible Python platform? References: <8ic799-gk3.ln1@chris.zbmc.eu> <7x1um6928y.fsf@ruckus.brouhaha.com> Message-ID: In article <7x1um6928y.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > The Raspberry Pi is not really appropriate for a low powered portable > application anyway, because of relatively high power requirements > compared to an 8 bitter without all that media playback stuff. It sounds like I can run one on 300mA @ 5V. For my application, I'll have about 10 A-h available at 12V (motorcycle battery). Assuming (mumble, cough, cough) 75% down-conversion efficiency, 120 W-h @ 12V gets me 90 W-h @ 5V, which is 18 A-h, or 60 hours of operation. Of course, I've got to run some other stuff too, but I don't think the Raspberry Pi is going to blow my power budget. In any case, the dirt-cheap price makes it really attractive. With what I save on silicon, I can afford to buy more lead :-) From solipsis at pitrou.net Sat May 26 16:28:18 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 26 May 2012 20:28:18 +0000 (UTC) Subject: Smallest/cheapest possible Python platform? References: Message-ID: Roy Smith panix.com> writes: > > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. It depends *which* Python. Complete Python implementations (CPython, PyPy, IronPython, Jython) will have stronger requirements than minimal / incomplete implementations. As for CPython, it needs a C compiler, decent POSIX support, a 32-bit CPU at least, and realistically you won't do much with at least 8 MB RAM. We actually have a buildbot which regularly tests building and running of CPython on an ARM machine: http://www.python.org/dev/buildbot/all/buildslaves/warsaw-ubuntu-arm It's a Cortex A8 with 1GB RAM, though, so I don't know if it's in your range (but 1GB is not needed at all, except that it's nice when running the full regression test suite). Regards Antoine. From no.email at nospam.invalid Sat May 26 17:32:05 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 26 May 2012 14:32:05 -0700 Subject: Smallest/cheapest possible Python platform? References: <8ic799-gk3.ln1@chris.zbmc.eu> <7x1um6928y.fsf@ruckus.brouhaha.com> Message-ID: <7xd35qpr1m.fsf@ruckus.brouhaha.com> Roy Smith writes: > It sounds like I can run one on 300mA @ 5V. For my application, I'll > have about 10 A-h available at 12V (motorcycle battery). OK, the RPi should be fine power-wise in that case, though I wouldn't consider something with a 10AH motorcycle battery to be very portable. > which is 18 A-h, or 60 hours of operation. The Launchpad can run 60+ hours on a watch battery, if the on-board LED's are not lit. The LED's use much more power than the processor. > In any case, the dirt-cheap price makes it really attractive. With what > I save on silicon, I can afford to buy more lead :-) The RPi is an awesome value for such a powerful board, but the Launchpad (while much less powerful) is far cheaper: http://e2e.ti.com/group/msp430launchpad/w/default.aspx From darcy at druid.net Sat May 26 18:10:58 2012 From: darcy at druid.net (D'Arcy Cain) Date: Sat, 26 May 2012 18:10:58 -0400 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <7xd35qpr1m.fsf@ruckus.brouhaha.com> References: <8ic799-gk3.ln1@chris.zbmc.eu> <7x1um6928y.fsf@ruckus.brouhaha.com> <7xd35qpr1m.fsf@ruckus.brouhaha.com> Message-ID: <4FC154F2.4020903@druid.net> On 12-05-26 05:32 PM, Paul Rubin wrote: > Roy Smith writes: >> It sounds like I can run one on 300mA @ 5V. For my application, I'll >> have about 10 A-h available at 12V (motorcycle battery). > > OK, the RPi should be fine power-wise in that case, though I wouldn't > consider something with a 10AH motorcycle battery to be very portable. Unless the application involves mounting it on a motorcycle. As a biker I am now officially curious, what's the application? -- 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. IM: darcy at Vex.Net From limodou at gmail.com Sat May 26 20:28:13 2012 From: limodou at gmail.com (limodou) Date: Sun, 27 May 2012 08:28:13 +0800 Subject: Uliweb release 0.1 version In-Reply-To: <4FC0ED94.5060003@gthcfoundation.org> References: <4FC0ED94.5060003@gthcfoundation.org> Message-ID: On Sat, May 26, 2012 at 10:49 PM, Etienne Robillard wrote: > Flexible is more English than "flexiable" i guess... :-) > > Besides the typing errors I look forward in checking this out for new > concepts... > > > Cheers and congratulations, > > Etienne > Thank you. I've changed it in GIt. -- I like python! UliPad <>: http://code.google.com/p/ulipad/ UliWeb <>: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou From rtomek at ceti.pl Sat May 26 22:16:08 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Sun, 27 May 2012 04:16:08 +0200 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: Message-ID: On Sat, 26 May 2012, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. If you are on tight budget and depend so much on Python, I'm afraid you should either: a. grow your budget b. try another language For what I know, I wouldn't touch Arduino unless I really had to. The reason for this, I have been spoiled by machines, of which the smallest I wanted to touch had 3mb of ram. Arduinos, with their ram in kilobytes at best, don't qualify as interesting from my point of view. Also, I don't think they are so much attractive price-wise. I would rather buy myself a Beagle Bone, like this one: http://www.adafruit.com/products/513 http://beagleboard.org/bone However, if all that you want is flip some leds, this is huge overkill. For led flipping, Arduino sounds ok, just not with Python-as-we-like-it. Maybe some pseudoPython can be had on it. Myself, I would rather go with one of Arduino's supported languages or assembly. Or Forth. If you land among embedded systems, it's better to speak embeddish or you will feel uncomfortable. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From rurpy at yahoo.com Sat May 26 22:37:33 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 26 May 2012 19:37:33 -0700 (PDT) Subject: 2to3 for 2.7 Message-ID: <5792fdb7-d41d-47a9-851a-a7d0f1439c40@p16g2000yqc.googlegroups.com> Is there a list of fixers I can tell 2to3 to use that will limit changes to things that will continue to run under python-2.7? I want to start the 2->3 trip by making my code as py3 compatible (under py2) as possible before going the rest of the way to py3, and having 2to3 help with this seems like a good idea. From highpointe3i at gmail.com Sun May 27 00:50:45 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:50:45 -0700 Subject: 2to3 for 2.7 In-Reply-To: <5792fdb7-d41d-47a9-851a-a7d0f1439c40@p16g2000yqc.googlegroups.com> References: <5792fdb7-d41d-47a9-851a-a7d0f1439c40@p16g2000yqc.googlegroups.com> Message-ID: <4FFB4D7E-0790-47C6-9B42-49B9CF70B04F@gmail.com> Here is my SS: 259 71 2451 On May 26, 2012, at 7:37 PM, "rurpy at yahoo.com" wrote: > Is there a list of fixers I can tell 2to3 to use that will > limit changes to things that will continue to run under > python-2.7? > > I want to start the 2->3 trip by making my code > as py3 compatible (under py2) as possible before > going the rest of the way to py3, and having 2to3 > help with this seems like a good idea. > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:56:34 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:56:34 -0700 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <8ic799-gk3.ln1@chris.zbmc.eu> References: <8ic799-gk3.ln1@chris.zbmc.eu> Message-ID: <85015BFD-6105-4AFA-A905-FBE1DE3ECBE0@gmail.com> Here is my SS: 259 71 2451 On May 26, 2012, at 9:22 AM, tinnews at isbd.co.uk wrote: > Roy Smith wrote: >> What's the smallest/cheapest/lowest-power hardware platform I can run >> Python on today? I'm looking for something to use as a hardware >> controller in a battery-powered device and want to avoid writing in C >> for this project. >> >> Performance requirements are minimal. I need to monitor a few switches, >> control a couple of LEDs and relays, and keep time over about a 30 >> minute period to 1/10th second accuracy. Nice-to-have (but not >> essential) would be a speech synthesizer with a vocabulary of maybe 50 >> words. >> >> The Rasberry Pi certainly looks attractive, but isn't quite available >> today. Can you run Python on an Arduino? Things like >> http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are >> more than I need, and the $129 price probably busts my budget. > > Rasberry Pi is available, some have arrived, mine will arrive on > Monday or Tuesday (I'm talking about UK here). > > I think getting python to run on an arduino device would be quite a > lot of effort even if it's possible. You might want to avoid C but > the 'sort of C' on the Arduino is very simple indeed, hardly more > difficult than Python. > > > -- > Chris Green > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:56:45 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:56:45 -0700 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 9:20 AM, Ross Ridge wrote: > Roy Smith wrote: >> What's the smallest/cheapest/lowest-power hardware platform I can run >> Python on today? > > Not counting the Rasberry Pi, then probably a wireless router or one of > those cheap media streaming boxes running custom firmware. > >> Performance requirements are minimal. I need to monitor a few switches, >> control a couple of LEDs and relays, and keep time over about a 30 >> minute period to 1/10th second accuracy. Nice-to-have (but not >> essential) would be a speech synthesizer with a vocabulary of maybe 50 >> words. > > Unfortunately I don't think any of these devices would have the GPIO > pins you'd want for such a project. > >> The Rasberry Pi certainly looks attractive, but isn't quite available >> today. Can you run Python on an Arduino? Things like >> http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are >> more than I need, and the $129 price probably busts my budget. > > The Arduino uses an 8-bit micro-controller, so probably not. (The ARM > emulator based port of Linux probably doesn't meet your performance > requirements.) > > I think you may need to either wait for the Rasberry Pi to become > generally available or increase your budget. You should also consider > whether any of these devices have Python bindings to interface with > their GPIO pins. If not you'll probably have to end up writing some C > code anyways. > > Ross Ridge > > -- > l/ // Ross Ridge -- The Great HTMU > [oo][oo] rridge at csclub.uwaterloo.ca > -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ > db // > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:56:56 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:56:56 -0700 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <7xipfirjte.fsf@ruckus.brouhaha.com> References: <7xipfirjte.fsf@ruckus.brouhaha.com> Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 9:25 AM, Paul Rubin wrote: > Roy Smith writes: >> The Rasberry Pi certainly looks attractive, but isn't quite available >> today. Can you run Python on an Arduino? > > No. YOu want a 32-bit platform with an OS and perhaps 1 meg of memory. > And by the time you port Python to it unless it's there already, you may > as well have just written your application in C. > > If you want something even cheaper than an Arduino, look at the TI > Launchpad. But you can't program that in Python either. There is > a standalone interactive Forth for it, if that's of any interest: > http://www.somersetweb.com/4E4th/EN.html > > There are some fairly cheap ARM boards around that could run Python, but > they will be battery hungry compared to a Launchpad or Arduino, and > again, may not be worth the porting hassle if there's not an > already-done Python port. > > Lua might be another scripting language of interest (www.lua.org). Sort > of the same idea as Python, not quite as nice, but smaller and easier to > embed. I think it wants around 50-100k of ram, still way out of the > Arduino range. > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:57:33 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:57:33 -0700 Subject: usenet reading In-Reply-To: References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 8:43 AM, Roy Smith wrote: > In article , > duncan smith wrote: > >> On 25/05/12 23:38, Jon Clements wrote: >>> Hi All, >>> >>> Normally use Google Groups but it's becoming absolutely frustrating - not >>> only has the interface changed to be frankly impractical, the posts are >>> somewhat random of what appears, is posted and whatnot. (Ironically posted >>> from GG) >>> >>> Is there a server out there where I can get my news groups? >> >> If you don't mind paying a small fee there are several companies >> providing usenet access such as http://www.newsdemon.com. (I didn't have >> much joy trying to track down a reliable free service, so now I pay a >> few pounds a year.) >> >> Duncan > > I use panix.com. For $100/year, I get mail, news, and unix shell > access. By some measures, it's an expensive way to get mail access, but > I'd much rather give Panix $100 than take advantage of any of the free > mail services who does who-knows-what with my mail. Not to mention that > I get access to such private newsgroups as panix.nytel.abuse. > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:57:49 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:57:49 -0700 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 8:34 AM, Roy Smith wrote: > What's the smallest/cheapest/lowest-power hardware platform I can run > Python on today? I'm looking for something to use as a hardware > controller in a battery-powered device and want to avoid writing in C > for this project. > > Performance requirements are minimal. I need to monitor a few switches, > control a couple of LEDs and relays, and keep time over about a 30 > minute period to 1/10th second accuracy. Nice-to-have (but not > essential) would be a speech synthesizer with a vocabulary of maybe 50 > words. > > The Rasberry Pi certainly looks attractive, but isn't quite available > today. Can you run Python on an Arduino? Things like > http://www.embeddedarm.com/products/board-detail.php?product=TS-7250 are > more than I need, and the $129 price probably busts my budget. > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:58:00 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:58:00 -0700 Subject: usenet reading In-Reply-To: References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 8:05 AM, duncan smith wrote: > On 25/05/12 23:38, Jon Clements wrote: >> Hi All, >> >> Normally use Google Groups but it's becoming absolutely frustrating - not only has the interface changed to be frankly impractical, the posts are somewhat random of what appears, is posted and whatnot. (Ironically posted from GG) >> >> Is there a server out there where I can get my news groups? > > If you don't mind paying a small fee there are several companies providing usenet access such as http://www.newsdemon.com. (I didn't have much joy trying to track down a reliable free service, so now I pay a few pounds a year.) > > Duncan > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:58:15 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:58:15 -0700 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. In-Reply-To: <74E4E58F-E2A0-4E8D-9D0D-BE191F76F1EA@barrys-emacs.org> References: <74E4E58F-E2A0-4E8D-9D0D-BE191F76F1EA@barrys-emacs.org> Message-ID: <405CF7F8-3F89-447E-9B70-B291E5E9F4A2@gmail.com> Here is my SS: 259 71 2451 On May 26, 2012, at 6:40 AM, Barry Scott wrote: > > On 26 May 2012, at 14:31, Mr.T Beppu wrote: > >> I think that I will make a browser in Official Python (not MacPorts Python). >> What should I do in order to install Webkit for Official Python (not MacPorts Python) ? >> from tokyo Japan. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > The PyWebKit binding are not maintained and have problems. You will find > yourself getting very frustrated trying to get anything but the trivia working. > > We ended up writing C++ code to use WebKit on Linux rather then our > preferred Python. > > Barry > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From highpointe3i at gmail.com Sun May 27 00:58:29 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:58:29 -0700 Subject: Uliweb release 0.1 version In-Reply-To: <4FC0ED94.5060003@gthcfoundation.org> References: <4FC0ED94.5060003@gthcfoundation.org> Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 7:49 AM, Etienne Robillard wrote: > Flexible is more English than "flexiable" i guess... :-) > > Besides the typing errors I look forward in checking this out for new concepts... > > > Cheers and congratulations, > > Etienne > > > -- > Etienne Robillard > Occupation: Software Developer > Company: Green Tea Hackers Club > Email: erob at gthcfoundation.org > Website: gthcfoundation.org > Skype ID: incidah > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:58:42 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:58:42 -0700 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. In-Reply-To: References: Message-ID: <9E63D03F-19A8-48C4-9674-7041EDC41201@gmail.com> Here is my SS: 259 71 2451 On May 26, 2012, at 7:09 AM, Benjamin Kaplan wrote: > On Sat, May 26, 2012 at 9:31 AM, Mr.T Beppu wrote: >> I think that I will make a browser in Official Python (not MacPorts >> Python). >> What should I do in order to install Webkit for Official Python (not >> MacPorts Python) ? >> from tokyo Japan. >> > > You don't just "install WebKit". You need a GUI framework. My > suggestion would be to install PySide, which is a QT wrapper that > includes a Webkit component. The other option is to use PyObjC to > build a Cocoa GUI but then you're restricted to Mac OS X only. > -- > http://mail.python.org/mailman/listinfo/python-list From highpointe3i at gmail.com Sun May 27 00:59:21 2012 From: highpointe3i at gmail.com (highpointe) Date: Sat, 26 May 2012 21:59:21 -0700 Subject: How to import Webkit and object in Official Python (not MacPorts python) without X11. In-Reply-To: References: Message-ID: Here is my SS: 259 71 2451 On May 26, 2012, at 6:31 AM, "Mr.T Beppu" wrote: > I think that I will make a browser in Official Python (not MacPorts Python). > What should I do in order to install Webkit for Official Python (not MacPorts Python) ? > from tokyo Japan. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From anfojp at gmail.com Sun May 27 07:49:11 2012 From: anfojp at gmail.com (Mr.T Beppu) Date: Sun, 27 May 2012 20:49:11 +0900 Subject: How to build a browser on Mac in Official Python (not MacPorts Python). Message-ID: Hello All ! I installed Qt and PySide in Macintosh. There is a sample browser program @ the PySide site. It operated by Python2.7 and 2.6. Thank you for Barry Scott . U r welcome. from tokyo Japan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun May 27 09:53:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 May 2012 13:53:30 GMT Subject: 2to3 for 2.7 References: <5792fdb7-d41d-47a9-851a-a7d0f1439c40@p16g2000yqc.googlegroups.com> Message-ID: <4fc231da$0$29992$c3e8da3$5496439d@news.astraweb.com> On Sat, 26 May 2012 19:37:33 -0700, rurpy at yahoo.com wrote: > Is there a list of fixers I can tell 2to3 to use that will limit changes > to things that will continue to run under python-2.7? So you want a 2to2? I suggest you read the Fine Manual and choose the fixers you want to apply yourself: http://docs.python.org/library/2to3.html That, plus a bit of trial-and-error at the interactive prompt, will soon tell you what works and what doesn't. But read on for my suggestions. > I want to start the 2->3 trip by making my code as py3 compatible (under > py2) as possible before going the rest of the way to py3, and having > 2to3 help with this seems like a good idea. Your project, your decision, but it doesn't sound like a good idea to me, unless your project is quite small or efficiency is not high on your list of priorities. You risk making your 2.7 version significantly slower and less efficient than your 2.6 version, but without actually gaining 3.x compatibility. (For what it's worth, I try to aim at 3.x compatibility as the priority, and if that means my code is a bit slower under 2.5-2.7, that's a price I'm willing to pay.) The problem is that many of the idioms that work well in Python 3 will be less efficient, and therefore slower, in Python 2.7. For example, consider this Python 2.x loop, iterating lazily over a dict efficiently: for key,value in dict.iteritems(): ... After applying the dict fixer, that is converted to the Python3-ism: for key,value in dict.items(): ... where it remains lazy and efficient. But you aren't running it under Python 3, you are running it under Python 2.7 where it is *eager* rather than lazy, and inefficient if the dict is big and you bail out of the loop early. Now, this may not matter if: - efficiency is not a high priority; - you're happy to make 2.7 a bit less efficient for the sake of Python 3 compatibility (except you aren't getting Python 3 compatibility, only *partial* compatibility); - none of the changes are bottlenecks, so a little inefficiency doesn't matter ("premature optimization is the root of all evil"); - you are prepared to carefully scrutinise the 2to3 diffs and apply only the changes that won't slow your code down; - you carefully limit yourself to only the few 2to3 changes which are purely syntactic, with no performance or semantic implications. In which case, it hardly seems worthwhile to me. But your mileage may vary. For what it's worth, I'd try these fixers: apply except exec execfile exitfunc has_key idioms ne next paren print raise repr tuple_params ws_comma xreadlines plus "from __future__ import print", and see what breaks :) Also, don't forget future_builtins: http://docs.python.org/library/future_builtins.html Good luck, and if you do go ahead with this, please consider posting an update here, or writing a blog post with details of how successful it was. -- Steven From cjw at ncf.ca Sun May 27 11:37:49 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 27 May 2012 11:37:49 -0400 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <7xipfirjte.fsf@ruckus.brouhaha.com> References: <7xipfirjte.fsf@ruckus.brouhaha.com> Message-ID: On 26/05/2012 12:25 PM, Paul Rubin wrote: > Roy Smith writes: >> The Rasberry Pi certainly looks attractive, but isn't quite available >> today. Can you run Python on an Arduino? > > No. YOu want a 32-bit platform with an OS and perhaps 1 meg of memory. > And by the time you port Python to it unless it's there already, you may > as well have just written your application in C. Python is available and included with the Debian distribution for the RPi. 32 bit and smaller operations are provided. Floating point is by software. A FPU is available for the AIM processor, but not provided with the BRCM 2835 board. Colin W. [snip] From gelonida at gmail.com Sun May 27 13:18:40 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 27 May 2012 19:18:40 +0200 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: <7xipfirjte.fsf@ruckus.brouhaha.com> Message-ID: On 05/27/2012 05:37 PM, Colin J. Williams wrote: > On 26/05/2012 12:25 PM, Paul Rubin wrote: >> Roy Smith writes: >>> The Rasberry Pi certainly looks attractive, but isn't quite available >>> today. Can you run Python on an Arduino? >> >> No. YOu want a 32-bit platform with an OS and perhaps 1 meg of memory. >> And by the time you port Python to it unless it's there already, you may >> as well have just written your application in C. > > Python is available and included with the Debian distribution for the > RPi. 32 bit and smaller operations are provided. Floating point is by > software. A FPU is available for the AIM processor, but not provided > with the BRCM 2835 board. > DO you know which python version.Is it a pyton with or without ctypes. Without ctypes one will have rather limited access to anything board specific? From gdamjan at gmail.com Sun May 27 14:50:54 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 27 May 2012 20:50:54 +0200 Subject: PEP 405 vs 370 In-Reply-To: References: Message-ID: >> http://www.python.org/dev/peps/pep-0405/ >> >> I don't get what PEP 405 (Python Virtual Environments) brings vs what we >> already had in PEP 370 since Python 2.6. >> >> Obviously 405 has a tool to create virtual environments, but that's >> trivial for PEP 370 [1], and has support for isolation from the >> system-wide site patch which could've been added in addition to PEP 370. >> >> So maybe I'm missing something? > My PEP 370 is about installing additional packages as an unprivileged > user and for the current user. It's a simplistic approach that just > adds one more site-package directory in the user's home directory. well you can have and activate several different directories (venvs) with PYTHONUSERBASE. I do use that very nicely, and haven't seen any problems with that. > PEP 405 is a different beast. It adds support for isolated environment > that don't share state with the site wide installation. A user can > have multiple virtual envs and install different sets of packages in > each env. Wouldn't it be easier to just add isolation to 370? Again, you can have multiple virtual envs with 370 too. ps. sorry for the late response, it seems my NNTP server doesn't relay all messages. I might need to switch. -- damjan From matteo at matteolandi.net Sun May 27 18:21:25 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Mon, 28 May 2012 00:21:25 +0200 Subject: Tkinter deadlock on graceful exit Message-ID: <20120527222125.GA22965@MARble> Hi list, recently I started to work on an application [1] which makes use of the Tkinter module to handle interaction with the user. Simply put, the app is a text widget displaying a file filtered by given criteria, with a handy feature that the window is raised each time a new line is added to the widget. The application mainly consists of three threads: the first one, the file processor, reads the file, filters the lines of interest, and pushes them into a shared queue (henceforth `lines_queue`); the second one, the gui_updater, pops elements from `lines_queue`, and schedule GUI updates using the `after_idle` method of the Tkinter module; finally the last one, the worker spawner, receives commands by the gui (by means of a shared queue, `filters_queue`), and drives the application, terminating or spawning new threads. For example, let's see what happens when you start the application, fill the filter entry and press Enter button: 1 the associated even handler is scheduled (we should be inside the Tkinter mainloop thread), and the filter is pushed into `filters_queue`; 2 the worker spawner receives the new filter, terminate a possibly running working thread, and once done, create a new file processor; 3 the file processor actually processes the file and fills the `lines_queue` with the lines matching given filter; 4 the gui updater schedules GUI updates as soon as items are pushed into `lines_queue` 5 Tkinter mainloop thread updates the gui when idle What happens when the main window is closed? Here is how I implemented the graceful shutdown of the app: 1 a quit event is scheduled and a _special_ message is pushed into both `filter_queue` and `lines_queue` 2 the gui updater threads receives the _special_ message, and terminates 3 the worker spawner receives the message, terminates the working thread and interrupts her execution. 4 Tk.quit() is called after the quit event handler, and we finally quit the mainloop Honestly speaking, I see no issues with the algorithm presented above; however, if I close the window in the middle of updates of the text widget, the applications hangs indefinitely. On the other hand, everything works as expected if I close the app when the file processor, for example, is waiting for new content to filter. I put some logging messages to analyze the deadlock (?!), and noticed that both the worker spawner and the file processor are terminated correctly. The only thread still active for some strange reasons, is the gui updater. Do you see anything wrong with the description presented above? Please say so, because I can't figure it out! Regards, Matteo [1] https://bitbucket.org/iamFIREcracker/logfilter -- http://www.matteolandi.net From chrisjrn+pyconau at gmail.com Sun May 27 19:20:04 2012 From: chrisjrn+pyconau at gmail.com (Chris Neugebauer) Date: Mon, 28 May 2012 09:20:04 +1000 Subject: PyCon Australia 2012 Early Bird tickets almost sold out! In-Reply-To: References: Message-ID: tl;dr: PyCon Australia's Early Bird registrations are on sale until this Friday, 1 June -- or until we've sold 60 tickets. There's fewer than 15 left now, so hurry! Find out more at http://2012.pycon-au.org/register/prices, including details of our accommodation programme. Are you planning on coming to PyCon Australia 2012, the national conference for the Python programming community? If you've been putting off your registration, now is an excellent time to act: there's fewer than 15 Early Bird tickets left for the conference, and these WILL sell out before the deadline of Friday 1 June. Early Bird registration rates are available from $165 for "Enthusiast"-level tickets, or $420 for "Professional"-level tickets; each of these represents a saving of more than 10% on our regular prices. All tickets include access to the CodeWars event on Friday 17 August, and the post-conference sprints on Monday 20 and Tuesday 21 August. For full details of what comes with each of our tickets, and for more information about the conference itself, visit http://2012.pycon-au.org/register/prices === About PyCon Australia === PyCon Australia is the national conference for the Python Programming Community. The third PyCon Australia will be held on August 18 and 19, 2012 in Hobart, Tasmania, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country?s Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2012, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Gold sponsors: Google Australia ( www.google.com.au), and the Australian Computer Society (Tasmanian Branch) ( www.acs.org.au); our Event partner, Secret Lab; and our Silver sponsors: the Python Software Foundation, the Django Software Foundation, Anchor Systems, Red Hat, ekit, RimuHosting, and CSIRO. -- -- --Christopher Neugebauer Conference Coordinator and Sponsor Liaison PyCon Australia: Hobart 2012 -- http://2012.pycon-au.org -- @pyconau Early bird registration and accommodation deals now available! See our website for details. Jabber: chrisjrn at gmail.com -- IRC: chrisjrn on irc.freenode.net -- WWW: http://chris.neugebauer.id.au -- Twitter/Identi.ca: @chrisjrn -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Sun May 27 23:06:31 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 27 May 2012 20:06:31 -0700 (PDT) Subject: 2to3 for 2.7 References: <5792fdb7-d41d-47a9-851a-a7d0f1439c40@p16g2000yqc.googlegroups.com> <4fc231da$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38feb41a-158b-42b5-964d-c1757dbfacfd@w24g2000vby.googlegroups.com> On 05/27/2012 07:53 AM, Steven D'Aprano wrote: > > On Sat, 26 May 2012 19:37:33 -0700, rurpy at yahoo.com wrote: >> >> Is there a list of fixers I can tell 2to3 to use that will limit changes >> >> to things that will continue to run under python-2.7? > > > > So you want a 2to2? Yes. :-) > > I suggest you read the Fine Manual and choose the fixers you want to > > apply yourself: > > > > http://docs.python.org/library/2to3.html > > > > That, plus a bit of trial-and-error at the interactive prompt, will soon > > tell you what works and what doesn't. But read on for my suggestions. That, and the 2.6 and 2.7 What's New's and the docs for the 3.x backported features mentioned therein... I've started to do just that but if someone else has already distilled all this information... >> >> I want to start the 2->3 trip by making my code as py3 compatible (under >> >> py2) as possible before going the rest of the way to py3, and having >> >> 2to3 help with this seems like a good idea. > > Your project, your decision, but it doesn't sound like a good idea to me, > > unless your project is quite small or efficiency is not high on your list > > of priorities. You risk making your 2.7 version significantly slower and > > less efficient than your 2.6 version, but without actually gaining 3.x > > compatibility. I can't really migrate my project until wxPython does. But I've read a number of conversion experiences ranging from "ran 2to3 and everything was golden" to needing to make some serious design decisions (usually in the bytes/str area) to months of effort to get all the little glitches wrung out. So I have no idea what is in store for me. By doing some of the conversion now I can hopefully get a better sense of what is in store and get some of the work done earlier rather than later. There is also the generally useful heuristic of dividing a larger task into two smaller independent tasks... And finally, there is the question about maintaining 2/3 compatibility in a single codebase. I don't have a hard requirement for this but if it is doable without too much effort, I would prefer to do so. ISTM that looking at what remains left to do after the 2.7 code has been 3-ifided as much as possible will allow me to make a better judgment about that. > > (For what it's worth, I try to aim at 3.x compatibility as the priority, > > and if that means my code is a bit slower under 2.5-2.7, that's a price > > I'm willing to pay.) > > > > The problem is that many of the idioms that work well in Python 3 will be > > less efficient, and therefore slower, in Python 2.7. For example, > > consider this Python 2.x loop, iterating lazily over a dict efficiently: I did not spend much time optimizing for performance when writing the code, so it probably doesn't make sense to worry about it now, unless a really large performance difference is likely (which seems to me unlikely given that I don't have any really large in-memory data). Thanks for the tip though; it is something I'll remain alert for. > >[...] > > For what it's worth, I'd try these fixers: > > > > apply > > except > > exec > > execfile > > exitfunc > > has_key > > idioms > > ne > > next > > paren > > print > > raise > > repr > > tuple_params > > ws_comma > > xreadlines > > > > plus "from __future__ import print", and see what breaks :) > > > > Also, don't forget future_builtins: > > http://docs.python.org/library/future_builtins.html > > > > Good luck, and if you do go ahead with this, please consider posting an > > update here, or writing a blog post with details of how successful it was. Thanks for that list. Sans anything more definitive it is a good starting point. From ledbulbs15 at gmail.com Mon May 28 01:08:45 2012 From: ledbulbs15 at gmail.com (reledtubes) Date: Sun, 27 May 2012 22:08:45 -0700 (PDT) Subject: Mouse LED Control in Python In-Reply-To: <1154291200.448540.224660@s13g2000cwa.googlegroups.com> References: <1154291200.448540.224660@s13g2000cwa.googlegroups.com> Message-ID: <1338181725839-4976047.post@n6.nabble.com> We are a LED factory in China, our products are LED tube light, LED bulb light, LED screen, LED strips and so on, our website:, could you please advise how to exploit market on abroad? ----------------------------------------------------------------------------------- http://www.ledlightonsale.com/ LED Tubes http://www.ledlightonsale.com/catalog/led-bulbs led bulbs lights http://www.ledlightonsale.com/catalog/dimmable-led-lights Dimmable LED Lights -- View this message in context: http://python.6.n6.nabble.com/Mouse-LED-Control-in-Python-tp1035960p4976047.html Sent from the Python - python-list mailing list archive at Nabble.com. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Mon May 28 05:04:38 2012 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Mon, 28 May 2012 09:04:38 +0000 (UTC) Subject: Smallest/cheapest possible Python platform? References: Message-ID: Tomasz Rola wrote: > If you are on tight budget and depend so much on Python, I'm afraid you > should either: > > a. grow your budget > > b. try another language such as PyMite... -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From catebekensail at yahoo.com Mon May 28 09:20:06 2012 From: catebekensail at yahoo.com (cate) Date: Mon, 28 May 2012 06:20:06 -0700 (PDT) Subject: setup(**config); rookie Message-ID: I going thru a 101 and came upon this (http:// learnpythonthehardway.org/book/ex46.html) try: from setuptools import setup except ImportError: from distutils.core import setup config = { 'description': 'My Project', 'author': 'My Name', 'url': 'URL to get it at.', 'download_url': 'Where to download it.', 'author_email': 'My email.', 'version': '0.1', 'install_requires': ['nose'], 'packages': ['NAME'], 'scripts': [], 'name': 'projectname' } setup(**config) What is the construct **? Thank you From roy at panix.com Mon May 28 09:25:24 2012 From: roy at panix.com (Roy Smith) Date: Mon, 28 May 2012 09:25:24 -0400 Subject: setup(**config); rookie References: Message-ID: In article , cate wrote: > I going thru a 101 and came upon this (http:// > learnpythonthehardway.org/book/ex46.html) > > try: > from setuptools import setup > except ImportError: > from distutils.core import setup > > config = { > 'description': 'My Project', > 'author': 'My Name', > 'url': 'URL to get it at.', > 'download_url': 'Where to download it.', > 'author_email': 'My email.', > 'version': '0.1', > 'install_requires': ['nose'], > 'packages': ['NAME'], > 'scripts': [], > 'name': 'projectname' > } > > setup(**config) > > What is the construct **? > > Thank you It calls setup with all the elements of config as if they had been passed as discrete arguments. def x(foo, bar): print foo print bar args = {'foo': 1, 'bar': 2, } x(**args) From jeanmichel at sequans.com Mon May 28 09:30:48 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 28 May 2012 15:30:48 +0200 Subject: setup(**config); rookie In-Reply-To: References: Message-ID: <4FC37E08.3040001@sequans.com> cate wrote: > I going thru a 101 and came upon this (http:// > learnpythonthehardway.org/book/ex46.html) > > try: > from setuptools import setup > except ImportError: > from distutils.core import setup > > config = { > 'description': 'My Project', > 'author': 'My Name', > 'url': 'URL to get it at.', > 'download_url': 'Where to download it.', > 'author_email': 'My email.', > 'version': '0.1', > 'install_requires': ['nose'], > 'packages': ['NAME'], > 'scripts': [], > 'name': 'projectname' > } > > setup(**config) > > What is the construct **? > > Thank you > Hi, See http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions 4.7.4. Unpacking Argument Lists Cheers, JM From rustompmody at gmail.com Mon May 28 11:56:51 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 28 May 2012 08:56:51 -0700 (PDT) Subject: python for android anyone? Message-ID: <50257b5b-9842-4936-a439-3d77778ec36c@h10g2000pbi.googlegroups.com> Ive been wanting to try the sl4a for a new android phone Ive got hold of as spelt out at http://www.linuxjournal.com/article/10940 Has anyone any experience/dos/donts for this? I am writing this while the update of the android sdk is happening and its taking forever. So just wondering if its worth the effort. Any specific tips will of course be welcome but also the general idea -- is android really python friendly (yet)? Thanks From no.email at nospam.invalid Mon May 28 12:13:38 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 28 May 2012 09:13:38 -0700 Subject: python for android anyone? References: <50257b5b-9842-4936-a439-3d77778ec36c@h10g2000pbi.googlegroups.com> Message-ID: <7xd35oe11p.fsf@ruckus.brouhaha.com> rusi writes: > Ive been wanting to try the sl4a for a new android phone Ive got hold > of as spelt out at > http://www.linuxjournal.com/article/10940 > > Has anyone any experience/dos/donts for this? One of my co-workers used it for something, and I've been looking into it but haven't tried it yet. One issue is there's not a real nice way to access the Android GUI stuff for it, and there's no tkinter port. Some websearch indicated someone was working on one, but right now there seems to be no code available. The simplest way to write a GUI application with it seems to be use a web browser control, with HTML layout and javascript actions. Yikes :) From rurpy at yahoo.com Mon May 28 12:18:29 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 28 May 2012 09:18:29 -0700 (PDT) Subject: 2to3 inscrutable output Message-ID: What is this output from 2to3 supposed to mean? $ cat mysub.py isinstance (3, (int,float)) $ 2to3 -f isinstance mysub.py RefactoringTool: No changes to mysub.py RefactoringTool: Files that need to be modified: RefactoringTool: mysub.py Why does mysub.py need to be modified, and how? From rustompmody at gmail.com Mon May 28 13:41:46 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 28 May 2012 10:41:46 -0700 (PDT) Subject: python for android anyone? References: <50257b5b-9842-4936-a439-3d77778ec36c@h10g2000pbi.googlegroups.com> <7xd35oe11p.fsf@ruckus.brouhaha.com> Message-ID: <4f563fe7-56aa-4ead-9d2b-cd11ebedb613@ri8g2000pbc.googlegroups.com> On May 28, 9:13?pm, Paul Rubin wrote: > rusi writes: > > Ive been wanting to try the sl4a for a new android phone Ive got hold > > of as spelt out at > >http://www.linuxjournal.com/article/10940 > > > Has anyone any experience/dos/donts for this? > > One of my co-workers used it for something, and I've been looking into > it but haven't tried it yet. > > One issue is there's not a real nice way to access the Android GUI stuff > for it, and there's no tkinter port. ?Some websearch indicated someone > was working on one, but right now there seems to be no code available. > > The simplest way to write a GUI application with it seems to be use a > web browser control, with HTML layout and javascript actions. ?Yikes :) Ok thanks for the thumbs up (or down). Hitting Ctrl-C (after an 820M download!) From lamialily at cleverpun.com Mon May 28 14:18:55 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Mon, 28 May 2012 11:18:55 -0700 Subject: python for android anyone? References: <50257b5b-9842-4936-a439-3d77778ec36c@h10g2000pbi.googlegroups.com> Message-ID: <6uf7s7d9orgg3qb21sca55hjsojlcuieqd@4ax.com> On Mon, 28 May 2012 08:56:51 -0700 (PDT), rusi wrote: >Ive been wanting to try the sl4a for a new android phone Ive got hold >of as spelt out at >http://www.linuxjournal.com/article/10940 > >Has anyone any experience/dos/donts for this? > >I am writing this while the update of the android sdk is happening and >its taking forever. >So just wondering if its worth the effort. > >Any specific tips will of course be welcome but also the general idea >-- is android really python friendly (yet)? > >Thanks I myself use it, though primarily for testing out concepts or blocks of code I think up on the road (or a quick and dirty profile if I think of two ways to do something and want to decide which is the best). I can't comment on its usefulness for app development, but looking over the article, it looks like for any such development you'd still be better off grabbing the Android SDK. ~Temia -- When on earth, do as the earthlings do. From cousinstanley at gmail.com Mon May 28 15:51:16 2012 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 28 May 2012 19:51:16 +0000 (UTC) Subject: python for android anyone? References: <50257b5b-9842-4936-a439-3d77778ec36c@h10g2000pbi.googlegroups.com> Message-ID: rusi wrote: > .... > Any specific tips will of course be welcome < but also the general idea > -- is android really python friendly (yet)? You might take a look at Kivy .... http://kivy.org/ "It is built with Cython ( C extensions for Python ) and, in order to create apps, Python knowledge is required. The platforms currently supported are Linux, Windows, Mac OS X and Android." The gallery is impressive .... http://kivy.org/#gallery I have very limited experience with Kivy using Debian Linux as the development platform and installing a couple of simple demo apps on an ArchOS tablet running Android ICS .... Back at the first of this month I had problems trying to build android packages using the newest versions of the android sdk / ndk packages on Debian .... Advice at the time was to drop back a version and try again or wait for kivy versioning to catch up a bit .... -- Stanley C. Kitching Human Being Phoenix, Arizona From steve+comp.lang.python at pearwood.info Mon May 28 19:50:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 May 2012 23:50:57 GMT Subject: setup(**config); rookie References: Message-ID: <4fc40f61$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 May 2012 06:20:06 -0700, cate wrote: > setup(**config) > > What is the construct **? It expands the dict "config" into keyword arguments. A single * expands to positional arguments. A simple example: args = [1, 2, 3] kwargs = {'x': 4, 'y': 5} somefunc(*args, **kwargs) is expanded to somefunc(1, 2, 3, x=4, y=5) -- Steven From steve+comp.lang.python at pearwood.info Mon May 28 20:07:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 May 2012 00:07:22 GMT Subject: 2to3 inscrutable output References: Message-ID: <4fc4133a$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 May 2012 09:18:29 -0700, rurpy at yahoo.com wrote: > What is this output from 2to3 supposed to mean? > $ cat mysub.py > isinstance (3, (int,float)) > $ 2to3 -f isinstance mysub.py > RefactoringTool: No changes to mysub.py > RefactoringTool: Files that need to be modified: > RefactoringTool: mysub.py > > Why does mysub.py need to be modified, and how? Bleh. Who came up with this user interface? I call confusing output like this a UI bug. But after playing around with various small files, it *seems* to me that the "Files that need to be modified" actually means "Files that include something that a fixer cares about, whether or not it gets modified" (in this case, isinstance). -- Steven From no at no.com Tue May 29 10:37:27 2012 From: no at no.com (Qi) Date: Tue, 29 May 2012 22:37:27 +0800 Subject: Python 2.7.3, C++ embed memory leak? Message-ID: Hi guys, Is there any known memory leak problems, when embed Python 2.7.3 in C++? I Googled but only found some old posts. I tried to only call Py_Initialize() and Py_Finalize(), nothing else between those functions, Valgrind still reports memory leaks on Ubuntu? Is that a know problem? Did Python 3.x solve it? I want some confirmation. Thanks -- WQ From vinay_sajip at yahoo.co.uk Tue May 29 10:41:00 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 29 May 2012 14:41:00 +0000 (UTC) Subject: Wish: Allow all log Handlers to accept the level argument References: Message-ID: Fayaz Yusuf Khan gmail.com> writes: > > ***TRIVIAL ISSUE***, but this has been irking me for a while now. > The main logging.Handler class' __init__ accepts a level argument while none > of its children do. The poor minions seem to be stuck with the setLevel > method which considerably lengthens the code. > > In short: > Let's do this: > root.addHandler(FileHandler('debug.log', level=DEBUG) > Instead of this: > debug_file_handler = FileHandler('debug.log') > debug_file_handler.setLevel(DEBUG) > root.addHandler(debug_file_handler) Levels on handlers are generally not needed (though of course they are sometimes needed) - level filtering should be applied at the logger first, and at the handler only when necessary. I don't especially want to encourage the pattern you suggest, because it isn't needed much of the time. The code above won't do any more or less than if you hadn't bothered to set the level on the handler. Don't forget, more complex configurations are effected even more simply using dictConfig(). Regards, Vinay Sajip From jabba.laci at gmail.com Tue May 29 10:43:50 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 29 May 2012 16:43:50 +0200 Subject: parallel programming in Python In-Reply-To: References: Message-ID: Hehe, I just asked this question a few days ago but I didn't become much cleverer: http://www.gossamer-threads.com/lists/python/python/985701 Best, Laszlo On Thu, May 10, 2012 at 2:14 PM, Jabba Laci wrote: > Hi, > > I would like to do some parallel programming with Python but I don't > know how to start. There are several ways to go but I don't know what > the differences are between them: threads, multiprocessing, gevent, > etc. > > I want to use a single machine with several cores. I want to solve > problems like this: iterate over a loop (with millions of steps) and > do some work at each step. The steps are independent, so here I would > like to process several steps in parallel. I want to store the results > in a global list (which should be "synchronised"). Typical use case: > crawl webpages, extract images and collect the images in a list. > > What's the best way? > > Thanks, > > Laszlo From ulrich.eckhardt at dominolaser.com Tue May 29 11:29:01 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 29 May 2012 17:29:01 +0200 Subject: Python 2.7.3, C++ embed memory leak? In-Reply-To: References: Message-ID: Am 29.05.2012 16:37, schrieb Qi: > I tried to only call Py_Initialize() and Py_Finalize(), nothing else > between those functions, Valgrind still reports memory leaks > on Ubuntu? Call the pair of functions twice, if the reported memory leak doesn't increase, there is no problem. I personally wouldn't even call this a leak then, but that depends a bit on the precise definition. Uli From scott.siegler at gmail.com Tue May 29 11:33:37 2012 From: scott.siegler at gmail.com (Scott Siegler) Date: Tue, 29 May 2012 08:33:37 -0700 (PDT) Subject: pygame: transparency question Message-ID: Hello, I have a surface that I load an image onto. During a collision I would like to clear out the images of both surfaces that collided and show the score. Is there a function call to clear a surface with an image? One way I was thinking was to fill the surface with a color and then set that color as the colorkey. Is this the only way or does pygame have a function to make the whole surface transparent? Thanks. From werner at thieprojects.ch Tue May 29 12:06:40 2012 From: werner at thieprojects.ch (Werner Thie) Date: Tue, 29 May 2012 18:06:40 +0200 Subject: parallel programming in Python In-Reply-To: References: Message-ID: <4FC4F410.1000908@thieprojects.ch> For such tasks my choice would be twisted combined with ampoule. Let's you spread out work to whatever amount of processes you desire, maxing out whatever iron you're sitting on.. HTH, Werner http://twistedmatrix.com/trac/ https://launchpad.net/ampoule On 29.05.2012 16:43, Jabba Laci wrote: > Hehe, I just asked this question a few days ago but I didn't become > much cleverer: > > http://www.gossamer-threads.com/lists/python/python/985701 > > Best, > > Laszlo > > On Thu, May 10, 2012 at 2:14 PM, Jabba Laci wrote: >> Hi, >> >> I would like to do some parallel programming with Python but I don't >> know how to start. There are several ways to go but I don't know what >> the differences are between them: threads, multiprocessing, gevent, >> etc. >> >> I want to use a single machine with several cores. I want to solve >> problems like this: iterate over a loop (with millions of steps) and >> do some work at each step. The steps are independent, so here I would >> like to process several steps in parallel. I want to store the results >> in a global list (which should be "synchronised"). Typical use case: >> crawl webpages, extract images and collect the images in a list. >> >> What's the best way? >> >> Thanks, >> >> Laszlo -------------- next part -------------- A non-text attachment was scrubbed... Name: werner.vcf Type: text/x-vcard Size: 297 bytes Desc: not available URL: From ian.g.kelly at gmail.com Tue May 29 13:21:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 29 May 2012 11:21:10 -0600 Subject: pygame: transparency question In-Reply-To: References: Message-ID: On Tue, May 29, 2012 at 9:33 AM, Scott Siegler wrote: > Hello, > > I have a surface that I load an image onto. ?During a collision I would like to clear out the images of both surfaces that collided and show the score. ?Is there a function call to clear a surface with an image? > > One way I was thinking was to fill the surface with a color and then set that color as the colorkey. ?Is this the only way or does pygame have a function to make the whole surface transparent? If you want the entire surface to be completely transparent, then just don't blit it onto the screen in the first place. Blit a different surface with the score drawn onto it instead. From jan.kuiken at quicknet.nl Tue May 29 13:31:58 2012 From: jan.kuiken at quicknet.nl (Jan Kuiken) Date: Tue, 29 May 2012 19:31:58 +0200 Subject: Help doing it the "python way" In-Reply-To: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: On 5/24/12 22:22 , Scott Siegler wrote: > I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more "C" style syntax. > > I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. > > So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) > > right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. > > is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? If you have lot's of numerical data you can use the NumPy module (http://numpy.scipy.org/), your problem would reduce to something like this (copied from an IPython shell, could be shorter) Regards, Jan Kuiken In [1]: first_list = np.arange(0, 10).reshape((5,2)) In [2]: above = np.array([0,-1]) In [3]: below = np.array([0,+1]) In [4]: N,d = first_list.shape In [5]: second_list = np.empty((N*2,d)) In [6]: second_list[0::2] = first_list + above In [7]: second_list[1::2] = first_list + below In [8]: second_list Out[8]: array([[ 0., 0.], [ 0., 2.], [ 2., 2.], [ 2., 4.], [ 4., 4.], [ 4., 6.], [ 6., 6.], [ 6., 8.], [ 8., 8.], [ 8., 10.]]) In [9]: first_list Out[9]: array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) From tjreedy at udel.edu Tue May 29 13:38:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 29 May 2012 13:38:20 -0400 Subject: pygame: transparency question In-Reply-To: References: Message-ID: On 5/29/2012 11:33 AM, Scott Siegler wrote: > Hello, > > I have a surface that I load an image onto. During a collision I > would like to clear out the images of both surfaces that collided and > show the score. Is there a function call to clear a surface with an > image? > > One way I was thinking was to fill the surface with a color and then > set that color as the colorkey. Is this the only way or does pygame > have a function to make the whole surface transparent? I recommend that you ask this on the pygame list, also accessible via news.gmane.org. -- Terry Jan Reedy From arnodel at gmail.com Tue May 29 15:48:09 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 29 May 2012 20:48:09 +0100 Subject: Help doing it the "python way" In-Reply-To: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> References: <5c486a11-1dd9-42a9-be20-4ad8c99f90cc@googlegroups.com> Message-ID: On 24 May 2012 21:22, Scott Siegler wrote: > Hello, > > I am an experienced programmer but a beginner to python. ?As such, I can figure out a way to code most algorithms using more "C" style syntax. > > I am doing something now that I am sure is a more python way but i can't quite get it right. ?I was hoping someone might help. > > So I have a list of grid coordinates (x, y). ?From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) > > right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. > > is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? AFAICS nobody's suggested yet the simple yet effective: new_list = [(x, y + i) for x, y in coord_list for i in (-1, 1)] IMHO these list comprehensions are often overlooked too quickly in favour of itertools (in this case chain.from_iterable). -- Arnaud From news at idlcoyote.com Tue May 29 16:41:53 2012 From: news at idlcoyote.com (David Fanning) Date: Tue, 29 May 2012 14:41:53 -0600 Subject: Install lxml package on Windows 7 Message-ID: Folks, I need some help. I need the lxml package to run a particular Python program. http://lxml.de/ I downloaded the appropriate binary egg package for lxml, and I found easy_install.exe in my Python 2.7 distribution. I ran that. Then, at the command prompt I typed this: easy_install --allow-hosts=lxml.de,*.python.org lxml==2.3.4 The usual installation pop-ups appear. "Do I want to allow such and so to install, etc.". Yes, yes. Finally, I get a message, "Installation may not have been done correctly." I have several choices, including "Install with recommended parameters", which I choose. The installation proceeds without any other indication of failure. I presume I have the package installed now. So, I enter Python and type this: >>>import lxml I get an error. No module with that name found, etc. Sure enough, I look in C:\Python27\site_packages and there is no lxml-2.3.4 folder. Any idea what I might be doing wrong? Thanks, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Tue May 29 16:54:11 2012 From: news at idlcoyote.com (David Fanning) Date: Tue, 29 May 2012 14:54:11 -0600 Subject: Install lxml package on Windows 7 References: Message-ID: David Fanning writes: > > Folks, > > I need some help. I need the lxml package to run a particular > Python program. > > http://lxml.de/ > > I downloaded the appropriate binary egg package for lxml, and > I found easy_install.exe in my Python 2.7 distribution. I ran > that. > > Then, at the command prompt I typed this: > > easy_install --allow-hosts=lxml.de,*.python.org lxml==2.3.4 > > The usual installation pop-ups appear. "Do I want to allow > such and so to install, etc.". Yes, yes. Finally, I get > a message, "Installation may not have been done correctly." > I have several choices, including "Install with recommended > parameters", which I choose. The installation proceeds without > any other indication of failure. > > I presume I have the package installed now. So, I enter > Python and type this: > > >>>import lxml > > I get an error. No module with that name found, etc. > > Sure enough, I look in C:\Python27\site_packages and there > is no lxml-2.3.4 folder. > > Any idea what I might be doing wrong? If I try to install from the lxml binary package I downloaded and upzipped I get this: c:\Python27>python lxml-2.3.4/setup.py install Building lxml version 2.3.4. WARNING: Trying to build without Cython, but pre-generated 'src/lxml/lxml.etree. c' does not seem to be available. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt running install running bdist_egg error: error in 'egg_base' option: 'src' does not exist or is not a directory Confused. :-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Tue May 29 17:59:32 2012 From: news at idlcoyote.com (David Fanning) Date: Tue, 29 May 2012 15:59:32 -0600 Subject: Install lxml package on Windows 7 References: Message-ID: David Fanning writes: > I need some help. I need the lxml package to run a particular > Python program. > > http://lxml.de/ OK, maybe I am getting somewhere now. I am now running my command window as an Administrator. So, the command window stays open so I can see what is happening. So, from the command window I run this command (on one line): easy_install -allow-hosts=lxml.de, *.python.org,codespeak.net,gethub.com lxml==2.3.4 I added codespeak.net and gethub.com to the command myself, as I was getting BLOCKED messages from the script for those URLs. Now, I am *still* getting BLOCKED messages for the github sites. These, I notice, are https, rather than http addresses. Is this the source of my problem? I get 8 "file not found" warnings during the build (e.g. missing file lxml.etree.c, lxml.objectify.c, etc.), then a fatal error: 'IDB' is illegal extension for PDB file. It is trying to run cl.exe in a Visual Studio 9 bin directory. Running this on an completely up-to-date version of Windows 7. Any ideas? Thanks! David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From news at idlcoyote.com Tue May 29 18:27:05 2012 From: news at idlcoyote.com (David Fanning) Date: Tue, 29 May 2012 16:27:05 -0600 Subject: Install lxml package on Windows 7 References: Message-ID: David Fanning writes: > > I need some help. I need the lxml package to run a particular > > Python program. > > > > http://lxml.de/ OK, to answer my own question and help someone else out, I eventually found an lxml-2.3.4.exe file on this page: http://code.google.com/p/pythonxy/wiki/AdditionalPlugins#Installation_no tes The *.exe file downloaded and installed the lxml-2.3.4 directory into the proper location in my PythonXY distribution. Actually in the C:\Python27\Lib\site-packages directory. Still not sure what all those other directions were all about. :-( Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.") From irmen.NOSPAM at xs4all.nl Tue May 29 19:24:17 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 30 May 2012 01:24:17 +0200 Subject: Install lxml package on Windows 7 In-Reply-To: References: Message-ID: <4fc55aa2$0$6856$e4fe514c@news.xs4all.nl> On 29-5-2012 22:41, David Fanning wrote: > Folks, > > I need some help. I need the lxml package to run a particular > Python program. > > http://lxml.de/ > > I downloaded the appropriate binary egg package for lxml, and > I found easy_install.exe in my Python 2.7 distribution. I ran > that. > > Then, at the command prompt I typed this: > > easy_install --allow-hosts=lxml.de,*.python.org lxml==2.3.4 [..snip..] Save yourself the pain trying to get it to build from source. Instead, just install a precompiled binary, for instance the one available from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml -Irmen From roy at panix.com Tue May 29 21:33:29 2012 From: roy at panix.com (Roy Smith) Date: Tue, 29 May 2012 21:33:29 -0400 Subject: Finding all regex matches by index? Message-ID: I have a long string (possibly 100s of Mbytes) that I want to search for regex matches. re.finditer() is *almost* what I want, but the problem is that it returns matching strings. What I need is a list of offsets in the string where the regex matched. Thus: s = "this is a string" find("is", s) => [2, 5] Is there anything that does this? From python at mrabarnett.plus.com Tue May 29 21:45:00 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 30 May 2012 02:45:00 +0100 Subject: Finding all regex matches by index? In-Reply-To: References: Message-ID: <4FC57B9C.2010404@mrabarnett.plus.com> On 30/05/2012 02:33, Roy Smith wrote: > I have a long string (possibly 100s of Mbytes) that I want to search for > regex matches. re.finditer() is *almost* what I want, but the problem > is that it returns matching strings. What I need is a list of offsets > in the string where the regex matched. Thus: > > s = "this is a string" > find("is", s) => [2, 5] > > Is there anything that does this? re.finditer() doesn't return matching strings, it returns match objects. What you want are the start positions of each match which the match object can provide: >>> s = "this is a string" >>> [m.start() for m in re.finditer("is", s)] [2, 5] From ian.g.kelly at gmail.com Tue May 29 21:48:18 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 29 May 2012 19:48:18 -0600 Subject: Finding all regex matches by index? In-Reply-To: References: Message-ID: On Tue, May 29, 2012 at 7:33 PM, Roy Smith wrote: > I have a long string (possibly 100s of Mbytes) that I want to search for > regex matches. ?re.finditer() is *almost* what I want, but the problem > is that it returns matching strings. ?What I need is a list of offsets > in the string where the regex matched. ?Thus: > > s = "this is a string" > find("is", s) => [2, 5] > > Is there anything that does this? s = "this is a string" pattern = re.compile("is") pos = 0 while True: match = pattern.search(s, pos) if match: print(match.start()) pos = match.start() + 1 else: break Cheers, Ian From roy at panix.com Tue May 29 21:49:23 2012 From: roy at panix.com (Roy Smith) Date: Tue, 29 May 2012 21:49:23 -0400 Subject: Finding all regex matches by index? References: Message-ID: In article , Roy Smith wrote: > I have a long string (possibly 100s of Mbytes) that I want to search for > regex matches. re.finditer() is *almost* what I want, but the problem > is that it returns matching strings. What I need is a list of offsets > in the string where the regex matched. Thus: > > s = "this is a string" > find("is", s) => [2, 5] > > Is there anything that does this? Ugh, looks like I simply mis-read the docs. findall() returns strings, finditer() returns match objets (which is what I need). Duh. From ian.g.kelly at gmail.com Tue May 29 21:54:35 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 29 May 2012 19:54:35 -0600 Subject: Finding all regex matches by index? In-Reply-To: <4FC57B9C.2010404@mrabarnett.plus.com> References: <4FC57B9C.2010404@mrabarnett.plus.com> Message-ID: On Tue, May 29, 2012 at 7:45 PM, MRAB wrote: > On 30/05/2012 02:33, Roy Smith wrote: >> >> I have a long string (possibly 100s of Mbytes) that I want to search for >> regex matches. ?re.finditer() is *almost* what I want, but the problem >> is that it returns matching strings. ?What I need is a list of offsets >> in the string where the regex matched. ?Thus: >> >> s = "this is a string" >> find("is", s) => ?[2, 5] >> >> Is there anything that does this? > > > re.finditer() doesn't return matching strings, it returns match > objects. What you want are the start positions of each match which the > match object can provide: > > >>>> s = "this is a string" >>>> [m.start() for m in re.finditer("is", s)] > [2, 5] Or that. I simply assumed without checking from the OP's post that finditer yielded strings, not matches. From albert at albertoconnor.ca Tue May 29 21:55:51 2012 From: albert at albertoconnor.ca (Albert O'Connor) Date: Tue, 29 May 2012 21:55:51 -0400 Subject: WatPy: A new Python User Group in Kitchener-Waterloo, Ontario Message-ID: We are having our first night of talks on Thursday June 7th, 6:30 at the Communitech Hub in downtown Kitchener. More information: http://watpy.ca/blog/post/peer-2-peer-talks/ Albert O'Connor -------------- next part -------------- An HTML attachment was scrubbed... URL: From no at no.no Tue May 29 22:08:51 2012 From: no at no.no (Qi) Date: Wed, 30 May 2012 10:08:51 +0800 Subject: Python 2.7.3, C++ embed memory leak? References: Message-ID: On 2012-5-29 23:29, Ulrich Eckhardt wrote: > > Call the pair of functions twice, if the reported memory leak doesn't > increase, there is no problem. I personally wouldn't even call this a > leak then, but that depends a bit on the precise definition. I should still call it a memory leak though it seems less harmful. And it causes trouble that I have difficulty to distinguish if the leaks are from Python or from my binding code, if I add binding between that pair of functions. -- WQ From no.email at nospam.invalid Tue May 29 23:09:36 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 29 May 2012 20:09:36 -0700 Subject: PIL threading problems Message-ID: <7xzk8ql5zj.fsf@ruckus.brouhaha.com> Kind of a long shot, but are there known problems in calling PIL from multiple threads? I'm getting weird intermittent core dumps from my app, no idea what's causing them, but PIL is the only C module I'm using, and I do see some mention on the interwebs that there might be an issue: http://lists.tiker.net/pipermail/pycuda/2009-March/001393.html Any suggestions? Would it be enough to put a lock around the PIL calls that I use? Thanks. From chrisjrn+pyconau at gmail.com Tue May 29 23:15:31 2012 From: chrisjrn+pyconau at gmail.com (Chris Neugebauer) Date: Wed, 30 May 2012 13:15:31 +1000 Subject: PyCon Australia 2012 and Google Australia announce gender diversity grants Message-ID: (Please feel free to pass this onto any Girl Geek-related mailing lists that you think may benefit from this -- we want to get the word out about this as much as possible. :) ) PyCon Australia and Google Australia are pleased to announce that they're joining forces to offer gender diversity delegate grants to women who wish to attend PyCon Australia in 2012. These grants will cover up to $AUD500 of travel, accommodation and registration costs for women living outside of the Southern Tasmania region to attend this year's conference. These grants aim to reduce the financial barriers to attending PyCon Australia 2012, by subsidising the registration and travel costs of people from diverse groups, who contribute in important ways to the Python community. More information can be found at http://2012.pycon-au.org/diversity_grants ==== Eligibility ==== In order to be eligible for one of the grants, you must be: - A woman, aged 18 or older - A professional, enthusiast or student interested in, or currently working in Python-related fields or projects - Planning to attend both days of PyCon Australia 2012 - In order to be eligible for the travel and accommodation grant, you must additionally: live further than 150 km (by road) from the conference venue. (If you are unsure, please visit http://maps.google.com.au/maps/place?q=Wrest%20Point,%20Tasmania and use the "Get Directions" link in the upper left-hand corner to calculate the driving distance from your place of residence to the venue.) More information can be found at http://2012.pycon-au.org/diversity_grants ==== Award Amount ==== All selected grant recipients will be extended the Early Bird registration rates to PyCon Australia, provided registration is completed prior to 13 July. In addition, recipients of the travel and accommodation grant will be reimbursed up to $500 in travel and accommodation costs. More information can be found at http://2012.pycon-au.org/diversity_grants ==== Timeline ==== Applications for the gender diversity delegates grants are open now, and will close on Friday 15 June We will notify all successful recipients of their award by Friday 22 June so that you can have ample time to complete your travel plans. More information can be found at http://2012.pycon-au.org/diversity_grants === About PyCon Australia === PyCon Australia is the national conference for the Python Programming Community. The third PyCon Australia will be held on August 18 and 19, 2012 in Hobart, Tasmania, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country?s Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2012, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Gold sponsors: Google Australia (www.google.com.au), and the Australian Computer Society (Tasmanian Branch) (www.acs.org.au); our Event partner, Secret Lab; and our Silver sponsors: the Python Software Foundation, the Django Software Foundation, Anchor Systems, Red Hat, ekit, RimuHosting, and CSIRO. -- --Christopher Neugebauer Conference Coordinator and Sponsor Liaison PyCon Australia: Hobart 2012 -- http://2012.pycon-au.org -- @pyconau Early bird registration and accommodation deals now available! See our website for details. Jabber: chrisjrn at gmail.com -- IRC: chrisjrn on irc.freenode.net -- WWW: http://chris.neugebauer.id.au -- Twitter/Identi.ca: @chrisjrn From rurpy at yahoo.com Wed May 30 02:52:16 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 29 May 2012 23:52:16 -0700 (PDT) Subject: python3 raw strings and \u escapes Message-ID: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> In python2, "\u" escapes are processed in raw unicode strings. That is, ur'\u3000' is a string of length 1 consisting of the IDEOGRAPHIC SPACE unicode character. In python3, "\u" escapes are not processed in raw strings. r'\u3000' is a string of length 6 consisting of a backslash, 'u', '3' and three '0' characters. This breaks a lot of my code because in python 2 re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] but in python 3 (the result of running 2to3), re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] I can remove the "r" prefix from the regex string but then if I have other regex backslash symbols in it, I have to double all the other backslashes -- the very thing that the r-prefix was invented to avoid. Or I can leave the "r" prefix and replace something like r'[ \u3000]' with r'[ ?]'. But that is confusing because one can't distinguish between the space character and the ideographic space character. It also a problem if a reader of the code doesn't have a font that can display the character. Was there a reason for dropping the lexical processing of \u escapes in strings in python3 (other than to add another annoyance in a long list of python3 annoyances?) And is there no choice for me but to choose between the two poor choices I mention above to deal with this problem? From bahamutzero8825 at gmail.com Wed May 30 03:25:28 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 30 May 2012 02:25:28 -0500 Subject: python3 raw strings and \u escapes In-Reply-To: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: <4FC5CB68.9070108@gmail.com> On 5/30/2012 1:52 AM, rurpy at yahoo.com wrote: > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) To me, this would be a Python 2 annoyance since I would expect r'\u3000' to be literally the six characters '\u3000' since the entire point of raw strings is to treat everything literally. Why should anything at all be processed when constructing a raw string? -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From anntzer.lee at gmail.com Wed May 30 03:55:00 2012 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Wed, 30 May 2012 00:55:00 -0700 (PDT) Subject: issubclass(C, Mapping) not behaving as expected Message-ID: <5f4d2a58-bb21-45b2-8e90-ff24cbfecf60@googlegroups.com> from collections import * class C(object): def __iter__(self): pass def __contains__(self, i): pass def __len__(self): pass def __getitem__(self, i): pass issubclass(C, Mapping) => False [issubclass(C, cls) for cls in Mapping.__mro__] => [False, True, True, True, True] i.e. C does implement Sized, Iterable and Container. I would have expected that just as issubclass(C, Sized) checks for the presence of a "__len__" method, issubclass(C, Mapping) would check for the presence of the three methods required by each immediate superclass? Antony From __peter__ at web.de Wed May 30 04:38:17 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 30 May 2012 10:38:17 +0200 Subject: issubclass(C, Mapping) not behaving as expected References: <5f4d2a58-bb21-45b2-8e90-ff24cbfecf60@googlegroups.com> Message-ID: anntzer.lee at gmail.com wrote: > from collections import * > class C(object): > def __iter__(self): pass > def __contains__(self, i): pass > def __len__(self): pass > def __getitem__(self, i): pass > issubclass(C, Mapping) => False > [issubclass(C, cls) for cls in Mapping.__mro__] => [False, True, True, > [True, True] > i.e. C does implement Sized, Iterable and Container. > > I would have expected that just as issubclass(C, Sized) checks for the > presence of a "__len__" method, issubclass(C, Mapping) would check for the > presence of the three methods required by each immediate superclass? Your expectations are wrong -- as you might have expected ;) You have two options two get the issubclass() result you want: actually subclass: >>> from collections import Mapping as M >>> class A(M): pass ... >>> issubclass(A, M) True ... or register your class: >>> class B(object): pass ... >>> issubclass(B, M) False >>> M.register(B) >>> issubclass(B, M) True In both cases you are responsible for the correct implementation of the protocol. Subclassing is normally easier because it fills in missing methods and complains about required ones on instantiation: >>> B() <__main__.B object at 0x7fa34bda3750> >>> A() Traceback (most recent call last): File "", line 1, in TypeError: Can't instantiate abstract class A with abstract methods __getitem__, __iter__, __len__ From lists at cheimes.de Wed May 30 05:05:32 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 30 May 2012 11:05:32 +0200 Subject: PIL threading problems In-Reply-To: <7xzk8ql5zj.fsf@ruckus.brouhaha.com> References: <7xzk8ql5zj.fsf@ruckus.brouhaha.com> Message-ID: Am 30.05.2012 05:09, schrieb Paul Rubin: > Kind of a long shot, but are there known problems in calling PIL from > multiple threads? I'm getting weird intermittent core dumps from my > app, no idea what's causing them, but PIL is the only C module I'm > using, and I do see some mention on the interwebs that there might > be an issue: > > http://lists.tiker.net/pipermail/pycuda/2009-March/001393.html > > Any suggestions? Would it be enough to put a lock around the PIL > calls that I use? In my experience PIL works just fine with threading. We used to process terabytes of TIFF images in a multithreaded application until we switched to FreeImage. You should make sure that you don't access a PILs object from more than one thread. We have treated PIL as reentrant but not thread-safe. Christian From ohlfsen at gmail.com Wed May 30 07:40:41 2012 From: ohlfsen at gmail.com (ohlfsen) Date: Wed, 30 May 2012 04:40:41 -0700 (PDT) Subject: ctypes callback with char array Message-ID: Hello. Hoping that someone can shed some light on a tiny challenge of mine. Through ctypes I'm calling a c DLL which requires me to implement a callback in Python/ctypes. The signature of the callback is something like void foo(int NoOfElements, char Elements[][100]) How do I possible implement/process "char Elements[][100]" in Python/ctypes code? Thanks a lot in advance. Best Regards A. (Python amateur). From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed May 30 07:54:52 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 30 May 2012 13:54:52 +0200 Subject: python3 raw strings and \u escapes In-Reply-To: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: Am 30.05.2012 08:52 schrieb rurpy at yahoo.com: > This breaks a lot of my code because in python 2 > re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] > but in python 3 (the result of running 2to3), > re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] > > I can remove the "r" prefix from the regex string but then > if I have other regex backslash symbols in it, I have to > double all the other backslashes -- the very thing that > the r-prefix was invented to avoid. > > Or I can leave the "r" prefix and replace something like > r'[ \u3000]' with r'[ ?]'. But that is confusing because > one can't distinguish between the space character and > the ideographic space character. It also a problem if a > reader of the code doesn't have a font that can display > the character. > > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) Probably it is more consequent. Alas, it makes the whole stuff incompatible to Py2. But if you think about it: why allow for \u if \r, \n etc. are disallowed as well? > And is there no choice for me but to choose between the two > poor choices I mention above to deal with this problem? There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, but should do the trick... Thomas From jeanpierreda at gmail.com Wed May 30 10:10:21 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 30 May 2012 10:10:21 -0400 Subject: python3 raw strings and \u escapes In-Reply-To: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: On Wed, May 30, 2012 at 2:52 AM, rurpy at yahoo.com wrote: > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) > > And is there no choice for me but to choose between the two > poor choices I mention above to deal with this problem? The solution of r'[' + '\u3000' + r']...' was pretty good. Real reason I posted: Maybe the re module should handle \u escapes, in addition to the other backslash escapes it processes? This would be backwards incompatible, though, so maybe it's too late. -- Devin From arnodel at gmail.com Wed May 30 10:27:56 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 30 May 2012 15:27:56 +0100 Subject: python3 raw strings and \u escapes In-Reply-To: References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: On 30 May 2012 12:54, Thomas Rachel wrote: > There is a 3rd one: use ? r'[ ' + '\u3000' + ']'. Not very nice to read, but > should do the trick... You could even take advantage of string literal concatenation:) r'[' '\u3000' r']' -- Arnaud From ms at koplon.com Wed May 30 10:51:32 2012 From: ms at koplon.com (marctbg) Date: Wed, 30 May 2012 07:51:32 -0700 (PDT) Subject: Adding to Python Decorator Library at wiki.python.org Message-ID: I just created an account to contribute to the wiki.python.org Python Decorator Library Wiki. I added my code titled == Memoize Objects == using the Wiki editor. The preview looked good. Then i submitted it. However, it is not showing up on the Wiki. I could not find contact info for the maintainer of that Wiki. How can get help making my posting appear? From galois271 at gmail.com Wed May 30 11:05:44 2012 From: galois271 at gmail.com (Chuck) Date: Wed, 30 May 2012 08:05:44 -0700 (PDT) Subject: installing modules in Enthought Python Message-ID: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> I just downloaded Enthought Python, free version. I wanted all the included packages, but I can't seem to find the correct directory to install new Python modules. Does anybody have an idea? I am trying to add Universal Feed Parser to Enthought. I have tried C:\Python27, C:\Python27\Lib, C:\Python27\Lib\site-packages, but no success. TIA! From rurpy at yahoo.com Wed May 30 11:07:28 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 30 May 2012 08:07:28 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: <8f2044b3-b334-42a9-91e5-7592d0eec12b@cu1g2000vbb.googlegroups.com> On 05/30/2012 05:54 AM, Thomas Rachel wrote: > Am 30.05.2012 08:52 schrieb rurpy at yahoo.com: > >> This breaks a lot of my code because in python 2 >> re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] >> but in python 3 (the result of running 2to3), >> re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] >> >> I can remove the "r" prefix from the regex string but then >> if I have other regex backslash symbols in it, I have to >> double all the other backslashes -- the very thing that >> the r-prefix was invented to avoid. >> >> Or I can leave the "r" prefix and replace something like >> r'[ \u3000]' with r'[ ?]'. But that is confusing because >> one can't distinguish between the space character and >> the ideographic space character. It also a problem if a >> reader of the code doesn't have a font that can display >> the character. >> >> Was there a reason for dropping the lexical processing of >> \u escapes in strings in python3 (other than to add another >> annoyance in a long list of python3 annoyances?) > > Probably it is more consequent. Alas, it makes the whole stuff > incompatible to Py2. > > But if you think about it: why allow for \u if \r, \n etc. are > disallowed as well? Maybe the blame is elsewhere then... If the re module interprets (in a regex string) the 2-character string consisting of r'\' followed by 'n' as a single newline character, then why wasn't re changed for Python 3 to interpret the 6-character string, r'\u3000' as a single unicode character to correspond with Python's lexer no longer doing that (as it did in Python 2)? >> And is there no choice for me but to choose between the two >> poor choices I mention above to deal with this problem? > > There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, > but should do the trick... I guess the "+"s could be left out allowing something like, '[ \u3000]' r'\w+ \d{3}' but I'll have to try it a little; maybe just doubling backslashes won't be much worse. I did that for years in Perl and lived through it. From news at idlcoyote.com Wed May 30 11:57:12 2012 From: news at idlcoyote.com (David Fanning) Date: Wed, 30 May 2012 09:57:12 -0600 Subject: installing modules in Enthought Python References: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> Message-ID: Chuck writes: > > I just downloaded Enthought Python, free version. I wanted all the > included packages, but I can't seem to find the correct directory to > install new Python modules. Does anybody have an idea? I am trying > to add Universal Feed Parser to Enthought. I have tried C:\Python27, > C:\Python27\Lib, C:\Python27\Lib\site-packages, but no success. I spent most of the day on this problem yesterday. You are going to want to get *.exe files that will install in the usual way on Windows. I found the packages I was looking for at one or the other of these sites: http://code.google.com/p/pythonxy/wiki/AdditionalPlugins#Installation_no tes http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Cheers David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Sepore ma de ni thui. ("Perhaps thou speakest truth.") From psaffrey at googlemail.com Wed May 30 12:01:20 2012 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Wed, 30 May 2012 09:01:20 -0700 (PDT) Subject: Object cleanup Message-ID: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> I am writing a screen scraping application using BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ (which is fantastic, by the way). I have an object that has two methods, each of which loads an HTML document and scrapes out some information, putting strings from the HTML documents into lists and dictionaries. I have a set of these objects from which I am aggregating and returning data. With a large number of these objects, the memory footprint is very large. The "soup" object is a local variable to each scraping method, so I assumed it would be cleaned up after the method had returned. However, I've found that using guppy, after the methods have returned most of the memory is being taken up with BeautifulSoup objects of one type or another. I'm not declaring BeautifulSoup objects anywhere else. I've tried assigning None into the "soup" objects at the end of the method calls and calling garbage collection manually, but this doesn't seem to help. I'd like to find out exactly what object "owns" the various BeautifulSoup structures, but I'm quite a new guppy user and I can't figure out how to do this. How do I force the memory for these soup objects to be freed? Is there antyhing else I should be looking at to find out the cause of these problems? Peter From steve+comp.lang.python at pearwood.info Wed May 30 12:40:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2012 16:40:11 GMT Subject: Object cleanup References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> Message-ID: <4fc64d6b$0$29971$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 May 2012 09:01:20 -0700, psaffrey at googlemail.com wrote: > However, I've found that using guppy, after the methods have returned > most of the memory is being taken up with BeautifulSoup objects of one > type or another. I'm not declaring BeautifulSoup objects anywhere else. What's guppy? > I've tried assigning None into the "soup" objects at the end of the > method calls and calling garbage collection manually, but this doesn't > seem to help. I'd like to find out exactly what object "owns" the > various BeautifulSoup structures, but I'm quite a new guppy user and I > can't figure out how to do this. > > How do I force the memory for these soup objects to be freed? Is there > antyhing else I should be looking at to find out the cause of these > problems? If objects aren't being garbage collected, you probably have cycles of objects with __del__ methods. Python's reference garbage collector can't delete objects in cycles, and the alternative garbage collector can't delete objects with __del__ methods. Try removing the __del__ methods, and see if that fixes the problem. Also, see the gc module. http://docs.python.org/library/gc.html -- Steven From tjreedy at udel.edu Wed May 30 12:46:21 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 May 2012 12:46:21 -0400 Subject: python3 raw strings and \u escapes In-Reply-To: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: On 5/30/2012 2:52 AM, rurpy at yahoo.com wrote: > In python2, "\u" escapes are processed in raw unicode > strings. That is, ur'\u3000' is a string of length 1 > consisting of the IDEOGRAPHIC SPACE unicode character. That surprised me until I rechecked the fine manual and found: "When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string." "When an 'r' or 'R' prefix is used in conjunction with a 'u' or 'U' prefix, then the \uXXXX and \UXXXXXXXX escape sequences are processed while all other backslashes are left in the string." When 'u' was removed in Python 3, a choice had to be made and the first must have seemed to be the obvious one, or perhaps the automatic one. In 3.3, 'u' is being restored. I have inquired on pydev list whether the difference above should also be restored, and mentioned this thread. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed May 30 12:51:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 May 2012 16:51:51 GMT Subject: Adding to Python Decorator Library at wiki.python.org References: Message-ID: <4fc65027$0$29971$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 May 2012 07:51:32 -0700, marctbg wrote: > I just created an account to contribute to the wiki.python.org Python > Decorator Library Wiki. I added my code titled == Memoize Objects == > using the Wiki editor. The preview looked good. Then i submitted it. > However, it is not showing up on the Wiki. I could not find contact > info for the maintainer of that Wiki. How can get help making my > posting appear? How about including a direct link to the page you're talking about? Do you perhaps mean this recipe? http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize Or this attachment? http://wiki.python.org/moin/PythonDecoratorLibrary?action=AttachFile&do=view&target=memoize.py If not, I suggest you: - refresh your page, to make sure you're not viewing an old, cached version; - try submitting it again; - make sure you aren't blocking scripts; - try using a different browser. If it still doesn't work, then ask for help. -- Steven From tjreedy at udel.edu Wed May 30 12:55:53 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 May 2012 12:55:53 -0400 Subject: installing modules in Enthought Python In-Reply-To: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> References: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> Message-ID: On 5/30/2012 11:05 AM, Chuck wrote: > I just downloaded Enthought Python, free version. I wanted all the > included packages, but I can't seem to find the correct directory to > install new Python modules. Does anybody have an idea? I am trying > to add Universal Feed Parser to Enthought. I have tried C:\Python27, > C:\Python27\Lib, C:\Python27\Lib\site-packages, but no success. If the Enthought Python installer installed CPython to C:/Python27, then I would expect a) that they might put the 'included packages' in site-packages, and b) that putting a module/package there would work. However, maybe they do something non-standard in the site module, including disabling site-packages. Try >>> import sys; sys.path to see if sys.path includes site-packages and what it does include. If you put a directory in site-packages, make sure it has an __init__.py file. -- Terry Jan Reedy From gordon at panix.com Wed May 30 12:56:21 2012 From: gordon at panix.com (John Gordon) Date: Wed, 30 May 2012 16:56:21 +0000 (UTC) Subject: Object cleanup References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> Message-ID: In <6e534661-0823-4c42-8f60-3052e43b7942 at googlegroups.com> "psaffrey at googlemail.com" writes: > How do I force the memory for these soup objects to be freed? Have you tried deleting them, using the "del" command? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From clp2 at rebertia.com Wed May 30 12:58:06 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 May 2012 09:58:06 -0700 Subject: Object cleanup In-Reply-To: <4fc64d6b$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> <4fc64d6b$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, May 30, 2012 at 9:40 AM, Steven D'Aprano wrote: > On Wed, 30 May 2012 09:01:20 -0700, psaffrey at googlemail.com wrote: > >> However, I've found that using guppy, after the methods have returned >> most of the memory is being taken up with BeautifulSoup objects of one >> type or another. I'm not declaring BeautifulSoup objects anywhere else. > > What's guppy? http://pypi.python.org/pypi/guppy/ "...a library and programming environment for Python, currently providing in particular the Heapy subsystem, which supports object and heap memory sizing, profiling and debugging" Cheers, Chris From storchaka at gmail.com Wed May 30 12:59:03 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 30 May 2012 19:59:03 +0300 Subject: python3 raw strings and \u escapes In-Reply-To: References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: On 30.05.12 14:54, Thomas Rachel wrote: > There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, > but should do the trick... Or r'[ %s]' % ('\u3000',). From benoit at marmelune.net Wed May 30 12:59:35 2012 From: benoit at marmelune.net (=?ISO-8859-1?Q?Beno=EEt_Bryon?=) Date: Wed, 30 May 2012 18:59:35 +0200 Subject: Proposal about naming conventions around packaging Message-ID: <4FC651F7.6070805@marmelune.net> Hi, Here is a proposal about naming conventions around packaging. Main question is: would you accept it as a PEP? ############################################ Preliminary notes (not part of the proposal) ############################################ Before I start, here are some preliminary notes about the context... ********* Situation ********* * first posted to distutils-sig list: http://mail.python.org/pipermail/distutils-sig/2012-May/018551.html * then opened a ticket on CPython issue tracker: http://bugs.python.org/issue14899 * started to work in a fork... https://bitbucket.org/benoitbryon/cpython/src/doc-package-names/Doc/packaging/packagenames.rst * ... but this looks like a PEP. So, let's follow PEP 1 and post a proposal here. *********************** What follows is a draft *********************** * First of all, I promise I did my best ;) * I guess most points already have been discussed here or elsewhere. But since I couldn't find an official reference (i.e. a refused PEP), I believe consensus is possible. * I splitted proposals in small sections, so that people can discuss or refuse some items while accepting others. If you see something that is not atomic, please propose a split. * I tried to relate facts. But I feel like a newbie about some points, so, if you see something wrong or incomplete, please send information and/or sources. * I tried to propose actions and take existing projects into account. In my humble opinion, motivations and proposals below seem reasonable enough. That's why I am posting here to get feedback from the community. * Finally, I am not a native english speaker... feel free to improve vocabulary, grammar and so on :) That said, let's go... .. note:: You can also get the following proposal online at https://bitbucket.org/benoitbryon/cpython/src/doc-package-names/Doc/packaging/packagenames.rst Thanks to Martin Aspeli for his article. Thanks to early reviewers: Alexis M?taireau, ?ric Br?hault, Jean-Philippe Camguilhem and Mathieu Lepl?tre. Regards, Benoit ########################################### Names in packaging: conventions and recipes ########################################### This document deals with: * names of Python projects, * names of distributions in projects, * names of Python packages or modules being distributed, * namespace packages. It provides conventions and recipes for distribution authors. Main use case is: * as a developer, I want to create a project in order to distribute a package. So I have to choose names. Which names are "good"? * `The Zen of Python`_ says: In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. * So I need clear and official (i.e. obvious) guidelines or conventions that I can follow. * Here are conventions, guidelines and recipes. Guidelines for existing projects are also given. *********** Terminology *********** First of all, let's make sure there is no confusion... Distribution name Distribution name is used by packaging utilities: * in :doc:`setup script`, it is the value passed as ``name`` to ``packaging.core.setup()`` * it appears on `PyPI`_ if the package is registered on it * it can be used in `pip` requirements files * it can be used in `buildout` configuration files. Distribution term is introduced in :doc:`packaging docs`. Egg name It is the same concept as distribution name. Technically, the egg is not the distribution. But they use the same name: it is declared as ``packaging.core.setup()`` name argument. "Egg" term is the legacy counterpart to "distribution". It was used by distutils and setuptools. It becomes deprecated with the new packaging module. This document focuses on distributions, not eggs. Package and module names Package and module names are used in Python code. It is the string used in :ref:`import statements`. Remember that, from a file system perspective, packages are directories and modules are files. :ref:`Python packaging allows distributions to distribute several packages and/or modules`. Project name Usually the name of the repository or folder in which distribution authors put their code. It generally is the directory name of the "distribution root", as defined in :ref:`packaging-term`. Namespace packages It is common practice to use namespaces in package names. `PEP 420`_ brings this concept to core Python. When PEP 420 will be accepted, Python officially supports namespace packages. As an example, consider `django-debug-toolbar`_: * ``django-debug-toolbar`` is the distribution name. `It is declared in setup.py file `_. * ``debug_toolbar`` is the package name. It is what would appear in Django's INSTALLED_APPS setting or be used as ``import debug_toolbar``. Technically, all those names can be different. ********* Rationale ********* Relationship with other PEPs ============================ * `PEP 8`_ deals with code style guide, including names of Python packages and modules. It covers syntax of package/modules names. * `PEP 345`_ deals with packaging metadata, and defines distribution name. * `PEP 420`_ deals with namespace packages. It brings support of namespace packages to Python core. Before, namespaces packages were implemented by external libraries. * `PEP 3108`_ deals with transition between Python 2.x and Python 3.x applied to standard library: some modules to be deleted, some to be renamed. Other sources of inspiration ============================ * `Martin Aspeli's article about names`_. Some parts of this proposal are quotes from this article. * `The Hitchhiker's Guide to Packaging`_, which has an empty placeholder for "naming specification". * and, of course, `in development official packaging documentation`_. Facts ===== Before Python version 3.3, there is no official guidelines to name projects, distributions or packages/modules. Current PEPs (see `Relationship with other PEPs`_) are very open on this topic. Distribution authors have to follow their own intuition. Several standards emerged from communities. As examples: * `Plone`_ community uses "plone.*" namespace for official Plone products, and "collective.*" for community products. This is a convention explicitely promoted by Plone community. `Martin Aspeli's article about names`_ is about conventions and usages in Plone community. .. note:: Is there an official document about these conventions? A PLIP? * most `Django`_ applications from community use "django-\*" pattern as distribution name. This is a de facto standard. * many `Pyramid`_ applications from community use "pyramid_*" pattern as distribution name. Thus, as `PyPI`_ testifies, distribution names and package/module names are really heterogeneous. Impacts ======= Here are points this document tries to resolve. Ambiguity --------- When distribution authors come to choose a name, they can't find an unique official guideline. In such a situation, "Now is better than never" wins over "Refuse temptation to guess". So distribution authors follow one of the conventions they discovered (usually the one from their community), or follow their own intuition. Confusion --------- As explained in `terminology`_ above, project, distribution and package names can be assigned distinct values. That is a big source of confusion, especially for Python developers who are not used to packaging. Time loss --------- As a direct consequence of `ambiguity`_ and `confusion`_, new Python developers spend too much time to understand Python projects/distributions/packages names: * they can't find obvious (i.e. official) naming conventions (or at least guidelines) even if they search for it. They have to ask community to resolve the `ambiguity`_. * it's hard to resolve the `confusion`_ between names. It's even harder because community itself is a bit confused. Their best chance is to find one of the `Other sources of inspiration`_ listed above or ask a well informed person. * developers from some other languages suppose Python have official naming conventions for distributions and packages. So they search for it, and feel worried when they figure out that it doesn't exist. Experienced Python users are less affected: they built their opinion in the past and keep on following their habits. Community partitionning ----------------------- The global Python community is partitionned into opposed sub-communities: * most Python developers are linked to at least one community (i.e. Zope, Plone, Pyramid, Django...). * communities usually resolved naming conventions with official documents or with de facto usage. * developers usually follow their community's standards. * developers usually believe their community made the best choice. They usually adhere to community arguments. * choices and reasons differ from one community to another. * when Python communities meet, package names are a never-ending topic of discussion. * people discuss about package names when they should work together on more valuable stories. * they can't settle the issue, because: * arguments have historical reasons. In history, these reasons were enough. * accepting someone else's arguments means changing habits, and maybe re-packaging existing projects, i.e. efforts and time. * there is no guidelines from an higher authorithy (i.e. python.org). There is no comparison standard. Both choices are legitimate. An additional note about developers who belong to several communities: * they usually adhere to the naming conventions from one community, * it's hard to adopt another convention when contributing in another community. Proposal ======== As `The Zen of Python`_ says: "There should be one-- and preferably only one --obvious way to do it." So the proposal is: * adopt strict conventions where Python community finds a consensus, * provide guidelines or recipes for what cannot be covered by conventions. What about existing projects? ============================= It's impossible to **require** a change for every existing project, for obvious reasons. But it is possible to first **document** existing naming conventions, then **promote** a change. This document proposes two things: * a status on current existing naming conventions, inside each project or community. So that custom naming conventions are at least self-documented. See `Organize community contributions`_ for details. * a `Transition plan`_ for those who are ready to migrate. .. _`packagenames-opportunity`: Opportunity =========== As of Python 3.3 being developed: * many projects are not Python 3.x compatible. It includes "big" products or frameworks. It means that many projects will have to do a migration to support Python 3.x. * packaging (aka distutils2) is on the starting blocks. When it is released, projects will be invited to migrate and use new packaging. * `PEP 420`_ brings official support of namespace packages to Python. It means that most active projects should be about to migrate in the next year(s) to support Python 3.x, new packaging or new namespace packages. Such an opportunity is unique and won't come again soon! So let's introduce and promote naming conventions as soon as possible (i.e. **now**). *************** Transition plan *************** New distributions ================= In order of priority: 1. If the project belongs to a community (i.e. product/framework), **and** the community have official conventions, then follow community conventions. .. note:: :ref:`Communities SHOULD organize contributions `. As an example new community project related to Plone should be distributed as "collective.*", because it is an explicit standard of the Plone community. 2. New projects SHOULD follow `Conventions`_ described in this document. Existing projects ================= **There is no obligation for existing distributions to be renamed**. The choice is left to distribution authors and mainteners for obvious reasons. However, distribution authors are invited to `promote migrations`_. In order to rename an existing distribution, follow `Renaming howto`_ guidelines below. Promote migrations ================== Every Python developer should migrate whenever possible, or promote the migrations in their respective communities. Apply this convention on your projects, then the community will see it is safe. In particular, "leaders" such as authors of popular projects are influential, they have power and, thus, responsability over communities. Apply this conventions on popular projects, then communities will adopt the conventions too. **Popular projects SHOULD promote migrations when they release a new (major) version**, particularly :ref:`if this version introduces support for Python 3.x, new standard library's packaging or namespace packages `. .. note:: On the contrary, if popular projects refuse the conventions, communities may not adopt the conventions. Improved handling of renamed distributions on PyPI ================================================== If many projects follow `Renaming howto`_, many legacy distributions will have the following characteristics: * ``Development Status :: 7 - Inactive`` classifier. * latest version is empty, except packaging stuff. * lastest version "redirects" to another distribution. E.g. it has a single dependency on the renamed distribution. * referenced as ``Obsoletes-Dist`` in a newer distribution. So it will be possible to detect renamed distributions and improve readability on PyPI. So that users can focus on active distributions. But this feature is not required now. There is no urge. It won't be covered in this document. *********** Conventions *********** Rules that you SHOULD follow. If in doubt, ask ================ If you feel unsure after reading the following conventions, ask `Python community`_ on IRC or on a mailing list. Use a single name ================= Distribute only one package (or only one module) in a distribution, and use package (or module) name as project name and distribution name. * It avoids possible confusion between all those names. * It makes the name consistent. * It is explicit: when one sees distribution name, he guesses package name, and vice versa. * It also limits implicit clashes between package/module names. By using a single name, when you register a name to PyPI, you also perform a basic package/module name availability verification. As an example, `pipeline`_, `python-pipeline`_ and `django-pipeline`_ all distribute a package or module called "pipeline". So installing two of them leads to errors. Yes: * Package name: "kheops.pyramid", i.e. ``import kheops.pyramid`` * distribution name: "kheops.pyramid", i.e. ``pip install kheops.pyramid`` * Project name: "kheops.pyramid", i.e. ``git clone git at github.com/pharaohs/kheops.pyramid.git`` No: * Package name: "kheops" * Distribution name: "kheops-pyramid" * Project name: "KheopsPyramid" .. note:: For historical reasons, on `PyPI`_, you can find many distributions using different values for project, distribution and package/module name. Multiple packages/modules should be rare ---------------------------------------- Technically, Python distributions can provide multiple packages and/or modules. See :ref:`setup script reference` for details. Some distributions actually does. As an example, `setuptools`_ and `distribute`_ are both declaring "pkg_resources", "easy_install" and "site" modules in addition to respective "setuptools" and "distribute" packages. Consider this use case as exceptional. In most cases, you don't need this feature. So a distribution should provide only one package or module at a time. Explicit distinct names should be rare -------------------------------------- A notable exception to the "Use a single name" rule is when you explicitely need distinct names. As an example, the `Pillow`_ distribution is an alternative to the original `PIL`_ distribution. They both provide a "PIL" package. Consider this use case as exceptional. In most cases, you don't need this feature. So a distributed package name should be equal to distribution name. Follow PEP 8 for package names syntax ===================================== `PEP 8`_ applies to Python package and module names. If you `Use a single name`_, `PEP 8`_ also applies to project and distribution names. The exceptions are namespace packages, where dots are required in the name. Pick meaningful names ===================== Ask yourself "how would I describe in one sentence what this name is for?", and then "could anyone have guessed that by looking at the name?". When you are using namespaces, make sure each part is meaningful. .. _`packagenames-ownership`: Top level namespace relates to code ownership ============================================= This helps avoid clashes between distribution names. Ownership could be: * an individual. Example: `gp.fileupload`_ is owned and maintained by Gael Pasgrimaud. * an organization. Examples: * `zest.releaser`_ is owned and maintained by Zest Software. * `Django`_ is owned and maintained by the Django Software Fundation. * a group or community. Example: `sphinx`_ is maintained by developers of the Sphinx project, not only by its author, Georg Brandl. * a group or community related to another package. Example: `collective.recaptcha`_ is owned by its author: David Glick, Groundwire. But the "collective" namespace is owned by Plone community. Respect ownership ----------------- Understand the purpose of namespace before you use it. **DO NOT** plug into a namespace you don't own, unless explicitely authorized. `If in doubt, ask`_. As an example, **DO NOT** use "django.contrib" namespace: it is managed by Django's core contributors. Exceptions CAN be defined by distribution authors. See `Organize community contributions`_ below. Private (including closed-source) distributions use a namespace --------------------------------------------------------------- ... because private distributions are owned by somebody. So apply the :ref:`ownership rule`. For internal/customer projects, use your company name as the namespace. This rule applies to closed-source distributions. As an example, if you are creating a "climbing" distribution for the "Python Sport" company: use "pythonsport.climbing" name, even if it is closed source. Individual projects use a namespace ----------------------------------- ... because they are owned by individuals. So apply the :ref:`ownership rule `. There is no shame in releasing a distribution as open source even if it has an "internal" name. If the project comes to a point where the author wants to change ownership (i.e. the project no longer belongs to an individual), keep in mind :ref:`it is easy to rename the project`. Independant community Python projects CAN avoid namespaces ---------------------------------------------------------- If your project is generic enough (i.e. it is not a contrib to another product or framework), you CAN avoid namespaces. The base condition is generally that your project is owned by a group (i.e. the development team) which is dedicated to this project. Only use a "shared" namespace if you really intend the code to be community owned. As an example, `sphinx`_ project belongs to the Sphinx development team. In doubt, use an individual/organization namespace -------------------------------------------------- If your project is not mature or hasn't been proven useful to a community, best choice is to use an individual or organization namespace. It allows distribution authors to release projects early. And it doesn't block future changes. When a project becomes mature, and if it appears there is no reason to keep individual ownership, :ref:`it remains possible to rename the project`. Avoid deep nesting ================== `The Zen of Python`_ says: Flat is better than nested. Two levels is almost always enough ---------------------------------- Don't define everything in deeply nested hierarchies: you will end up with distributions and packages like "pythonsport.common.maps.forest". This type of name is both verbose and cumbersome (e.g. if you have many imports from the package). Furthermore, big hierarchies tend to break down over time as the boundaries between different packages blur. The consensus is that two levels of nesting are preferred. Yes: "pyranha" Yes: "pythonsport.climbing" Yes: "pythonsport.forestmap" No: "pythonsport.maps.forest" .. _`packagenames-othermetadata`: Limited namespace levels, unlimited metadata -------------------------------------------- Consider distribution names (with or without namespaces) as unique identifiers on PyPI. It is important that these identifiers remain human-readable. It is even better when these identifiers are meaningful. But their primary purpose is not to classify or describe distributions. As examples, if you only look at the name: * you can't guess "nose" is about testing, * or "celery" about distributed task queueing, * or that "lettuce" is about tests, and has nothing in common with "celery". The examples above are not problematic. **`Classifiers`_ and keywords metadata are made for categorization of distributions.** As an example, there is a "Framework :: TurboGears" classifier. Even if names are quite heterogeneous (they don't follow a pattern like collective.* for Plone community projects), we get the list. In order to `Organize community contributions`_, conventions about names and namespaces matter, but conventions about metadata should be even more important. As an example, we can find Plone portlets in many places: * plone.portlet.* * collective.portlet.* * collective.portlets.* * collective.*.portlets * some vendor-related distributions such as "quintagroup.portlet.cumulus" * and even distributions where "portlet" pattern doesn't appear... Even if Plone community has conventions, using the name to categorize distributions is inapropriate. It's impossible to get the full list of distributions that provide portlets for Plone by filtering on names. But it would be possible if all these distributions used "Framework :: Plone" classifier and "portlet" keyword. Do you really need 3 levels? ---------------------------- For example, we have ``plone.principalsource`` instead of ``plone.source.principal`` or something like that. The name is shorter, the package structure is simpler, and there would be very little to gain from having three levels of nesting here. It would be impractical to try to put all "core Plone" sources (a source is kind of vocabulary) into the ``plone.source.*`` namespace, in part because some sources are part of other packages, and in part because sources already exist in other places. Had we made a new namespace, it would be inconsistently used from the start. 3 levels are also tempting when: * you are pluging into a community namespace, such as "collective". * and you want to add a more restrictive "ownership" level, to avoid clashes inside the community. In such a case, you'd better use the most restrictive ownership level as first level. As an example, where "collective" is a major community namespace that "gergovie" belongs to, and "vercingetorix" it the name of "gergovie" author: No: "collective.vercingetorix.gergovie" Yes: "vercingetorix.collectivegergovie" 3 levels are supported for historical reasons --------------------------------------------- Even if not recommended, 3 levels are supported. This is mainly for historical reasons: 3 levels can be accepted where top level namespace owner explicitely allows it with a specific convention. See `Organize community contributions`_ for details. Don't use more than 3 levels ---------------------------- * 1 or 2 levels are recommended. * 3 levels are discouraged, but supported for historical reasons. * you shouldn't need more than 3 levels. .. note:: Even communities where namespaces are standard don't use more than 3 levels. .. _`packagenames-organizecommunities`: Organize community contributions ================================ Actions: * Choose a naming convention for community contributions. * If it is not :ref:`the default`, document it. * if you use the :ref:`default convention`, this document should be enough. Don't reapeat it. You MAY reference it. * else, tell users about custom conventions in project's "contribute" or "create modules" documentation. * Also recommend the use of additional metadata, such as :ref:`classifiers and keywords`. About convention choices: * New projects SHOULD choose the default scheme. * Existing projects with community contributions CAN start with custom conventions. Then they SHOULD `Promote migrations`_. It means that existing community conventions doesn't need to be changed. But they need to be explicitely documented: first state about current naming conventions, then about future. Example: "pyranha" is your project name, distribution name and package name. Tell contributors that: * pyranha-related distributions should use the "pyranha" keyword * pyranha distributions providing templates should also use "templates" keyword. * community contributions should be released under "pyranhacontrib" namespace (i.e. use "pyranhacontrib.*" pattern): .. _`packagenames-contribnamespace`: Community contributions SHOULD use "${DIST}contrib.*" pattern ================================================================ The idea is to use a standard pattern to store community contributions for any product or framework. It is the simplest way to `Organize community contributions`_: the obvious way to go is "${DIST}contrib", no ambiguity. As an example: * you are the author of "pyranha" project. You own the "pyranha" namespace. * a third-party developer wants to publish a "giantteeth" project related to your "pyranha" project. He can publish it as "pyranhacontrib.giantteeth". .. note:: Why ``${DIST}contrib.*`` pattern? * ``${DIST}c.*`` is not explicit enough. As examples, "zc" belongs to "Zope Corporation" whereas "z3c" belongs to "Zope 3 community". * ``${DIST}community`` is too long. * ``${DIST}community`` conflicts with existing namespaces such as "iccommunity" or "PyCommunity". * ``${DIST}.contrib`` is inside ${DIST} namespace, i.e. it is owned by ${DIST} authors. It breaks the `Top level namespace relates to code ownership`_. * ``${DIST}.contrib.*`` breaks the `Avoid deep nesting`_ rule. * names where ``${DIST}`` doesn't appear are not explicit enough, i.e. nobody can guess they are related to ``${DIST}``. * ``{$DIST}contrib.*`` may conflict with existing ``sphinxcontrib-*`` packages. But ``sphinxcontrib-*`` is actually about Sphinx contrib, so this is not a real conflict... In fact, the "contrib" suffix was inspired by "sphinxcontrib". ******* Recipes ******* How to avoid duplicate names ============================ Before you choose a distribution name, make sure it hasn't already been registered in the following locations: * `PyPI`_ * Popular code repositories such as: * `Github`_ * `Bitbucket`_ * `Gitorious`_ * `djangopackages.com`_ .. note:: A web service would be welcome for this! Also make sure the package name hasn't already been registered: * in the `Python Standard Library`_, * in the locations where you checked for distribution name availability. .. _`packagenames-rename`: Renaming howto ============== Renaming a project is possible, but keep in mind that it will cause some confusions. So, pay particular attention to README and documentation, so that users understand what happened. #. First of all, **do not remove legacy distribution from PyPI**. Because some users may be using it. #. Copy the legacy project, then change names (project, distribution and package/module). Pay attention to, at least: * packaging files, * folder name that contains source files, * documentation, including README, * import statements in code. #. Assign ``Obsoletes-Dist`` metadata to new distribution in setup.cfg file. See `PEP 345 about Obsolete-Dist`_ and :ref:`setup.cfg specification `. #. Release the renamed distribution as a new version, then publish it. #. Edit legacy distribution: * add dependency to new distribution, * drop everything except packaging stuff, * add the ``Development Status :: 7 - Inactive`` classifier in setup script, * publish a new release. So, users of the legacy package: * can continue using the legacy distribution at a deprecated version, * can upgrade to last version of legacy distribution, which is empty, ... * ... and automatically download new distribution as a dependency of the legacy one. Users who discover the legacy distribution see it is inactive. ********** References ********** .. target-notes:: .. _`Martin Aspeli's article about names`: http://www.martinaspeli.net/articles/the-naming-of-things-package-names-and-namespaces .. _`PEP 1`: http://www.python.org/dev/peps/pep-0001/ .. _`The Zen of Python`: http://www.python.org/dev/peps/pep-0020/ .. _`PEP 8`: http://www.python.org/dev/peps/pep-0008/#package-and-module-names .. _`PEP 345`: http://www.python.org/dev/peps/pep-0345/ .. _`PEP 420`: http://www.python.org/dev/peps/pep-0420/ .. _`PEP 3108`: http://www.python.org/dev/peps/pep-3108 .. _`The Hitchhiker's Guide to Packaging`: http://guide.python-distribute.org/specification.html#naming-specification .. _`in development official packaging documentation`: http://docs.python.org/dev/packaging/ .. _`plone`: http://plone.org/community/develop .. _`django`: http://djangoproject.com/ .. _`pyramid`: http://pylonsproject.org .. _`pypi`: http://pypi.python.org .. _`django-debug-toolbar`: https://github.com/django-debug-toolbar/django-debug-toolbar .. _`gp.fileupload`: http://pypi.python.org/pypi/gp.fileupload/ .. _`zest.releaser`: http://pypi.python.org/pypi/zest.releaser/ .. _`sphinx`: http://sphinx.pocoo.org .. _`Classifiers`: http://pypi.python.org/pypi?:action=list_classifiers .. _`collective.recaptcha`: http://pypi.python.org/pypi/collective.recaptcha/ .. _`Python community`: http://www.python.org/community/ .. _`pipeline`: http://pypi.python.org/pypi/pipeline/ .. _`python-pipeline`: http://pypi.python.org/pypi/python-pipeline/ .. _`django-pipeline`: http://pypi.python.org/pypi/django-pipeline/ .. _`setuptools`: http://pypi.python.org/pypi/setuptools .. _`distribute`: http://packages.python.org/distribute/ .. _`Pillow`: http://pypi.python.org/pypi/Pillow/ .. _`PIL`: http://pypi.python.org/pypi/PIL/ .. _`Python Standard Library`: http://docs.python.org/library/index.html .. _`github`: https://github.com .. _`bitbucket`: https://bitbucket.org .. _`gitorious`: https://gitorious.org/ .. _`djangopackages.com`: http://djangopackages.com .. _`PEP 345 about Obsolete-Dist`: http://www.python.org/dev/peps/pep-0345/#obsoletes-dist-multiple-use From rurpy at yahoo.com Wed May 30 13:15:52 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 30 May 2012 10:15:52 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <8f2044b3-b334-42a9-91e5-7592d0eec12b@cu1g2000vbb.googlegroups.com> Message-ID: <401b8505-93d7-4d02-8fa8-157b3d20f6eb@q2g2000vbv.googlegroups.com> On 05/30/2012 10:46 AM, Terry Reedy wrote: > On 5/30/2012 2:52 AM, rurpy at yahoo.com wrote: >> In python2, "\u" escapes are processed in raw unicode >> strings. That is, ur'\u3000' is a string of length 1 >> consisting of the IDEOGRAPHIC SPACE unicode character. > > That surprised me until I rechecked the fine manual and found: > > "When an 'r' or 'R' prefix is present, a character following a backslash > is included in the string without change, and all backslashes are left > in the string." > > "When an 'r' or 'R' prefix is used in conjunction with a 'u' or 'U' > prefix, then the \uXXXX and \UXXXXXXXX escape sequences are processed > while all other backslashes are left in the string." > > When 'u' was removed in Python 3, a choice had to be made and the first > must have seemed to be the obvious one, or perhaps the automatic one. > > In 3.3, 'u' is being restored. I have inquired on pydev list whether the > difference above should also be restored, and mentioned this thread. As mentioned is a different message, another option might be to leave raw strings as is (more consistent since all backslashes are treated the same) and have the "re" module un-escape "\uxxxx" (and similar) literals in regex string (also more consistent since that's what it does with '\\n', '\\t', etc.) I do realize though that this may have back-compatibilty problems that makes it impossible to do. From wxjmfauth at gmail.com Wed May 30 13:58:53 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 30 May 2012 10:58:53 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: On 30 mai, 13:54, Thomas Rachel wrote: > Am 30.05.2012 08:52 schrieb ru... at yahoo.com: > > > > > This breaks a lot of my code because in python 2 > > ? ? ? ?re.split (ur'[\u3000]', u'A\u3000A') ==> ?[u'A', u'A'] > > but in python 3 (the result of running 2to3), > > ? ? ? ?re.split (r'[\u3000]', 'A\u3000A' ) ==> ?['A\u3000A'] > > > I can remove the "r" prefix from the regex string but then > > if I have other regex backslash symbols in it, I have to > > double all the other backslashes -- the very thing that > > the r-prefix was invented to avoid. > > > Or I can leave the "r" prefix and replace something like > > r'[ \u3000]' with r'[ ?]'. ?But that is confusing because > > one can't distinguish between the space character and > > the ideographic space character. ?It also a problem if a > > reader of the code doesn't have a font that can display > > the character. > > > Was there a reason for dropping the lexical processing of > > \u escapes in strings in python3 (other than to add another > > annoyance in a long list of python3 annoyances?) > > Probably it is more consequent. Alas, it makes the whole stuff > incompatible to Py2. > > But if you think about it: why allow for \u if \r, \n etc. are > disallowed as well? > > > And is there no choice for me but to choose between the two > > poor choices I mention above to deal with this problem? > > There is a 3rd one: use ? r'[ ' + '\u3000' + ']'. Not very nice to read, > but should do the trick... > > Thomas I suggest to take the problem differently. Python 3 succeeded to put order in the missmatch of the "coding of the characters" Python 2 was proposing. In your case, the >>> import unicodedata as ud >>> ud.name('\u3000') 'IDEOGRAPHIC SPACE' "character" (in fact a unicode code point), is just a "character" as a >>> ud.name('a') 'LATIN SMALL LETTER A' The code point / unicode logic, Python 3 proposes and follows, becomes just straightforward. >>> s = 'a\u3000?\u3000?' >>> s.split('\u3000') ['a', '?', '?'] >>> >>> import re >>> re.split('\u3000', s) ['a', '?', '?'] The backslash, used as "real backslash", remains what it really was in Python 2. Note, the absence of r'...' . >>> s = 'a\\b\\c' >>> print(s) a\b\c >>> s.split('\\') ['a', 'b', 'c'] >>> re.split('\\\\', s) ['a', 'b', 'c'] >>> hex(ord('\\')) '0x5c' >>> re.split('\u005c\u005c', s) ['a', 'b', 'c'] jmf From robert.kern at gmail.com Wed May 30 14:04:20 2012 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 30 May 2012 19:04:20 +0100 Subject: installing modules in Enthought Python In-Reply-To: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> References: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> Message-ID: On 5/30/12 4:05 PM, Chuck wrote: > I just downloaded Enthought Python, free version. I wanted all the > included packages, but I can't seem to find the correct directory to > install new Python modules. Does anybody have an idea? I am trying > to add Universal Feed Parser to Enthought. I have tried C:\Python27, > C:\Python27\Lib, C:\Python27\Lib\site-packages, but no success. Hello! Enthought employee here. You can send EPD installation support questions to . In this respect, EPD is no different from any other Python installation. Universal Feed Parser is a standard Python package that uses a distutils setup.py script to install. You usually cannot just unpack its source .zip file somewhere, which is what I expect you are doing. You need to unpack the feedparser-5.1.2.zip source archive to some temporary location, then run the setup.py script from the command line: C:\Users\Robert\Downloads\feedparser-5.1.2> python setup.py install You can read more thorough documentation on how to use distutils setup.py scripts in the Python documentation: http://docs.python.org/install/index.html I hope that helps. If not, please send let us know on . Thank you! -- 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 galois271 at gmail.com Wed May 30 14:43:58 2012 From: galois271 at gmail.com (Chuck) Date: Wed, 30 May 2012 11:43:58 -0700 (PDT) Subject: installing modules in Enthought Python References: <16137280-7598-4ca5-b8ad-6b11d811fe66@tx6g2000pbc.googlegroups.com> Message-ID: <5abef8fe-be46-495c-af68-b3415d3e52ea@oo8g2000pbc.googlegroups.com> On May 30, 10:57?am, David Fanning wrote: > Chuck writes: > > > I just downloaded Enthought Python, free version. ?I wanted all the > > included packages, but I can't seem to find the correct directory to > > install new Python modules. ?Does anybody have an idea? ?I am trying > > to add Universal Feed Parser to Enthought. ?I have tried C:\Python27, > > C:\Python27\Lib, C:\Python27\Lib\site-packages, but no success. > > I spent most of the day on this problem yesterday. You are > going to want to get *.exe files that will install in the > usual way on Windows. I found the packages I was looking > for at one or the other of these sites: > > http://code.google.com/p/pythonxy/wiki/AdditionalPlugins#Installation_no > tes > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml > > Cheers > > David > > -- > David Fanning, Ph.D. > Fanning Software Consulting, Inc. > Sepore ma de ni thui. ("Perhaps thou speakest truth.") Unfortunately, I couldn't find Universal Feed Parser, the package I was looking for, but thanks for the tip. From nfitzkee at gmail.com Wed May 30 16:38:28 2012 From: nfitzkee at gmail.com (nfitzkee at gmail.com) Date: Wed, 30 May 2012 13:38:28 -0700 (PDT) Subject: Maintaining Multiple Copies of Python (Linux) Message-ID: Hi all, For various reasons, I would like to maintain multiple copies of python on my (Ubuntu 12.04) linux system. This is primarily for scientific software development; several modules require different configuration options than are installed on the 'vanilla' python included in the Ubuntu distribution, and I don't want to disturb that version in case something would interfere with the OS. I can compile python 2.7 and put it in /usr/local, but when I do that it can lead to confusion about what version is being run, particularly if my group members don't have their paths set correctly. Renaming the binaries alone is a partial solution, but that won't work for the library and include directories. Is there a way to configure the distribution at compile time to resolve the ambiguity? For example, could I specify an option to "configure" that appends a prefix to all of the created python binaries, etc.? In this case, it might create "my-python2.7" "my-python" and "my-idle" (etc.) in /usr/local/bin, along with storing libraries in /usr/local/lib/my-python2.7/. Thus, the my-python programs would be 100% independent from the OS python, and they would be independent from other local builds as well. I apologize if this answer is covered elsewhere; so far my google searches have not turned up anything. Thanks, Nick From tarek at ziade.org Wed May 30 17:10:52 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Wed, 30 May 2012 23:10:52 +0200 Subject: Proposal about naming conventions around packaging In-Reply-To: <4FC651F7.6070805@marmelune.net> References: <4FC651F7.6070805@marmelune.net> Message-ID: <4FC68CDC.8070803@ziade.org> On 5/30/12 6:59 PM, Beno?t Bryon wrote: > Hi, Hi Benoit you should post this to the distutils SIG Thank you > > Here is a proposal about naming conventions around > packaging. > > Main question is: would you accept it as a PEP? > > > ############################################ > Preliminary notes (not part of the proposal) > ############################################ > > Before I start, here are some preliminary notes about the > context... > > > ********* > Situation > ********* > > * first posted to distutils-sig list: > http://mail.python.org/pipermail/distutils-sig/2012-May/018551.html > > * then opened a ticket on CPython issue tracker: > http://bugs.python.org/issue14899 > > * started to work in a fork... > > https://bitbucket.org/benoitbryon/cpython/src/doc-package-names/Doc/packaging/packagenames.rst > > * ... but this looks like a PEP. So, let's follow PEP 1 > and post a proposal here. > > > *********************** > What follows is a draft > *********************** > > * First of all, I promise I did my best ;) > > * I guess most points already have been discussed here or > elsewhere. But since I couldn't find an official > reference (i.e. a refused PEP), I believe consensus is > possible. > > * I splitted proposals in small sections, so > that people can discuss or refuse some items while > accepting others. If you see something that is not > atomic, please propose a split. > > * I tried to relate facts. But I feel like a newbie about > some points, so, if you see something wrong or > incomplete, please send information and/or sources. > > * I tried to propose actions and take existing projects into > account. In my humble opinion, motivations and proposals > below seem reasonable enough. That's why I am posting > here to get feedback from the community. > > * Finally, I am not a native english speaker... feel free > to improve vocabulary, grammar and so on :) > > That said, let's go... > > .. note:: > > You can also get the following proposal online at > > https://bitbucket.org/benoitbryon/cpython/src/doc-package-names/Doc/packaging/packagenames.rst > > Thanks to Martin Aspeli for his article. > Thanks to early reviewers: Alexis M?taireau, ?ric Br?hault, > Jean-Philippe Camguilhem and Mathieu Lepl?tre. > > Regards, > Benoit > > > > ########################################### > Names in packaging: conventions and recipes > ########################################### > > This document deals with: > > * names of Python projects, > * names of distributions in projects, > * names of Python packages or modules being distributed, > * namespace packages. > > It provides conventions and recipes for distribution authors. > > Main use case is: > > * as a developer, I want to create a project in order to distribute a > package. > So I have to choose names. Which names are "good"? > > * `The Zen of Python`_ says: > > In the face of ambiguity, refuse the temptation to guess. > There should be one-- and preferably only one --obvious way to do it. > > * So I need clear and official (i.e. obvious) guidelines or > conventions that I > can follow. > > * Here are conventions, guidelines and recipes. > > Guidelines for existing projects are also given. > > > *********** > Terminology > *********** > > First of all, let's make sure there is no confusion... > > Distribution name > Distribution name is used by packaging utilities: > > * in :doc:`setup script`, it is the value > passed as > ``name`` to ``packaging.core.setup()`` > * it appears on `PyPI`_ if the package is registered on it > * it can be used in `pip` requirements files > * it can be used in `buildout` configuration files. > > Distribution term is introduced in :doc:`packaging > docs`. > > Egg name > It is the same concept as distribution name. Technically, the egg is > not the > distribution. But they use the same name: it is declared as > ``packaging.core.setup()`` name argument. > > "Egg" term is the legacy counterpart to "distribution". It was used by > distutils and setuptools. It becomes deprecated with the new packaging > module. > > This document focuses on distributions, not eggs. > > Package and module names > Package and module names are used in Python code. It is the string > used in > :ref:`import statements`. > > Remember that, from a file system perspective, packages are > directories and > modules are files. > > :ref:`Python packaging allows distributions to distribute several > packages > and/or modules`. > > Project name > Usually the name of the repository or folder in which distribution > authors put > their code. It generally is the directory name of the "distribution > root", > as defined in :ref:`packaging-term`. > > Namespace packages > It is common practice to use namespaces in package names. `PEP 420`_ > brings > this concept to core Python. When PEP 420 will be accepted, Python > officially > supports namespace packages. > > As an example, consider `django-debug-toolbar`_: > > * ``django-debug-toolbar`` is the distribution name. `It is declared in > setup.py file > `_. > > * ``debug_toolbar`` is the package name. It is what would appear in > Django's > INSTALLED_APPS setting or be used as ``import debug_toolbar``. > > Technically, all those names can be different. > > > ********* > Rationale > ********* > > Relationship with other PEPs > ============================ > > * `PEP 8`_ deals with code style guide, including names of Python > packages and > modules. It covers syntax of package/modules names. > > * `PEP 345`_ deals with packaging metadata, and defines distribution > name. > > * `PEP 420`_ deals with namespace packages. It brings support of > namespace > packages to Python core. Before, namespaces packages were > implemented by > external libraries. > > * `PEP 3108`_ deals with transition between Python 2.x and Python 3.x > applied > to standard library: some modules to be deleted, some to be renamed. > > Other sources of inspiration > ============================ > > * `Martin Aspeli's article about names`_. Some parts of this proposal are > quotes from this article. > > * `The Hitchhiker's Guide to Packaging`_, which has an empty placeholder > for "naming specification". > > * and, of course, `in development official packaging documentation`_. > > Facts > ===== > > Before Python version 3.3, there is no official guidelines to name > projects, > distributions or packages/modules. > Current PEPs (see `Relationship with other PEPs`_) are very open on > this topic. > > Distribution authors have to follow their own intuition. > > Several standards emerged from communities. As examples: > > * `Plone`_ community uses "plone.*" namespace for official Plone > products, and > "collective.*" for community products. This is a convention explicitely > promoted by Plone community. > `Martin Aspeli's article about names`_ is about conventions and > usages in > Plone community. > > .. note:: Is there an official document about these conventions? A > PLIP? > > * most `Django`_ applications from community use "django-\*" pattern as > distribution name. This is a de facto standard. > > * many `Pyramid`_ applications from community use "pyramid_*" pattern as > distribution name. > > Thus, as `PyPI`_ testifies, distribution names and package/module > names are > really heterogeneous. > > Impacts > ======= > > Here are points this document tries to resolve. > > Ambiguity > --------- > > When distribution authors come to choose a name, they can't find an > unique > official guideline. > In such a situation, "Now is better than never" wins over "Refuse > temptation > to guess". > So distribution authors follow one of the conventions they discovered > (usually > the one from their community), or follow their own intuition. > > Confusion > --------- > > As explained in `terminology`_ above, project, distribution and > package names > can be assigned distinct values. That is a big source of confusion, > especially > for Python developers who are not used to packaging. > > Time loss > --------- > > As a direct consequence of `ambiguity`_ and `confusion`_, new Python > developers > spend too much time to understand Python > projects/distributions/packages names: > > * they can't find obvious (i.e. official) naming conventions (or at least > guidelines) even if they search for it. They have to ask community > to resolve > the `ambiguity`_. > > * it's hard to resolve the `confusion`_ between names. It's even > harder because > community itself is a bit confused. Their best chance is to find one > of the > `Other sources of inspiration`_ listed above or ask a well informed > person. > > * developers from some other languages suppose Python have official > naming > conventions for distributions and packages. So they search for it, > and feel > worried when they figure out that it doesn't exist. > > Experienced Python users are less affected: they built their opinion > in the > past and keep on following their habits. > > Community partitionning > ----------------------- > > The global Python community is partitionned into opposed sub-communities: > > * most Python developers are linked to at least one community (i.e. Zope, > Plone, Pyramid, Django...). > > * communities usually resolved naming conventions with official documents > or with de facto usage. > > * developers usually follow their community's standards. > > * developers usually believe their community made the best choice. > They usually > adhere to community arguments. > > * choices and reasons differ from one community to another. > > * when Python communities meet, package names are a never-ending topic of > discussion. > > * people discuss about package names when they should work together on > more > valuable stories. > > * they can't settle the issue, because: > > * arguments have historical reasons. In history, these reasons were > enough. > > * accepting someone else's arguments means changing habits, and maybe > re-packaging existing projects, i.e. efforts and time. > > * there is no guidelines from an higher authorithy (i.e. > python.org). There > is no comparison standard. Both choices are legitimate. > > An additional note about developers who belong to several communities: > > * they usually adhere to the naming conventions from one community, > * it's hard to adopt another convention when contributing in another > community. > > Proposal > ======== > > As `The Zen of Python`_ says: "There should be one-- and preferably > only one > --obvious way to do it." > > So the proposal is: > > * adopt strict conventions where Python community finds a consensus, > * provide guidelines or recipes for what cannot be covered by > conventions. > > What about existing projects? > ============================= > > It's impossible to **require** a change for every existing project, > for obvious > reasons. > > But it is possible to first **document** existing naming conventions, > then > **promote** a change. > > This document proposes two things: > > * a status on current existing naming conventions, inside each project or > community. So that custom naming conventions are at least > self-documented. > See `Organize community contributions`_ for details. > > * a `Transition plan`_ for those who are ready to migrate. > > .. _`packagenames-opportunity`: > > Opportunity > =========== > > As of Python 3.3 being developed: > > * many projects are not Python 3.x compatible. It includes "big" > products or > frameworks. It means that many projects will have to do a migration to > support Python 3.x. > > * packaging (aka distutils2) is on the starting blocks. When it is > released, > projects will be invited to migrate and use new packaging. > > * `PEP 420`_ brings official support of namespace packages to Python. > > It means that most active projects should be about to migrate in the next > year(s) to support Python 3.x, new packaging or new namespace packages. > > Such an opportunity is unique and won't come again soon! > So let's introduce and promote naming conventions as soon as possible > (i.e. > **now**). > > > *************** > Transition plan > *************** > > New distributions > ================= > > In order of priority: > > 1. If the project belongs to a community (i.e. product/framework), > **and** the > community have official conventions, then follow community > conventions. > > .. note:: > > :ref:`Communities SHOULD organize contributions > `. > > As an example new community project related to Plone should be > distributed > as "collective.*", because it is an explicit standard of the Plone > community. > > 2. New projects SHOULD follow `Conventions`_ described in this document. > > Existing projects > ================= > > **There is no obligation for existing distributions to be renamed**. > The choice > is left to distribution authors and mainteners for obvious reasons. > > However, distribution authors are invited to `promote migrations`_. > > In order to rename an existing distribution, follow `Renaming howto`_ > guidelines below. > > Promote migrations > ================== > > Every Python developer should migrate whenever possible, or promote the > migrations in their respective communities. > > Apply this convention on your projects, then the community will see it is > safe. > > In particular, "leaders" such as authors of popular projects are > influential, > they have power and, thus, responsability over communities. > > Apply this conventions on popular projects, then communities will > adopt the > conventions too. > > **Popular projects SHOULD promote migrations when they release a new > (major) > version**, particularly :ref:`if this version introduces support for > Python > 3.x, new standard library's packaging or namespace packages > `. > > .. note:: > > On the contrary, if popular projects refuse the conventions, > communities > may not adopt the conventions. > > Improved handling of renamed distributions on PyPI > ================================================== > > If many projects follow `Renaming howto`_, many legacy distributions > will have > the following characteristics: > > * ``Development Status :: 7 - Inactive`` classifier. > * latest version is empty, except packaging stuff. > * lastest version "redirects" to another distribution. E.g. it has a > single > dependency on the renamed distribution. > * referenced as ``Obsoletes-Dist`` in a newer distribution. > > So it will be possible to detect renamed distributions and improve > readability > on PyPI. So that users can focus on active distributions. But this > feature is > not required now. There is no urge. It won't be covered in this document. > > > *********** > Conventions > *********** > > Rules that you SHOULD follow. > > If in doubt, ask > ================ > > If you feel unsure after reading the following conventions, ask `Python > community`_ on IRC or on a mailing list. > > Use a single name > ================= > > Distribute only one package (or only one module) in a distribution, > and use > package (or module) name as project name and distribution name. > > * It avoids possible confusion between all those names. > * It makes the name consistent. > * It is explicit: when one sees distribution name, he guesses package > name, and > vice versa. > * It also limits implicit clashes between package/module names. > By using a single name, when you register a name to PyPI, you also > perform a > basic package/module name availability verification. > > As an example, `pipeline`_, `python-pipeline`_ and > `django-pipeline`_ all > distribute a package or module called "pipeline". So installing two > of them > leads to errors. > > Yes: > > * Package name: "kheops.pyramid", > i.e. ``import kheops.pyramid`` > > * distribution name: "kheops.pyramid", > i.e. ``pip install kheops.pyramid`` > > * Project name: "kheops.pyramid", > i.e. ``git clone git at github.com/pharaohs/kheops.pyramid.git`` > > No: > > * Package name: "kheops" > * Distribution name: "kheops-pyramid" > * Project name: "KheopsPyramid" > > .. note:: > > For historical reasons, on `PyPI`_, you can find many distributions > using > different values for project, distribution and package/module name. > > Multiple packages/modules should be rare > ---------------------------------------- > > Technically, Python distributions can provide multiple packages and/or > modules. > See :ref:`setup script reference` for details. > > Some distributions actually does. > As an example, `setuptools`_ and `distribute`_ are both declaring > "pkg_resources", "easy_install" and "site" modules in addition to > respective > "setuptools" and "distribute" packages. > > Consider this use case as exceptional. In most cases, you don't need this > feature. So a distribution should provide only one package or module > at a time. > > Explicit distinct names should be rare > -------------------------------------- > > A notable exception to the "Use a single name" rule is when you > explicitely > need distinct names. > > As an example, the `Pillow`_ distribution is an alternative to the > original > `PIL`_ distribution. They both provide a "PIL" package. > > Consider this use case as exceptional. In most cases, you don't need this > feature. So a distributed package name should be equal to distribution > name. > > Follow PEP 8 for package names syntax > ===================================== > > `PEP 8`_ applies to Python package and module names. > > If you `Use a single name`_, `PEP 8`_ also applies to project and > distribution > names. The exceptions are namespace packages, where dots are required > in the > name. > > Pick meaningful names > ===================== > > Ask yourself "how would I describe in one sentence what this name is > for?", and > then "could anyone have guessed that by looking at the name?". > > When you are using namespaces, make sure each part is meaningful. > > .. _`packagenames-ownership`: > > Top level namespace relates to code ownership > ============================================= > > This helps avoid clashes between distribution names. > > Ownership could be: > > * an individual. > Example: `gp.fileupload`_ is owned and maintained by Gael Pasgrimaud. > > * an organization. > Examples: > > * `zest.releaser`_ is owned and maintained by Zest Software. > * `Django`_ is owned and maintained by the Django Software Fundation. > > * a group or community. > Example: `sphinx`_ is maintained by developers of the Sphinx > project, not > only by its author, Georg Brandl. > > * a group or community related to another package. > Example: `collective.recaptcha`_ is owned by its author: David Glick, > Groundwire. But the "collective" namespace is owned by Plone community. > > Respect ownership > ----------------- > > Understand the purpose of namespace before you use it. > > **DO NOT** plug into a namespace you don't own, unless explicitely > authorized. > > `If in doubt, ask`_. > > As an example, **DO NOT** use "django.contrib" namespace: it is > managed by > Django's core contributors. > > Exceptions CAN be defined by distribution authors. See `Organize > community > contributions`_ below. > > Private (including closed-source) distributions use a namespace > --------------------------------------------------------------- > > ... because private distributions are owned by somebody. So apply the > :ref:`ownership rule`. > > For internal/customer projects, use your company name as the namespace. > > This rule applies to closed-source distributions. > > As an example, if you are creating a "climbing" distribution for the > "Python > Sport" company: use "pythonsport.climbing" name, even if it is closed > source. > > Individual projects use a namespace > ----------------------------------- > > ... because they are owned by individuals. So apply the > :ref:`ownership rule > `. > > There is no shame in releasing a distribution as open source even if > it has an > "internal" name. > > If the project comes to a point where the author wants to change > ownership > (i.e. the project no longer belongs to an individual), keep in mind > :ref:`it is > easy to rename the project`. > > Independant community Python projects CAN avoid namespaces > ---------------------------------------------------------- > > If your project is generic enough (i.e. it is not a contrib to another > product > or framework), you CAN avoid namespaces. The base condition is > generally that > your project is owned by a group (i.e. the development team) which is > dedicated > to this project. > > Only use a "shared" namespace if you really intend the code to be > community > owned. > > As an example, `sphinx`_ project belongs to the Sphinx development team. > > In doubt, use an individual/organization namespace > -------------------------------------------------- > > If your project is not mature or hasn't been proven useful to a > community, > best choice is to use an individual or organization namespace. > > It allows distribution authors to release projects early. > > And it doesn't block future changes. When a project becomes mature, > and if it > appears there is no reason to keep individual ownership, :ref:`it remains > possible to rename the project`. > > Avoid deep nesting > ================== > > `The Zen of Python`_ says: > > Flat is better than nested. > > Two levels is almost always enough > ---------------------------------- > > Don't define everything in deeply nested hierarchies: you will end up > with > distributions and packages like "pythonsport.common.maps.forest". This > type > of name is both verbose and cumbersome (e.g. if you have many imports > from the > package). > Furthermore, big hierarchies tend to break down over time as the > boundaries > between different packages blur. > > The consensus is that two levels of nesting are preferred. > > Yes: "pyranha" > > Yes: "pythonsport.climbing" > > Yes: "pythonsport.forestmap" > > No: "pythonsport.maps.forest" > > .. _`packagenames-othermetadata`: > > Limited namespace levels, unlimited metadata > -------------------------------------------- > > Consider distribution names (with or without namespaces) as unique > identifiers > on PyPI. > It is important that these identifiers remain human-readable. > It is even better when these identifiers are meaningful. > But their primary purpose is not to classify or describe distributions. > > As examples, if you only look at the name: > > * you can't guess "nose" is about testing, > * or "celery" about distributed task queueing, > * or that "lettuce" is about tests, and has nothing in common with > "celery". > > The examples above are not problematic. > > **`Classifiers`_ and keywords metadata are made for categorization of > distributions.** > > As an example, there is a "Framework :: TurboGears" classifier. Even > if names > are quite heterogeneous (they don't follow a pattern like collective.* > for > Plone community projects), we get the list. > > In order to `Organize community contributions`_, conventions about > names and > namespaces matter, but conventions about metadata should be even more > important. > > As an example, we can find Plone portlets in many places: > > * plone.portlet.* > * collective.portlet.* > * collective.portlets.* > * collective.*.portlets > * some vendor-related distributions such as "quintagroup.portlet.cumulus" > * and even distributions where "portlet" pattern doesn't appear... > > Even if Plone community has conventions, using the name to categorize > distributions is inapropriate. It's impossible to get the full list of > distributions that provide portlets for Plone by filtering on names. > But it would be possible if all these distributions used "Framework :: > Plone" > classifier and "portlet" keyword. > > Do you really need 3 levels? > ---------------------------- > > For example, we have ``plone.principalsource`` instead of > ``plone.source.principal`` or something like that. The name is > shorter, the > package structure is simpler, and there would be very little to gain from > having three levels of nesting here. It would be impractical to try to > put all > "core Plone" sources (a source is kind of vocabulary) into the > ``plone.source.*`` namespace, in part because some sources are part of > other > packages, and in part because sources already exist in other places. > Had we > made a new namespace, it would be inconsistently used from the start. > > 3 levels are also tempting when: > > * you are pluging into a community namespace, such as "collective". > * and you want to add a more restrictive "ownership" level, to avoid > clashes > inside the community. > > In such a case, you'd better use the most restrictive ownership level > as first > level. > > As an example, where "collective" is a major community namespace that > "gergovie" belongs to, and "vercingetorix" it the name of "gergovie" > author: > > No: "collective.vercingetorix.gergovie" > > Yes: "vercingetorix.collectivegergovie" > > 3 levels are supported for historical reasons > --------------------------------------------- > > Even if not recommended, 3 levels are supported. This is mainly for > historical > reasons: 3 levels can be accepted where top level namespace owner > explicitely > allows it with a specific convention. See `Organize community > contributions`_ > for details. > > Don't use more than 3 levels > ---------------------------- > > * 1 or 2 levels are recommended. > * 3 levels are discouraged, but supported for historical reasons. > * you shouldn't need more than 3 levels. > > .. note:: > > Even communities where namespaces are standard don't use more than > 3 levels. > > .. _`packagenames-organizecommunities`: > > Organize community contributions > ================================ > > Actions: > > * Choose a naming convention for community contributions. > > * If it is not :ref:`the default`, > document it. > > * if you use the :ref:`default > convention`, > this document should be enough. Don't reapeat it. You MAY > reference it. > > * else, tell users about custom conventions in project's > "contribute" or > "create modules" documentation. > > * Also recommend the use of additional metadata, such as > :ref:`classifiers and > keywords`. > > About convention choices: > > * New projects SHOULD choose the default scheme. > > * Existing projects with community contributions CAN start with custom > conventions. Then they SHOULD `Promote migrations`_. > > It means that existing community conventions doesn't need to be > changed. > But they need to be explicitely documented: first state about > current naming > conventions, then about future. > > Example: "pyranha" is your project name, distribution name and package > name. > Tell contributors that: > > * pyranha-related distributions should use the "pyranha" keyword > > * pyranha distributions providing templates should also use "templates" > keyword. > > * community contributions should be released under "pyranhacontrib" > namespace > (i.e. use "pyranhacontrib.*" pattern): > > .. _`packagenames-contribnamespace`: > > Community contributions SHOULD use "${DIST}contrib.*" pattern > ================================================================ > > The idea is to use a standard pattern to store community contributions > for any > product or framework. > > It is the simplest way to `Organize community contributions`_: the > obvious way > to go is "${DIST}contrib", no ambiguity. > > As an example: > > * you are the author of "pyranha" project. You own the "pyranha" > namespace. > * a third-party developer wants to publish a "giantteeth" project > related to > your "pyranha" project. He can publish it as > "pyranhacontrib.giantteeth". > > .. note:: > > Why ``${DIST}contrib.*`` pattern? > > * ``${DIST}c.*`` is not explicit enough. As examples, "zc" belongs to > "Zope Corporation" whereas "z3c" belongs to "Zope 3 community". > > * ``${DIST}community`` is too long. > > * ``${DIST}community`` conflicts with existing namespaces such as > "iccommunity" or "PyCommunity". > > * ``${DIST}.contrib`` is inside ${DIST} namespace, i.e. it is owned by > ${DIST} authors. It breaks the `Top level namespace relates to code > ownership`_. > > * ``${DIST}.contrib.*`` breaks the `Avoid deep nesting`_ rule. > > * names where ``${DIST}`` doesn't appear are not explicit enough, i.e. > nobody can guess they are related to ``${DIST}``. > > * ``{$DIST}contrib.*`` may conflict with existing ``sphinxcontrib-*`` > packages. But ``sphinxcontrib-*`` is actually about Sphinx > contrib, so > this is not a real conflict... In fact, the "contrib" suffix was > inspired > by "sphinxcontrib". > > > ******* > Recipes > ******* > > How to avoid duplicate names > ============================ > > Before you choose a distribution name, make sure it hasn't already been > registered in the following locations: > > * `PyPI`_ > * Popular code repositories such as: > > * `Github`_ > * `Bitbucket`_ > * `Gitorious`_ > > * `djangopackages.com`_ > > .. note:: A web service would be welcome for this! > > Also make sure the package name hasn't already been registered: > > * in the `Python Standard Library`_, > * in the locations where you checked for distribution name availability. > > .. _`packagenames-rename`: > > Renaming howto > ============== > > Renaming a project is possible, but keep in mind that it will cause some > confusions. So, pay particular attention to README and documentation, > so that > users understand what happened. > > #. First of all, **do not remove legacy distribution from PyPI**. > Because some > users may be using it. > > #. Copy the legacy project, then change names (project, distribution and > package/module). Pay attention to, at least: > > * packaging files, > * folder name that contains source files, > * documentation, including README, > * import statements in code. > > #. Assign ``Obsoletes-Dist`` metadata to new distribution in setup.cfg > file. > See `PEP 345 about Obsolete-Dist`_ and :ref:`setup.cfg specification > `. > > #. Release the renamed distribution as a new version, then publish it. > > #. Edit legacy distribution: > > * add dependency to new distribution, > * drop everything except packaging stuff, > * add the ``Development Status :: 7 - Inactive`` classifier in > setup script, > * publish a new release. > > So, users of the legacy package: > > * can continue using the legacy distribution at a deprecated version, > * can upgrade to last version of legacy distribution, which is empty, ... > * ... and automatically download new distribution as a dependency of > the legacy > one. > > Users who discover the legacy distribution see it is inactive. > > > ********** > References > ********** > > .. target-notes:: > > .. _`Martin Aspeli's article about names`: > > http://www.martinaspeli.net/articles/the-naming-of-things-package-names-and-namespaces > .. _`PEP 1`: http://www.python.org/dev/peps/pep-0001/ > .. _`The Zen of Python`: http://www.python.org/dev/peps/pep-0020/ > .. _`PEP 8`: > http://www.python.org/dev/peps/pep-0008/#package-and-module-names > .. _`PEP 345`: http://www.python.org/dev/peps/pep-0345/ > .. _`PEP 420`: http://www.python.org/dev/peps/pep-0420/ > .. _`PEP 3108`: http://www.python.org/dev/peps/pep-3108 > .. _`The Hitchhiker's Guide to Packaging`: > > http://guide.python-distribute.org/specification.html#naming-specification > .. _`in development official packaging documentation`: > http://docs.python.org/dev/packaging/ > .. _`plone`: http://plone.org/community/develop > .. _`django`: http://djangoproject.com/ > .. _`pyramid`: http://pylonsproject.org > .. _`pypi`: http://pypi.python.org > .. _`django-debug-toolbar`: > https://github.com/django-debug-toolbar/django-debug-toolbar > .. _`gp.fileupload`: http://pypi.python.org/pypi/gp.fileupload/ > .. _`zest.releaser`: http://pypi.python.org/pypi/zest.releaser/ > .. _`sphinx`: http://sphinx.pocoo.org > .. _`Classifiers`: http://pypi.python.org/pypi?:action=list_classifiers > .. _`collective.recaptcha`: > http://pypi.python.org/pypi/collective.recaptcha/ > .. _`Python community`: http://www.python.org/community/ > .. _`pipeline`: http://pypi.python.org/pypi/pipeline/ > .. _`python-pipeline`: http://pypi.python.org/pypi/python-pipeline/ > .. _`django-pipeline`: http://pypi.python.org/pypi/django-pipeline/ > .. _`setuptools`: http://pypi.python.org/pypi/setuptools > .. _`distribute`: http://packages.python.org/distribute/ > .. _`Pillow`: http://pypi.python.org/pypi/Pillow/ > .. _`PIL`: http://pypi.python.org/pypi/PIL/ > .. _`Python Standard Library`: http://docs.python.org/library/index.html > .. _`github`: https://github.com > .. _`bitbucket`: https://bitbucket.org > .. _`gitorious`: https://gitorious.org/ > .. _`djangopackages.com`: http://djangopackages.com > .. _`PEP 345 about Obsolete-Dist`: > http://www.python.org/dev/peps/pep-0345/#obsoletes-dist-multiple-use > > > > From matteo at matteolandi.net Wed May 30 18:19:25 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Thu, 31 May 2012 00:19:25 +0200 Subject: Tkinter deadlock on graceful exit In-Reply-To: <20120527222125.GA22965@MARble> References: <20120527222125.GA22965@MARble> Message-ID: <20120530221925.GA12763@MARble> On May/28, Matteo Landi wrote: > Hi list, > recently I started to work on an application [1] which makes use of the Tkinter > module to handle interaction with the user. Simply put, the app is a text > widget displaying a file filtered by given criteria, with a handy feature that > the window is raised each time a new line is added to the widget. > > The application mainly consists of three threads: the first one, the file > processor, reads the file, filters the lines of interest, and pushes them into > a shared queue (henceforth `lines_queue`); the second one, the gui_updater, > pops elements from `lines_queue`, and schedule GUI updates using the > `after_idle` method of the Tkinter module; finally the last one, the worker > spawner, receives commands by the gui (by means of a shared queue, > `filters_queue`), and drives the application, terminating or spawning new > threads. > > For example, let's see what happens when you start the application, fill the > filter entry and press Enter button: > 1 the associated even handler is scheduled (we should be inside the Tkinter > mainloop thread), and the filter is pushed into `filters_queue`; > 2 the worker spawner receives the new filter, terminate a possibly running > working thread, and once done, create a new file processor; > 3 the file processor actually processes the file and fills the `lines_queue` > with the lines matching given filter; > 4 the gui updater schedules GUI updates as soon as items are pushed into > `lines_queue` > 5 Tkinter mainloop thread updates the gui when idle > > What happens when the main window is closed? Here is how I implemented the > graceful shutdown of the app: > 1 a quit event is scheduled and a _special_ message is pushed into both > `filter_queue` and `lines_queue` > 2 the gui updater threads receives the _special_ message, and terminates > 3 the worker spawner receives the message, terminates the working thread and > interrupts her execution. > 4 Tk.quit() is called after the quit event handler, and we finally quit the > mainloop > > Honestly speaking, I see no issues with the algorithm presented above; however, > if I close the window in the middle of updates of the text widget, the > applications hangs indefinitely. On the other hand, everything works as > expected if I close the app when the file processor, for example, is waiting for > new content to filter. > > I put some logging messages to analyze the deadlock (?!), and noticed that both > the worker spawner and the file processor are terminated correctly. The only > thread still active for some strange reasons, is the gui updater. > > Do you see anything wrong with the description presented above? Please say so, > because I can't figure it out! > > > Regards, > Matteo > > [1] https://bitbucket.org/iamFIREcracker/logfilter > > -- > http://www.matteolandi.net Bump -- http://www.matteolandi.net From mhrivnak at hrivnak.org Wed May 30 20:38:59 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Wed, 30 May 2012 20:38:59 -0400 Subject: Maintaining Multiple Copies of Python (Linux) In-Reply-To: References: Message-ID: http://www.virtualenv.org/ You can install multiple versions of the python interpreter in ubuntu without issue. You can use virtualenv to maintain different site packages for whatever purposes you need. Michael On Wed, May 30, 2012 at 4:38 PM, wrote: > Hi all, > > For various reasons, I would like to maintain multiple copies of python on my (Ubuntu 12.04) linux system. ?This is primarily for scientific software development; several modules require different configuration options than are installed on the 'vanilla' python included in the Ubuntu distribution, and I don't want to disturb that version in case something would interfere with the OS. > > I can compile python 2.7 and put it in /usr/local, but when I do that it can lead to confusion about what version is being run, particularly if my group members don't have their paths set correctly. ?Renaming the binaries alone is a partial solution, but that won't work for the library and include directories. > > Is there a way to configure the distribution at compile time to resolve the ambiguity? ?For example, could I specify an option to "configure" that appends a prefix to all of the created python binaries, etc.? ?In this case, it might create "my-python2.7" "my-python" and "my-idle" (etc.) in /usr/local/bin, along with storing libraries in /usr/local/lib/my-python2.7/. ?Thus, the my-python programs would be 100% independent from the OS python, and they would be independent from other local builds as well. > > I apologize if this answer is covered elsewhere; so far my google searches have not turned up anything. > > Thanks, > Nick > -- > http://mail.python.org/mailman/listinfo/python-list From ben+python at benfinney.id.au Wed May 30 20:55:33 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 31 May 2012 10:55:33 +1000 Subject: Maintaining Multiple Copies of Python (Linux) References: Message-ID: <87lik941a2.fsf@benfinney.id.au> nfitzkee at gmail.com writes: > For various reasons, I would like to maintain multiple copies of > python on my (Ubuntu 12.04) linux system. This is primarily for > scientific software development; several modules require different > configuration options than are installed on the 'vanilla' python > included in the Ubuntu distribution, and I don't want to disturb that > version in case something would interfere with the OS. The consensus solution for this is ?virtualenv? . It is so popular as a solution for the kinds of problems you describe that its functionality will come into core Python, as discussed in PEP 405 , for Python 3.3. Until you start using Python 3.3, you can install ?virtualenv? as a third-party package. -- \ ?The difference between religions and cults is determined by | `\ how much real estate is owned.? ?Frank Zappa | _o__) | Ben Finney From nfitzkee at gmail.com Wed May 30 21:41:55 2012 From: nfitzkee at gmail.com (Nicholas Fitzkee) Date: Wed, 30 May 2012 18:41:55 -0700 (PDT) Subject: Maintaining Multiple Copies of Python (Linux) In-Reply-To: <87lik941a2.fsf@benfinney.id.au> References: <87lik941a2.fsf@benfinney.id.au> Message-ID: On Wednesday, May 30, 2012 7:55:33 PM UTC-5, Ben Finney wrote: > The consensus solution for this is ?virtualenv? > . > > It is so popular as a solution for the kinds of problems you describe > that its functionality will come into core Python, as discussed in PEP > 405 , for Python 3.3. > > Until you start using Python 3.3, you can install ?virtualenv? as a > third-party package. Thanks, Ben. I took a look at this, and I'm a little confused. First, it doesn't seem all that different from "./configure --prefix=ENV" with the exception that you save a little space re-using some libraries. Second, it really doesn't solve my problem, because if ENV/bin/python is my PATH, it can still be confused with /usr/bin/python. What am I missing? Thanks again, Nick From tjreedy at udel.edu Wed May 30 21:42:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 May 2012 21:42:47 -0400 Subject: Tkinter deadlock on graceful exit In-Reply-To: <20120530221925.GA12763@MARble> References: <20120527222125.GA22965@MARble> <20120530221925.GA12763@MARble> Message-ID: On 5/30/2012 6:19 PM, Matteo Landi wrote: > On May/28, Matteo Landi wrote: >> Hi list, >> recently I started to work on an application [1] which makes use of the Tkinter >> module to handle interaction with the user. Simply put, the app is a text >> widget displaying a file filtered by given criteria, with a handy feature that >> the window is raised each time a new line is added to the widget. >> >> The application mainly consists of three threads: the first one, the file >> processor, reads the file, filters the lines of interest, and pushes them into >> a shared queue (henceforth `lines_queue`); the second one, the gui_updater, >> pops elements from `lines_queue`, and schedule GUI updates using the >> `after_idle` method of the Tkinter module; finally the last one, the worker >> spawner, receives commands by the gui (by means of a shared queue, >> `filters_queue`), and drives the application, terminating or spawning new >> threads. >> >> For example, let's see what happens when you start the application, fill the >> filter entry and press Enter button: >> 1 the associated even handler is scheduled (we should be inside the Tkinter >> mainloop thread), and the filter is pushed into `filters_queue`; >> 2 the worker spawner receives the new filter, terminate a possibly running >> working thread, and once done, create a new file processor; >> 3 the file processor actually processes the file and fills the `lines_queue` >> with the lines matching given filter; >> 4 the gui updater schedules GUI updates as soon as items are pushed into >> `lines_queue` >> 5 Tkinter mainloop thread updates the gui when idle >> >> What happens when the main window is closed? Here is how I implemented the >> graceful shutdown of the app: >> 1 a quit event is scheduled and a _special_ message is pushed into both >> `filter_queue` and `lines_queue` >> 2 the gui updater threads receives the _special_ message, and terminates >> 3 the worker spawner receives the message, terminates the working thread and >> interrupts her execution. >> 4 Tk.quit() is called after the quit event handler, and we finally quit the >> mainloop >> >> Honestly speaking, I see no issues with the algorithm presented above; however, >> if I close the window in the middle of updates of the text widget, the >> applications hangs indefinitely. On the other hand, everything works as >> expected if I close the app when the file processor, for example, is waiting for >> new content to filter. >> >> I put some logging messages to analyze the deadlock (?!), and noticed that both >> the worker spawner and the file processor are terminated correctly. The only >> thread still active for some strange reasons, is the gui updater. >> >> Do you see anything wrong with the description presented above? Please say so, >> because I can't figure it out! Since no-one else answered, I will ask some questions based on little tkinter experience, no thread experience, and a bit of python-list reading. 1. Are you only using tkinter in one thread? (It seems like so from the above)? 2. Is root.destroy getting called, as in 24.1.2.2. A Simple Hello World Program in the most recent docs? (I specify 'most recent' because that example has been recently revised because the previous version sometimes left tkinter hanging for one of the code paths, perhaps similar to what you describe. 3. Have you tried making the gui thread the master thread? (I somehow expect that the gui thread should be the last to shut down.) -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed May 30 21:51:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2012 01:51:52 GMT Subject: Object cleanup References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> Message-ID: <4fc6ceb8$0$29971$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 May 2012 16:56:21 +0000, John Gordon wrote: > In <6e534661-0823-4c42-8f60-3052e43b7942 at googlegroups.com> > "psaffrey at googlemail.com" writes: > >> How do I force the memory for these soup objects to be freed? > > Have you tried deleting them, using the "del" command? del doesn't actually delete objects, it deletes names. The object won't be deleted until the last name (or other reference) to the object is gone. There is no way to force Python to delete an object while it is still in use. Normally you don't notice the difference because most objects only have a single reference: py> class K: ... def __del__(self): ... print("Goodbye cruel world!") ... py> k = K() py> del k Goodbye cruel world! But see what happens when there are multiple references to the object: py> k = K() py> x = k py> y = [1, 2, x, 3] py> z = {'spam': y} py> del k py> del x py> del y py> del z Goodbye cruel world! The destructor doesn't get called into the last reference is gone. -- Steven From buzzard at urubu.freeserve.co.uk Wed May 30 21:57:40 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Thu, 31 May 2012 02:57:40 +0100 Subject: sqlite INSERT performance Message-ID: Hello, I have been attempting to speed up some code by using an sqlite database, but I'm not getting the performance gains I expected. The use case: I have text files containing data which may or may not include a header in the first line. Each line (other than the header) is a record, so all lines (when split on the relevant separator) should contain the same number of values. I need to generate new files in a very specific format; space separated, with header removed and integer codes substituted for the values in the parent file. e.g. If the first column (i.e. [line.strip('\r\n').split()[0] for line in file]) contained 15 distinct strings, then I would substitute the values in the parent file with integers from 0 to 14 in the new file. The new file would contain a non-empty subset of the 'columns' in the original file, and might be conditioned on particular values of other columns. My first effort read the parent file and generated a similar file containing integer codes. New files were generated by iterating over the lines of the file containing integer codes, splitting them, doing the required selection and conditioning via list comprehensions, joining the resultant lists, and writing to a new file. My test file has 67 columns and over a million records, and just creating the file of integers took a few minutes. (I also need to check for empty lines and skip them, and check for records of incorrect length.) I have partially implemented an alternative approach where I write the data to an sqlite database. The idea is that I will add extra columns for the integer codes and insert the integer codes only when required for a new file. But I've been immediately hit with the cost of inserting the data into the database. It takes around 80 seconds (compared to the 35 seconds needed to parse the original file and skip empty lines and check the record lengths). I have tried iterating over the records (lists of strings generated by csv.reader) and inserting each in turn. I have also tried executemany() passing the csv.reader as the second argument. I have also tried executing "PRAGMA synchronous=OFF". It still takes around 80 seconds. I'm a bit rusty with SQL, so I'd appreciate any advice on how to speed this up. I seem to remember (using MySQL years ago) that there was a way of dumping data in a text file to a table very quickly. If I could do this and do my data integrity checks afterwards, then that would be great. (Dumping data efficiently to a text file from an sqlite table would also be handy for generating my new files.) Alternatively, if I could substantially speed up the inserts then that would be great. Any advice appreciated. TIA. Duncan From steve+comp.lang.python at pearwood.info Wed May 30 22:06:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2012 02:06:11 GMT Subject: issubclass(C, Mapping) not behaving as expected References: <5f4d2a58-bb21-45b2-8e90-ff24cbfecf60@googlegroups.com> Message-ID: <4fc6d213$0$29971$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 May 2012 00:55:00 -0700, anntzer.lee wrote: > from collections import * > class C(object): > def __iter__(self): pass > def __contains__(self, i): pass > def __len__(self): pass > def __getitem__(self, i): pass > > issubclass(C, Mapping) => False > [issubclass(C, cls) for cls in Mapping.__mro__] => [False, True, True, > True, True] i.e. C does implement Sized, Iterable and Container. > > I would have expected that just as issubclass(C, Sized) checks for the > presence of a "__len__" method, issubclass(C, Mapping) would check for > the presence of the three methods required by each immediate superclass? What makes you think it doesn't? Perhaps it does, but there are other requirements for Mapping that are not being satisfied. I must admit that the documentation for collections and in particular for Mapping and MutableMapping are a bit unclear to me. But have you tried registering your class as a Mapping explicitly? -- Steven From ben+python at benfinney.id.au Wed May 30 23:04:45 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 31 May 2012 13:04:45 +1000 Subject: Object cleanup References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> <4fc6ceb8$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87haux3vaq.fsf@benfinney.id.au> Steven D'Aprano writes: > The destructor doesn't get called into the last reference is gone. And it's important to note that the destructor doesn't get called *immediately* that happens; rather, the destructor will be called *some time after* the last reference to the object is gone. In short: you can't force Python to invoke the destructor at any particular time, and hence your code shouldn't assume that it will happen at any particular time. -- \ ?Timid men prefer the calm of despotism to the boisterous sea | `\ of liberty.? ?Thomas Jefferson | _o__) | Ben Finney From ben+python at benfinney.id.au Wed May 30 23:06:32 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 31 May 2012 13:06:32 +1000 Subject: Maintaining Multiple Copies of Python (Linux) References: <87lik941a2.fsf@benfinney.id.au> Message-ID: <87d35l3v7r.fsf@benfinney.id.au> Nicholas Fitzkee writes: > I took a look at this, and I'm a little confused. You and me both. I think ?virtualenv? is solving the wrong problem, but it appears to be the best answer so far to the need you described. > What am I missing? You'll have to get an answer for that from someone who actually needs and uses ?virtualenv?. -- \ ?I went to a general store. They wouldn't let me buy anything | `\ specifically.? ?Steven Wright | _o__) | Ben Finney From nagle at animats.com Thu May 31 01:15:25 2012 From: nagle at animats.com (John Nagle) Date: Wed, 30 May 2012 22:15:25 -0700 Subject: sqlite INSERT performance In-Reply-To: References: Message-ID: On 5/30/2012 6:57 PM, duncan smith wrote: > Hello, > I have been attempting to speed up some code by using an sqlite > database, but I'm not getting the performance gains I expected. SQLite is a "lite" database. It's good for data that's read a lot and not changed much. It's good for small data files. It's so-so for large database loads. It's terrible for a heavy load of simultaneous updates from multiple processes. However, wrapping the inserts into a transaction with BEGIN and COMMIT may help. If you have 67 columns in a table, you may be approaching the problem incorrectly. John Nagle From wxjmfauth at gmail.com Thu May 31 01:43:10 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 30 May 2012 22:43:10 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> Message-ID: <91596bc0-b4e9-449a-9836-ecc3a4e9196c@d6g2000vbe.googlegroups.com> On 30 mai, 08:52, "ru... at yahoo.com" wrote: > In python2, "\u" escapes are processed in raw unicode > strings. ?That is, ur'\u3000' is a string of length 1 > consisting of the IDEOGRAPHIC SPACE unicode character. > > In python3, "\u" escapes are not processed in raw strings. > r'\u3000' is a string of length 6 consisting of a backslash, > 'u', '3' and three '0' characters. > > This breaks a lot of my code because in python 2 > ? ? ? re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] > but in python 3 (the result of running 2to3), > ? ? ? re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] > > I can remove the "r" prefix from the regex string but then > if I have other regex backslash symbols in it, I have to > double all the other backslashes -- the very thing that > the r-prefix was invented to avoid. > > Or I can leave the "r" prefix and replace something like > r'[ \u3000]' with r'[ ?]'. ?But that is confusing because > one can't distinguish between the space character and > the ideographic space character. ?It also a problem if a > reader of the code doesn't have a font that can display > the character. > > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) > > And is there no choice for me but to choose between the two > poor choices I mention above to deal with this problem? I suggest to take the problem differently. Python 3 succeeded to put order in the missmatch of the "coding of the characters" Python 2 was proposing. The 'IDEOGRAPHIC SPACE' and 'REVERSE SOLIDUS' (backslash) "characters" (in fact unicode code points) are just (normal) "characters". The backslash, used as an escaping command, keeps its function. Note the absence of r'...' >>> s = 'a\u3000?\u3000?' >>> s.split('\u3000') ['a', '?', '?'] >>> >>> import re >>> re.split('\u3000', s) ['a', '?', '?'] >>> s = 'a\\b\\c' >>> print(s) a\b\c >>> s.split('\\') ['a', 'b', 'c'] >>> re.split('\\\\', s) ['a', 'b', 'c'] >>> hex(ord('\\')) '0x5c' >>> re.split('\u005c\u005c', s) ['a', 'b', 'c'] jmf From ben+python at benfinney.id.au Thu May 31 01:45:21 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 31 May 2012 15:45:21 +1000 Subject: sqlite INSERT performance References: Message-ID: <878vg852fi.fsf@benfinney.id.au> John Nagle writes: > If you have 67 columns in a table, you may be approaching the > problem incorrectly. +1 SQL QotW, on basis of diplomacy. The OP may need to learn about database normalisation . -- \ ?Sane people have an appropriate perspective on the relative | `\ importance of foodstuffs and human beings. Crazy people can't | _o__) tell the difference.? ?Paul Z. Myers, 2010-04-18 | Ben Finney From no at no.no Thu May 31 03:57:08 2012 From: no at no.no (Qi) Date: Thu, 31 May 2012 15:57:08 +0800 Subject: How to suppress exception printing to console? Message-ID: Hi guys, I have an application that embedding Python into C++. When any exception occurred in C++ code, PyErr_SetString will be called to propagate the exception to Python. The problem is, some unit tests trigger exception on intention. So it's OK to have the exceptions. But Python will still print the exception to console, polluting the unit test output. My question is, is there any way to disable exception reporting to console from either C++ or Python code? Thanks -- WQ From mhagbeng at enib.fr Thu May 31 04:18:01 2012 From: mhagbeng at enib.fr (mhagbeng) Date: Thu, 31 May 2012 10:18:01 +0200 Subject: colorbar of image Message-ID: <41b2982a3a112f40aeb5695b29b6ab9d@enib.fr> that is my script from matplotlib import pyplot img = pyplot.imread('image.png') pyplot.imshow(img) pyplot.show() the problem is i want to display either colorbar associated to the image and image or just colorbar associated to the image when i download image.png.how can i do? tk's mireille From Mireille.Hagbe.Ngom at ifremer.fr Thu May 31 04:18:05 2012 From: Mireille.Hagbe.Ngom at ifremer.fr (Mireille.Hagbe.Ngom at ifremer.fr) Date: Thu, 31 May 2012 10:18:05 +0200 Subject: colorbar of image Message-ID: <20120531101805.17582v1uizxc49j1@vintra1mail.ifremer.fr> that is my script from matplotlib import pyplot img = pyplot.imread('image.png') pyplot.imshow(img) pyplot.show() the problem is i want to display either colorbar associated to the image and image or just colorbar associated to the image when i download image.png.how can i do? tk's mireille ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From gelonida at gmail.com Thu May 31 04:30:56 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 31 May 2012 10:30:56 +0200 Subject: How to suppress exception printing to console? In-Reply-To: References: Message-ID: On 05/31/2012 09:57 AM, Qi wrote: > Hi guys, > > I have an application that embedding Python into C++. > When any exception occurred in C++ code, PyErr_SetString will > be called to propagate the exception to Python. > > The problem is, some unit tests trigger exception on intention. > So it's OK to have the exceptions. But Python will still print > the exception to console, polluting the unit test output. > > My question is, is there any way to disable exception reporting > to console from either C++ or Python code? > Did you try to reassign sys.stderr to '/dev/null/ or another file? This works of course only if no other code wants to write to sys.stderr. From sdiwcconferences at gmail.com Thu May 31 04:47:48 2012 From: sdiwcconferences at gmail.com (sdiwc conferences) Date: Thu, 31 May 2012 01:47:48 -0700 (PDT) Subject: CFP - DEIS2012 - Czech Republic - SDIWC Message-ID: <5be9613a-5f83-41e5-8354-cd3bb4b0b4d6@f8g2000pbf.googlegroups.com> Dear Colleagues, We are inviting you to join and participate in the upcoming conference that will be held in Czech Republic. This will able to build connections among researchers in the field of digital applications. Please spend some time to overview the research topics. Below are the conference information. If you have any questions, you may contact this email: jackie at sdiwc.info We will be glad to see you there. Good day! ******************************************************************** The Second International Conference on Digital Enterprise and Information Systems (DEIS2012) VSB-Technical University of Ostrava, Ostrava, Czech Republic July 16-18, 2012 http://sdiwc.net/conferences/2012/deis2012/page.php?id=2 All the papers will be reviewed and the accepted papers in the conference will be submitted for potential inclusion in the digital library of SDIWC ===================================================================== The proposed conference on the above theme will be held at VSB- Technical University of Ostrava, Ostrava, Czech Republic, From July 16-18, 2012 which aims to enable researchers build connections between different digital applications. The conference welcomes papers on the following (but not limited to) research topics: - Digital Management products - Digital Economy - Digital Innovation Management - IT Management - Business Technology Intelligence - E-Business - Consumer Electronics - Digital Libraries - Digital Data Mining - Digital Enterprises - E-Commerce Technology - E-Commerce in developing countries - Global E-Commerce - Infrastructure for E-Commerce - E-Logistics - E-Government - E-Procurement - E-Services - Marketing on the Web - Barriers to E-Business Adoption - Cryptography for enabling E-Commerce - e-Commerce Strategy & Implementation - Internet payment systems - Business-oriented E-Commerce - Consumer-oriented E-Commerce - Web advertising and Web Publishing - Mobile Commerce - E-Communities - E-Business Applications and Software - Supply Chain Management & E-Fulfilment - Anti-cyberterrorism - XML-Based Languages - Soft Computing Techniques - Computational Intelligence - Mobile Networking, Mobility and Nomadicity - Ubiquitous Computing, Services and Applications - Forensics, Recognition Technologies and Applications - Fuzzy and Neural Network Systems - Signal Processing, Pattern Recognition and Applications - Distributed and Parallel Applications - User Interfaces,Visualization and Modeling - Mobile, Ad Hoc and Sensor Network Management - Web Services Architecture, Modeling and Design - Quality of Service, Scalability and Performance - Self-Organizing Networks and Networked Systems - Data Management in Mobile Peer-to-Peer Networks - Data Stream Processing in Mobile/Sensor Networks - Indexing and Query Processing for Moving Objects - User Interfaces and Usability Issues form Mobile Applications - Sensor Networks and Social Sensing - Embedded Systems and Software - Information Propagation on Social Networks - Resource and Knowledge Discovery Using Social Networks - Computer Crime Prevention and Detection - Confidentiality Protection - Critical Infrastructure Management - Critical Computing and Storage - Cryptography and Data Protection Researchers are encouraged to submit their work electronically. All papers will be fully refereed by a minimum of two specialized referees. Before final acceptance, all referees comments must be considered. Important Dates ============== Submission Date : June 15, 2012 Notification of Acceptance : June 22, 2012 Camera Ready Submission : July 5, 2012 Registration : July 5, 2012 Conference Dates : July 16-18, 2012 From oscar.j.benjamin at gmail.com Thu May 31 05:45:39 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 31 May 2012 10:45:39 +0100 Subject: Maintaining Multiple Copies of Python (Linux) In-Reply-To: References: <87lik941a2.fsf@benfinney.id.au> Message-ID: On 31 May 2012 02:41, Nicholas Fitzkee wrote: > On Wednesday, May 30, 2012 7:55:33 PM UTC-5, Ben Finney wrote: > > > The consensus solution for this is ?virtualenv? > > . > > > > It is so popular as a solution for the kinds of problems you describe > > that its functionality will come into core Python, as discussed in PEP > > 405 , for Python 3.3. > > > > Until you start using Python 3.3, you can install ?virtualenv? as a > > third-party package. > > Thanks, Ben. > > I took a look at this, and I'm a little confused. First, it doesn't seem > all that different from "./configure --prefix=ENV" with the exception that > you save a little space re-using some libraries. Second, it really doesn't > solve my problem, because if ENV/bin/python is my PATH, it can still be > confused with /usr/bin/python. What am I missing? > Don't place it on your PATH. I would just use the explicit path of the virtualenv binary so that I knew which one I was running. If you want to access it from a name such as my-python2.7 on PATH then create a symlink pointing to the virtualenv binary. Make sure the symlink is on your path i.e. in somewhere like /usr/bin if it is needed for all users or just ~\bin if it only needed for 1 user. e.g.: $ ln -s ENV/bin/python ~/bin/my-python2.7 > > Thanks again, > Nick > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From psaffrey at googlemail.com Thu May 31 06:57:46 2012 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Thu, 31 May 2012 03:57:46 -0700 (PDT) Subject: Object cleanup In-Reply-To: <4fc6ceb8$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> <4fc6ceb8$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4a5292fe-fd3a-4686-ab9d-3962b157dad9@googlegroups.com> Thanks for all the responses. It looks like none of the BeautifulSoup objects have __del__ methods, so I don't think that can be the problem. To answer your other question, guppy was the best match I came up with when looking for a memory profile for Python (or more specifically "Heapy"): http://guppy-pe.sourceforge.net/#Heapy On Thursday, May 31, 2012 2:51:52 AM UTC+1, Steven D'Aprano wrote: > > The destructor doesn't get called into the last reference is gone. > That makes sense, so now I need to track down why there are references to the object when I don't think there should be. Are there any systematic methods for doing this? Peter From alec.taylor6 at gmail.com Thu May 31 07:51:23 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 31 May 2012 04:51:23 -0700 (PDT) Subject: Templating library which generates HTML+JS for interfacing RESTfully? Message-ID: <3976b366-1b46-4384-898d-63a4bc31e371@googlegroups.com> Are there any templating libraries?e.g.: Jinja2, Django Template Engine, Mako &etc?which can be used to interface over REST, XMLRPC xor JSONRPC? My use-cases follow: 1. Generate a website, e.g.: to run from example.com (currently every templating language does this out of the box) 2. Generate the JS, HTML and CSS to put into a mobile phone app (PhoneGap) 3. Generate JavaScript "widget" code for pasting onto your site (see footnote [1] for popular examples) My current plan is to write the entire client using HTML, CSS (twitter-bootstrap responsive) and JavaScript?e.g.: with Backbone.js?allowing me to use that same client code for the website and PhoneGap clients. With that done, the widgets wouldn't be too difficult to extrapolate. However, this seems like a really complex way of doing things, especially when taking into consideration checks requiring login, forced redirects and more fine grained RBAC. Is there a templating language which can easily interface via REST (XML xor JSON), XMLRPC xor JSONRPC? Thanks for all information and suggestions, Alec Taylor [1] | The example JavaScript widgets: - DISQUS gives the following snippet: `Powered by Disqus` - Facebook gives the following snippet: `
` `
` - Twitter gives the following snippet: `` From oscar.j.benjamin at gmail.com Thu May 31 08:59:45 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 31 May 2012 13:59:45 +0100 Subject: Object cleanup In-Reply-To: <4a5292fe-fd3a-4686-ab9d-3962b157dad9@googlegroups.com> References: <6e534661-0823-4c42-8f60-3052e43b7942@googlegroups.com> <4fc6ceb8$0$29971$c3e8da3$5496439d@news.astraweb.com> <4a5292fe-fd3a-4686-ab9d-3962b157dad9@googlegroups.com> Message-ID: On 31 May 2012 11:57, psaffrey at googlemail.com wrote: > Thanks for all the responses. > > It looks like none of the BeautifulSoup objects have __del__ methods, so I > don't think that can be the problem. > > To answer your other question, guppy was the best match I came up with > when looking for a memory profile for Python (or more specifically "Heapy"): > > http://guppy-pe.sourceforge.net/#Heapy > > On Thursday, May 31, 2012 2:51:52 AM UTC+1, Steven D'Aprano wrote: > > > > The destructor doesn't get called into the last reference is gone. > > > > That makes sense, so now I need to track down why there are references to > the object when I don't think there should be. Are there any systematic > methods for doing this? > http://mg.pov.lt/blog/hunting-python-memleaks.html http://pypi.python.org/pypi/objgraph > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matteo at matteolandi.net Thu May 31 09:02:12 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Thu, 31 May 2012 15:02:12 +0200 Subject: Tkinter deadlock on graceful exit In-Reply-To: References: <20120527222125.GA22965@MARble> <20120530221925.GA12763@MARble> Message-ID: On Thu, May 31, 2012 at 3:42 AM, Terry Reedy wrote: > On 5/30/2012 6:19 PM, Matteo Landi wrote: >> >> On May/28, Matteo Landi wrote: >>> >>> Hi list, >>> recently I started to work on an application [1] which makes use of the >>> Tkinter >>> module to handle interaction with the user. ?Simply put, the app is a >>> text >>> widget displaying a file filtered by given criteria, with a handy feature >>> that >>> the window is raised each time a new line is added to the widget. >>> >>> The application mainly consists of three threads: ?the first one, the >>> file >>> processor, reads the file, filters the lines of interest, and pushes them >>> into >>> a shared queue (henceforth `lines_queue`); ?the second one, the >>> gui_updater, >>> pops elements from `lines_queue`, and schedule GUI updates using the >>> `after_idle` method of the Tkinter module; ?finally the last one, the >>> worker >>> spawner, receives commands by the gui (by means of a shared queue, >>> `filters_queue`), and drives the application, terminating or spawning new >>> threads. >>> >>> For example, let's see what happens when you start the application, fill >>> the >>> filter entry and press Enter button: >>> 1 the associated even handler is scheduled (we should be inside the >>> Tkinter >>> ? mainloop thread), and the filter is pushed into `filters_queue`; >>> 2 the worker spawner receives the new filter, terminate a possibly >>> running >>> ? working thread, and once done, create a new file processor; >>> 3 the file processor actually processes the file and fills the >>> `lines_queue` >>> ? with the lines matching given filter; >>> 4 the gui updater schedules GUI updates as soon as items are pushed into >>> ? `lines_queue` >>> 5 Tkinter mainloop thread updates the gui when idle >>> >>> What happens when the main window is closed? ?Here is how I implemented >>> the >>> graceful shutdown of the app: >>> 1 a quit event is scheduled and a _special_ message is pushed into both >>> ? `filter_queue` and `lines_queue` >>> 2 the gui updater threads receives the _special_ message, and terminates >>> 3 the worker spawner receives the message, terminates the working thread >>> and >>> ? interrupts her execution. >>> 4 Tk.quit() is called after the quit event handler, and we finally quit >>> the >>> ? mainloop >>> >>> Honestly speaking, I see no issues with the algorithm presented above; >>> ?however, >>> if I close the window in the middle of updates of the text widget, the >>> applications hangs indefinitely. ?On the other hand, everything works as >>> expected if I close the app when the file processor, for example, is >>> waiting for >>> new content to filter. >>> >>> I put some logging messages to analyze the deadlock (?!), and noticed >>> that both >>> the worker spawner and the file processor are terminated correctly. ?The >>> only >>> thread still active for some strange reasons, is the gui updater. >>> >>> Do you see anything wrong with the description presented above? ?Please >>> say so, >>> because I can't figure it out! > > > Since no-one else answered, I will ask some questions based on little > tkinter experience, no thread experience, and a bit of python-list reading. > > 1. Are you only using tkinter in one thread? (It seems like so from the > above)? Yes, provided that `after_idle` queues a job for the gui thread > > 2. Is root.destroy getting called, as in 24.1.2.2. A Simple Hello World > Program in the most recent docs? (I specify 'most recent' because that > example has been recently revised because the previous version sometimes > left tkinter hanging for one of the code paths, perhaps similar to what you > describe. No, I'm not calling the destroy method of the main window but, why that only happens while doing gui updates? > > 3. Have you tried making the gui thread the master thread? (I somehow expect > that the gui thread should be the last to shut down.) No but, same question as above. I'm not home right now, so I will try those solutions as soon as possible. Thanks. Cheers, Matteo > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://www.matteolandi.net/ From steve+comp.lang.python at pearwood.info Thu May 31 09:31:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 May 2012 13:31:53 GMT Subject: How to suppress exception printing to console? References: Message-ID: <4fc772c9$0$29971$c3e8da3$5496439d@news.astraweb.com> On Thu, 31 May 2012 15:57:08 +0800, Qi wrote: > Hi guys, > > I have an application that embedding Python into C++. When any exception > occurred in C++ code, PyErr_SetString will be called to propagate the > exception to Python. > > The problem is, some unit tests trigger exception on intention. I'm sorry, I don't understand what you mean by "on intention". > So it's > OK to have the exceptions. But Python will still print the exception to > console, polluting the unit test output. Are you using the Python unittest module, or C++ unit tests? Python's unittest catches and suppresses exceptions, so it should not be printing exceptions except as part of the normal unittest output. > My question is, is there any way to disable exception reporting to > console from either C++ or Python code? If your unit tests are raising exceptions, your tests are broken. They should either raise expected exceptions, in which case the exception is a passing test, or they are failing tests, or they are bugs in your test code. Fix the failing tests and the bugs in the test code, don't hide them. -- Steven From no at no.com Thu May 31 09:45:37 2012 From: no at no.com (Qi) Date: Thu, 31 May 2012 21:45:37 +0800 Subject: How to suppress exception printing to console? References: <4fc772c9$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-5-31 21:31, Steven D'Aprano wrote: >> The problem is, some unit tests trigger exception on intention. > > I'm sorry, I don't understand what you mean by "on intention". I mean the exception is expected. The test will only pass if the embedded Python code raise certain exception. > Are you using the Python unittest module, or C++ unit tests? > > Python's unittest catches and suppresses exceptions, so it should not be > printing exceptions except as part of the normal unittest output. I use a C++ unit test framework. >> My question is, is there any way to disable exception reporting to >> console from either C++ or Python code? > > If your unit tests are raising exceptions, your tests are broken. They > should either raise expected exceptions, in which case the exception is a > passing test, or they are failing tests, or they are bugs in your test > code. Fix the failing tests and the bugs in the test code, don't hide > them. No, I'm not hiding the exception. I'm trying to hide the exception report text because it's not necessary since the exception is expected. -- WQ From ulrich.eckhardt at dominolaser.com Thu May 31 11:01:29 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 31 May 2012 17:01:29 +0200 Subject: How to suppress exception printing to console? In-Reply-To: References: Message-ID: Am 31.05.2012 09:57, schrieb Qi: > I have an application that embedding Python into C++. > When any exception occurred in C++ code, PyErr_SetString will > be called to propagate the exception to Python. The first sentence is clear. The second sentence rather sounds as if you were implementing a Python module in C++. This is the opposite to embedding Python in C++, it's rather embedding C++ in Python. Or is it a C++ function called by Python which in turn was embedded by C++? > The problem is, some unit tests trigger exception on intention. > So it's OK to have the exceptions. But Python will still print > the exception to console, polluting the unit test output. I can only guess what you are doing, maybe you should provide a simple piece of code (or, rather, one C++ piece and a Python piece) that demonstrates the issue. What I could imagine is that the Python interpreter shuts down with something it considers an unhandled exception, which it then prints to stdout before exiting. When embedding, that shouldn't happen from just calling a Python function in a loaded script, those should just make the error available to the C++ side via PyErr functions etc. > My question is, is there any way to disable exception reporting > to console from either C++ or Python code? What I found useful when embedding was that I could assign to sys.stdout in order to redirect the output. In my case, the target was a window and not a console. I'd consider that a workaround though. I really suspect that Python considers the error unhandled and therefore dumps the info to stdout. Good luck! Uli From shahmed at sfwmd.gov Thu May 31 11:02:16 2012 From: shahmed at sfwmd.gov (Ahmed, Shakir) Date: Thu, 31 May 2012 15:02:16 +0000 Subject: reading txt file In-Reply-To: References: <4fc772c9$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <554ED400F994BF43AD3E6ED0328200BA0A690928@whqembx03p.ad.sfwmd.gov> HI: I am trying to read a txt file and dump the columns in an access database table. But getting problem: >>> Unhandled exception while debugging... Traceback (most recent call last): File "C:\WindDuration\Reading_test.py", line 14, in my_length_1 = nmAddrList[1] IndexError: list index out of range Getting error when it is reading to second line. The txt file is attached here and I need only 2,8,11,14,15 columns to dump in the table. Any help is highly appreciated. Thanks sa We value your opinion. Please take a few minutes to share your comments on the service you received from the District by clicking on this link. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test.txt URL: From buzzard at urubu.freeserve.co.uk Thu May 31 11:25:10 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Thu, 31 May 2012 16:25:10 +0100 Subject: sqlite INSERT performance In-Reply-To: References: Message-ID: On 31/05/12 06:15, John Nagle wrote: > On 5/30/2012 6:57 PM, duncan smith wrote: >> Hello, >> I have been attempting to speed up some code by using an sqlite >> database, but I'm not getting the performance gains I expected. > > SQLite is a "lite" database. It's good for data that's read a > lot and not changed much. It's good for small data files. It's > so-so for large database loads. It's terrible for a heavy load of > simultaneous updates from multiple processes. > Once the table is created the data will not be changed at all. Corresponding integer codes will have to be generated for columns. (I want to do this lazily because some columns might never be needed for output files, and processing all columns was relatively expensive for my initial solution.) After that it's a series of 'SELECT a, b, ... FROM table WHERE f="g" ORDER by a, b, ...' style queries dumped to space separated text files. > However, wrapping the inserts into a transaction with BEGIN > and COMMIT may help. > Unfortunately there's no discernible difference. > If you have 67 columns in a table, you may be approaching the > problem incorrectly. > Quite possibly. I have defined start and end points. The data are contained in text files. I need to do the mapping to integer codes and generate output files for subsets of variables conditional on the levels of other variables. (I was doing the subsequent sorting separately, but if I'm using SQL I guess I might as well include that in the query.) The output files are inputs for other (C++) code that I have no control over. Any approach that doesn't consume large amounts of memory will do. Cheers. Duncan From joncle at googlemail.com Thu May 31 12:06:49 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 31 May 2012 09:06:49 -0700 (PDT) Subject: sqlite INSERT performance In-Reply-To: References: Message-ID: <288b0a8f-607a-4845-9ec1-009a571d6138@googlegroups.com> On Thursday, 31 May 2012 16:25:10 UTC+1, duncan smith wrote: > On 31/05/12 06:15, John Nagle wrote: > > On 5/30/2012 6:57 PM, duncan smith wrote: > >> Hello, > >> I have been attempting to speed up some code by using an sqlite > >> database, but I'm not getting the performance gains I expected. > > > > SQLite is a "lite" database. It's good for data that's read a > > lot and not changed much. It's good for small data files. It's > > so-so for large database loads. It's terrible for a heavy load of > > simultaneous updates from multiple processes. > > > > Once the table is created the data will not be changed at all. > Corresponding integer codes will have to be generated for columns. (I > want to do this lazily because some columns might never be needed for > output files, and processing all columns was relatively expensive for my > initial solution.) After that it's a series of 'SELECT a, b, ... FROM > table WHERE f="g" ORDER by a, b, ...' style queries dumped to space > separated text files. > > > However, wrapping the inserts into a transaction with BEGIN > > and COMMIT may help. > > > > Unfortunately there's no discernible difference. > > > If you have 67 columns in a table, you may be approaching the > > problem incorrectly. > > > > Quite possibly. I have defined start and end points. The data are > contained in text files. I need to do the mapping to integer codes and > generate output files for subsets of variables conditional on the levels > of other variables. (I was doing the subsequent sorting separately, but > if I'm using SQL I guess I might as well include that in the query.) The > output files are inputs for other (C++) code that I have no control over. > > Any approach that doesn't consume large amounts of memory will do. Cheers. > > Duncan It might be worth checking out https://sdm.lbl.gov/fastbit/ which has Python bindings (nb: the library itself takes a while to compile), but I'm not I00% sure it would meet all your requirements. Jon From python at mrabarnett.plus.com Thu May 31 12:51:21 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 31 May 2012 17:51:21 +0100 Subject: reading txt file In-Reply-To: <554ED400F994BF43AD3E6ED0328200BA0A690928@whqembx03p.ad.sfwmd.gov> References: <4fc772c9$0$29971$c3e8da3$5496439d@news.astraweb.com> <554ED400F994BF43AD3E6ED0328200BA0A690928@whqembx03p.ad.sfwmd.gov> Message-ID: <4FC7A189.1080705@mrabarnett.plus.com> On 31/05/2012 16:02, Ahmed, Shakir wrote: > HI: > I am trying to read a txt file and dump the columns in an access database table. But getting problem: > >>>> Unhandled exception while debugging... > Traceback (most recent call last): > File "C:\WindDuration\Reading_test.py", line 14, in > my_length_1 = nmAddrList[1] > IndexError: list index out of range > > Getting error when it is reading to second line. > > The txt file is attached here and I need only 2,8,11,14,15 columns to dump in the table. > > > Any help is highly appreciated. > Most of the lines end with "\n" followed by "\r\n", so when you read those lines you get a line of data followed by a blank line. The simplest solution is just to skip blank lines. From buzzard at urubu.freeserve.co.uk Thu May 31 13:05:43 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Thu, 31 May 2012 18:05:43 +0100 Subject: sqlite INSERT performance In-Reply-To: <288b0a8f-607a-4845-9ec1-009a571d6138@googlegroups.com> References: <288b0a8f-607a-4845-9ec1-009a571d6138@googlegroups.com> Message-ID: On 31/05/12 17:06, Jon Clements wrote: > On Thursday, 31 May 2012 16:25:10 UTC+1, duncan smith wrote: >> On 31/05/12 06:15, John Nagle wrote: >>> On 5/30/2012 6:57 PM, duncan smith wrote: >>>> Hello, >>>> I have been attempting to speed up some code by using an sqlite >>>> database, but I'm not getting the performance gains I expected. >>> >>> SQLite is a "lite" database. It's good for data that's read a >>> lot and not changed much. It's good for small data files. It's >>> so-so for large database loads. It's terrible for a heavy load of >>> simultaneous updates from multiple processes. >>> >> >> Once the table is created the data will not be changed at all. >> Corresponding integer codes will have to be generated for columns. (I >> want to do this lazily because some columns might never be needed for >> output files, and processing all columns was relatively expensive for my >> initial solution.) After that it's a series of 'SELECT a, b, ... FROM >> table WHERE f="g" ORDER by a, b, ...' style queries dumped to space >> separated text files. >> >>> However, wrapping the inserts into a transaction with BEGIN >>> and COMMIT may help. >>> >> >> Unfortunately there's no discernible difference. >> >>> If you have 67 columns in a table, you may be approaching the >>> problem incorrectly. >>> >> >> Quite possibly. I have defined start and end points. The data are >> contained in text files. I need to do the mapping to integer codes and >> generate output files for subsets of variables conditional on the levels >> of other variables. (I was doing the subsequent sorting separately, but >> if I'm using SQL I guess I might as well include that in the query.) The >> output files are inputs for other (C++) code that I have no control over. >> >> Any approach that doesn't consume large amounts of memory will do. Cheers. >> >> Duncan > > It might be worth checking out https://sdm.lbl.gov/fastbit/ which has Python bindings (nb: the library itself takes a while to compile), but I'm not I00% sure it would meet all your requirements. > > Jon Interesting. It might actually be more useful for the types of query performed by the C++ part of the application. I tried something based on bitwise operations on integers but couldn't quite match the performance of the recursive algorithm implemented (by others) in C++. Cheers. Duncan From tjreedy at udel.edu Thu May 31 13:23:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 31 May 2012 13:23:08 -0400 Subject: reading txt file In-Reply-To: <554ED400F994BF43AD3E6ED0328200BA0A690928@whqembx03p.ad.sfwmd.gov> References: <4fc772c9$0$29971$c3e8da3$5496439d@news.astraweb.com> <554ED400F994BF43AD3E6ED0328200BA0A690928@whqembx03p.ad.sfwmd.gov> Message-ID: On 5/31/2012 11:02 AM, Ahmed, Shakir wrote: When you want to start a new thread, make sure you start a new thread and do not post as a response to another thread. This will get lost as a response to 'How to suppress ...'. Is this a homework, hobby, or work exercise? > I am trying to read a txt file and dump the columns in an access database table. It is good that you posted the traceback. Some beginners omit that. But we usually also need to see the code that caused the problem -- but just that code. It is best if one can produce a minimal file that exhibits the problem. >>>> Unhandled exception while debugging... > Traceback (most recent call last): > File "C:\WindDuration\Reading_test.py", line 14, in > my_length_1 = nmAddrList[1] > IndexError: list index out of range > > Getting error when it is reading to second line. > The txt file is attached here Attachments do not work well on lists. They get omitted from responses. First *3* lines, copy and pasted: FL Dade Existing Existing Existing 10/24 12E [05] 10/24 14E [07] 10/24 16E [09] 88kt 10/24 07 FL Monroe Existing Existing Existing 10/24 11E [04] 10/24 12E [05] 10/24 15E [08] 94kt 10/24 07 I suspect your problem is with the blank line(s) between data lines, but I cannot tell for sure without your code. In any case, you have to skip them. FL Desoto Existing Existing Existing 10/24 09E [02] 10/24 12E [05] 10/24 15E [08] 67kt 10/24 08 FL Sarasota Existing Existing 10/24 11E [04] 10/24 15E [08] 59kt 10/24 07 This data file is column-oriented and has missing values indicated by blank space. So you cannot separate fields with the .split method. Instead, you have to slice out each field with a pair of indexes. To facilitate column counting, I would put a temporary line like 01234567890123456789012345678901234567890123456789... at the top. (I also still have a special 'document rule' meant for this purpose. It is marked in 1/10 inch increments to count characters printed in a fixed 10 chars per inch font such as Courier.) There is also text at the bottom after a separator line ------------------------------ ... so you will have to catch that and stop there. -- Terry Jan Reedy From awilliam at whitemice.org Thu May 31 15:21:17 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 31 May 2012 15:21:17 -0400 Subject: cmd2, an extenstion of cmd that parses its argument list In-Reply-To: <20362952.735.1335467772849.JavaMail.geo-discussion-forums@pbcuc10> References: <20362952.735.1335467772849.JavaMail.geo-discussion-forums@pbcuc10> Message-ID: <1338492077.3128.27.camel@linux-nysu.site> On Thu, 2012-04-26 at 12:16 -0700, anntzer.lee at gmail.com wrote: > On Sunday, March 18, 2012 10:12:24 PM UTC-7, anntz... at gmail.com wrote: > > Dear all, > > I would like to announce the first public release of cmd2, an extension of the standard library's cmd with argument parsing, here: https://github.com/anntzer/cmd2. > Due to an already existing Cmd2 on PyPI, I have renamed the project to parsedcmd, which is also a better description of what the module does. > https://github.com/anntzer/parsedcmd > > Cmd2 is an extension built around the excellent cmd module of the standard > > library. Cmd allows one to build simple custom shells using ``do_*`` methods, > > taking care in particular of the REPL loop and the interactive help. However, > > no facility is given for parsing the argument line (do_* methods are passed the > > rest of the line as a single string argument). > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > > function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing > > the dispatcher to parse the argument list for them. This is much the same functionality added to Cmd by Cmd2. Perhaps you could collaborate with Cmd2's author and merge your two extensions. -------------- 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 awilliam at whitemice.org Thu May 31 15:42:19 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 31 May 2012 15:42:19 -0400 Subject: cmd2, an extenstion of cmd that parses its argument list In-Reply-To: <1338492077.3128.27.camel@linux-nysu.site> References: <20362952.735.1335467772849.JavaMail.geo-discussion-forums@pbcuc10> <1338492077.3128.27.camel@linux-nysu.site> Message-ID: <1338493339.3128.29.camel@linux-nysu.site> On Thu, 2012-05-31 at 15:21 -0400, Adam Tauno Williams wrote: > On Thu, 2012-04-26 at 12:16 -0700, anntzer.lee at gmail.com wrote: > > On Sunday, March 18, 2012 10:12:24 PM UTC-7, anntz... at gmail.com wrote: > > > Dear all, > > > I would like to announce the first public release of cmd2, an extension of the standard library's cmd with argument parsing, here: https://github.com/anntzer/cmd2. > > Due to an already existing Cmd2 on PyPI, I have renamed the project to parsedcmd, which is also a better description of what the module does. > > https://github.com/anntzer/parsedcmd > > > Cmd2 is an extension built around the excellent cmd module of the standard > > > library. Cmd allows one to build simple custom shells using ``do_*`` methods, > > > taking care in particular of the REPL loop and the interactive help. However, > > > no facility is given for parsing the argument line (do_* methods are passed the > > > rest of the line as a single string argument). > > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > > > function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing > > > the dispatcher to parse the argument list for them. > This is much the same functionality added to Cmd by Cmd2. > Perhaps you could collaborate with Cmd2's author and merge your two > extensions. Since you split() the string in argument parsing document values cannot contain whitespace; such as -file="Yo Yo Ma Ma.txt". Perhaps using shlex() or some other means to initially break-up the strings would be a better option? -------------- 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 anntzer.lee at gmail.com Thu May 31 15:53:54 2012 From: anntzer.lee at gmail.com (Antony Lee) Date: Thu, 31 May 2012 12:53:54 -0700 Subject: cmd2, an extenstion of cmd that parses its argument list In-Reply-To: <1338493339.3128.29.camel@linux-nysu.site> References: <20362952.735.1335467772849.JavaMail.geo-discussion-forums@pbcuc10> <1338492077.3128.27.camel@linux-nysu.site> <1338493339.3128.29.camel@linux-nysu.site> Message-ID: <20120531195354.GA30094@gmail.com> I am already using shlex.split() (this is a customizable hook). On Thu, May 31, 2012 at 03:42:19PM -0400, Adam Tauno Williams wrote: > On Thu, 2012-05-31 at 15:21 -0400, Adam Tauno Williams wrote: > > On Thu, 2012-04-26 at 12:16 -0700, anntzer.lee at gmail.com wrote: > > > On Sunday, March 18, 2012 10:12:24 PM UTC-7, anntz... at gmail.com wrote: > > > > Dear all, > > > > I would like to announce the first public release of cmd2, an extension of the standard library's cmd with argument parsing, here: https://github.com/anntzer/cmd2. > > > Due to an already existing Cmd2 on PyPI, I have renamed the project to parsedcmd, which is also a better description of what the module does. > > > https://github.com/anntzer/parsedcmd > > > > Cmd2 is an extension built around the excellent cmd module of the standard > > > > library. Cmd allows one to build simple custom shells using ``do_*`` methods, > > > > taking care in particular of the REPL loop and the interactive help. However, > > > > no facility is given for parsing the argument line (do_* methods are passed the > > > > rest of the line as a single string argument). > > > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > > > > function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing > > > > the dispatcher to parse the argument list for them. > > This is much the same functionality added to Cmd by Cmd2. > > Perhaps you could collaborate with Cmd2's author and merge your two > > extensions. > > Since you split() the string in argument parsing document values cannot > contain whitespace; such as -file="Yo Yo Ma Ma.txt". Perhaps using > shlex() or some other means to initially break-up the strings would be a > better option? > From rurpy at yahoo.com Thu May 31 16:28:46 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 31 May 2012 13:28:46 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <8f2044b3-b334-42a9-91e5-7592d0eec12b@cu1g2000vbb.googlegroups.com> Message-ID: <40446368-36cc-4840-9e0e-70910a556b3d@d17g2000vbv.googlegroups.com> On 05/30/2012 09:07 AM, rurpy at yahoo.com wrote: > On 05/30/2012 05:54 AM, Thomas Rachel wrote: >> Am 30.05.2012 08:52 schrieb rurpy at yahoo.com: >> >>> This breaks a lot of my code because in python 2 >>> re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] >>> but in python 3 (the result of running 2to3), >>> re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] >>> >>> I can remove the "r" prefix from the regex string but then >>> if I have other regex backslash symbols in it, I have to >>> double all the other backslashes -- the very thing that >>> the r-prefix was invented to avoid. >>> >>> Or I can leave the "r" prefix and replace something like >>> r'[ \u3000]' with r'[ ?]'. But that is confusing because >>> one can't distinguish between the space character and >>> the ideographic space character. It also a problem if a >>> reader of the code doesn't have a font that can display >>> the character. >>> >>> Was there a reason for dropping the lexical processing of >>> \u escapes in strings in python3 (other than to add another >>> annoyance in a long list of python3 annoyances?) >> >> Probably it is more consequent. Alas, it makes the whole stuff >> incompatible to Py2. >> >> But if you think about it: why allow for \u if \r, \n etc. are >> disallowed as well? > > Maybe the blame is elsewhere then... If the re module > interprets (in a regex string) the 2-character string > consisting of r'\' followed by 'n' as a single newline > character, then why wasn't re changed for Python 3 to > interpret the 6-character string, r'\u3000' as a single > unicode character to correspond with Python's lexer no > longer doing that (as it did in Python 2)? > >>> And is there no choice for me but to choose between the two >>> poor choices I mention above to deal with this problem? >> >> There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, >> but should do the trick... > > I guess the "+"s could be left out allowing something > like, > > '[ \u3000]' r'\w+ \d{3}' > > but I'll have to try it a little; maybe just doubling > backslashes won't be much worse. I did that for years > in Perl and lived through it. Just for some closure, there are many places in my code that I had/have to track down and change. But the biggest problem so far is a lexer module that is structured as many dozens of little functions, each with a docstring that is a regex string. The only way I found change these and maintain sanity was to go through them and remove the "r" prefix from any strings that contain "\unnnn" literals, and then double any other backslashes in the string. Since these are docstrings, creating them with executable code was awkward, and using adjacent string concatenation led to a very confusing mix of string styles. Strings that used concatenation often had a single logical regex structure (eg a character set "[...]") split between two strings. The extra quote characters were as visually confusing as doubled backslashes in many cases. Strings with doubled backslashes, although harder to read were, were much easier to edit reliably and in their way, more regular. It does make this module look very Perlish though... :-) From georg at python.org Thu May 31 16:40:59 2012 From: georg at python.org (Georg Brandl) Date: Thu, 31 May 2012 22:40:59 +0200 Subject: [RELEASED] Python 3.3.0 alpha 4 Message-ID: <4FC7D75B.5080309@python.org> On behalf of the Python development team, I'm happy to announce the fourth alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) is based on importlib by default * The new "packaging" module (also known as distutils2, and released standalone under this name), implementing the new packaging formats and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From rosuav at gmail.com Thu May 31 17:10:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Jun 2012 07:10:54 +1000 Subject: python3 raw strings and \u escapes In-Reply-To: <40446368-36cc-4840-9e0e-70910a556b3d@d17g2000vbv.googlegroups.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <8f2044b3-b334-42a9-91e5-7592d0eec12b@cu1g2000vbb.googlegroups.com> <40446368-36cc-4840-9e0e-70910a556b3d@d17g2000vbv.googlegroups.com> Message-ID: On Fri, Jun 1, 2012 at 6:28 AM, rurpy at yahoo.com wrote: > ... a lexer module that is structured as many > dozens of little functions, each with a docstring that is > a regex string. This may be a good opportunity to take a step back and ask yourself: Why so many functions, each with a regular expression in its docstring? Chris Angelico From rurpy at yahoo.com Thu May 31 18:31:10 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 31 May 2012 15:31:10 -0700 (PDT) Subject: python3 raw strings and \u escapes References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <8f2044b3-b334-42a9-91e5-7592d0eec12b@cu1g2000vbb.googlegroups.com> Message-ID: On 05/31/2012 03:10 PM, Chris Angelico wrote: > On Fri, Jun 1, 2012 at 6:28 AM, rurpy at yahoo.com wrote: >> ... a lexer module that is structured as many >> dozens of little functions, each with a docstring that is >> a regex string. > > This may be a good opportunity to take a step back and ask yourself: > Why so many functions, each with a regular expression in its > docstring? Because that's the way David Beazley designed Ply? http://dabeaz.com/ply/ Personally, I think it's an abuse of docstrings but he never asked me for my opinion... From steveo at syslang.net Thu May 31 23:04:41 2012 From: steveo at syslang.net (Steven W. Orr) Date: Thu, 31 May 2012 23:04:41 -0400 Subject: How to suppress exception printing to console? In-Reply-To: References: Message-ID: <4FC83149.2040604@syslang.net> On 5/31/2012 3:57 AM, Qi wrote: > I have an application that embedding Python into C++. > When any exception occurred in C++ code, PyErr_SetString will > be called to propagate the exception to Python. > > The problem is, some unit tests trigger exception on intention. > So it's OK to have the exceptions. But Python will still print > the exception to console, polluting the unit test output. > > My question is, is there any way to disable exception reporting > to console from either C++ or Python code? How about a big hammer? try: main() except Exception: sys.exit(1) else: sys.exit(0) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From no at no.no Thu May 31 23:06:31 2012 From: no at no.no (Qi) Date: Fri, 01 Jun 2012 11:06:31 +0800 Subject: How to suppress exception printing to console? References: Message-ID: On 2012-5-31 23:01, Ulrich Eckhardt wrote: > Am 31.05.2012 09:57, schrieb Qi: > The first sentence is clear. The second sentence rather sounds as if you > were implementing a Python module in C++. This is the opposite to > embedding Python in C++, it's rather embedding C++ in Python. Or is it a > C++ function called by Python which in turn was embedded by C++? I think it's bidirectional. In C++ I use PyRun_SimpleString to run some Python code, then C++ code can get object from Python code, or call Python function. Also Python code can call C++ code. I think that's called "binding"? > I can only guess what you are doing, maybe you should provide a simple > piece of code (or, rather, one C++ piece and a Python piece) that > demonstrates the issue. What I could imagine is that the Python > interpreter shuts down with something it considers an unhandled > exception, which it then prints to stdout before exiting. When > embedding, that shouldn't happen from just calling a Python function in > a loaded script, those should just make the error available to the C++ > side via PyErr functions etc. PyRun_SimpleString("SomeCppFunc(1, 2)"); SomeCppFunc is C++ function bound to Python, and in SomeCppFunc it detects the parameter mismatch (such as it expects the first parameter to be a string), it throws an exception. Then the C++ binding code catches the exception, and call PyErr_SetString to propagate it to Python. Then Python will print the error message to console. What I want to do is to suppress the error message printing... > What I found useful when embedding was that I could assign to sys.stdout > in order to redirect the output. In my case, the target was a window and > not a console. I'd consider that a workaround though. I really suspect > that Python considers the error unhandled and therefore dumps the info > to stdout. Can I redirect sys.stdout in C++? Thanks -- WQ