From steve+comp.lang.python at pearwood.info Fri Jul 1 00:11:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 01 Jul 2011 14:11:06 +1000 Subject: Safely modify a file in place -- am I doing it right? References: <4e0b6383$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e0d48da$0$29980$c3e8da3$5496439d@news.astraweb.com> steve+comp.lang.python at pearwood.info wrote: > I have a script running under Python 2.5 that needs to modify files in > place. I want to do this with some level of assurance that I won't lose > data. E.g. this is not safe: > [snip] Thanks to all who replied, your comments were helpful. -- Steven From steve+comp.lang.python at pearwood.info Fri Jul 1 00:29:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 01 Jul 2011 14:29:35 +1000 Subject: Enhanced dir() function Message-ID: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> The dir() function is designed for interactive use, inspecting objects for the names of attributes and methods. Here is an enhanced version that allows you to pass a glob to filter the names you see: http://code.activestate.com/recipes/577774-enhancing-dir-with-globs/ E.g. instead of this: >>> dir(str) ['__add__', '__class__', ... snip 60+ other names ... 'upper', 'zfill'] you can easily filter the results to show only names that interest you, by passing a glob: >>> dir(str, '*split*') ['rsplit', 'split', 'splitlines'] Comments and improvements welcome. -- Steven From ptmcg at austin.rr.com Fri Jul 1 02:09:18 2011 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 30 Jun 2011 23:09:18 -0700 (PDT) Subject: ANN: pyparsing 1.5.6 released! Message-ID: <653d4abd-e1f0-4265-b0e3-d2c591a702bc@e35g2000yqc.googlegroups.com> After about 10 months, there is a new release of pyparsing, version 1.5.6. This release contains some small enhancements, some bugfixes, and some new examples. Most notably, this release includes the first public release of the Verilog parser. I have tired of restricting this parser for commercial use, and so I am distributing it under the same license as pyparsing, with the request that if you use it for commmercial use, please make a commensurate donation to your local Red Cross. Change summary: --------------- - Cleanup of parse action normalizing code, to be more version- tolerant, and robust in the face of future Python versions - much thanks to Raymond Hettinger for this rewrite! - Removal of exception cacheing, addressing a memory leak condition in Python 3. Thanks to Michael Droettboom and the Cape Town PUG for their analysis and work on this problem! - Fixed bug when using packrat parsing, where a previously parsed expression would duplicate subsequent tokens - reported by Frankie Ribery on stackoverflow, thanks! - Added 'ungroup' helper method, to address token grouping done implicitly by And expressions, even if only one expression in the And actually returns any text - also inspired by stackoverflow discussion with Frankie Ribery! - Fixed bug in srange, which accepted escaped hex characters of the form '\0x##', but should be '\x##'. Both forms will be supported for backwards compatibility. - Enhancement to countedArray, accepting an optional expression to be used for matching the leading integer count - proposed by Mathias on the pyparsing mailing list, good idea! - Added the Verilog parser to the provided set of examples, under the MIT license. While this frees up this parser for any use, if you find yourself using it in a commercial purpose, please consider making a charitable donation as described in the parser's header. - Added the excludeChars argument to the Word class, to simplify defining a word composed of all characters in a large range except for one or two. Suggested by JesterEE on the pyparsing wiki. - Added optional overlap parameter to scanString, to return overlapping matches found in the source text. - Updated oneOf internal regular expression generation, with improved parse time performance. - Slight performance improvement in transformString, removing empty strings from the list of string fragments built while scanning the source text, before calling ''.join. Especially useful when using transformString to strip out selected text. - Enhanced form of using the "expr('name')" style of results naming, in lieu of calling setResultsName. If name ends with an '*', then this is equivalent to expr.setResultsName('name',listAllMatches=True). - Fixed up internal list flattener to use iteration instead of recursion, to avoid stack overflow when transforming large files. - Added other new examples: . protobuf parser - parses Google's protobuf language . btpyparse - a BibTex parser contributed by Matthew Brett, with test suite test_bibparse.py (thanks, Matthew!) . groupUsingListAllMatches.py - demo using trailing '*' for results names Download pyparsing 1.5.6 at http://sourceforge.net/projects/pyparsing/, or use 'easy_install pyparsing'. You can also access pyparsing's epydoc documentation online at http://packages.python.org/pyparsing/. The pyparsing Wiki is at http://pyparsing.wikispaces.com. -- Paul ======================================== Pyparsing is a pure-Python class library for quickly developing recursive-descent parsers. Parser grammars are assembled directly in the calling Python code, using classes such as Literal, Word, OneOrMore, Optional, etc., combined with operators '+', '|', and '^' for And, MatchFirst, and Or. No separate code-generation or external files are required. Pyparsing can be used in many cases in place of regular expressions, with shorter learning curve and greater readability and maintainability. Pyparsing comes with a number of parsing examples, including: - "Hello, World!" (English, Korean, Greek, and Spanish(new)) - chemical formulas - Verilog parser - Google protobuf parser - time expression parser/evaluator - configuration file parser - web page URL extractor - 5-function arithmetic expression parser - subset of CORBA IDL - chess portable game notation - simple SQL parser - Mozilla calendar file parser - EBNF parser/compiler - Python value string parser (lists, dicts, tuples, with nesting) (safe alternative to eval) - HTML tag stripper - S-expression parser - macro substitution preprocessor From nad at acm.org Fri Jul 1 02:20:21 2011 From: nad at acm.org (Ned Deily) Date: Thu, 30 Jun 2011 23:20:21 -0700 Subject: treeviewcontrol in tkinter.ttk References: <4e0cad83$0$6583$9b4e6d93@newsspool3.arcor-online.net> Message-ID: In article <4e0cad83$0$6583$9b4e6d93 at newsspool3.arcor-online.net>, Wolfgang Meiners wrote: > when i type the following code under python3, version 3.2 using osx 10.6.8: [...] You might want to ask your question on the Tkinter list and/or possibly the Tcl Mac list. http://mail.python.org/mailman/listinfo/tkinter-discuss https://lists.sourceforge.net/lists/listinfo/tcl-mac -- Ned Deily, nad at acm.org From ulrich.eckhardt at dominolaser.com Fri Jul 1 02:50:56 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 01 Jul 2011 08:50:56 +0200 Subject: how to call a function for evry 10 secs References: Message-ID: Ulrich Eckhardt wrote: > I'll take this to the developers mailinglist and see if they > consider the behaviour a bug. Filed as bug #12459. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From daniil.re at gmail.com Fri Jul 1 03:03:39 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Fri, 1 Jul 2011 18:03:39 +1100 Subject: urllib, urlretrieve method, how to get headers? Message-ID: Hello, everyone! How can I get headers with urlretrieve? I want to send request and get headers with necessary information before I execute urlretrieve(). Or are there any alternatives for urlretrieve()? -- Regards, Daniil From __peter__ at web.de Fri Jul 1 03:26:41 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Jul 2011 09:26:41 +0200 Subject: Trying to chain processes together on a pipeline References: <4E096D3B.3080300@gmail.com> Message-ID: Andrew Berg wrote: > Okay, so I've refactored those except WindowsError blocks into calls to > a function and fixed the os.devnull bug, but I still can't get the > triple chain working. I added calls to ffmpeg_proc.stdout.close() and > sox_proc.stdout.close(), but I really am not sure where to put them. The > following code works if SoX isn't part of the chain (that is, if vol == > 1), but not otherwise (the Nero encoder says "truncation error" after it > finishes; the same error I get if omit the close() calls): I can't reproduce your setup, but I'd try using communicate() instead of wait() and close(). From clp2 at rebertia.com Fri Jul 1 03:30:44 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Jul 2011 00:30:44 -0700 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: On Fri, Jul 1, 2011 at 12:03 AM, ?????? ?????? wrote: > Hello, everyone! > > How can I get headers with urlretrieve? I want to send request and get > headers with necessary information before I execute urlretrieve(). Or > are there any alternatives for urlretrieve()? You can use regular urlopen(), get the headers using the .info() method of the resulting object, and do the file writing manually. Cheers, Chris -- http://rebertia.com From __peter__ at web.de Fri Jul 1 03:43:03 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Jul 2011 09:43:03 +0200 Subject: urllib, urlretrieve method, how to get headers? References: Message-ID: ?????? ?????? wrote: > How can I get headers with urlretrieve? I want to send request and get > headers with necessary information before I execute urlretrieve(). Or > are there any alternatives for urlretrieve()? It's easy to do it manually: >>> import urllib2 Connect to website and inspect headers: >>> f = urllib2.urlopen("http://www.python.org") >>> f.headers["Content-Type"] 'text/html' Write page content to file: >>> with open("tmp.html", "w") as dest: ... dest.writelines(f) ... Did we get what we expected? >>> with open("tmp.html") as f: print f.read().split("title")[1] ... >Python Programming Language – Official Website>> From bahamutzero8825 at gmail.com Fri Jul 1 04:02:16 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 01 Jul 2011 03:02:16 -0500 Subject: Trying to chain processes together on a pipeline In-Reply-To: References: <4E096D3B.3080300@gmail.com> Message-ID: <4E0D7F08.4080207@gmail.com> On 2011.07.01 02:26 AM, Peter Otten wrote: > I can't reproduce your setup, but I'd try using communicate() instead of > wait() and close(). I don't really know what communicate() does. The docs don't give much info or any examples (that explain communicate() anyway), and don't say when communicate() is useful. From clp2 at rebertia.com Fri Jul 1 04:24:50 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Jul 2011 01:24:50 -0700 Subject: Trying to chain processes together on a pipeline In-Reply-To: <4E0D7F08.4080207@gmail.com> References: <4E096D3B.3080300@gmail.com> <4E0D7F08.4080207@gmail.com> Message-ID: On Fri, Jul 1, 2011 at 1:02 AM, Andrew Berg wrote: > On 2011.07.01 02:26 AM, Peter Otten wrote: >> I can't reproduce your setup, but I'd try using communicate() instead of >> wait() and close(). > I don't really know what communicate() does. "Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate." It then returns the read data as two strings. It's pretty straightforward. > The docs don't give much > info or any examples (that explain communicate() anyway), and don't say > when communicate() is useful. They are slightly roundabout in that respect. The warnings for .wait() and .stdout/err explain communicate()'s utility: "Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. ***Use communicate() to avoid that.***" [emphasis added] Cheers, Chris -- http://rebertia.com From daniil.re at gmail.com Fri Jul 1 04:26:00 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Fri, 1 Jul 2011 19:26:00 +1100 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: Thanks, everyone! Problem solved. -- Regards, Daniil From daniil.re at gmail.com Fri Jul 1 04:53:48 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Fri, 1 Jul 2011 19:53:48 +1100 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: Hello again! Another question: urlopen() reads full file's content, but how can I get page by small parts? Regards, Daniil From wingusr at gmail.com Fri Jul 1 06:33:37 2011 From: wingusr at gmail.com (TP) Date: Fri, 1 Jul 2011 03:33:37 -0700 Subject: Is the Usenet to mailing list gateway borked? In-Reply-To: <1771444.cVGEfx5fSG@PointedEars.de> References: <1443196.SuA9gRusQu@PointedEars.de> <972lctFifgU1@mid.individual.net> <1771444.cVGEfx5fSG@PointedEars.de> Message-ID: On Thu, Jun 30, 2011 at 11:41 AM, Thomas 'PointedEars' Lahn wrote: > Thomas Guettler wrote: > >> On 30.06.2011 03:24, Thomas 'PointedEars' Lahn wrote: >>> Andrew Berg wrote: >>>> [?] >>> >>> As for your question in the Subject, I do not know since I am reading the >>> newsgroup. >>> >>> Therefore, however, I can tell you that the mailing list to Usenet >>> gateway is seriously borked, as missing References header fields are not >>> generated by the gateway. ?As a result, there are few if any threads left >>> in the newsgroup, which makes it an increasing PITA to read. ?(And no, >>> threading by Subject is a stupid idea.) >>> >>> Would someone responsible *please* fix this? ?I am willing to provide >>> assistance, see also my suggestion in >>> . >> >> Who is responsible? > > If I knew that I would not ask here. > >> I think in the past there were not many broken threads. I wonder what >> changed this. > > One factor, as I see it, is an increasing number of people using e-mail > clients that do not generate the References header field, as it is only a > SHOULD, not a MUST per RFC 5322, or people using mail clients that are FUBAR > (like G2, Google Groups and Mail). ?But that header field is mandatory for > Network News (RFC 5536), and if it is missing you create a mess for > newsreaders (applications and people alike). ?"Bugs" making a slumbering > real bug in the gateway implementation apparent. > > But that appears to be only half the truth as e.g. I can retrieve none of > the messages that of > 15:19 GMT+02:00 today refers to, regardless from where they supposedly > originated. ?I am not deleting messages locally and I have a rather fast and > reliable newsfeed, so the messages should have arrived by now. > > -- > PointedEars > > Bitte keine Kopien per E-Mail. / Please do not Cc: me. > -- > http://mail.python.org/mailman/listinfo/python-list > Not sure if this is relevant. I use mail.google.com to follow mailing lists and a large proportion of python-list traffic ends up in my gmail spam folder for some reason? -- TP From gisle.vanem at gmail.com Fri Jul 1 09:32:11 2011 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Fri, 1 Jul 2011 15:32:11 +0200 Subject: FOX Toolkit Message-ID: <4e0dcc5c$1@news.broadpark.no> In http://docs.python.org/faq/gui.html I came across FOX Toolkit and the binding FXPy. The latter, it seems is no longer officially supported (hasn't for the last 7-8 years). So my question. Has anybody to your knowledge tweaked FOX and FXPy to work with Python 2.7? --gv From jjposner at codicesoftware.com Fri Jul 1 11:18:29 2011 From: jjposner at codicesoftware.com (John Posner) Date: Fri, 01 Jul 2011 11:18:29 -0400 Subject: Using decorators with argument in Python In-Reply-To: <4E0B7D6A.1080404@stoneleaf.us> References: <4e0a0a8b$1@dnews.tpgi.com.au> <4E0B5F7C.7030802@codicesoftware.com> <4E0B7D6A.1080404@stoneleaf.us> Message-ID: <4E0DE545.8060804@codicesoftware.com> On 2:59 PM, Ethan Furman wrote: > def __call__(self, func=None): > if func is None: > return self._call() > self.func = func > return self > def _call(self): > print("\n" + self.char * 50) > self.func() > print(self.char * 50 + '\n') > I believe the "if" block should be: if func is None: self._call() return Or perhaps the _call() method should be revised: def _call(self): print("\n" + self.char * 50) retval = self.func() print(self.char * 50 + '\n') return retval -John From rune.strand at gmail.com Fri Jul 1 12:15:19 2011 From: rune.strand at gmail.com (Rune Strand) Date: Fri, 1 Jul 2011 09:15:19 -0700 (PDT) Subject: how to call a function for evry 10 secs In-Reply-To: Message-ID: <0dced078-212a-4841-9e1c-704697c4bcc6@glegroupsg2000goo.googlegroups.com> from threading import Timer def Func_to_call: do_stuff() my_timer = Timer(10, Func_to_call) my_timer.start() From kozmikyak at gmail.com Fri Jul 1 12:27:07 2011 From: kozmikyak at gmail.com (kozmikyak) Date: Fri, 1 Jul 2011 09:27:07 -0700 (PDT) Subject: An ODBC interface for Python 3? Message-ID: Does anyone here have a Python 3 environment that can access MSSQL using SQLAlchemy, running on a Windows 7 box? If so, I would like some assistance making it happen. The last post on this was mid-2010. It was mentioned that pyodbc had a Python 3 branch. I've been unable to get it compiled and working on Windows 7 32-bit or 64-bit, even after applying patches mentioned in one of the project's tracking issues. Right now anyone forced to support Windows clients, Microsoft SQL, and SQLAlchemy has no option if wanting to use Python 3.2. Neither pymssql or pyodbc compiles out-of-the-box for Python 3.2. ceODBC compiles and runs, but SQLAlchemy project has stated that it has no desire to write yet another dialect supporting ceODBC for MSSQL. I'm not mentioning this just to complain; I'm just stating it out in the open so that it's known. Indeed, even if one doesn't want to use MSSQL, the only free ODBC interface I know of that works on Python 3 is ceODBC, and it is not supported by other modules such as SQLAlchemy. I'm wondering how I could best make something like this happen. I've written to the SQLAlchemy and pyodbc projects. I have average Python programming skills and have a Windows Python environment with C compiler installed; perhaps if the authors respond I can assist. If someone else has already figured out how to make this happen, please let me know. From kushal.kumaran+python at gmail.com Fri Jul 1 13:01:42 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 1 Jul 2011 22:31:42 +0530 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: On Fri, Jul 1, 2011 at 2:23 PM, ?????? ?????? wrote: > Hello again! > Another question: urlopen() reads full file's content, but how can I > get page by small parts? > Set the Range header for HTTP requests. The format is specified here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35. Note that web servers are not *required* to support this header. In [10]: req = urllib2.Request('http://cdimage.debian.org/debian-cd/6.0.2.1/amd64/iso-cd/debian-6.0.2.1-amd64-CD-1.iso', headers = { 'Range' : 'bytes=0-499' }) In [11]: f = urllib2.urlopen(req) In [12]: data = f.read() In [13]: len(data) Out[13]: 500 In [14]: print f.headers Date: Fri, 01 Jul 2011 16:59:39 GMT Server: Apache/2.2.14 (Unix) Last-Modified: Sun, 26 Jun 2011 16:54:45 GMT ETag: "ebff2f-28700000-4a6a04ab27f10" Accept-Ranges: bytes Content-Length: 500 Age: 225 Content-Range: bytes 0-499/678428672 Connection: close Content-Type: application/octet-stream -- regards, kushal From clp2 at rebertia.com Fri Jul 1 13:02:32 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Jul 2011 10:02:32 -0700 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: On Fri, Jul 1, 2011 at 1:53 AM, ?????? ?????? wrote: > Hello again! > Another question: urlopen() reads full file's content, but how can I > get page by small parts? I don't think that's true. Just pass .read() the number of bytes you want to read, just as you would with an actual file object. Cheers, Chris From wm at localhost.localdomain Fri Jul 1 13:14:34 2011 From: wm at localhost.localdomain (Waldek M.) Date: Fri, 1 Jul 2011 19:14:34 +0200 Subject: ANN: pyparsing 1.5.6 released! References: <653d4abd-e1f0-4265-b0e3-d2c591a702bc@e35g2000yqc.googlegroups.com> Message-ID: <1e9otj3eg0e9l.dlg@localhost.localdomain> Dnia Thu, 30 Jun 2011 23:09:18 -0700 (PDT), Paul McGuire napisa?(a): > After about 10 months, there is a new release of pyparsing, version > 1.5.6. This release contains some small enhancements, some bugfixes, > and some new examples. Thanks! That is great news. I'm not using pyparsing right now, but I used to and surely will. I just wish it was included in the standard Python distribution some day... Best regards, Waldek From python.list at tim.thechases.com Fri Jul 1 13:20:57 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 01 Jul 2011 12:20:57 -0500 Subject: Enhanced dir() function In-Reply-To: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E0E01F9.80803@tim.thechases.com> On 06/30/2011 11:29 PM, Steven D'Aprano wrote: > The dir() function is designed for interactive use, inspecting objects for > the names of attributes and methods. > > Here is an enhanced version that allows you to pass a glob to filter the > names you see: > > Comments and improvements welcome. Having not seen any other comments on it fly by, I thought I'd respond. While in general I like the idea, I'm not sure when I'd go to the effort of bringing the function into my namespace when I could just do something like >>> [s for s in dir(...) if test_of_interest(s)] If it came in as an effortless (i.e. O(1) where I do it once and never again; not an O(n) where n=the number of times I invoke Python) default replacement for dir(), I'd reach for it a lot more readily. I seem to recall there's some environment-var or magic file-name that gets sourced on every startup. I use the list-comp version on a regular basis: # implementation of which magic methods? [s for s in dir(foo) if s.startswith('__') and s.endswith('__')] # ignore magic methods [s for s in dir(foo) if not (s.startswith('__') and s.endswith('__'))] # constants [s for s in dir(foo) if s.isupper()] # keywording [s for s in dir(foo) if 'bar' in s.lower()] Anyways, even if it just includes a brief blurb about "and this is how you get it automatically in every Python session" (or a link to the docs on how to do that), it would raise it from "meh" to "nifty". -tim From steve+comp.lang.python at pearwood.info Fri Jul 1 14:32:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2011 04:32:44 +1000 Subject: Enhanced dir() function References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e0e12cd$0$29995$c3e8da3$5496439d@news.astraweb.com> Tim Chase wrote: > On 06/30/2011 11:29 PM, Steven D'Aprano wrote: >> The dir() function is designed for interactive use, inspecting objects >> for the names of attributes and methods. >> >> Here is an enhanced version that allows you to pass a glob to filter the >> names you see: >> >> Comments and improvements welcome. > > Having not seen any other comments on it fly by, I thought I'd > respond. While in general I like the idea, I'm not sure when I'd > go to the effort of bringing the function into my namespace when > I could just do something like > > >>> [s for s in dir(...) if test_of_interest(s)] If test_of_interest is complex, then the list comp is the better solution. Globbing dir is intended for simple globs (naturally!), not complex filter functions of arbitrary complexity. The equivalent is globbing in the shell: [steve at sylar python]$ dir p*.py parallel_map.py partition.py perms.py proc.py pyprimes.py paragraphs.py peekable.py pi.py progress.py > If it came in as an effortless (i.e. O(1) where I do it once and > never again; not an O(n) where n=the number of times I invoke > Python) default replacement for dir(), I'd reach for it a lot > more readily. I seem to recall there's some environment-var or > magic file-name that gets sourced on every startup. There is some talk on the python-ideas mailing list about enhancing the built-in dir(). But in the meantime, you can add it to your site.py module, or better still, use your own personal startup file rather than the system site.py. I have an environment variable set in my .bashrc file: export PYTHONSTARTUP=/home/steve/python/startup.py and then put code I want to run at startup in startup.py. For Windows users, I don't know how to set environment variables, but I dare say it would be something similar: set the environment variable PYTHONSTARTUP to a file name, and put the code in that file. > I use the list-comp version on a regular basis: > > # implementation of which magic methods? > [s for s in dir(foo) if s.startswith('__') and s.endswith('__')] This would become: dir(foo, "__*__") > # ignore magic methods > [s for s in dir(foo) if not (s.startswith('__') and > s.endswith('__'))] dir(foo, "[!_]*[!_]") although strictly speaking, my version only tests for one leading and trailing underscore, not two. > # constants > [s for s in dir(foo) if s.isupper()] That's beyond the capabilities of simple globbing. > # keywording > [s for s in dir(foo) if 'bar' in s.lower()] I'm of two minds about case-insensitive globbing. It could be done with a slight change to the function, but I'm not sure if I want to. > Anyways, even if it just includes a brief blurb about "and this > is how you get it automatically in every Python session" (or a > link to the docs on how to do that), it would raise it from "meh" > to "nifty". Thanks for the feedback. -- Steven From ethan at stoneleaf.us Fri Jul 1 14:40:17 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jul 2011 11:40:17 -0700 Subject: Enhanced dir() function In-Reply-To: <4E0E01F9.80803@tim.thechases.com> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> <4E0E01F9.80803@tim.thechases.com> Message-ID: <4E0E1491.8070007@stoneleaf.us> Tim Chase wrote: > If it came in as an effortless (i.e. O(1) where I do it once and never > again; not an O(n) where n=the number of times I invoke Python) default > replacement for dir(), I'd reach for it a lot more readily. I seem to > recall there's some environment-var or magic file-name that gets sourced > on every startup. interact.py 8<----------------------------------------------- import os, sys sys.ps1 = '--> ' from cookbook.utils import dir # or whereever you keep your copy sys.modules['__builtin__'].dir = dir 8<----------------------------------------------- ~Ethan~ From hartwig.linux at gmail.com Fri Jul 1 16:02:15 2011 From: hartwig.linux at gmail.com (H Linux) Date: Fri, 1 Jul 2011 13:02:15 -0700 (PDT) Subject: Nested/Sub Extensions in Python Message-ID: <23a9eb92-65b9-4825-b23b-b01e7c04599c@q15g2000yqk.googlegroups.com> Dear all, I am currently fighting with a problem writing a set of Python extensions in C. I want to structure the whole package (here called smt for sub-module test) into different sub-modules, e.g. according to this layout: smt.foo.func() I can only build a module >import foo >print foo.func(1,2) Once I try to nest this, I cannot get the module to load anymore: >import smt.bar Traceback (most recent call last): File "", line 1, in ImportError: No module named bar I have found the following hints on the web: http://stackoverflow.com/questions/1681281/nested-python-c-extensions-modules I have also found that XEN has a python module which does this, but http://www.google.de/codesearch#4Wqoij9clTg/tools/python/setup.py Still I am unable to get this to work. What am I missing? In case it matters, this is on Ubuntu10.4/Python2.6.5 Below are listings from my source files. Thanks in advance for any help, Hartwig 1. setup.py: from distutils.core import setup, Extension PACKAGE_NAME = 'smt' setup( name = PACKAGE_NAME, version = '0.1', author = 'Myself', packages = [PACKAGE_NAME], ext_modules = [ Extension('foo', ['src/foo.c']), Extension('smt.bar', ['src/bar.c']) ] ) 2. src/bar.c #include static PyObject* bar_func(PyObject *self, PyObject *args) { PyObject *a, *b; if (!PyArg_UnpackTuple(args, "func", 2, 2, &a, &b)) { return NULL; } return PyNumber_Add(a, b); } static PyMethodDef bar_methods[] = { {"func", bar_func, METH_VARARGS, NULL}, {NULL, NULL} }; PyMODINIT_FUNC initbar(void) { Py_InitModule("smt.bar", bar_methods); } 3. src/foo.c #include static PyObject* foo_func(PyObject *self, PyObject *args) { PyObject *a, *b; if (!PyArg_UnpackTuple(args, "func", 2, 2, &a, &b)) { return NULL; } return PyNumber_Add(a, b); } static PyMethodDef foo_methods[] = { {"func", foo_func, METH_VARARGS, NULL}, {NULL, NULL} }; PyMODINIT_FUNC initfoo(void) { Py_InitModule("foo", foo_methods); } 4. Code Layout: ??? setup.py ??? smt ??? ??? __init__.py ??? src ??? bar.c ??? foo.c From leandrodsferreira at gmail.com Fri Jul 1 16:06:03 2011 From: leandrodsferreira at gmail.com (Leandro Ferreira) Date: Fri, 1 Jul 2011 13:06:03 -0700 (PDT) Subject: How to get a dateiled process information on windows? Message-ID: <99a392c4-a919-40e5-894d-7589d53bd99f@r2g2000vbj.googlegroups.com> I need to write an application that monitors the memory consumption of a process, there is some library that facilitates this work? I searched on google found nothing more interesting. Thanks in advance From mail at timgolden.me.uk Fri Jul 1 16:19:39 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 01 Jul 2011 21:19:39 +0100 Subject: How to get a dateiled process information on windows? In-Reply-To: <99a392c4-a919-40e5-894d-7589d53bd99f@r2g2000vbj.googlegroups.com> References: <99a392c4-a919-40e5-894d-7589d53bd99f@r2g2000vbj.googlegroups.com> Message-ID: <4E0E2BDB.2040904@timgolden.me.uk> On 01/07/2011 21:06, Leandro Ferreira wrote: > I need to write an application that monitors the memory consumption of > a process, there is some library that facilitates this work? > I searched on google found nothing more interesting. Have a look at WMI TJG From alister.ware at ntlworld.com Fri Jul 1 17:15:18 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Fri, 01 Jul 2011 21:15:18 GMT Subject: Does anyone know of a python tapi module Message-ID: The subject probably say is all but to elaborate. I am looking for a way to communicate with a tapi driver for a PBX so I can experiment with creating some CTI (Computer Telephony Integration) software. -- From lists at cheimes.de Fri Jul 1 17:58:05 2011 From: lists at cheimes.de (Christian Heimes) Date: Fri, 01 Jul 2011 23:58:05 +0200 Subject: How to get a dateiled process information on windows? In-Reply-To: <99a392c4-a919-40e5-894d-7589d53bd99f@r2g2000vbj.googlegroups.com> References: <99a392c4-a919-40e5-894d-7589d53bd99f@r2g2000vbj.googlegroups.com> Message-ID: Am 01.07.2011 22:06, schrieb Leandro Ferreira: > I need to write an application that monitors the memory consumption of > a process, there is some library that facilitates this work? > I searched on google found nothing more interesting. Have a look at psutil http://code.google.com/p/psutil/ . It works on all major platforms and gives you extended system information (processes, threads, memory, cpu). Christian From werner at thieprojects.ch Fri Jul 1 20:28:13 2011 From: werner at thieprojects.ch (Werner Thie) Date: Fri, 01 Jul 2011 14:28:13 -1000 Subject: Does anyone know of a python tapi module In-Reply-To: References: Message-ID: <4E0E661D.1070905@thieprojects.ch> On 7/1/11 11:15 AM, Alister Ware wrote: > The subject probably say is all but to elaborate. > > I am looking for a way to communicate with a tapi driver for a PBX so I > can experiment with creating some CTI (Computer Telephony Integration) > software. > > I used TAPI since its inception for quite a few projects, but am not aware of anything pythonic. Attempting to cough up an interface layer I would resort to using Chris Sells tfx wrapper fro TAPI, which helps a lot keeping things in check and becoming overly complex. HTH, Werner http://books.google.com/books?id=3M_mIvtdGqUC&pg=PA82&lpg=PA82&dq=chris+sell+tfx&source=bl&ots=5UhAxbFTym&sig=7hRn0oUbyZsm_yyDvASKD-AT1jo&hl=en&ei=w2UOTsPlBJOisAP57JyrDg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBkQ6AEwAA From pavlovevidence at gmail.com Fri Jul 1 20:28:29 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 1 Jul 2011 17:28:29 -0700 (PDT) Subject: Nested/Sub Extensions in Python In-Reply-To: <23a9eb92-65b9-4825-b23b-b01e7c04599c@q15g2000yqk.googlegroups.com> Message-ID: <22ac5469-baa7-4abd-abe7-bc6d04659b26@glegroupsg2000goo.googlegroups.com> On Friday, July 1, 2011 1:02:15 PM UTC-7, H Linux wrote: > Once I try to nest this, I cannot get the module to load anymore: > >import smt.bar > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named bar [snip] > PyMODINIT_FUNC > initbar(void) > { > Py_InitModule("smt.bar", bar_methods); > } This should be: Py_InitModule("bar", bar_methods); That's probably it; other than that, it looks like you did everything right. What does the installed file layout look like after running distutils setup? Carl Banks From daniil.re at gmail.com Fri Jul 1 20:47:01 2011 From: daniil.re at gmail.com (=?UTF-8?B?0JTQsNC90LjQuNC7INCg0YvQttC60L7Qsg==?=) Date: Sat, 2 Jul 2011 11:47:01 +1100 Subject: urllib, urlretrieve method, how to get headers? In-Reply-To: References: Message-ID: Thanks, everyone! Problem solved. -- Regards, Daniil From kb1pkl at aim.com Fri Jul 1 21:46:48 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Fri, 01 Jul 2011 21:46:48 -0400 Subject: Nested/Sub Extensions in Python In-Reply-To: <23a9eb92-65b9-4825-b23b-b01e7c04599c@q15g2000yqk.googlegroups.com> References: <23a9eb92-65b9-4825-b23b-b01e7c04599c@q15g2000yqk.googlegroups.com> Message-ID: <1309571103-sup-3333@dalek> Excerpts from H Linux's message of Fri Jul 01 16:02:15 -0400 2011: > Dear all, > > I am currently fighting with a problem writing a set of Python > extensions in C. If you haven't seen it yet, Cython is a *very* nice tool for writing C extensions. http://cython.org/ -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln From boyd.blackwell at gmail.com Fri Jul 1 22:17:45 2011 From: boyd.blackwell at gmail.com (bdb112) Date: Fri, 1 Jul 2011 19:17:45 -0700 (PDT) Subject: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import? Message-ID: First a trap for new players, then a question to developers Code accelerated by numpy can be slowed down by a large factor is you neglect to import numpy.sum . from timeit import Timer frag = 'x=sum(linspace(0,1,1000))' Timer(frag ,setup='from numpy import linspace').timeit(1000) # 0.6 sec Timer(frag, setup='from numpy import sum, linspace').timeit(1000) # difference is I import numpy.sum # 0.04 sec 15x faster! This is obvious of course - but it is very easy to forget to import numpy.sum and pay the price in execution. Question: Can I replace the builtin sum function globally for test purposes so that my large set of codes uses the replacement? The replacement would simply issue warnings.warn() if it detected an ndarray argument, then call the original sum I could then find the offending code and use the appropriate import to get numpy.sum From marduk at letterboxes.org Fri Jul 1 22:54:10 2011 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 01 Jul 2011 22:54:10 -0400 Subject: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import? In-Reply-To: References: Message-ID: <1309575251.7019.2.camel@localhost.localdomain> On Friday, July 1 at 19:17 (-0700), bdb112 said: > Question: > Can I replace the builtin sum function globally for test purposes so > that my large set of codes uses the replacement? > > The replacement would simply issue warnings.warn() if it detected an > ndarray argument, then call the original sum > I could then find the offending code and use the appropriate import to > get numpy.sum You shouldn't do this, but you could use the __builtins__ module e.g. >>> __builtins__.sum = numpy.sum # bad From rosuav at gmail.com Fri Jul 1 23:12:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jul 2011 13:12:02 +1000 Subject: Is the Usenet to mailing list gateway borked? In-Reply-To: References: <1443196.SuA9gRusQu@PointedEars.de> <972lctFifgU1@mid.individual.net> <1771444.cVGEfx5fSG@PointedEars.de> Message-ID: On Fri, Jul 1, 2011 at 8:33 PM, TP wrote: > Not sure if this is relevant. I use mail.google.com to follow mailing > lists and a large proportion of python-list traffic ends up in my > gmail spam folder for some reason? Set a filter (you can "Filter messages like this") that says "Never spam". That stops that from happening. ChrisA From nospam at torek.net Fri Jul 1 23:13:05 2011 From: nospam at torek.net (Chris Torek) Date: 2 Jul 2011 03:13:05 GMT Subject: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import? References: Message-ID: In article bdb112 wrote: >First a trap for new players, then a question to developers > >Code accelerated by numpy can be slowed down by a large factor is you >neglect to import numpy.sum . > >from timeit import Timer >frag = 'x=sum(linspace(0,1,1000))' >Timer(frag ,setup='from numpy import linspace').timeit(1000) ># 0.6 sec >Timer(frag, setup='from numpy import sum, linspace').timeit(1000) # >difference is I import numpy.sum ># 0.04 sec 15x faster! > >This is obvious of course - but it is very easy to forget to import >numpy.sum and pay the price in execution. > >Question: >Can I replace the builtin sum function globally for test purposes so >that my large set of codes uses the replacement? >The replacement would simply issue warnings.warn() if it detected an >ndarray argument, then call the original sum >I could then find the offending code and use the appropriate import to >get numpy.sum Sure, just execute code along these lines before running any of the tests: import __builtin__ import warnings _sys_sum = sum # grab it before we change __builtin__.sum def hacked_sum(sequence, start=0): if isinstance(sequence, whatever): warnings.warn('your warning here') return _sys_sum(sequence, start) __builtin__.sum = hacked_sum (You might want to grab a stack trace too, using the traceback module.) You said "without using import" but all you have to do is arrange for python to import this module before running any of your own code, e.g., with $PYTHONHOME and a modified site file. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From rune.strand at gmail.com Sat Jul 2 02:53:00 2011 From: rune.strand at gmail.com (Rune) Date: Fri, 1 Jul 2011 23:53:00 -0700 (PDT) Subject: how to call a function for evry 10 secs In-Reply-To: Message-ID: <15f652f7-442c-4df2-9b51-1c563ba80611@glegroupsg2000goo.googlegroups.com> >Dennis Lee Bieber: > Timer() is a one-shot; per the OPs requirements even it would need > to be placed within a loop to invoke multiple calls -- so there isn't > much gain in terms of lines of code... And worse, since it calls the > function asynchronously and not sequentially, a delay time for each > instance would have to be computed inside the loop too... The first/last task for the called function may be to instantiate a new Timer - depending on what "every 10 secs" means. The OP does not detail his actual problem, so I can't see that the async/sequential issue. From rune.strand at gmail.com Sat Jul 2 02:53:00 2011 From: rune.strand at gmail.com (Rune) Date: Fri, 1 Jul 2011 23:53:00 -0700 (PDT) Subject: how to call a function for evry 10 secs In-Reply-To: Message-ID: <15f652f7-442c-4df2-9b51-1c563ba80611@glegroupsg2000goo.googlegroups.com> >Dennis Lee Bieber: > Timer() is a one-shot; per the OPs requirements even it would need > to be placed within a loop to invoke multiple calls -- so there isn't > much gain in terms of lines of code... And worse, since it calls the > function asynchronously and not sequentially, a delay time for each > instance would have to be computed inside the loop too... The first/last task for the called function may be to instantiate a new Timer - depending on what "every 10 secs" means. The OP does not detail his actual problem, so I can't see that the async/sequential issue. From anand.ibmgsi at gmail.com Sat Jul 2 03:49:50 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Sat, 2 Jul 2011 13:19:50 +0530 Subject: how to call a function for evry 10 secs In-Reply-To: References: Message-ID: > > > Hi All, > > I need to call a function for evry 10 secs > > how can i achieve this in python > > > import time > while True: > time.sleep(10) > function() > Please don't reinvent the wheel... Use the python apscheduler module. http://packages.python.org/APScheduler/#installing-apscheduler Thanks and Regards, ============================================== Anand Jeyahar https://sites.google.com/site/< https://sites.google.com/site/aangjie/home/quotes> anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From marek.belisko at gmail.com Sat Jul 2 05:40:46 2011 From: marek.belisko at gmail.com (Belisko Marek) Date: Sat, 2 Jul 2011 11:40:46 +0200 Subject: poll of filesystem Message-ID: Hi, just want to use poll method to get data from /proc file system. Use simple code for it. Problem is it seems poll return POLLIN flag but when I try to read data it's always empty. Could be a problem changes are so fast that print can't print it? Code: #!/usr/bin/python import select from select import POLLIN, POLLERR p = select.poll() fd = open("/proc/loadavg", "r") p.register(fd.fileno(), POLLIN) while True: events = p.poll(1000) if (events == -1): print "timeout" fd0, event = events[0] if (event == POLLIN): print fd.read() Thanks, marek -- as simple and primitive as possible ------------------------------------------------- Marek Belisko - OPEN-NANDRA Freelance Developer Ruska Nova Ves 219 | Presov, 08005 Slovak Republic Tel: +421 915 052 184 skype: marekwhite icq: 290551086 web: http://open-nandra.com From nobody at nowhere.net.no Sat Jul 2 07:42:32 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 02 Jul 2011 19:42:32 +0800 Subject: How to save a email message? Message-ID: Hello, I'm trying to gather some mail and save it. I don't get why it isn't saved as expected. ========================================================================== >>> import poplib, socket, sys >>> from configparser import Error as ProtocolError >>> args= sys.argv[1:] # this is fake but is here as example >>> def Pop3_access(*args): >>> '''Accessing a pop server, doing a function and return a result''' >>> func= args[0]; args= args[1:] >>> try: >>> pop= poplib.POP3(srv_info[0]) >>> pop.user(srv_info[1]) >>> pop.pass_(srv_info[2]) >>> except (poplib.error_proto): >>> raise ProtocolError >>> except (socket.timeout,socket.gaierror): >>> try: pop.quit() >>> except NameError: pass # it wasn't started >>> return >>> result= func(pop, args) >>> pop.quit() >>> return result >>> def func(pop, N): ... return pop.retr(N) ... >>> msg= Pop3_access(func, 4) >>> from io import BytesIO as B >>> fp= B() >>> for l in msg[1]: ... fp.write(l) ... fp.write('\n'.encode()) ... 34 1 50 1 63 1 65 1 36 1 52 1 41 1 114 1 45 1 38 1 74 1 56 1 37 1 34 1 28 1 23 1 33 1 56 1 57 1 17 1 44 1 31 1 54 1 30 1 30 1 0 1 31 1 0 1 39 1 0 1 12 1 32 1 49 1 0 1 6 1 64 1 68 1 0 1 >>> from mailbox import mbox as Mbx >>> mbx= Mbx('/tmp/mb', True) >>> mbx.add(fp) 0 >>> mbx.get_message(0) >>> print(mbx.get_message(0)) >>> =================================================================== The result is an empty message, but the fp.getvalue() shows file-like stream. Am I missing some point? -- goto /dev/null From bahamutzero8825 at gmail.com Sat Jul 2 08:25:39 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 02 Jul 2011 07:25:39 -0500 Subject: Trying to chain processes together on a pipeline In-Reply-To: References: <4E096D3B.3080300@gmail.com> Message-ID: <4E0F0E43.4090401@gmail.com> This code is working: > try: > ffmpeg_proc = subprocess.Popen(queue[position].ffmpeg_cmd, > stdout=subprocess.PIPE, stderr=open(os.devnull, 'w')) > except WindowsError as exc: > log_windows_error(exc, queue[position].ffmpeg_cmd, 'critical') > break > if queue[position].vol != 1: > try: > sox_proc = subprocess.Popen(queue[position].sox_cmd, > stdin=ffmpeg_proc.stdout, stdout=subprocess.PIPE, > stderr=open(os.devnull, 'w')) > wav_pipe = sox_proc.stdout > except WindowsError as exc: > log_windows_error(exc, queue[position].sox_cmd, 'critical') > break > finally: > ffmpeg_proc.stdout.close() > else: > wav_pipe = ffmpeg_proc.stdout > try: > nero_aac_proc = subprocess.Popen(queue[position].nero_aac_cmd, > stdin=wav_pipe) > except WindowsError as exc: > log_windows_error(exc, queue[position].nero_aac_cmd, 'critical') > break > finally: > if queue[position].vol != 1: > sox_proc.stdout.close() > else: > ffmpeg_proc.stdout.close() > ffmpeg_proc.wait() > if queue[position].vol != 1: > sox_proc.wait() > nero_aac_proc.wait() I can't figure out what I changed since the last time I tried and failed, though; I only ran it again after directing the stderr of FFmpeg and SoX to actual files to see if they could gives me any clues. From steve+comp.lang.python at pearwood.info Sat Jul 2 09:08:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2011 23:08:35 +1000 Subject: How to save a email message? References: Message-ID: <4e0f1854$0$29976$c3e8da3$5496439d@news.astraweb.com> TheSaint wrote: > Hello, > I'm trying to gather some mail and save it. I don't get why it isn't saved > as expected. Short answer: you need to seek the fp file object back to the start of the file by calling fp.seek(0). Otherwise, when you add it to the mail box, if gets EOF immediately and nothing gets added. More comments below: > ========================================================================== > >>>> import poplib, socket, sys >>>> from configparser import Error as ProtocolError >>>> args= sys.argv[1:] # this is fake but is here as example It makes it very hard for us to run your code when you paste the interactive session. For small snippets, it's okay to just post the interactive session, but for more substantial code, it is best to past the function definition ready for us to copy and paste: def foo(): pass >>> foo("arg") >>> >>>> def Pop3_access(*args): >>>> '''Accessing a pop server, doing a function and return a result''' >>>> func= args[0]; args= args[1:] Why don't you declare func as a named argument? def Pop3_access(func, *args): >>>> try: >>>> pop= poplib.POP3(srv_info[0]) >>>> pop.user(srv_info[1]) >>>> pop.pass_(srv_info[2]) >>>> except (poplib.error_proto): >>>> raise ProtocolError >>>> except (socket.timeout,socket.gaierror): >>>> try: pop.quit() >>>> except NameError: pass # it wasn't started >>>> return >>>> result= func(pop, args) >>>> pop.quit() >>>> return result > >>>> def func(pop, N): > ... return pop.retr(N) > ... >>>> msg= Pop3_access(func, 4) >>>> from io import BytesIO as B >>>> fp= B() >>>> for l in msg[1]: > ... fp.write(l) > ... fp.write('\n'.encode()) > ... > 34 > 1 > 50 > 1 [...] For those wondering, as I was, what all these numbers are, the BytesIO.write() method returns the number of bytes written. At this point, fp is a file-like object containing a number of bytes, but the file pointer is at the end of the file, so when you read from it, it immediately gets EOF (i.e. empty). >>> from io import BytesIO as B >>> x = B() >>> x.write(bytes("hello", 'ascii')) 5 >>> x.read() b'' But if you seek back to the beginning: >>> x.seek(0) 0 >>> x.read() b'hello' >>>> from mailbox import mbox as Mbx *raises eyebrow* Do you need to rename mbox? You don't even save a keypress: shift-m b x and m b o x both take 4 keypresses. -- Steven From hartwig.linux at gmail.com Sat Jul 2 09:35:19 2011 From: hartwig.linux at gmail.com (H Linux) Date: Sat, 2 Jul 2011 06:35:19 -0700 (PDT) Subject: Nested/Sub Extensions in Python References: <22ac5469-baa7-4abd-abe7-bc6d04659b26@glegroupsg2000goo.googlegroups.com> Message-ID: On Jul 2, 2:28?am, Carl Banks wrote: > On Friday, July 1, 2011 1:02:15 PM UTC-7, H Linux wrote: > > Once I try to nest this, I cannot get the module to load anymore: > > >import smt.bar > > Traceback (most recent call last): > > ? File "", line 1, in > > ImportError: No module named bar > > [snip] > > > PyMODINIT_FUNC > > initbar(void) > > { > > ? ?Py_InitModule("smt.bar", bar_methods); > > } > > This should be: Py_InitModule("bar", bar_methods); > That's probably it; other than that, it looks like you did everything right. Thanks for your help, but I actually tried both ways. This does not seem to be the problem, as it fails both ways with identical error message. >?What does the installed file layout look like after running distutils setup? Tree output is: /usr/local/lib/python2.6/dist-packages/ ??? foo.so ??? smt ??? ??? bar.so ??? ??? __init__.py ??? ??? __init__.pyc ??? smt-0.1.egg-info Just in case anyone is willing to have a look, here is a link to the complete module as built with: python setup.py sdist: https://docs.google.com/leaf?id=0Byt62fSE5VC5NTgxOTFkYzQtNzI3NC00OTUzLWI1NzMtNmJjN2E0ZTViZTJi&hl=en_US If anyone has any other ideas how to get it to work, thanks in advance... Hartwig From hartwig.linux at gmail.com Sat Jul 2 09:36:18 2011 From: hartwig.linux at gmail.com (H Linux) Date: Sat, 2 Jul 2011 06:36:18 -0700 (PDT) Subject: Nested/Sub Extensions in Python References: <23a9eb92-65b9-4825-b23b-b01e7c04599c@q15g2000yqk.googlegroups.com> Message-ID: <68ab655f-7ce6-41f9-aa36-fc192e8d9a3c@gv8g2000vbb.googlegroups.com> On Jul 2, 3:46?am, Corey Richardson wrote: > Excerpts from H Linux's message of Fri Jul 01 16:02:15 -0400 2011: > > > Dear all, > > > I am currently fighting with a problem writing a set of Python > > extensions in C. > > If you haven't seen it yet, Cython is a *very* nice tool for writing > C extensions.http://cython.org/ Thanks for the tip, I'll have a look. Still fighting with plain python though... From rupole at hotmail.com Sat Jul 2 10:12:54 2011 From: rupole at hotmail.com (Roger Upole) Date: Sat, 2 Jul 2011 10:12:54 -0400 Subject: An ODBC interface for Python 3? References: Message-ID: kozmikyak wrote: > Does anyone here have a Python 3 environment that can access MSSQL > using SQLAlchemy, running on a Windows 7 box? If so, I would like > some assistance making it happen. > > The last post on this was mid-2010. It was mentioned that pyodbc had > a Python 3 branch. I've been unable to get it compiled and working on > Windows 7 32-bit or 64-bit, even after applying patches mentioned in > one of the project's tracking issues. > > Right now anyone forced to support Windows clients, Microsoft SQL, and > SQLAlchemy has no option if wanting to use Python 3.2. Neither > pymssql or pyodbc compiles out-of-the-box for Python 3.2. ceODBC > compiles and runs, but SQLAlchemy project has stated that it has no > desire to write yet another dialect supporting ceODBC for MSSQL. > > I'm not mentioning this just to complain; I'm just stating it out in > the open so that it's known. Indeed, even if one doesn't want to use > MSSQL, the only free ODBC interface I know of that works on Python 3 > is ceODBC, and it is not supported by other modules such as > SQLAlchemy. > > I'm wondering how I could best make something like this happen. I've > written to the SQLAlchemy and pyodbc projects. I have average Python > programming skills and have a Windows Python environment with C > compiler installed; perhaps if the authors respond I can assist. > > If someone else has already figured out how to make this happen, > please let me know. Pywin32 has an odbc module that works with Python 3.2. Roger From nobody at nowhere.net.no Sat Jul 2 10:35:25 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sat, 02 Jul 2011 22:35:25 +0800 Subject: How to save a email message? References: <4e0f1854$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: Thank you very much. > But if you seek back to the beginning: > >>>> x.seek(0) > 0 >>>> x.read() > b'hello' > Found the matter and *is* working I discover another problem: one message contains also a different encoding, but mostly it is not possible to represent that writing on the normale console output. > >>>>> from mailbox import mbox as Mbx > > raises eyebrow > > Do you need to rename mbox? You don't even save a keypress: > shift-m b x and m b o x both take 4 keypresses. You stroke a right point :D I could just use its own name The code was not exactly run from the python shell. I was trying to make a *complete* picture from my module. In fact there aren't the arguments to access the pop server. I'd like to mention that I've looked into the output file, which shows only "From MAILER DEAMON" + date of the action, but no message at all. -- goto /dev/null From PointedEars at web.de Sat Jul 2 10:55:00 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 02 Jul 2011 16:55 +0200 Subject: Is the Usenet to mailing list gateway borked? References: <1443196.SuA9gRusQu@PointedEars.de> <972lctFifgU1@mid.individual.net> <1771444.cVGEfx5fSG@PointedEars.de> Message-ID: <4738709.ypaU67uLZW@PointedEars.de> TP wrote: > Thomas 'PointedEars' Lahn wrote: >> [Why are threads broken in the newsgroup?] > > Not sure if this is relevant. I use mail.google.com to follow mailing > lists and a large proportion of python-list traffic ends up in my > gmail spam folder for some reason? Your e-mail problems are unrelated to what happens in the newsgroup, the fact aside that you are posting more text than necessary. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From twestley at gmail.com Sat Jul 2 12:29:42 2011 From: twestley at gmail.com (Terry) Date: Sat, 2 Jul 2011 09:29:42 -0700 (PDT) Subject: How does CO_FUTURE_DIVISION compiler flag get propagated? Message-ID: I've built a Python app for the iPhone, http://www.sabonrai.com/PythonMath/. Like embedding Python in another app, it uses PyRun_SimpleString() to execute commands entered by the user. For evaluating expressions, it uses PyEval_EvalCode() with the dictionary from the __main__ module. Future division ("from __future__ import division") works within scripts executed by import or execfile(). However, it does not work when entered interactively in the interpreter like this: >>> from __future__ import division >>> a=2/3 You get classic (integer) division, but if you enter it as follows, you get future (float) division. >>> from __future__ import division;a=2/3 It appears that the CO_FUTURE_DIVISION compiler flag is not being retained in the interpreter so that later commands get compiled without that flag. I found a hint in http://groups.google.com/group/comp.lang.python/browse_thread/thread/13a90a9f6eb96c73/960e47f572a59711?lnk=gst&q=co_future_division#960e47f572a59711, but I don't see that PyRun_SimpleStringFlags returns the flags it uses. I guess I could watch for the user to enter the import command but that's really brittle. Thanks. From johnjsal at gmail.com Sat Jul 2 12:56:39 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 09:56:39 -0700 (PDT) Subject: Why won't this decorator work? Message-ID: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> I thought I had finally grasped decorators, but the error I'm getting ('str' type is not callable) is confusing me. Here is my code. Also, the commented sentence is from the Python docs, which says it doesn't even need to be callable, if that matters. I also commented out a few things in the move method. They were just to see if it would work, but those lines raised even more errors! import random #space = 0 def move(roll): # global space # space += roll return 'You moved to space {0}.'.format(roll) @move def roll_die(): return random.randint(1, 6) # The return value of the decorator need not be callable # roll_die = move(roll_die) I tried running the command "roll_die()" and I get the error message. Thanks. From python at mrabarnett.plus.com Sat Jul 2 13:33:33 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Jul 2011 18:33:33 +0100 Subject: Why won't this decorator work? In-Reply-To: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> Message-ID: <4E0F566D.70404@mrabarnett.plus.com> On 02/07/2011 17:56, John Salerno wrote: > I thought I had finally grasped decorators, but the error I'm getting > ('str' type is not callable) is confusing me. Here is my code. Also, > the commented sentence is from the Python docs, which says it doesn't > even need to be callable, if that matters. I also commented out a few > things in the move method. They were just to see if it would work, but > those lines raised even more errors! > > import random > > #space = 0 > > def move(roll): > # global space > # space += roll > return 'You moved to space {0}.'.format(roll) > > @move > def roll_die(): > return random.randint(1, 6) > > # The return value of the decorator need not be callable > # roll_die = move(roll_die) > > > > I tried running the command "roll_die()" and I get the error message. > > Thanks. A decorator should return a callable. This: @move def roll_die(): return random.randint(1, 6) is equivalent to this: def roll_die(): return random.randint(1, 6) roll_die = move(roll_die) You should be defining a function (a callable) and then passing it to a decorator which returns a callable. As it is, you're defining a function and then passing it to a decorator which is returning a string. Strings aren't callable. From nobody at nowhere.com Sat Jul 2 13:49:18 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 02 Jul 2011 18:49:18 +0100 Subject: poll of filesystem References: Message-ID: On Sat, 02 Jul 2011 11:40:46 +0200, Belisko Marek wrote: > just want to use poll method to get data from /proc file system. Use > simple code for it. Problem is it seems poll return POLLIN flag but > when I try to read data it's always empty. Could be a problem changes > are so fast that print can't print it? poll() doesn't work for files; they are always readable. It's meant for pipes, sockets and character devices (ttys, etc). If you're looking for a way to find out when a file has changed, there isn't one (Linux has inotify, but that isn't portable and it doesn't work with /proc). The reason why fd.read() doesn't return any data after the first call is that you're already at EOF; you need to reset the file position with fd.seek(0) to read more data (however: for /proc, I would recommend closing the file and reopening it). From alister.ware at ntlworld.com Sat Jul 2 13:57:06 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sat, 02 Jul 2011 17:57:06 GMT Subject: Does anyone know of a python tapi module References: Message-ID: On Fri, 01 Jul 2011 14:28:13 -1000, Werner Thie wrote: > On 7/1/11 11:15 AM, Alister Ware wrote: >> The subject probably say is all but to elaborate. >> >> I am looking for a way to communicate with a tapi driver for a PBX so I >> can experiment with creating some CTI (Computer Telephony Integration) >> software. >> >> > I used TAPI since its inception for quite a few projects, but am not > aware of anything pythonic. Attempting to cough up an interface layer I > would resort to using Chris Sells tfx wrapper fro TAPI, which helps a > lot keeping things in check and becoming overly complex. > > HTH, Werner > > http://books.google.com/books?id=3M_mIvtdGqUC&pg=PA82&lpg=PA82&dq=chris +sell+tfx&source=bl&ots=5UhAxbFTym&sig=7hRn0oUbyZsm_yyDvASKD- AT1jo&hl=en&ei=w2UOTsPlBJOisAP57JyrDg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBkQ6AEwAA thanks for taking the time to look Unfortunately I only have a nodding acquaintance with C & don't want togo down that route. looks like I will have to see if I can work something out using the ctypes module -- From johnjsal at gmail.com Sat Jul 2 14:08:38 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 11:08:38 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> Message-ID: <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> On Jul 2, 12:33?pm, MRAB wrote: > On 02/07/2011 17:56, John Salerno wrote: > > > > > > > > > > > I thought I had finally grasped decorators, but the error I'm getting > > ('str' type is not callable) is confusing me. Here is my code. Also, > > the commented sentence is from the Python docs, which says it doesn't > > even need to be callable, if that matters. I also commented out a few > > things in the move method. They were just to see if it would work, but > > those lines raised even more errors! > > > import random > > > #space = 0 > > > def move(roll): > > # ? ?global space > > # ? space += roll > > ? ? ?return 'You moved to space {0}.'.format(roll) > > > @move > > def roll_die(): > > ? ? ?return random.randint(1, 6) > > > # The return value of the decorator need not be callable > > # roll_die = move(roll_die) > > > I tried running the command "roll_die()" and I get the error message. > > > Thanks. > > A decorator should return a callable. > > This: > > ? ? ?@move > ? ? ?def roll_die(): > ? ? ? ? ?return random.randint(1, 6) > > is equivalent to this: > > ? ? ?def roll_die(): > ? ? ? ? ?return random.randint(1, 6) > > ? ? ?roll_die = move(roll_die) > > You should be defining a function (a callable) and then passing it to a > decorator which returns a callable. > > As it is, you're defining a function and then passing it to a decorator > which is returning a string. Strings aren't callable. But why does the documentation say "The return value of the decorator need not be callable"? And why, if I remove the decorator and just leave the two functions as if, does the call to move(roll_die()) work? Isn't that what the decorator syntax is essentially doing? From rahul.nbg at gmail.com Sat Jul 2 14:17:35 2011 From: rahul.nbg at gmail.com (aregee) Date: Sat, 2 Jul 2011 11:17:35 -0700 (PDT) Subject: need to extend this C code so that it initiates this python script (python C api) Message-ID: <0c796071-c699-4aae-b5b6-6fa7378b03a6@j14g2000prn.googlegroups.com> hi i need help with extending this http://paste.pound-python.org/show/8918/ c code so that it can initiate this python script http://paste.pound-python.org/show/8917/ and export file path here.. btw I tried to run following python code : #include //changed this to python2.7/Python.h didn't work the I changed it to Python.h // Error msg : fatal error: Python.h : no file or directory compilation terminated //python-dev and python2.7-dev is already installed. void process_expression(char* filename, int num, char** exp) { FILE* exp_file; // Initialize a global variable for // display of expression results PyRun_SimpleString("x = 0"); // Open and execute the file of // functions to be made available // to user expressions exp_file = fopen(filename, "r"); PyRun_SimpleFile(exp_file, exp); // Iterate through the expressions // and execute them while(num--) { PyRun_SimpleString(*exp++); PyRun_SimpleString("print x"); } } int main(int argc, char** argv) { Py_Initialize(); if(argc != 3) { printf("Usage: %s FILENAME EXPRESSION+\n"); return 1; } process_expression(argv[1], argc - 1, argv + 2); return 0; } thanks aregee Ar From python.list at tim.thechases.com Sat Jul 2 14:45:51 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 02 Jul 2011 13:45:51 -0500 Subject: Why won't this decorator work? In-Reply-To: <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <4E0F675F.2090209@tim.thechases.com> On 07/02/2011 01:08 PM, John Salerno wrote: > On Jul 2, 12:33 pm, MRAB wrote: >> roll_die = move(roll_die) >> >> You should be defining a function (a callable) and then passing it to a >> decorator which returns a callable. > > But why does the documentation say "The return value of the decorator > need not be callable"? I must not be looking at the same documentation you are...could you provide a link? The only time I know of that the return value of a decorator need not be callable is if you want to totally break the syntax of the function. :-/ > And why, if I remove the decorator and just leave the two > functions as if, does the call to move(roll_die()) work? Isn't > that what the decorator syntax is essentially doing? Are you doing move(roll_die()) #call roll_die() and pass results to move() or move(roll_die) # pass the function-object roll_die to move() ? The decorator syntax is the equivalent of roll_die = move(roll_die) -tkc From ian.g.kelly at gmail.com Sat Jul 2 14:49:15 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Jul 2011 12:49:15 -0600 Subject: Why won't this decorator work? In-Reply-To: <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: On Sat, Jul 2, 2011 at 12:08 PM, John Salerno wrote: > But why does the documentation say "The return value of the decorator > need not be callable"? Because the language does not enforce the restriction that the return value should be a callable. If it's not a callable, then the result will just be that something non-callable is bound to the "roll_die" name -- which could be useful, but is probably a bad idea in general. > And why, if I remove the decorator and just > leave the two functions as if, does the call to move(roll_die()) work? > Isn't that what the decorator syntax is essentially doing? No. The decorator syntax is doing: roll_die = move(roll_die) If you then call roll_die, that is equivalent to "move(roll_die)()", which is not the same thing as "move(roll_die())". Cheers, Ian From cbrown at cbrownsystems.com Sat Jul 2 15:16:36 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Sat, 2 Jul 2011 12:16:36 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: On Jul 2, 11:08?am, John Salerno wrote: > On Jul 2, 12:33?pm, MRAB wrote: > > > > > On 02/07/2011 17:56, John Salerno wrote: > > > > I thought I had finally grasped decorators, but the error I'm getting > > > ('str' type is not callable) is confusing me. > > > def move(roll): > > > return 'You moved to space {0}.'.format(roll) > > > A decorator should return a callable. Well, should typically return a callable, but there are exceptions... > > > This: > > > ? ? ?@move > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > is equivalent to this: > > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > ? ? ?roll_die = move(roll_die) > > > You should be defining a function (a callable) and then passing it to a > > decorator which returns a callable. > > > As it is, you're defining a function and then passing it to a decorator > > which is returning a string. Strings aren't callable. > > But why does the documentation say "The return value of the decorator > need not be callable"? Well, because it need not be callable: i.e., if the return value is not callable, that is perfectly legal. You very rarely want to return something else, but an example of this is the @property decorator: it returns a property object, which is not callable. > And why, if I remove the decorator and just > leave the two functions as if, does the call to move(roll_die()) work? > Isn't that what the decorator syntax is essentially doing? No; instead it's doing the similar looking but quite different move(roll_die)() As you wrote it, move(roll_die) returns the string 'You moved to space .' which is not callable. You typically want instead something like: def move(roll): # note that roll is a function, not a number def wrapper(): result = roll() print 'You moved to space {0}.'.format(result) return result return wrapper # which is a function Now move returns a callable (the function 'wrapper') so move(roll_die) is callable, and move(roll_die)() is legal. Cheers - Chas From cbrown at cbrownsystems.com Sat Jul 2 15:16:48 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Sat, 2 Jul 2011 12:16:48 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: On Jul 2, 11:08?am, John Salerno wrote: > On Jul 2, 12:33?pm, MRAB wrote: > > > > > On 02/07/2011 17:56, John Salerno wrote: > > > > I thought I had finally grasped decorators, but the error I'm getting > > > ('str' type is not callable) is confusing me. > > > def move(roll): > > > return 'You moved to space {0}.'.format(roll) > > > A decorator should return a callable. Well, should typically return a callable, but there are exceptions... > > > This: > > > ? ? ?@move > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > is equivalent to this: > > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > ? ? ?roll_die = move(roll_die) > > > You should be defining a function (a callable) and then passing it to a > > decorator which returns a callable. > > > As it is, you're defining a function and then passing it to a decorator > > which is returning a string. Strings aren't callable. > > But why does the documentation say "The return value of the decorator > need not be callable"? Well, because it need not be callable: i.e., if the return value is not callable, that is perfectly legal. You very rarely want to return something else, but an example of this is the @property decorator: it returns a property object, which is not callable. > And why, if I remove the decorator and just > leave the two functions as if, does the call to move(roll_die()) work? > Isn't that what the decorator syntax is essentially doing? No; instead it's doing the similar looking but quite different move(roll_die)() As you wrote it, move(roll_die) returns the string 'You moved to space .' which is not callable. You typically want instead something like: def move(roll): # note that roll is a function, not a number def wrapper(): result = roll() print 'You moved to space {0}.'.format(result) return result return wrapper # which is a function Now move returns a callable (the function 'wrapper') so move(roll_die) is callable, and move(roll_die)() is legal. Cheers - Chas From cbrown at cbrownsystems.com Sat Jul 2 15:17:04 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Sat, 2 Jul 2011 12:17:04 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <4df5c388-9e99-4b7d-93ec-968054f1871a@x38g2000pri.googlegroups.com> On Jul 2, 11:08?am, John Salerno wrote: > On Jul 2, 12:33?pm, MRAB wrote: > > > > > On 02/07/2011 17:56, John Salerno wrote: > > > > I thought I had finally grasped decorators, but the error I'm getting > > > ('str' type is not callable) is confusing me. > > > def move(roll): > > > return 'You moved to space {0}.'.format(roll) > > > A decorator should return a callable. Well, should typically return a callable, but there are exceptions... > > > This: > > > ? ? ?@move > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > is equivalent to this: > > > ? ? ?def roll_die(): > > ? ? ? ? ?return random.randint(1, 6) > > > ? ? ?roll_die = move(roll_die) > > > You should be defining a function (a callable) and then passing it to a > > decorator which returns a callable. > > > As it is, you're defining a function and then passing it to a decorator > > which is returning a string. Strings aren't callable. > > But why does the documentation say "The return value of the decorator > need not be callable"? Well, because it need not be callable: i.e., if the return value is not callable, that is perfectly legal. You very rarely want to return something else, but an example of this is the @property decorator: it returns a property object, which is not callable. > And why, if I remove the decorator and just > leave the two functions as if, does the call to move(roll_die()) work? > Isn't that what the decorator syntax is essentially doing? No; instead it's doing the similar looking but quite different move(roll_die)() As you wrote it, move(roll_die) returns the string 'You moved to space .' which is not callable. You typically want instead something like: def move(roll): # note that roll is a function, not a number def wrapper(): result = roll() print 'You moved to space {0}.'.format(result) return result return wrapper # which is a function Now move returns a callable (the function 'wrapper') so move(roll_die) is callable, and move(roll_die)() is legal. Cheers - Chas From drsalists at gmail.com Sat Jul 2 15:30:53 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jul 2011 12:30:53 -0700 Subject: poll of filesystem In-Reply-To: References: Message-ID: On Sat, Jul 2, 2011 at 2:40 AM, Belisko Marek wrote: > Hi, > > just want to use poll method to get data from /proc file system. Use > simple code for it. Problem is it seems poll return POLLIN flag but > when I try to read data it's always empty. Could be a problem changes > are so fast that print can't print it? > If you're wanting to watch when a file grows, you probably should just read in a loop. Not that this is likely what you need. If you're wanting to see when a file changes, you could detect mtime changes with os.stat. This isn't 100% precise, but it should be good enough for most uses of loadavg. Make sure to put a sleep in your loop, unless your loop is busy with other things already. Various non-portable solutions might be good ways to go for you, because /proc/loadavg isn't portable anyway. These include uevent, fanotify and perhaps inotify (there was apparently some discussion of removing the inotify /proc restriction a while back, not sure if anything happened with that). I'm not confident any or all of these will work, but if you're concerned about efficiency, you should explore them. If you don't care about efficiency much, the mtime thing is probably the way to go - there's little question that should work: python -c 'import os; print(os.stat("/proc/loadavg").st_mtime)' -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat Jul 2 15:52:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jul 2011 12:52:11 -0700 Subject: from module import * using __import__? Message-ID: Is there a decent way of running "from import *"? Perhaps using __import__? Does it mean using the copy module or adding an element to globals() somehow? Yes, I think I do have a good use for this: importing either pure python or cython versions of a module into a single namespace that can provide the same interface (transparent to the caller), whether C extension modules are viable in the current interpreter or not. So you have a stub module that provides one or the other, depending on availability and suitability. Related bit: I want it to pylint smoothly despite being in a python package, so I'd like to use normal import for the pure python, and __import__ (or similar) for the cython - where the pure python and cython are automatically generated from the same .m4 file, and the cython is attempted first, falling back on the pure python if there's an ImportError. I'd like to believe pylint is going to check the pure python this way, and ignore the fact that it often cannot import the cython. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Sat Jul 2 15:55:41 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 02 Jul 2011 21:55:41 +0200 Subject: How does CO_FUTURE_DIVISION compiler flag get propagated? References: Message-ID: <87wrg0wj7m.fsf@xemacs.org> Terry writes: > Future division ("from __future__ import division") works within > scripts executed by import or execfile(). However, it does not work > when entered interactively in the interpreter like this: > >>>> from __future__ import division >>>> a=2/3 Are you referring to the interactive interpreter normally invoked by just running "python"? That seems to work for me: Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 2/3 0 >>> from __future__ import division >>> 2/3 0.6666666666666666 From johnjsal at gmail.com Sat Jul 2 16:39:23 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 13:39:23 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: On Jul 2, 1:45?pm, Tim Chase wrote: > I must not be looking at the same documentation you are...could > you provide a link? The only time I know of that the return value > of a decorator need not be callable is if you want to totally > break the syntax of the function. :-/ http://docs.python.org/py3k/whatsnew/2.4.html?highlight=decorator Sort of around the middle of the PEP 318 section. But I think I understand now. I was thinking the decorator I made was creating move(roll_die()), which I see now that it is not. Perhaps a decorator isn't what I need in my case, although it seems like it might be. Basically what I want to do is this: I first to need to roll a die to get a random number, then pass that number to the move method of a Player class. Can this be done with a decorator, or is it better just to do it like move(roll_die()) and be done with it? From pavlovevidence at gmail.com Sat Jul 2 16:43:29 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 2 Jul 2011 13:43:29 -0700 (PDT) Subject: Nested/Sub Extensions in Python In-Reply-To: Message-ID: <4f8df99e-2d09-4845-8327-5f5c3012e952@glegroupsg2000goo.googlegroups.com> On Saturday, July 2, 2011 6:35:19 AM UTC-7, H Linux wrote: > On Jul 2, 2:28?am, Carl Banks > wrote: > > On Friday, July 1, 2011 1:02:15 PM UTC-7, H Linux wrote: > > > Once I try to nest this, I cannot get the module to load anymore: > > > >import smt.bar > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ImportError: No module named bar > > > > [snip] > > > > > PyMODINIT_FUNC > > > initbar(void) > > > { > > > ? ?Py_InitModule("smt.bar", bar_methods); > > > } > > > > This should be: Py_InitModule("bar", bar_methods); > > That's probably it; other than that, it looks like you did everything right. > Thanks for your help, but I actually tried both ways. This does not > seem to be the problem, as it fails both ways with identical error > message. Correct, I misspoke. The problem would be if the initbar function name was misspelled. > >?What does the installed file layout look like after running distutils setup? > Tree output is: > /usr/local/lib/python2.6/dist-packages/ > ??? foo.so > ??? smt > ??? ??? bar.so > ??? ??? __init__.py > ??? ??? __init__.pyc > ??? smt-0.1.egg-info > > Just in case anyone is willing to have a look, here is a link to the > complete module as built with: > python setup.py sdist: > https://docs.google.com/leaf?id=0Byt62fSE5VC5NTgxOTFkYzQtNzI3NC00OTUzLWI1NzMtNmJjN2E0ZTViZTJi&hl=en_US > > If anyone has any other ideas how to get it to work, thanks in > advance... I got and built the package, and it imported smt.bar just fine for me. So my advice would be to rename all the modules. My guess is that there is a conflict for smt and Python is importing some other module or package. Is there a file called smt.py in your working directory? Try doing this: import smt print smt.__file__ And see if it prints at the location where your smt module is installed. If not, you have a conflict. And if that is the problem, in the future be more careful to keep your module namespace clean. Choose good, distinct names for modules and packages to lessen the risk of conflict. Carl Banks From saqib.ali.75 at gmail.com Sat Jul 2 17:59:51 2011 From: saqib.ali.75 at gmail.com (Saqib Ali) Date: Sat, 2 Jul 2011 14:59:51 -0700 (PDT) Subject: Inexplicable behavior in simple example of a set in a class Message-ID: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> I have written two EXTREMELY simple python classes. One class (myClass1) contains a data attribute (myNum) that contains an integer. The other class (myClass2) contains a data attribute (mySet) that contains a set. I instantiate 2 instances of myClass1 (a & b). I then change the value of a.myNum. It works as expected. Then I instantiate 2 instances of myClass2 (c & d). I then change the value of c.mySet. Bizarrely changing the value of c.mySet also affects the value of d.mySet which I haven't touched at all!?!?! Can someone explain this very strange behavior to me? I can't understand it for the life of me. Please see below the source code as well as the output. -------------------------- SOURCE CODE ------------------------------ import sets class myClass1: myNum = 9 def clearNum(self): self.myNum = 0 def __str__(self): return str(self.myNum) class myClass2: mySet = sets.Set(range(1,10)) def clearSet(self): self.mySet.clear() def __str__(self): return str(len(self.mySet)) if __name__ == "__main__": # Experiment 1. Modifying values of member integers in two different instances of a class # Works as expected. a = myClass1() b = myClass1() print "a = %s" % str(a) print "b = %s" % str(b) print "a.clearNum()" a.clearNum() print "a = %s" % str(a) print "b = %s\n\n\n" % str(b) # Experiment 2. Modifying values of member sets in two different instances of a class # Fails Unexplicably. d is not being modified. Yet calling c.clearSet() seems to change d.mySet's value c = myClass2() d = myClass2() print "c = %s" % str(c) print "d = %s" % str(d) print "c.clearSet()" c.clearSet() print "c = %s" % str(c) print "d = %s" % str(d) -------------------------- OUTPUT ------------------------------ > python.exe myProg.py a = 9 b = 9 a.clearNum() a = 0 b = 9 c = 9 d = 9 c.clearSet() c = 0 d = 0 From clp2 at rebertia.com Sat Jul 2 18:14:02 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 2 Jul 2011 15:14:02 -0700 Subject: Inexplicable behavior in simple example of a set in a class In-Reply-To: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> Message-ID: On Sat, Jul 2, 2011 at 2:59 PM, Saqib Ali wrote: > Then I instantiate 2 instances of myClass2 (c & d). I then change the > value of c.mySet. Bizarrely changing the value of c.mySet also affects > the value of d.mySet which I haven't touched at all!?!?! Can someone > explain this very strange behavior to me? I can't understand it for > the life of me. > class myClass2: > > ? ?mySet = sets.Set(range(1,10)) > > ? ?def clearSet(self): > ? ? ? ?self.mySet.clear() > > ? ?def __str__(self): > ? ? ? ? ?return str(len(self.mySet)) Please read a tutorial on object-oriented programming in Python. The official one is pretty good: http://docs.python.org/tutorial/classes.html If you do, you'll find out that your class (as written) has mySet as a class (Java lingo: static) variable, *not* an instance variable; thus, it is shared by all instances of the class, and hence the behavior you observed. Instance variables are properly created in the __init__() initializer method, *not* directly in the class body. Your class would be correctly rewritten as: class MyClass2(object): def __init__(self): self.mySet = sets.Set(range(1,10)) def clearSet(self): # ...rest same as before... Cheers, Chris -- http://rebertia.com From __peter__ at web.de Sat Jul 2 18:22:32 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Jul 2011 00:22:32 +0200 Subject: Inexplicable behavior in simple example of a set in a class References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> Message-ID: Saqib Ali wrote: > > > I have written two EXTREMELY simple python classes. One class > (myClass1) contains a data attribute (myNum) that contains an integer. > The other class (myClass2) contains a data attribute (mySet) that > contains a set. > > I instantiate 2 instances of myClass1 (a & b). I then change the value > of a.myNum. It works as expected. self.value = new_value sets the attribute to a new value while self.value.modifying_method() keeps the old value (the object with the same id(object)), but changes the state of that old object. All variables bound to that object will "see" that internal change of state. As integers are "immutable" objects whose state cannot be changed you'll never observe the behaviour described below with them. > Then I instantiate 2 instances of myClass2 (c & d). I then change the > value of c.mySet. Bizarrely changing the value of c.mySet also affects > the value of d.mySet which I haven't touched at all!?!?! Can someone > explain this very strange behavior to me? I can't understand it for > the life of me. What you access as c.mySet or d.mySet is really myClass2.mySet, i. e. a class attribute and not an instance attribute. If you want a set per instance you have to create it in the __init__() method: >>> class MyClass: ... def __init__(self): ... self.my_set = set(range(10)) ... def clear_set(self): ... self.my_set.clear() ... >>> a = MyClass() >>> b = MyClass() >>> a.my_set.add(42) >>> a.my_set, b.my_set (set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 42]), set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])) >>> b.clear_set() >>> a.my_set, b.my_set (set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 42]), set([])) From saqib.ali.75 at gmail.com Sat Jul 2 18:23:16 2011 From: saqib.ali.75 at gmail.com (Saqib Ali) Date: Sat, 2 Jul 2011 15:23:16 -0700 (PDT) Subject: Inexplicable behavior in simple example of a set in a class References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> Message-ID: <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> > Instance variables are properly created in the __init__() > initializer method, *not* directly in the class body. > > Your class would be correctly rewritten as: > > class MyClass2(object): > ? ? def __init__(self): > ? ? ? ? self.mySet = sets.Set(range(1,10)) > > ? ? def clearSet(self): > # ...rest same as before... Thanks Chris. That was certainly very helpful!! So just out of curiosity, why does it work as I had expected when the member contains an integer, but not when the member contains a set? From ben+python at benfinney.id.au Sat Jul 2 18:36:47 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jul 2011 08:36:47 +1000 Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <87y60gjon4.fsf@benfinney.id.au> John Salerno writes: > Basically what I want to do is this: I first to need to roll a die to > get a random number, then pass that number to the move method of a > Player class. Can this be done with a decorator, or is it better just > to do it like move(roll_die()) and be done with it? If what you want can be expressed with ?player.move(roll_die())?, I'm confused as to why you think decorators would help. A decorator is syntactic sugar for something quite different:: @foo(spam, eggs) @bar def baz(beans): """ ? """ is equivalent to:: def baz(beans): """ ? """ baz = foo(spam, eggs)(bar(baz)) except in the first instance, the function defined never gets bound to the name ?baz? even temporarily. * The function ?baz? is defined, resulting in a function object. (In the first example, it is never bound to the name ?baz?.) * The expression ?bar? is evaluated, and the result (probably a function named ?bar?) is called with the function object defined as ?baz?; the return value should be a new function. * The expression ?foo(spam, eggs)? is evaluated, and the result (the return value from that function call) is itself called, passing the return value from the call to ?bar?. * Finally, the return value from all of that is bound to the name ?baz?. Note that, in both ways of writing that, ?baz? is never called, but instead the function object ?baz? is used as a parameter. Also, the original function defined as ?baz? is no longer accessible. That seems quite unrelated to your stated requirements. If you're not accustomed to passing function objects around as data, that can be difficult to wrap your head around; if you didn't know you needed it, you probably don't in this case. -- \ ?Jealousy: The theory that some other fellow has just as little | `\ taste.? ?Henry L. Mencken | _o__) | Ben Finney From timr at probo.com Sat Jul 2 18:37:55 2011 From: timr at probo.com (Tim Roberts) Date: Sat, 02 Jul 2011 15:37:55 -0700 Subject: poll of filesystem References: Message-ID: <487v0755lagsc7okn7fesp9f5l8ssvdch3@4ax.com> Belisko Marek wrote: > >just want to use poll method to get data from /proc file system. Use >simple code for it. Problem is it seems poll return POLLIN flag but >when I try to read data it's always empty. Could be a problem changes >are so fast that print can't print it? Poll doesn't make sense here. The data in /proc/loadavg data is not text data that gets updated periodically. There is no file on disk somewhere called /proc/loadavg. Instead, reading /proc/loadavg causes a call into a kernel driver, and reads data directly from variables stored in the kernel. The data is ALWAYS available. If you want the data once a second, just do it the easy way: import time while True: print open('/proc/loadavg').read() time.sleep(1) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rantingrick at gmail.com Sat Jul 2 18:59:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 15:59:18 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! Message-ID: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Hello fellow programmers, scripters, hackers, and debutantes. I have cross posted this thread to three groups that i believe need to unite under the flag of unity for the benefit of all. Because when we unite we not only help ourselves, we promote freedom. In the next few paragraphs i will expose the source of this problem and propose a viable solution for how WE can solve the problem! It saddens me when i see API's that don't include at least three language choices. No *one* language is going to please the masses. I understand *WHY* this happens however it should never, *EVER* happen and i cannot lay blame solely on application developers because "we" have failed to provide them NOT ONLY with a unifying API model, but also our respective "plugin" interfaces to that unifying model. Yes folks "WE" are to blame for this dilemma. Who is "we" exactly? "We" is any language community who's language exhibits the traits of an API scripting language. For me that group includes (at the minimum) Python, Ruby, Basic, Perl, JavaScript, and whoever else wants to be part of this group. Everyone knows that no one language can solve all problems. And likewise everyone knows that even when two languages are similar (in few ways, or in many ways) people are always going to draw lines in the sand and prefer to use one language over another. It is natural to simply ones working environment. How many of you folks speak English on Mondays and Mandarin on Tuesdays and Spanish on Wednesdays and French on Thursdays and Bulgarian on Fridays and Pig Latin on Saturdays and Orc on Sundays? Anyone? Why i am not surprised! But we do this very same asinine thing on a daily basis whist jumping through the productivity limiting hoops. The stench of which rises up from every community of language developers in the world. We have not only created a mutual cess pool of laziness and selfishness , we are wallowing and rooting around in it completely oblivious of our collectively bombastic stupidity. So i ask yous, why should we continue to propagate hateful feelings, or have some among us feel left out because their favorite language is not included as an alternative in the API they are using at the time? Why should i need to switch back and forth between multiple languages, multiple syntaxes, multiple editors, multiple help files, multiple API help files, and suffer multiple headaches just because the status quo is to be selfish and not care about the greater "Programming Community". "Community". Hmm, now that is a word that can be applied in many dimensions. The "Python Community" is a community that inherits from the "Programming Community"... as is the "Ruby Community" and the "JavaScript Community" and so on and so forth. We are naturally good at taking care of our immediate community but for the community once removed we are failing miserably! And this community is the most important community of all! When we damage the programming community we damage ourselves and everyone else! [Thought Exercise] Just imagine for a second if automobiles where engineered the way programming languages are currently engineered. But wait! Before we jump into insightful analyolgies we must first understand why the automobile is such a versatile feat of engineering. The automobile -- no matter how large or small, not matter if truck or car or motorcycle or moped-- is designed to interface with a system... the "highway" system. The user of an automobile is never restricted from driving his favorite car. He is always happy because he is free. Free to choose and free to be.... HOWEVER NOT THE CASE WITH APIs! For API's we have just tossed freedom to the wind fro the sake of selfishness. We would have multiple language developers creating languages without any regard for a language independent system to plug said language into. But i am here to tell you that we can be different with our language style and still promote the freedom to choose. The tool is NOT Ruby or Python or whatever. The tool is software which manifests itself as "ones" and "zeros". Layers of abstraction that all compile to the same base units... 1's and 0's. Languages are abstractions of ones and zeros. Languages are NOT tools. Therefore we all have a vested interest in a unifying API. Well some would say... " it is up to the developer of an application what language they choose"... and this is true. But i say they can choose to allow the users to choose thereby maintaining not only a happier user base, but a more productive one as well. When are we going to see the light and start unifying our collective differences into a singular plug and play API and allowing the user of "our" abstraction language, "our" for loop, or "our" version of stdout.write the ultimate of all choices... the choice of FREEDOM. for danish inspirations see: http://wiki.services.openoffice.org/wiki/Uno Thank You From clp2 at rebertia.com Sat Jul 2 19:25:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 2 Jul 2011 16:25:45 -0700 Subject: Inexplicable behavior in simple example of a set in a class In-Reply-To: <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> Message-ID: On Sat, Jul 2, 2011 at 3:23 PM, Saqib Ali wrote: >> Instance variables are properly created in the __init__() >> initializer method, *not* directly in the class body. >> >> Your class would be correctly rewritten as: >> >> class MyClass2(object): >> ? ? def __init__(self): >> ? ? ? ? self.mySet = sets.Set(range(1,10)) >> >> ? ? def clearSet(self): >> # ...rest same as before... > > > Thanks Chris. That was certainly very helpful!! > > So just out of curiosity, why does it work as I had expected when the > member contains an integer, but not when the member contains a set? To explain that, one must first understand that name lookup on an object looks in the following places, in order: 1. the instance itself 2. the instance's class 3. the instance's superclasses So, if we have: class Foo(object): bar = 7 foo_inst = Foo() then both `foo_inst.bar` and `Foo.bar` refer to the same value. However, if we then do: foo_inst.bar = 42 then we'll have: foo_inst.bar == 42 and Foo.bar == 7 Now back to your actual question. In clearNum(), you do: self.myNum = 0 which creates a *new* instance variable that shadows the class variable of the same name, like in my example. If you check, you'll indeed see that myClass1.myNum is still 9 after calling clearNum(). By contrast, in clearSet() you do: self.mySet.clear() which just mutates the existing Set object in-place. No new variable is created, and mySet is still a class variable and thus shared by all instances. Further reading: http://effbot.org/zone/python-objects.htm http://effbot.org/zone/call-by-object.htm Cheers, Chris -- http://rebertia.com From rosuav at gmail.com Sat Jul 2 19:38:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 09:38:17 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: I know I shouldn't get sucked into responding to a rant, but it's like a black hole - it's inevitable you'll cross the horizon... On Sun, Jul 3, 2011 at 8:59 AM, rantingrick wrote: > It saddens me when i see API's that don't include at least three > language choices. No *one* language is going to please the masses. This is pretty much the entire argument, everything else is exposition. It takes work to suit your API to a different language. Let's take GNU Aspell as an example; it's a good tool, and the ability to spell-check something is sufficiently general that many programs can make use of it. Its list of "supported languages" isn't what we're looking for, though (it lists Afrikaans, Greek, English, etc); from what I see, it supports only C++. Should the Aspell team offer bindings for every known language? In your post, you recommend supporting a minimum of three. Which three? Why? I'm a great fan of an obscure language named Pike. Do I expect Aspell to be available for Pike? No, and I wouldn't even if your three-language rule were followed. So how can I implement a spellchecker in my code? By writing glue. I'll write a module that exposes the C++ API to Pike. (This is actually a real example. I ended up writing my aspell hook to run as a separate process for isolation's sake, but it comes to the same thing.) Unless the world consolidates into a smaller number of languages, this is always going to be the case. You want the freedom to choose your language and your API separately? You HAVE that freedom - you just have to write your own glue. Glue-writing is a skill in the same way that UI-building is; learn to do it well and you can do it quickly. There's no need to demand that other people write your glue for you, because chances are they won't do as good a job as an expert in the language. C or C++ bindings will cover most languages. Chris Angelico From rantingrick at gmail.com Sat Jul 2 19:46:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 16:46:46 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: <0035fdc3-1d47-4bfc-999a-0ba2186fb7b8@t9g2000vbv.googlegroups.com> On Jul 2, 6:38?pm, Chris Angelico wrote: [... snip expositions...] > C or C++ bindings will cover most languages. > > Chris Angelico This is pretty much the entire argument, everything else is exposition. From twestley at gmail.com Sat Jul 2 20:07:02 2011 From: twestley at gmail.com (Terry) Date: Sat, 2 Jul 2011 17:07:02 -0700 (PDT) Subject: How does CO_FUTURE_DIVISION compiler flag get propagated? References: <87wrg0wj7m.fsf@xemacs.org> Message-ID: On Jul 2, 3:55?pm, Hrvoje Niksic wrote: > Terry writes: > > Future division ("from __future__ import division") works within > > scripts executed by import or execfile(). However, it does not work > > when entered interactively in the interpreter like this: > > >>>> from __future__ import division > >>>> a=2/3 > > Are you referring to the interactive interpreter normally invoked by > just running "python"? ?That seems to work for me: > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 2/3 > 0 > >>> from __future__ import division > >>> 2/3 > > 0.6666666666666666 Yes, that works for me on my Mac. The problem I'm having is in a Python interpreter that I built for the iPhone. It uses PyRun_SimpleString() to execute user entered commands. After you import future division, it does not seem to remember it on subsequent commands. From rantingrick at gmail.com Sat Jul 2 20:21:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 17:21:08 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: On Jul 2, 6:38?pm, Chris Angelico wrote: [...] > It takes work to suit your API to a different language. Let's take GNU > Aspell as an example; [...] Should the Aspell team offer bindings for every > known language? In your post, you recommend supporting a minimum of > three. Which three? Why? No. Aspell should offer bindings for THE "Unity API" and the respective "abstraction communities" are then responsible for maintaining a plugin for their "abstraction" into THE Unity API. > I'm a great fan of an obscure language named Pike. Do I expect Aspell > to be available for Pike? You should expect this. However if it is not available you cannot blame Aspell for that! No, you MUST blame the pike community. But first we have to blame EVERYONE because the unity API does not exist... not yet! Or at least the mindset for it does not exists. > No, and I wouldn't even if your > three-language rule were followed. My rule is for "unlimited unity" not "limited numbers". > So how can I implement a > spellchecker in my code? By writing glue. I'll write a module that > exposes the C++ API to Pike. (This is actually a real example. I ended > up writing my aspell hook to run as a separate process for isolation's > sake, but it comes to the same thing.) Yeah and they have a name for that... "reinventing the wheel". An end user should NEVER EVER have to write glue code so their "abstraction of choice" can be used to to script an API. That's like expecting automobile drivers to build a car from a hunk of iron ore every time! No, we have car manufactures who specialize in building cars. However the respective programming language communities are all oblivious to the greater picture. An iteration is an iteration whether you use the "for x in iterable: x.blah()" or the "iterable.each{|x| x.blah}" or WHATEVER syntax you choose to use. It all boils down to the same 1's and 0's. Can't you see how our own sense of selfish pride is defeating productivity and discovery? Can't you see? It's fine to speak French, or Japanese, or English if you want. But eventually we will need a unifying natural language and likewise a unifying programming language. [Note to community] Actually from now on i want everyone to stop using the words programming and language together. Instead of "X programming language" i want to you say "X abstraction layer". Python programming language --> Python abstraction layer. Ruby programming language --> Ruby abstraction layer. X programming language --> X abstraction layer. You see, we constantly refer to languages as tools, and this mindset is lunacy! All languages compile to 1's and 0's. Languages are not TOOLS they are all ABSTRACTIONS of a single virtual tool AND THAT TOOL IS SOFTWARE!). So stop brainwashing yourselves and others with these foolish descriptors! Begin to focus your mind on unity and standardization. Then and only then can we combine our singular minds into the hive mind. From rosuav at gmail.com Sat Jul 2 20:36:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 10:36:55 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 10:21 AM, rantingrick wrote: > No. Aspell should offer bindings for THE "Unity API" and the > respective "abstraction communities" are then responsible for > maintaining a plugin for their "abstraction" into THE Unity API. > Your proposed "Unity API" (which I assume has nothing to do with Natty Narwhal's preferred interface) already exists. It's the C language. It's an abstraction layer between CPython, Pike, etc, and the underlying hardware. The C standard library has a huge set of utility functions like strcmp, malloc, and so on; by writing your code in C, you simply enhance the C library. Language authors make use of this enhanced C library to write functions to be called from that language. And I don't *blame* the PIke community; since I'm a part of it, and I'm quite probably the only part of it to need/want Aspell, I just write the facilities I want. ChrisA From drsalists at gmail.com Sat Jul 2 20:37:31 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jul 2011 17:37:31 -0700 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: On Sat, Jul 2, 2011 at 5:21 PM, rantingrick wrote: > On Jul 2, 6:38 pm, Chris Angelico wrote: > [...] > > It takes work to suit your API to a different language. Let's take GNU > > Aspell as an example; [...] Should the Aspell team offer bindings for > every > > known language? In your post, you recommend supporting a minimum of > > three. Which three? Why? > > No. Aspell should offer bindings for THE "Unity API" and the > respective "abstraction communities" are then responsible for > maintaining a plugin for their "abstraction" into THE Unity API. > Adding a new API is seldom the way to decrease the number of API's. At least, not without -=very=- centralized control over which API's get used. I actually rather like it that no language has achieved the dominance today that C once enjoyed, rightly or wrongly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jul 2 20:46:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 10:46:02 +1000 Subject: Inexplicable behavior in simple example of a set in a class In-Reply-To: <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: > So just out of curiosity, why does it work as I had expected when the > member contains an integer, but not when the member contains a set? It's not integer vs set; it's the difference between rebinding and calling a method. It's nothing to do with object orientation; the same happens with ordinary variables: >>> a=b=1 >>> a,b (1, 1) >>> a=2 >>> a,b (2, 1) >>> c=d=[] >>> c,d ({}, []) >>> c.append("Test") >>> c,d (['Test'], ['Test']) But: >>> c=['Foobar'] >>> c,d (['Foobar'], ['Test']) When you do a=2 or c=['Foobar'], you're rebinding the name to a new object. But c.append() changes that object, so it changes it regardless of which name you look for it by. Chris Angelico From rantingrick at gmail.com Sat Jul 2 20:58:33 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 17:58:33 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> Take Pidgin[1] as an example. Pidgin is a universal chat client. It's a glue between the many chat clients that exist... It's a monkey patch for chat multiplicity but you get the idea. However the Unity API cannot be a monkey patch. It must be a mutual undertaking from the beginning. Don't you people understand? Multiplicity is undermining our future evolution. [Anecdote] Once when i was a very young lad (long before computers were mainstream) i became terribly troubled by the fact that every generation must spend roughly a quarter of it's lifetime just catching up to the knowledge of the last generation. This fact does not seem very troublesome at first glance, but lets create a microcosm... ...what if you suffered from amnesia every morning and you had to spend 1/4 of the day catching up to where you were the day before? This would kill your productivity! But that is not the point i am making here folks! <\back on track> The fact that we constantly re-invent the wheel is a product of a very important missing feature of most humans of which is devastating to our evolution as intelligent agents. [The Punchline] Anyway, my solution to this collective "re-education" was the upload. We could simply plug up, upload all former knowledge, and off we'd go! [The Knockout] However when i shared my solution with someone [unnamed] he laughed and said: "But that would take the challenge out of life. Nothing remaining to learn if you can just download it"... aghast with horror i just shook my head. This person had no imagination! [The Moral] Stop being sheep and start the revolution people! Stop being slaves to multiplicity and be the master of the singularity. Our future (or lack thereof) is in YOUR hands! [1] http://www.pidgin.im/ From clp2 at rebertia.com Sat Jul 2 21:07:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 2 Jul 2011 18:07:49 -0700 Subject: Inexplicable behavior in simple example of a set in a class In-Reply-To: References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> Message-ID: On Sat, Jul 2, 2011 at 5:46 PM, Chris Angelico wrote: > On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: >> So just out of curiosity, why does it work as I had expected when the >> member contains an integer, but not when the member contains a set? > > It's not integer vs set; it's the difference between rebinding and > calling a method. It's nothing to do with object orientation; the same > happens with ordinary variables: >>>> c=d=[] >>>> c,d > ({}, []) Nasty typo in your pseudo-interpreter-session there... Cheers, Chris From python.list at tim.thechases.com Sat Jul 2 21:09:53 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 02 Jul 2011 20:09:53 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <0035fdc3-1d47-4bfc-999a-0ba2186fb7b8@t9g2000vbv.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <0035fdc3-1d47-4bfc-999a-0ba2186fb7b8@t9g2000vbv.googlegroups.com> Message-ID: <4E0FC161.9020105@tim.thechases.com> On 07/02/2011 06:46 PM, rantingrick wrote: > On Jul 2, 6:38 pm, Chris Angelico wrote: >>> It saddens me when i see API's that don't include at least three >>> language choices. No *one* language is going to please the masses. >> >> C or C++ bindings will cover most languages. > > This is pretty much the entire argument, everything else is > exposition. So you've got 3 interfaces: C, C++, and for the die-hards, Assembly. Sounds like you should be happy then ;-) (what? they weren't *your* top-3 language choices?) -tkc One API to rule them all, One API to find them, One API to bring them all and in the darkness create bindings for them? From rosuav at gmail.com Sat Jul 2 21:12:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 11:12:27 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 10:58 AM, rantingrick wrote: > > Take Pidgin[1] as an example. Pidgin is a universal chat client. It's > a glue between the many chat clients that exist... It's a monkey patch > for chat multiplicity but you get the idea. However the Unity API > cannot be a monkey patch. It must be a mutual undertaking from the > beginning. Don't you people understand? Multiplicity is undermining > our future evolution. It's protocol glue, not programming code glue. There's a difference; Pidgin replaces "chat client X", rather than piggybacking onto it. Proliferation of code layers results in a performance penalty that proliferation of chat clients doesn't. However, there is still a parallel. Any universal protocol will suffer either from complexity or narrowness - some suffer from both. If every API has to go through this Unity API, then either Unity will be as powerful and complex as C with all its libraries, or it'll overly restrict things. That's why Unity is really just C. ChrisA From rosuav at gmail.com Sat Jul 2 21:14:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 11:14:01 +1000 Subject: Inexplicable behavior in simple example of a set in a class In-Reply-To: References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 11:07 AM, Chris Rebert wrote: >>>>> c,d >> ({}, []) > > Nasty typo in your pseudo-interpreter-session there... Whoops! This is what I get for trying to be too smart! >>> c,d ([], []) Thanks for catching that, Chris. :) (another) Chris From dustin299 at gmail.com Sat Jul 2 21:21:03 2011 From: dustin299 at gmail.com (Dustin Cheung) Date: Sat, 2 Jul 2011 18:21:03 -0700 Subject: web browsing short cut Message-ID: Hey guys, I am new to python. I want to make a shortcut that opens my websites and re-sizes them to display on different areas on the screen. I looked around but i had no luck. Is that possible with python? if so can someone point to to the right direction? Here is what I came up with so far.. Thanks in advance, -------------------------------------------------------------------------------------------------------------- import webbrowser # The websites i want to open.. url1 = 'http://www.python.org/' url2 = 'http://www.google.com/' url3 = 'http://msn.com/' # the path to ie ie = webbrowser.get('c:\\program files\\internet explorer\\iexplore.exe') ie.open(url1) ie.open(url2) ie.open(url3) -- Dustin -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sat Jul 2 21:43:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 18:43:14 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> Message-ID: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> On Jul 2, 8:12?pm, Chris Angelico wrote: > Any universal protocol will suffer either from complexity or > narrowness - some suffer from both. If every API has to go through > this Unity API, then either Unity will be as powerful and complex as C > with all its libraries, or it'll overly restrict things. That's why > Unity is really just C. Well i never said we could not just use c of course. I'm trying to lubricate the imagination here :). However you have to convince the application devs of that. Most just create bindings for a well known language like Python or Ruby and call it a day. However some idiots go as far as writing their own mini language (Audacity comes to mind!) and we cannot allow this to happen! The same problem exists in GUI's. Why the hell is there so many GUI libraries? How many different label widgets do we need to re-invent? It's ludicrous! Okay somebody might argue that we cannot just have one because it would be too large. WHAT! Again imagination is the missing link here. There is a simple solution... it's called "from GUI import subset.x.y.z"! I mean what is the point of having two languages with the exact same syntax? Ruby: print 'blah' Python: print 'blah' Ruby: for x in blah: blah_blah_blah Python: for x in blah: blah_blah_blah WHAT? This multiplicity reminds me of a beginning CS student code: def add(1,2): return 1+2 def add(3,4): return 3+4 def ... Instead of: def add(x, y); return x+y asinine! Devs preach of code re-use but they propagate multiplicity in their language design. Sadly we are still in the stone age of programming and i don't know if i'll live long enough to see a real revolution. People are waiting in breads lines all day but do not consider why? (or they are too afraid to ask). From rosuav at gmail.com Sat Jul 2 21:49:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 11:49:28 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 11:43 AM, rantingrick wrote: > I mean what is the point of having two languages with the exact same > syntax? > > Ruby: print 'blah' > Python: print 'blah' > > Ruby: for x in blah: blah_blah_blah > Python: for x in blah: blah_blah_blah > > WHAT? > What's the point of having fifty languages in which "x+y" is an expression whose value is the sum of x and y? Let's ditch 'em all and just use one language, since _obviously_ the languages have the exact same syntax. Common syntax is an aid to learning. It means you can transfer knowledge from one language to another. It doesn't make either useless. Chris Angelico From rantingrick at gmail.com Sat Jul 2 22:08:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 19:08:07 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: <0ebac153-0e0d-49fd-96c0-af9f40fbf222@q1g2000vbj.googlegroups.com> > On Sat, Jul 2, 2011 at 7:37 PM, Dan Stromberg wrote: > > Adding a new API is seldom the way to decrease the number of API's. > At least, not without -=very=- centralized control over which API's > get used. > > I actually rather like it that no language has achieved the > dominance today that C once enjoyed, rightly or wrongly. You make a good point Dan! Like of most of my threads this one is evolving into something deeper and more profound. Like i recently pointed out in my last post we have many languages that are just slightly different (and sometimes spitting images) of others. For example Python and Ruby share some very close similarities. Of course they share many differences also but the point is we are duplicating too much methodology in our language designs. You make the argument that C is really all you need. And i whole hearty agree however you must also agree that there is a great need for Python and Ruby type languages. Languages that are much more user friendly than C and don't require memory management. Remember, most API users are not always CS majors. C is not beyond the scope of any normal functioning human being however it does require not only a steeper learning curve but caution whilst wielding it. I mean who wants a seg fault when scripting Open Office, or how about writing a page of boilerplate for what amounts to a half page script? For me the ideal situation we could have is a unity of all the high level languages. Dump all the repeated syntax's and try to compile the best of all into as few "scripting langages" as possible. Of we can do it in one GREAT, if not three or so sounds about correct. Then these "cream of the crop" could be integrated tightly with extension writing. So that you could start at the scripting level and move down as needed for speed and low level stuff when needed. But we need the application devs to take part or the whole house of cards comes tumbling down. And how do you motivate people to use a certain API. Simplicity is one way, peer pressure is another, bulling when necessarily can help. Whatever it takes because we all have a vested interest in unity. We must start the ball rolling.Continuing to propagate selfishness is a self defeating process. If you build it they will come! From clp2 at rebertia.com Sat Jul 2 22:10:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 2 Jul 2011 19:10:26 -0700 Subject: web browsing short cut In-Reply-To: References: Message-ID: On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung wrote: > Hey guys, > I am new to python. I want to make a shortcut that opens my websites > and?re-sizes?them to ?display on different areas on the screen. I looked > around but i had no luck. Is that possible with python? if so can someone > point to to the right direction? Here is what I came up with so far.. The window positioning+resizing bit will likely require using platform-specific APIs. Since you appear to be on Windows, the relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 ). You would use it to invoke some COM API that does window positioning+resizing. I am unable to give more details as I'm on a Mac. Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? Cheers, Chris From steve+comp.lang.python at pearwood.info Sat Jul 2 22:11:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2011 12:11:43 +1000 Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <4e0fcfdf$0$29969$c3e8da3$5496439d@news.astraweb.com> John Salerno wrote: > But why does the documentation say "The return value of the decorator > need not be callable"? The thing returned by a decorator does not need to be callable, but if you want to call it, then it better be! This is no different from this: my_func = "hello world" my_func() # fails because strings aren't callable So if I do this: def decorator(func): # ignores the function and returns a string return "hello world" @decorator def my_func(): x = 1 y = 2 return x+y print(my_func) # prints "hello world" my_func() # fails because strings aren't callable If that's useful to you, decorator syntax allows it. That is all the documentation means. > And why, if I remove the decorator and just > leave the two functions as if, does the call to move(roll_die()) work? > Isn't that what the decorator syntax is essentially doing? The call move(roll_die()) is similar to this: temp = roll_die() my_string = move(temp) which is perfectly fine, because you never call my_string. If you did, you'd get the same error, because strings aren't callable. The decorator syntax is completely different. It is doing this: # replace the function roll_die with the output of move, which is a string roll_die = move(roll_die) # now try to call "roll_die", actually a string roll_die() which is more like: move(roll_die)() See the difference? -- Steven From johnjsal at gmail.com Sat Jul 2 22:14:59 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 19:14:59 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> <4e0fcfdf$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 2, 9:11?pm, Steven D'Aprano wrote: > John Salerno wrote: > > But why does the documentation say "The return value of the decorator > > need not be callable"? > > The thing returned by a decorator does not need to be callable, but if you > want to call it, then it better be! > > This is no different from this: > > my_func = "hello world" > my_func() ?# fails because strings aren't callable > > So if I do this: > > def decorator(func): > ? ? # ignores the function and returns a string > ? ? return "hello world" > > @decorator > def my_func(): > ? ? x = 1 > ? ? y = 2 > ? ? return x+y > > print(my_func) ?# prints "hello world" > my_func() ?# fails because strings aren't callable > > If that's useful to you, decorator syntax allows it. That is all the > documentation means. > > > And why, if I remove the decorator and just > > leave the two functions as if, does the call to move(roll_die()) work? > > Isn't that what the decorator syntax is essentially doing? > > The call move(roll_die()) is similar to this: > > temp = roll_die() > my_string = move(temp) > > which is perfectly fine, because you never call my_string. If you did, you'd > get the same error, because strings aren't callable. > > The decorator syntax is completely different. It is doing this: > > # replace the function roll_die with the output of move, which is a string > roll_die = move(roll_die) ? > # now try to call "roll_die", actually a string > roll_die() > > which is more like: > > move(roll_die)() > > See the difference? > > -- > Steven Eesh, ok, I think I *still* don't quite get decorators, but I get it a little more now. Definitely not what I needed to do here. :) From johnjsal at gmail.com Sat Jul 2 22:19:43 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 19:19:43 -0700 (PDT) Subject: Anyone want to critique this program? Message-ID: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> Just thought I'd post this in the event anyone has a few spare minutes and feels like tearing apart a fairly simple attempt to write a game. :) I'll paste the exercise I was working on first, although I think it was meant to be an exercise in how to use lists. I went way beyond that, so maybe my program is overly complicated. It works, though, so that's a plus! The main questions I had about it are at the bottom, after the code. ---------- Snakes and Ladders can be a fun game for kids to play but you realize when you get older that the players actually have no choices at all. To illustrate just how little input the players have I want you to make a computer program that allows two players to play snakes and ladders on the board given. The rules of the game are simple. On each player's turn they roll one six sided die and move ahead that many squares. If they end their move at the base of a ladder then they automatically climb to the top of the ladder. If they end their move at the end of a snake they automatically slide down to its head. To win the game you must be the first player to land on the last square. If you are near the end and your roll would cause you to go past the end square you don't move for that turn. Your computerized version will look something like: Player 1 hit enter to roll You rolled: 3 You are at spot 3 Player 2 hit enter to roll You rolled: 6 You climbed a ladder You are at spot 17 although you can write this program without using lists, you should ask yourself how you can use lists to encode where the snakes and ladders are. ----------------- (I changed snakes to chutes, and I didn't paste in the game board picture. Just trust that the dictionary of lists in the beginning of the program is accurate, and that each set of numbers represents first the space you land on, and second the space you slide or climb to, e.g. [30, 35] means you landed on 30, and as a result of landing on a ladder space, you climbed up to space 35.) ------------------------------- import random game_information = '***Chutes and Ladders***\nUp to four (4) players may play.\n'\ 'There are 90 spaces on the board. '\ 'The player to reach space 90 first wins.' separator = '-' * 20 spaces = [None] * 90 c_l_spaces = {r'slid down a chute \\': [[14, 3], [20, 15], [39, 33], [66, 53], [69, 58], [79, 67], [84, 71], [88, 36]], 'climbed up a ladder |=|': [[6, 17], [24, 26], [30, 44], [49, 62], [82, 86]]} class Player: def __init__(self, number): self.number = number self.space = 0 def move(self, roll): global spaces if (self.space + roll) > 90: return (1, 'Your roll would move you off the game board. '\ 'You remain at space {0}.'.format(self.space)) elif (self.space + roll) == 90: return (0, 'You moved to the last space. You won the game!') else: self.space += roll try: space_type = spaces[self.space - 1][0] self.space = spaces[self.space - 1][1] except TypeError: return (1, 'You moved to space {0}.'.format(self.space)) else: return (1, 'You {0} to space {1}!'.format(space_type, self.space)) def roll_die(): roll = random.randint(1, 6) print('You rolled {0}.'.format(roll)) return roll def populate_game_board(): global spaces for key, values in c_l_spaces.items(): for space in values: spaces[space[0] - 1] = [key, space[1]] def initialize_players(): while True: try: num_players = int(input('Enter the number of players (0 to exit): ')) except ValueError: print('You have entered an invalid response.\n') else: if num_players == 0: print('You have quit the game.') return elif 1 <= num_players <= 4: break elif (num_players < 0) or (num_players > 4): print('You have entered an invalid number of players. \n') players = [] for num in range(num_players): players.append(Player(num + 1)) return players def start_game(players): game = 1 while game: for player in players: print('\n***Player {0}***'.format(player.number)) print('You are currently on space {0}.'.format(player.space)) game_update = player.move(roll_die()) print(game_update[1]) print(separator, end='') if game_update[0] == 0: game = 0 break if game: input('\nPress Enter for the next turn.') def initialize_game(): global game_information print(game_information) players = initialize_players() if players: populate_game_board() start_game(players) if __name__ == '__main__': initialize_game() -------------------------- My questions: 1. Are the functions I made necessary? Do they do enough or too much? 2. Is there a better way to implement the players than as a class? 3. Is there a better way to handle all the print calls that the program makes? 4. Are my try/except blocks used appropriately? Any other comments would be appreciated too! Thanks! From rantingrick at gmail.com Sat Jul 2 22:24:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 19:24:14 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: On Jul 2, 8:49?pm, Chris Angelico wrote: > On Sun, Jul 3, 2011 at 11:43 AM, rantingrick wrote: > > I mean what is the point of having two languages with the exact same > > syntax? > > > Ruby: print 'blah' > > Python: print 'blah' > > > Ruby: for x in blah: blah_blah_blah > > Python: for x in blah: blah_blah_blah > > > WHAT? > > What's the point of having fifty languages in which "x+y" is an > expression whose value is the sum of x and y? Let's ditch 'em all and > just use one language, since _obviously_ the languages have the exact > same syntax. It seem ludicrous at first glance but it is true! We have to much re- inventing going on! > Common syntax is an aid to learning. It means you can transfer > knowledge from one language to another. It doesn't make either > useless. Why do you constantly propagate multiplicity? Why do you feel that we need 100 or so languages when about three would cover everything? Sure people are free to create whatever Frankenstein language they want in the confines of their hobby time, but we need standards and we need them NOW. We want the world and we want it now! http://www.youtube.com/watch?v=xkp8fNODegU&feature=player_detailpage#t=472s From steve+comp.lang.python at pearwood.info Sat Jul 2 22:25:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2011 12:25:29 +1000 Subject: Inexplicable behavior in simple example of a set in a class References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> Message-ID: <4e0fd31a$0$29983$c3e8da3$5496439d@news.astraweb.com> Saqib Ali wrote: > I have written two EXTREMELY simple python classes. One class > (myClass1) contains a data attribute (myNum) that contains an integer. > The other class (myClass2) contains a data attribute (mySet) that > contains a set. > > I instantiate 2 instances of myClass1 (a & b). I then change the value > of a.myNum. It works as expected. > > Then I instantiate 2 instances of myClass2 (c & d). I then change the > value of c.mySet. Bizarrely changing the value of c.mySet also affects > the value of d.mySet which I haven't touched at all!?!?! But that is wrong -- you HAVE touched it. Look carefully: in myClass2, you have this: class myClass2: mySet = sets.Set(range(1,10)) def clearSet(self): self.mySet.clear() mySet is a class attribute, shared by ALL instances, and mySet.clear() modifies it in place. This is exactly the same as this snippet: >>> a = set([1, 2, 3]) >>> b = a >>> b.clear() >>> a set([]) >>> b set([]) In Python, attributes assigned in the class scope are shared between all instances. Attributes assigned directly on self are not: class Test: a = set([1, 2, 3]) def __init__(self): self.b = set([1, 2, 3]) >>> x = Test() >>> y = Test() >>> x.a is y.a # The same set is shared by both instances. True >>> x.b is y.b # Each instance gets its own set. False So why does myClass1 behave differently? Simple: look at the clear method: class myClass1: myNum = 9 def clearNum(self): self.myNum = 0 It assigns a new attribute, rather than modifying the object in place! Assignment to self.myNum creates a new unshared attribute: >>> z = myClass1() >>> z.myNum 9 >>> z.__dict__ # No instance attributes yet. {} >>> z.clearNum() >>> z.__dict__ # Now there is one. {'myNum': 0} >>> z.__class__.myNum # the class attribute still exists 9 The simplest way to fix this is to move the declaration of self.mySet into the __init__ method. -- Steven From rosuav at gmail.com Sat Jul 2 23:02:46 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 13:02:46 +1000 Subject: Anyone want to critique this program? In-Reply-To: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 12:19 PM, John Salerno wrote: > Just thought I'd post this in the event anyone has a few spare minutes > and feels like tearing apart a fairly simple attempt to write a > game. :) Sure! You seem to comprehend the basics, which is an order of magnitude better than some people I've tried to help... > game_information = '***Chutes and Ladders***\nUp to four (4) players > may play.\n'\ > ? ? ? ? ? ? ? ? ? 'There are 90 spaces on the board. '\ > ? ? ? ? ? ? ? ? ? 'The player to reach space 90 first wins.' I'd do this with a triple-quoted string - it'll simply go across multiple lines: game_information = """***Chutes and Ladders*** Up to four (4) players may play. There are 90 spaces on the board. The player to reach space 90 first wins.""" > c_l_spaces = {r'slid down a chute \\': [[14, 3], [20, 15], [39, 33], > [66, 53], > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[69, 58], [79, 67], [84, 71], [88, > 36]], > ? ? ? ? ? ? ?'climbed up a ladder |=|': [[6, 17], [24, 26], [30, 44], > [49, 62], [82, 86]]} It strikes me that this plus populate_game_board() is a little redundant; you could simply have the target dictionary as a literal: spaces={14:3, 20:15, ........ 6:17, 24:26} You can get the description "climbed up a ladder" or "slid down a chute" by seeing if spaces[space] is more or less than space. > ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ?space_type = spaces[self.space - 1][0] > ? ? ? ? ? ? ? ?self.space = spaces[self.space - 1][1] > ? ? ? ? ? ?except TypeError: > ? ? ? ? ? ? ? ?return (1, 'You moved to space > {0}.'.format(self.space)) > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?return (1, 'You {0} to space {1}!'.format(space_type, > self.space)) It strikes me as odd to use try/except/else for what's non-exceptional. I'd either use a regular if block, or possibly something completely different - like having a list like this: spaces=list(range(91)) # get a list [0, 1, 2, 3... 90] And then set the entries that have chutes/ladders, possibly from your original dict of lists (or something like it): for space in values: spaces[space[0]] = space[1] Then to see where you end up, just go: try: space=spaces[space] except ValueError: print("That would take you past the end of the board!") In this instance, except is being used for the exceptional condition, the case where you blow past the edge of the board - rather than the more normal situation of simply not hitting a chute/ladder. > ? ?players = [] > ? ?for num in range(num_players): > ? ? ? ?players.append(Player(num + 1)) Generally, anything that looks like this can become a list comprehension. It'll be faster (which won't matter here), and briefer. players = [Player(num+1) for num in range(num_players)] > def start_game(players): > > def initialize_game(): > ? ? ? ?start_game(players) > > if __name__ == '__main__': > ? ?initialize_game() start_game() would be more accurately called play_game(), since it doesn't return till the game's over. And it's a little odd that initialize_game() doesn't return till the game's over; I'd be inclined to have initialize_game() return after initializing, and then have the main routine subsequently call start_game() / play_game(). Just a minor naming issue! > 1. Are the functions I made necessary? Do they do enough or too much? For the most part, I would say your functions are fine. > 2. Is there a better way to implement the players than as a class? Better way? Hard to know. There are many ways things can be done, but the way you've chosen is as good as any. Certainly it's good enough for the task you're doing. > 3. Is there a better way to handle all the print calls that the > program makes? Again, I think it's fine. There's a general philosophy of separating "guts" from "interface" (which would mean isolating all the print statements from the game logic of moving pieces around), but in something this small, the only reason to do that is for the sake of practice. There's not much to be gained in small programs from fifty levels of indirection. > 4. Are my try/except blocks used appropriately? This is the one place where I'd recommend change. Use try/except to catch exceptional situations, not normalities. If your code is going through the except block most of the time, there's probably something wrong. Note I don't say there IS something wrong; it's an example of code smell, and can be correct. Your code has much in its favour. I've been wordy in suggestions but that doesn't mean you have bad code! :) Chris Angelico From crebert at ucsd.edu Sat Jul 2 23:08:11 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Sat, 2 Jul 2011 20:08:11 -0700 Subject: web browsing short cut In-Reply-To: References: Message-ID: > On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert wrote: >> On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung wrote: >> > Hey guys, >> > I am new to python. I want to make a shortcut that opens my websites >> > and?re-sizes?them to >> > point to to the right direction? Here is what I came up with so far.. >> >> The window positioning+resizing bit will likely require using >> platform-specific APIs. Since you appear to be on Windows, the >> relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 >> ). You would use it to invoke some COM API that does window >> positioning+resizing. I am unable to give more details as I'm on a >> Mac. >> >> Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? On Sat, Jul 2, 2011 at 7:34 PM, Dustin Cheung wrote: > Hey, > Thanks for showing me to pywin32. I'll look into it and see what i can come > up with. Also, I?haven't?tried the?Firefox?feature. I thought the bookmark > all feature only saved one browser with multiple tabs. Correct. I don't know your precise use-case and thought that this could possibly be sufficient but significantly less complicated. > I'm sorry but this > might be a stupid question but was do you mean by COM API? COM as in: http://en.wikipedia.org/wiki/Component_Object_Model API as in a programming interface: http://en.wikipedia.org/wiki/Application_programming_interface It's my understanding that most Windows GUI automation stuff tends to involve using COM. Again, I don't know specifics, I've just followed other Windows-specific posts on the mailinglist. Cheers, Chris From rosuav at gmail.com Sat Jul 2 23:14:46 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 13:14:46 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 12:24 PM, rantingrick wrote: > Why do you constantly propagate multiplicity? Why do you feel that we > need 100 or so languages when about three would cover everything? Sure > people are free to create whatever Frankenstein language they want in > the confines of their hobby time, but we need standards and we need > them NOW. > I specced up "the perfect language" a while ago. It gave you a clean slate with no facilities but one: Define Operator. Then you define whatever you want - let's say you start by defining = as assignment. Give it a precedence and associativity, mark it as binary, and start using it. Now, define + the same way, and -, and so on. Let's define the letter 'd' as an operator - a binary or unary operator, such that '2d6' means 'roll two six-sided dice, return the sum' (and unary 'd20' is equivalent to binary '1d20'). What's wrong with this language? It doesn't do anything, and it does everything. You could use the language for one thing and I use it for another thing. There is NO connection. We may as well be using different languages. You could have three languages in the world, if one is assembly language (for the one chip that everyone uses), one is this clean-slate language, and one is C. Have we improved anything? No. It won't be any easier to write an API for something; and it'll be a lot harder to maintain code ("wait wha? This programmer's defined + and * in opposite precedence to usual!"). But hey, there's only one language that you need to learn! Chris Angelico From steve+comp.lang.python at pearwood.info Sat Jul 2 23:21:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2011 13:21:34 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: <4e0fe03f$0$29972$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > Hello fellow programmers, scripters, hackers, and debutantes. Your ideas are intriguing to me and I wish to subscribe to your newsletter. -- Steven From johnjsal at gmail.com Sat Jul 2 23:41:48 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 2 Jul 2011 20:41:48 -0700 (PDT) Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> Message-ID: <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> On Jul 2, 10:02?pm, Chris Angelico wrote: > > game_information = '***Chutes and Ladders***\nUp to four (4) players > > may play.\n'\ > > ? ? ? ? ? ? ? ? ? 'There are 90 spaces on the board. '\ > > ? ? ? ? ? ? ? ? ? 'The player to reach space 90 first wins.' > > I'd do this with a triple-quoted string - it'll simply go across multiple lines: > game_information = """***Chutes and Ladders*** > Up to four (4) players may play. > There are 90 spaces on the board. > The player to reach space 90 first wins.""" Yeah, I considered that, but I just hate the way it looks when the line wraps around to the left margin. I wanted to line it all up under the opening quotation mark. The wrapping may not be as much of an issue when assigning a variable like this, but I especially don't like triple-quoted strings that wrap around inside function definitions. That seems to completely throw off the indentation. Do people still use triple-quotes in that situation? > > c_l_spaces = {r'slid down a chute \\': [[14, 3], [20, 15], [39, 33], > > [66, 53], > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[69, 58], [79, 67], [84, 71], [88, > > 36]], > > ? ? ? ? ? ? ?'climbed up a ladder |=|': [[6, 17], [24, 26], [30, 44], > > [49, 62], [82, 86]]} > > It strikes me that this plus populate_game_board() is a little > redundant; you could simply have the target dictionary as a literal: > > spaces={14:3, 20:15, ........ 6:17, 24:26} > > You can get the description "climbed up a ladder" or "slid down a > chute" by seeing if spaces[space] is more or less than space. Hmm, interesting. I'm not quite sure how I'd implement that yet, but the "14:3" structure seems cleaner (although I admit at first it looked weird, because I'm used to seeing strings as dictionary keywords!). > > ? ? ? ? ? ?try: > > ? ? ? ? ? ? ? ?space_type = spaces[self.space - 1][0] > > ? ? ? ? ? ? ? ?self.space = spaces[self.space - 1][1] > > ? ? ? ? ? ?except TypeError: > > ? ? ? ? ? ? ? ?return (1, 'You moved to space > > {0}.'.format(self.space)) > > ? ? ? ? ? ?else: > > ? ? ? ? ? ? ? ?return (1, 'You {0} to space {1}!'.format(space_type, > > self.space)) > > It strikes me as odd to use try/except/else for what's > non-exceptional. I'd either use a regular if block, or possibly > something completely different - like having a list like this: > > spaces=list(range(91)) # get a list [0, 1, 2, 3... 90] > > And then set the entries that have chutes/ladders, possibly from your > original dict of lists (or something like it): > > for space in values: > ? spaces[space[0]] = space[1] > > Then to see where you end up, just go: > try: > ? space=spaces[space] > except ValueError: > ? print("That would take you past the end of the board!") > > In this instance, except is being used for the exceptional condition, > the case where you blow past the edge of the board - rather than the > more normal situation of simply not hitting a chute/ladder. Originally I didn't have the try/except at all, I had nested if statements that seemed to be getting out of control. Then I realized if I just attempted to index the list and handle the exception, rather than check first if indexing the list was allowed, the code came out cleaner looking. But I agree with you, my "exception" is actually the more frequent occurrence, so I'm going to change that. > > ? ?players = [] > > ? ?for num in range(num_players): > > ? ? ? ?players.append(Player(num + 1)) > > Generally, anything that looks like this can become a list > comprehension. It'll be faster (which won't matter here), and briefer. > > players = [Player(num+1) for num in range(num_players)] Now this is the kind of tip I love. Something like list comprehensions just didn't even occur to me, so I'm definitely going to change that. > > def start_game(players): > > > def initialize_game(): > > ? ? ? ?start_game(players) > > > if __name__ == '__main__': > > ? ?initialize_game() > > start_game() would be more accurately called play_game(), since it > doesn't return till the game's over. And it's a little odd that > initialize_game() doesn't return till the game's over; I'd be inclined > to have initialize_game() return after initializing, and then have the > main routine subsequently call start_game() / play_game(). Just a > minor naming issue! Minor or not, it makes sense. I'm picky about things like that too, so now that you've pointed it out, I'm compelled to change the names so they make sense! :) > > 2. Is there a better way to implement the players than as a class? > > Better way? Hard to know. There are many ways things can be done, but > the way you've chosen is as good as any. Certainly it's good enough > for the task you're doing. Yeah, I don't need to know 10 different ways to do things. Mainly I asked this question because the original exercise seemed to focus on using lists to write the game, and I just couldn't think of an efficient way to use a list to store the player attributes like what space they were on. It just seemed a natural candidate for a class attribute. > > 3. Is there a better way to handle all the print calls that the > > program makes? > > Again, I think it's fine. There's a general philosophy of separating > "guts" from "interface" (which would mean isolating all the print > statements from the game logic of moving pieces around), but in > something this small, the only reason to do that is for the sake of > practice. There's not much to be gained in small programs from fifty > levels of indirection. Heh, then you should have seen the original version I wrote! All the print calls were *inside* the "move" method, but it felt strange to have the move method do the printing directly, so I changed it to a return statement and handled the printing elsewhere. Although I still wonder if I could abstract the print calls even further. The presence of all that text just seems like it begs for a clean way to handle it. > Your code has much in its favour. I've been wordy in suggestions but > that doesn't mean you have bad code! :) Thanks a lot for the tips! I'm going to go back over the whole thing and rework some of it. And I'm only doing this for the sake of learning, so even the small tips help me to think more like a programmer. :) From greg.ewing at canterbury.ac.nz Sat Jul 2 23:57:03 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jul 2011 15:57:03 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <0ebac153-0e0d-49fd-96c0-af9f40fbf222@q1g2000vbj.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <0ebac153-0e0d-49fd-96c0-af9f40fbf222@q1g2000vbj.googlegroups.com> Message-ID: <97a7kiFsn7U1@mid.individual.net> The place where this "Unity API" idea of yours falls down is that an API is only truly easy to use when it's designed to closely match the characteristics of the language it's being used from. For example, Python has a very powerful feature that most other languages don't have anything remotely like: very flexible keyword arguments. A truly Pythonic API will take advantage of them wherever it makes sense. An extreme example is PyGUI, where you can write things like win = Window(title = "Fred", width = 300, height = 100, position = (30, 50), movable = True, resizable = True) In fact, almost *any* attribute of any PyGUI object can be specified using keyword arguments in the constructor. In your typical C or C++ based API, either you have a constructor taking a zillion positional parameters that all have to be in the right order, or you have to set all the attributes individually afterwards: win = Window() win.title = "Fred" win.width = 300 win.height = 100 win.position = (30, 50) win.movable = True win.resizable = True Either way you end up with an API that feels very awkward when used from Python. -- Greg From greg.ewing at canterbury.ac.nz Sun Jul 3 00:00:03 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jul 2011 16:00:03 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: <97a7q6FtqcU1@mid.individual.net> rantingrick wrote: > Ruby: for x in blah: blah_blah_blah > Python: for x in blah: blah_blah_blah Here you're making the mistake of thinking that surface syntax is all that matters. Although the 'for' statements in Python and Ruby look very similar, underneath they're based on quite different mechanisms. They're not equivalent: the Python way leads to various powerful things such as generators; the Ruby way lends itself more to user-defined control structures. -- Greg From rosuav at gmail.com Sun Jul 3 00:00:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2011 14:00:16 +1000 Subject: Anyone want to critique this program? In-Reply-To: <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> Message-ID: On Sun, Jul 3, 2011 at 1:41 PM, John Salerno wrote: > Yeah, I considered that, but I just hate the way it looks when the > line wraps around to the left margin. I wanted to line it all up under > the opening quotation mark. The wrapping may not be as much of an > issue when assigning a variable like this, but I especially don't like > triple-quoted strings that wrap around inside function definitions. > That seems to completely throw off the indentation. Do people still > use triple-quotes in that situation? Jury's out on that one. You can either back-tab it to the left (looks ugly), or indent it and then clean it up in code (IS ugly). Up to you to figure out what's best for your code, and if you want to indent it, your current way is quite possibly the cleanest. > Minor or not, it makes sense. I'm picky about things like that too, so > now that you've pointed it out, I'm compelled to change the names so > they make sense! :) :) Names tend to stay the same when the functions they're attached to grow and shift. Sometimes you end up with these great warts in huge production code... it's sometimes just too much work to change things. > Thanks a lot for the tips! I'm going to go back over the whole thing > and rework some of it. And I'm only doing this for the sake of > learning, so even the small tips help me to think more like a > programmer. :) Learning's good! And Python's an excellent language for the purpose. Code quickly, invoke quickly (no compilation stage), and see the results of the work. ChrisA From greg.ewing at canterbury.ac.nz Sun Jul 3 00:06:28 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jul 2011 16:06:28 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> Message-ID: <97a866Fa5U1@mid.individual.net> Chris Angelico wrote: > Your proposed "Unity API" (which I assume has nothing to do with Natty > Narwhal's preferred interface) already exists. It's the C language. Or maybe GObject Introspection is closer to what you have in mind? A library that supports GI advertises enough information about itself for dynamic languages such as Python and Ruby to automatically construct fairly object-oriented interfaces. It's not perfect, though; for example, the old PyGtk module used to let you access most of what Gtk calls "properties" using Python attribute access, but with GI you have to call the get_property and set_property functions. Also you often can't just call a class to construct an object, but have to call a separate constructor function instead. -- Greg From rantingrick at gmail.com Sun Jul 3 00:13:36 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 21:13:36 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> Message-ID: <3b72b347-2c49-40e1-8ab6-2fb584c5bbc7@hd10g2000vbb.googlegroups.com> On Jul 2, 10:14?pm, Chris Angelico wrote: > I specced up "the perfect language" a while ago. It gave you a clean > slate with no facilities but one: Define Operator. [...] That was some great satire :) but the last thing we need is users with that much power. Take the example of Ruby allowing you to redefine built in types... disastrous. I understand that freedom is good however unbridled freedom is a recipe for disaster. From greg.ewing at canterbury.ac.nz Sun Jul 3 00:14:25 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jul 2011 16:14:25 +1200 Subject: Why won't this decorator work? In-Reply-To: References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <97a8l3F39sU1@mid.individual.net> Ian Kelly wrote: > If it's not a callable, then the result > will just be that something non-callable is bound to the "roll_die" > name -- which could be useful, but is probably a bad idea in general. There are legitimate uses -- for example, the following is a convenient way of creating a read-only property: @property def foo(self): return self.calculate_value_of_foo() -- Greg From rantingrick at gmail.com Sun Jul 3 00:34:55 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 21:34:55 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <0ebac153-0e0d-49fd-96c0-af9f40fbf222@q1g2000vbj.googlegroups.com> <97a7kiFsn7U1@mid.individual.net> Message-ID: On Jul 2, 10:57?pm, Gregory Ewing wrote: > The place where this "Unity API" idea of yours falls down > is that an API is only truly easy to use when it's designed > to closely match the characteristics of the language it's > being used from. > > For example, Python has a very powerful feature that most > other languages don't have anything remotely like: very > flexible keyword arguments. [...] > > ? ?win = Window(title = "Fred", width = 300, height = 100, > ? ? ?position = (30, 50), movable = True, resizable = True) With all due respect that's a frail argument Greg. I agree that python's keyword arguments are great but they can actually cause code to get messy when so many are passed in a notation like you present *ahem* ESPECIALLY when "somebody" refuses to follow the style guide (hint-hint). I would do this for clarity... win = Window( title="Fred", width=300, height=100, position=(30, 50), movable=True, resizable=True, ) psst: removed python style guide abominations :-) Strangely however it looks very similar to your next notation... > ? ?win = Window() > ? ?win.title = "Fred" > ? ?win.width = 300 > ? ?win.height = 100 > ? ?win.position = (30, 50) > ? ?win.movable = True > ? ?win.resizable = True hmm? I think it's actually easier to read in this final form. However i will agree that C's requirements for function parameters are a real pain in the arse. Thank Guido for Python! > Either way you end up with an API that feels very awkward > when used from Python. I think we need to provide a better example (than just mere conjecture) before we assume how an "imaginary" API would "feel". And don't forget, any API can feel awkward since you've only got the hooks that the devs deemed worthy for you to have. I can't tell you how many obstacles I've had to code around because an API was lacking or buggy. Turned my otherwise beautiful code into an Orwellian nightmare. From rantingrick at gmail.com Sun Jul 3 00:42:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 2 Jul 2011 21:42:53 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> Message-ID: <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> On Jul 2, 11:00?pm, Gregory Ewing wrote: > rantingrick wrote: > > Ruby: for x in blah: blah_blah_blah > > Python: for x in blah: blah_blah_blah > > Here you're making the mistake of thinking that surface syntax > is all that matters. Although the 'for' statements in Python and > Ruby look very similar, underneath they're based on quite > different mechanisms. They're not equivalent: the Python way > leads to various powerful things such as generators; the Ruby > way lends itself more to user-defined control structures. I agree however i see merit in both approaches. But why must we have completely different languages just for that those two approaches? We don't it's just a religious thing. Doesn't make sense to me. If Guido and Matz got together over some sake and Monty Python i'll bet they could hash out a singular replacement fro Ruby and Python in no time! From steve+comp.lang.python at pearwood.info Sun Jul 3 00:46:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2011 14:46:34 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <0ebac153-0e0d-49fd-96c0-af9f40fbf222@q1g2000vbj.googlegroups.com> <97a7kiFsn7U1@mid.individual.net> Message-ID: <4e0ff42b$0$29965$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > Turned my otherwise beautiful code into an Orwellian nightmare. Your code was spying on you, having your friends and family disappear during the night to be tortured, and having history re-written so that there was no longer any evidence that they ever existed? You have my sympathy. -- Steven From tjreedy at udel.edu Sun Jul 3 02:38:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Jul 2011 23:38:22 -0700 Subject: from module import * using __import__? In-Reply-To: References: Message-ID: On 7/2/2011 12:52 PM, Dan Stromberg wrote: > > Is there a decent way of running "from import *"? Perhaps > using __import__? > > Does it mean using the copy module or adding an element to globals() > somehow? > > Yes, I think I do have a good use for this: importing either pure python > or cython versions of a module into a single namespace that can provide > the same interface (transparent to the caller), whether C extension > modules are viable in the current interpreter or not. So you have a > stub module that provides one or the other, depending on availability > and suitability. I suggest you look at some of the Python module that import native code implementations when available. heapq for one. maybe functools. From hartwig.linux at gmail.com Sun Jul 3 05:57:40 2011 From: hartwig.linux at gmail.com (H Linux) Date: Sun, 3 Jul 2011 02:57:40 -0700 (PDT) Subject: Nested/Sub Extensions in Python References: <4f8df99e-2d09-4845-8327-5f5c3012e952@glegroupsg2000goo.googlegroups.com> Message-ID: <903667a2-64f1-4005-99b7-b2456379b17e@q1g2000vbj.googlegroups.com> On Jul 2, 10:43 pm, Carl Banks wrote: > I got and built the package, and it imported smt.bar just fine for me. > > So my advice would be to rename all the modules. My guess is that there is a conflict for smt and Python is importing some other module or package. Is there a file called smt.py in your working directory? ...(snip)... > And if that is the problem, in the future be more careful to keep your module namespace clean. Thanks a lot for your effort, those suggestions pointed me to the solution, even if my mistake was actually a bit different. The name of the module (abbreviated "Simple Test Module" => smt), which was just chosen for a minimal reproducible version, was not the culprit: I unfortunately tested in the directory where I previously built/ installed the module. Result: python picked up my local "smt" directory (see tree output in first post) instead of that from the installed module :-(. Hence, even a more unique module name would not have saved me. Anyway, problem finally solved and learned a bit more about the pitfalls of python, thanks again to your help, your efforts are greatly appreciated, Hartwig From aspineux at gmail.com Sun Jul 3 07:51:50 2011 From: aspineux at gmail.com (aspineux) Date: Sun, 3 Jul 2011 04:51:50 -0700 (PDT) Subject: HOWTO: Parsing email using Python part1 Message-ID: <153de04b-dd58-43b3-bcc4-a2c36c8d8332@a7g2000vby.googlegroups.com> Hi I have written an article about parsing email using Python. The article is at http://blog.magiksys.net/Parsing-email-using-python-header and the full content is here. Hope this help someone. Regards. A lot of programs and libraries commonly used to send emails don't comply with RFC. Ignore such kind of email is not an option because all mails are important. It is important to do it best when parsing emails, like does most popular MUA. Python's has one of the best library to parse emails: the email package. First part, how to decode mails header Regarding RFC 2047 non ascii text in the header must be encoded. RFC 2822 make the difference between different kind of header. *text field like Subject: or address fields like To:, each with different encoding rules. This is because RFC 822 forbids the use of some ascii characters at some place because they have some meaning, but these ascii characters can be used when they are encoded because the encoded version don't disturb the parsing of string. Python provides email.Header.decode_header() for decoding header. The function decode each atom and return a list of tuples ( text, encoding ) that you still have to decode and join to get the full text. This is done in my getmailheader() function. For addresses, Python provides email.utils.getaddresses() that split addresses in a list of tuple ( display-name, address ). display-name need to be decoded too and addresses must match the RFC2822 syntax. The function getmailaddresses() does all the job. Here are the functions in actions. import re import email from email.Utils import parseaddr from email.Header import decode_header # email address REGEX matching the RFC 2822 spec # from perlfaq9 # my $atom = qr{[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+}; # my $dot_atom = qr{$atom(?:\.$atom)*}; # my $quoted = qr{"(?:\\[^\r\n]|[^\\"])*"}; # my $local = qr{(?:$dot_atom|$quoted)}; # my $domain_lit = qr{\[(?:\\\S|[\x21-\x5a\x5e-\x7e])*\]}; # my $domain = qr{(?:$dot_atom|$domain_lit)}; # my $addr_spec = qr{$local\@$domain}; # # Python translation atom_rfc2822=r"[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+" atom_posfix_restricted=r"[a-zA-Z0-9_#\$&'*+/=?\^`{}~|\-]+" # without '!' and '%' atom=atom_rfc2822 dot_atom=atom + r"(?:\." + atom + ")*" quoted=r'"(?:\\[^\r\n]|[^\\"])*"' local="(?:" + dot_atom + "|" + quoted + ")" domain_lit=r"\[(?:\\\S|[\x21-\x5a\x5e-\x7e])*\]" domain="(?:" + dot_atom + "|" + domain_lit + ")" addr_spec=local + "\@" + domain email_address_re=re.compile('^'+addr_spec+'$') raw="""MIME-Version: 1.0 Received: by 10.229.233.76 with HTTP; Sat, 2 Jul 2011 04:30:31 -0700 (PDT) Date: Sat, 2 Jul 2011 13:30:31 +0200 Delivered-To: alain.spineux at gmail.com Message-ID: Subject: =?ISO-8859-1?Q?Dr.=20Pointcarr=E9?= From: Alain Spineux To: =?ISO-8859-1?Q?Dr=2E_Pointcarr=E9?= Content-Type: multipart/alternative; boundary=000e0cd68f223dea3904a714768b --000e0cd68f223dea3904a714768b Content-Type: text/plain; charset=ISO-8859-1 -- Alain Spineux --000e0cd68f223dea3904a714768b Content-Type: text/html; charset=ISO-8859-1 -- Alain Spineux --000e0cd68f223dea3904a714768b-- """ def getmailheader(header_text, default="ascii"): """Decode header_text if needed""" try: headers=decode_header(header_text) except email.Errors.HeaderParseError: # This already append in email.base64mime.decode() # instead return a sanitized ascii string return header_text.encode('ascii', 'replace').decode('ascii') else: for i, (text, charset) in enumerate(headers): try: headers[i]=unicode(text, charset or default, errors='replace') except LookupError: # if the charset is unknown, force default headers[i]=unicode(text, default, errors='replace') return u"".join(headers) def getmailaddresses(msg, name): """retrieve From:, To: and Cc: addresses""" addrs=email.utils.getaddresses(msg.get_all(name, [])) for i, (name, addr) in enumerate(addrs): if not name and addr: # only one string! Is it the address or is it the name ? # use the same for both and see later name=addr try: # address must be ascii only addr=addr.encode('ascii') except UnicodeError: addr='' else: # address must match adress regex if not email_address_re.match(addr): addr='' addrs[i]=(getmailheader(name), addr) return addrs msg=email.message_from_string(raw) subject=getmailheader(msg.get('Subject', '')) from_=getmailaddresses(msg, 'from') from_=('', '') if not from_ else from_[0] tos=getmailaddresses(msg, 'to') print 'Subject: %r' % subject print 'From: %r' % (from_, ) print 'To: %r' % (tos, ) And the ouput: Subject: u'Dr. Pointcarr\xe9' From: (u'Alain Spineux', 'alain.spineux at gmail.com') To: [(u'Dr. Pointcarr\xe9', 'alain.spineux at gmail.com')] From python at bdurham.com Sun Jul 3 09:18:23 2011 From: python at bdurham.com (python at bdurham.com) Date: Sun, 03 Jul 2011 09:18:23 -0400 Subject: HOWTO: Parsing email using Python part1 In-Reply-To: <153de04b-dd58-43b3-bcc4-a2c36c8d8332@a7g2000vby.googlegroups.com> References: <153de04b-dd58-43b3-bcc4-a2c36c8d8332@a7g2000vby.googlegroups.com> Message-ID: <1309699103.6572.2147708153@webmail.messagingengine.com> Alain, > I have written an article about parsing email using Python. The article is at http://blog.magiksys.net/Parsing-email-using-python-header and the full content is here. Very helpful - thank you! Regards, Malcolm From nobody at nowhere.net.no Sun Jul 3 10:45:33 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 03 Jul 2011 22:45:33 +0800 Subject: HOWTO: Parsing email using Python part1 References: <153de04b-dd58-43b3-bcc4-a2c36c8d8332@a7g2000vby.googlegroups.com> Message-ID: aspineux wrote: > Hope this help someone. > Yeah I will learn alot and surely applying to my code. Merci Beaucoup -- goto /dev/null From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Jul 3 14:01:51 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 3 Jul 2011 18:01:51 +0000 (UTC) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: John Salerno wrote: > Basically what I want to do is this: I first to need to roll a die to > get a random number, then pass that number to the move method of a > Player class. Can this be done with a decorator, or is it better just > to do it like move(roll_die()) and be done with it? A decorator basically modifies a function/method, so that ALL subsequent calls to it will behave differently. If you want ALL calls to your method to roll a die to get a random number, and then use that random number, why not just roll the die inside the method itself: def move(dist=None): if dist=None: dist = random.randint(1, 7) # etc If you don't want all calls to your method to roll the die, but only some, and if the choice of whether to roll or not depends on information outside the method, then you need to do the rolling outside the method and pass the result in. This is more or less what other people have mentioned (and what you seem to have also been considering): # In code that wants to move the player. . . if doIWantToMoveRandomly(): player.move(rollDie()) else: player.move(2) # or whatever non-random expression you want -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Jul 3 14:06:07 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 3 Jul 2011 18:06:07 +0000 (UTC) Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> Message-ID: John Salerno wrote: > On Jul 2, 10:02?pm, Chris Angelico wrote: >> I'd do this with a triple-quoted string - it'll simply go across >> multiple lines: game_information = """***Chutes and Ladders*** >> Up to four (4) players may play. >> There are 90 spaces on the board. >> The player to reach space 90 first wins.""" > > Yeah, I considered that, but I just hate the way it looks when the > line wraps around to the left margin. I wanted to line it all up > under the opening quotation mark. The wrapping may not be as much > of an issue when assigning a variable like this, but I especially > don't like triple-quoted strings that wrap around inside function > definitions. That seems to completely throw off the indentation. Do > people still use triple-quotes in that situation? I do, because I use an editor that intelligently indents wrapped text to the same indent level as the beginning of the line, instead of wrapping it all the way back to the margin. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From fetchinson at googlemail.com Sun Jul 3 14:50:20 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 3 Jul 2011 20:50:20 +0200 Subject: web hosting, first hand experiences? Message-ID: Hi folks, I know this comes up regularly but the thing is that the quality of service changes also quite regularly with many of the hosting companies. What's currently the best option for shared hosting of a turbogears application? I'm thinking of dreamhost and webfaction does anyone have any recent experiences with these two? Or others? Cheers, Daniel From roy at panix.com Sun Jul 3 15:20:39 2011 From: roy at panix.com (Roy Smith) Date: Sun, 03 Jul 2011 15:20:39 -0400 Subject: web hosting, first hand experiences? References: Message-ID: In article , Daniel Fetchinson wrote: > Hi folks, I know this comes up regularly but the thing is that the > quality of service changes also quite regularly with many of the > hosting companies. What's currently the best option for shared hosting > of a turbogears application? I'm thinking of dreamhost and webfaction > does anyone have any recent experiences with these two? Or others? > > Cheers, > Daniel I've got an account on dreamhost, from which I host a couple of very low traffic sites built on Drupal. They seem like good folks, and provide full shell access. For me, that was the differentiator; most places don't allow shell access on their shared hosting machines. The downside to dreamhost is they seem to overload their shared hosting machines. Performance can be sucky. Un clear how much of that is host overloading and how much of that is simply that Drupal is a pig :-) From rantingrick at gmail.com Sun Jul 3 17:09:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 3 Jul 2011 14:09:09 -0700 (PDT) Subject: RFC: tkSimpleDialog IMPROVED AGAIN!. Message-ID: Hello Folks, As many of you already know yours truly has posted improvements to the tkSimpleDialog many moons back HOWEVER i was looking over the code a few moments ago and realized even more improvements were needed. These improvements mainly concern naming conventions, comments, and docstrings although i have some deeper and profound thoughts on virtual functions/methods that i will probably save for another thread in the very near future. As for tkSimpleDialog.py I had to change quite a bit of python style guide abominations in this and previous edits. ----------------------- First let's see the code in it's ORIGINAL STATE: (Warning: freak show ahead!) ----------------------- ## Start Code: tkSimpleDialog.Dialog ## from Tkinter import * class Dialog(Toplevel): '''Class to open dialogs. This class is intended as a base class for custom dialogs ''' def __init__(self, parent, title = None): '''Initialize a dialog. Arguments: parent -- a parent window (the application window) title -- the dialog title ''' Toplevel.__init__(self, parent) # If the master is not viewable, don't # make the child transient, or else it # would be opened withdrawn if parent.winfo_viewable(): self.transient(parent) if title: self.title(title) self.parent = parent self.result = None body = Frame(self) self.initial_focus = self.body(body) body.pack(padx=5, pady=5) self.buttonbox() self.wait_visibility() # window needs to be visible for the grab self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) if self.parent is not None: self.geometry("+%d+%d" % (parent.winfo_rootx()+50, parent.winfo_rooty()+50)) self.initial_focus.focus_set() self.wait_window(self) def destroy(self): '''Destroy the window''' self.initial_focus = None Toplevel.destroy(self) # # construction hooks def body(self, master): '''create dialog body. return widget that should have initial focus. This method should be overridden, and is called by the __init__ method. ''' pass def buttonbox(self): '''add standard button box. override if you do not want the standard buttons ''' box = Frame(self) w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE) w.pack(side=LEFT, padx=5, pady=5) w = Button(box, text="Cancel", width=10, command=self.cancel) w.pack(side=LEFT, padx=5, pady=5) self.bind("", self.ok) self.bind("", self.cancel) box.pack() # # standard button semantics def ok(self, event=None): if not self.validate(): self.initial_focus.focus_set() # put focus back return self.withdraw() self.update_idletasks() try: self.apply() finally: self.cancel() def cancel(self, event=None): # put focus back to the parent window if self.parent is not None: self.parent.focus_set() self.destroy() # # command hooks def validate(self): '''validate the data This method is called automatically to validate the data before the dialog is destroyed. By default, it always validates OK. ''' return 1 # override def apply(self): '''process the data This method is called automatically to process the data, *after* the dialog is destroyed. By default, it does nothing. ''' pass # override ## End Code: tkSimpleDialog.Dialog## As you can see this code reeks of abominations. Not only is the interface poorly designed, but we have poor naming conventions, too much vertical spacing, unhelpful and poorly formatted doc-strings, not enough comments where needed and too many in other places. Not the kind of code you bring home for mom to stick on the fridge. D: ----------------------- Now lets see the code in it's CURRENT STATE (with cleaned up comments and doc-strings!) ----------------------- ## Start Code: New and improved dialog! ## import Tkinter as tk class Dialog(tk.Toplevel): def __init__(self, parent, title='Dialog'): """ Initialize a dialog; parent: A Tkinter.Toplevel instance. title: The dialog's title as a string. """ tk.Toplevel.__init__(self, parent) self.withdraw() if parent.winfo_viewable(): # If the parent window is not viewable, don't # make the child transient, or else it would be # opened withdrawn! self.transient(parent) if title: self.title(title) self.parent = parent # self.result is where we store any values for return to # the caller. self.result = None # We save the dialog's main widget frame just incase a # caller needs to access it later. self.frame = tk.Frame(self) # Next we call self.body to create the body of the dialog. # We save the return value as "self.initial_focus" so we # give it focus later. self.initial_focus = self.body(self.frame) self.frame.pack(padx=5, pady=5) self.buttonbox() def show(self): # XXX: Need "show" and "show_modal" methods! self.deiconify() # The window needs to be visible for the grab so we # call wait_visibility and let Tkinter do the waiting # for us. self.wait_visibility() self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) if self.parent is not None: self.geometry( "+%d+%d" %( self.parent.winfo_rootx()+50, self.parent.winfo_rooty()+50) ) self.initial_focus.focus_set() self.wait_window(self) return self.result def destroy(self): '''Destroy the window''' self.initial_focus = None tk.Toplevel.destroy(self) # # Construction Hooks. # def body(self, master): # XXX: create_body ''' OVERIDE; Create dialog body and return widget that should have initial focus. ''' pass def buttonbox(self): # XXX: create_buttonbox # XXX: Overiding this method can break funcionality if you do not # properly bind the ok and cancel buttons correctly! # RFC: Should we create a generic button creation methos or a mixin? '''add a standard button box; override if you do not want differnt buttons. ''' box = tk.Frame(self) w = tk.Button(box, text="OK", width=10, command=self.ok, default=tk.ACTIVE) w.pack(side=tk.LEFT, padx=5, pady=5) w = Button(box, text="Cancel", width=10, command=self.cancel) w.pack(side=tk.LEFT, padx=5, pady=5) self.bind("", self.ok) self.bind("", self.cancel) box.pack() # # Standard Button Callbacks. # def ok(self, event=None): # XXX: okButtonCallback | callbackOkButton | (cb*|*cb) """ Proces the data automatically when user presses ok button.""" if not self.validate(): self.initial_focus.focus_set() # put focus back return self.withdraw() self.update_idletasks() try: self.apply() finally: self.cancel() def cancel(self, event=None): # XXX: cancelButtonCallback | callbackCancelButton | (cb*|*cb) """ Return focus to the parent window and destroy self""" if self.parent is not None: self.parent.focus_set() self.destroy() # # Command Hooks. # def validate(self): # XXX: data_validate """ Validate the data; This method is called automatically to validate the data before the dialog is destroyed. By default, it always validates True. Overide to change behavoir to something more suitabe for your derived dialog. """ return True def apply(self): # XXX: data_process """ Process the data; This method is called automatically to process the data but only *after* the dialog is destroyed. By default, it does nothing. Overide to change the behavoir to something more suitabe for your derived dialog """ pass if __name__ == "__main__": root = Tk() import tkMessageBox ERROR_STR = "We don't have any \"{0}\"!" class MyDialog(Dialog): def body(self, master): self.strvar = tk.StringVar(master, "Eggs") self.label = tk.Label(self, text='Default') self.label.pack() self.options = OptionMenu( self, self.strvar, "Jam", "Ham", "Spam", ) self.options.pack() def validate(self): text = self.strvar.get() if text and text.lower() != 'spam': tkMessageBox.showerror( 'Order Error', ERROR_STR.format(text), parent=self ) return False return True def apply(self): self.result = self.strvar.get() m = MyDialog(root, title='Menu = spam') # Test changing widget values after initialization. m.label['text'] = 'What would you like to order?' # Show the modal dialog. result = m.show() print 'User Choose: {0}'.format(result) root.mainloop() ## End Code: New and improved dialog! ## Ahhh. As you can see i removed the cruft, cleaned up the spacing, formatted, improved the doc stings and comments AND even created a nice little test case at the bottom. Folks this is how a pythonista writes code. This is what you should stive for every day! HOWEVER i believe we can do even better than this Oh Yes!!! ----------------------- Name changes ----------------------- body -> create_body buttonbox -> create_buttonbox validate -> data_validate | validate_data apply -> data_process | process_data ----------------------- Methods ----------------------- Should we have show_modal and show methods? I believe so! ----------------------- Pitfalls ----------------------- Overiding the buttonbox method can be dangerous since bindings must be set correctly or the cancel and apply methods will break! I think we can improve this code by either (A) a mixin buttonbox class OR abstracting the button box creation and passing in a type string to the SimpleDialog intial method... RFC... bring it on folks! From ben+python at benfinney.id.au Sun Jul 3 17:37:01 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 04 Jul 2011 07:37:01 +1000 Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> Message-ID: <87pqlrjbb6.fsf@benfinney.id.au> John Salerno writes: > On Jul 2, 10:02?pm, Chris Angelico wrote: > > > > game_information = '***Chutes and Ladders***\nUp to four (4) players > > > may play.\n'\ > > > ? ? ? ? ? ? ? ? ? 'There are 90 spaces on the board. '\ > > > ? ? ? ? ? ? ? ? ? 'The player to reach space 90 first wins.' > > > > I'd do this with a triple-quoted string - it'll simply go across multiple lines: > > game_information = """***Chutes and Ladders*** > > Up to four (4) players may play. > > There are 90 spaces on the board. > > The player to reach space 90 first wins.""" > > Yeah, I considered that, but I just hate the way it looks when the > line wraps around to the left margin. import textwrap game_information = textwrap.dedent("""\ ***Chutes and Ladders*** Up to four (4) players may play. There are 90 spaces on the board. The player to reach space 90 first wins. """) -- \ ?Nothing is more sacred than the facts.? ?Sam Harris, _The End | `\ of Faith_, 2004 | _o__) | Ben Finney From aharrisreid at googlemail.com Sun Jul 3 17:57:17 2011 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sun, 03 Jul 2011 22:57:17 +0100 Subject: web hosting, first hand experiences? In-Reply-To: References: Message-ID: <4E10E5BD.6050502@googlemail.com> On 19:59, Daniel Fetchinson wrote: > Hi folks, I know this comes up regularly but the thing is that the > quality of service changes also quite regularly with many of the > hosting companies. What's currently the best option for shared hosting > of a turbogears application? I'm thinking of dreamhost and webfaction > does anyone have any recent experiences with these two? Or others? > > Cheers, > Daniel > Hi Daniel, I can wholeheartedly recommend WebFaction. I currently have an account running 3 different CherryPy applications (so TurboGears shouldn't pose any problems), and apart from initial teething problems, they have been running for months without interruption. As well as an excellent control panel, they give you full Linux command-line access to your site(s). The level of support is as good as you will get anywhere (short of having experts with you in the office!), and they know a huge amount about Python web applications. Nothing seems to be too much trouble for them. They also provide a 60-day money-back guarantee, so you can try-before-you-buy. Best wishes, Alan Harris-Reid ------------------------------------------------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Jul 3 18:11:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 3 Jul 2011 15:11:09 -0700 (PDT) Subject: Implicit initialization is EVIL! Message-ID: Tkinter has a major flaw and this flaw has been with us for many many years. What is the flaw? Well the title says it all folks... IMPLICIT INITIALIZATION IS EVIL. Still confused, well let me explain. Unlike most GUI libraries the Tkinter developers thought is would "just wonderful" if the root GUI window just sprang into existence if the programmer "somehow" forgot to create one. Does anyone remember the old adage... """ The road to hell is paved with good intentions? """ ...as you're about to see this road is paved in gold around thee parts! You're probably thinking to yourself that i am stretching the truth for the sake of drama? Well i wish i could answer yes, but i cannot. So without further "a due" let me show you some code... ## START CODE ## from Tkinter import * label = Label(parent=None, text='This is an example of poor GUI design!') label.pack() label.mainloop() ## END CODE ## As you can see the root window is auto created for the caller and this sort of hand holding only served to confuse the hell of out new folks! Sure it's "cute" (and all that type of nifty swiftly crap!) but it is EVIL! A new user should learn from day one the hierarchy of a GUI. -root window -optional widgets --optional sub windows ---optional widgets ---and on and on root = Tk() # Or a derived class of Tk frame = Frame(root) w = Widget(frame) and on and on and on We should never propagate this sort of confusion throughout our community. Please remove this dangerous design pattern immediately. From rosuav at gmail.com Sun Jul 3 18:21:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2011 08:21:48 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: Message-ID: On Mon, Jul 4, 2011 at 8:11 AM, rantingrick wrote: > A new user should learn from day one the hierarchy of a GUI. > > -root window > -optional widgets > --optional sub windows > ---optional widgets > ---and on and on You're forgetting all the other crucial parts of the hierarchy. A new user should be forced to declare a Desktop that s/he wants the window on, and a Screen, and choose which video driver to use too! Implicit acceptance of defaults is EVIL! Oh, and while you're at it, Python's habit of letting you skip variable declarations is EVIL too. A new user should learn from day one that variables need to be stored somewhere, so Python should stop coddling its newbies and actually get them to do things right: var(0x14205359) x # Don't forget to provide an address where the object will be located x=42 After all, everyone's gotta learn about segfaults some day! Chris Angelico From roy at panix.com Sun Jul 3 18:32:47 2011 From: roy at panix.com (Roy Smith) Date: Sun, 03 Jul 2011 18:32:47 -0400 Subject: Implicit initialization is EVIL! References: Message-ID: In article , Chris Angelico wrote: > var(0x14205359) x # Don't forget to provide an address where the > object will be located > x=42 > > After all, everyone's gotta learn about segfaults some day! 0x14205359 is more likely to give a bus error (odd address) than a segfault :-) From rantingrick at gmail.com Sun Jul 3 18:55:56 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 3 Jul 2011 15:55:56 -0700 (PDT) Subject: Virtual functions are virtually invisible! Message-ID: Hello Folks! In my quest to uncover the many asininities contained within the tkSimpleDialog.py module i found myself contemplating some the very fundamental aspects of the Python language proper. And this is aspect be... "Pythonic notation". But before i introduce you to my latest discovery of collective ineptitude i want to discuss some of the great pythonic notations we already enjoy. In the beginning, Mr. Van Rossum (in a stroke of complete brilliance i might add!) stumbled upon the idea of syntactical notation and he seized upon it! We all know how python uses indention to denote scopes (and i just love this aspect about the language!) but my next favorite notation is the leading and trailing double underscores that wrap special method names[1] Because they just JUMP out at you whilst reading code (and they should!). Even if they only say... """Hey, i am special and you should only care about me if you are an experienced pythonista, otherwise nothing to see here, move along lad!""" Actually i did not realize just HOW important this notation was to my code comprehension until i started tinkering with another language called "Ruby" (who BTW does not use any notation for this matter). Ruby doesn't use any special notation so all the member methods just blend into the crowd. Nothing jumps out and says "HEY, I'M SPECIAL, LOOK AT ME"... instead you start to get sea sick from the homogeneous structure of it all. You cannot quickly categorize the method hierarchy without extensive reading and wasted time. This is a shame! But this gushing over underscores is not the subject of my thread today, what concerns me is the fact that virtual methods in derived classes just blend in to the crowd. For me this presents major problem, because i don't know what "behind the scenes" actions are going to take place without a very personal relationship with the underlying code base. More wasted time! So what i am proposing is some way to differentiate methods that have been clobbered by the derived class. And it's not the fact that they have been clobbered that is of any concern to me, NO, what concerns me is that i don't know what "invisible" side effects are taking place "behind-the-scenes", much less which methods are the root of such invisible side effects. You know as Pyhthonista's we always frown on syntactic decorators HOWEVER like all good things these visual cues are best taken when in moderation. I believe in these cases syntactic decorators are not only needed but they are warranted! Of course the simplest solution is a doc string explaining the case to a reader. But as we all know even pyhtonista's refuse to follow the style guide so this will be a non starter. I think we really need some sort of visual cue in the form of forced syntactical notation (just like the special method underscores). [1] http://docs.python.org/reference/datamodel.html#special-method-names From rantingrick at gmail.com Sun Jul 3 19:08:35 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 3 Jul 2011 16:08:35 -0700 (PDT) Subject: RFC: tkSimpleDialog IMPROVED AGAIN!. References: Message-ID: <8b80d64e-0110-464a-9834-a0aba4d4b1e5@p31g2000vbs.googlegroups.com> Sorry folks. I found a few bugs in that pasted code of the new and improved tkSimpleDialog. I believe most here could debug it however just in case any newbies are watching i want the code to execute without error. ## START CODE ## import Tkinter as tk MESSAGE = """ You are following bad design patterns. NO SOUP FOR YOU! """ class Dialog(tk.Toplevel): def __init__(self, parent, title='Dialog'): if not isinstance(parent, (tk.Tk, tk.Toplevel)): raise Exception(MESSAGE) """ Initialize a dialog; parent: A Tkinter.Toplevel instance. title: The dialog's title as a string. """ tk.Toplevel.__init__(self, parent) self.withdraw() if parent.winfo_viewable(): # If the parent window is not viewable, don't # make the child transient, or else it would be # opened withdrawn! self.transient(parent) if title: self.title(title) self.parent = parent # self.result is where we store any values for return to # the caller. self.result = None # We save the dialog's main widget frame just incase a # caller needs to access it later. self.frame = tk.Frame(self) # Next we call self.body to create the body of the dialog. # We save the return value as "self.initial_focus" so we # give it focus later. self.initial_focus = self.body(self.frame) self.frame.pack(padx=5, pady=5) self.buttonbox() def show(self): # XXX: Need "show" and "show_modal" methods! self.deiconify() # The window needs to be visible for the grab so we # call wait_visibility and let Tkinter do the waiting # for us. self.wait_visibility() self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) if self.parent is not None: self.geometry( "+%d+%d" %( self.parent.winfo_rootx()+50, self.parent.winfo_rooty()+50) ) self.initial_focus.focus_set() self.wait_window(self) return self.result def destroy(self): """Destroy the window.""" self.initial_focus = None tk.Toplevel.destroy(self) # # Construction Hooks. # def body(self, master): # XXX: create_body """ OVERIDE: Create dialog body and return widget that should have initial focus. """ pass def buttonbox(self): # XXX: create_buttonbox # XXX: Overiding this method can break funcionality if # you do not properly bind the ok and cancel buttons # correctly! # RFC: Should we create a generic button creation method # or a mixin? """ Add a standard button box; Override if you do not want differnt buttons. """ box = tk.Frame(self) w = tk.Button( box, text="OK", width=10, command=self.ok, default=tk.ACTIVE ) w.pack(side=tk.LEFT, padx=5, pady=5) w = tk.Button( box, text="Cancel", width=10, command=self.cancel ) w.pack(side=tk.LEFT, padx=5, pady=5) self.bind("", self.ok) self.bind("", self.cancel) box.pack() # # Standard Button Callbacks. # def ok(self, event=None): # XXX: okButtonCallback | callbackOkButton | (cb*|*cb) """ Proces the data automatically when user presses ok button.""" if not self.validate(): self.initial_focus.focus_set() # put focus back return self.withdraw() self.update_idletasks() try: self.apply() finally: self.cancel() def cancel(self, event=None): # XXX: cancelButtonCallback | callbackCancelButton | (cb*|*cb) """ Return focus to the parent window and destroy self""" if self.parent is not None: self.parent.focus_set() self.destroy() # # Command Hooks. # def validate(self): # XXX: data_validate """ Validate the data; This method is called automatically to validate the data before the dialog is destroyed. By default, it always validates True. Overide to change behavoir to something more suitabe for your derived dialog. """ return True def apply(self): # XXX: data_process """ Process the data; This method is called automatically to process the data but only *after* the dialog is destroyed. By default, it does nothing. Overide to change the behavoir to something more suitabe for your derived dialog """ pass if __name__ == "__main__": root = tk.Tk() import tkMessageBox ERROR_STR = "We don't have any \"{0}\"!" class MyDialog(Dialog): def body(self, master): self.strvar = tk.StringVar(master, "Eggs") self.label = tk.Label(self, text='Default') self.label.pack() self.options = tk.OptionMenu( self, self.strvar, "Jam", "Ham", "Spam", ) self.options.pack() def validate(self): text = self.strvar.get() if text and text.lower() != 'spam': tkMessageBox.showerror( 'Order Error', ERROR_STR.format(text), parent=self ) return False return True def apply(self): self.result = self.strvar.get() m = MyDialog(root, title='Menu = spam') # Test changing widget values after initialization. m.label['text'] = 'What would you like to order?' # Show the modal dialog. result = m.show() print 'User Choose: {0}'.format(result) root.mainloop() ## END CODE ## From chaouki.amir at gmail.com Sun Jul 3 19:41:35 2011 From: chaouki.amir at gmail.com (amir chaouki) Date: Sun, 3 Jul 2011 16:41:35 -0700 (PDT) Subject: Problem!! Message-ID: i have written code on linux for parsing text files and it works great but when i try to run it on windows it goes crazy, do you have any idea??? From irmen.NOSPAM at xs4all.nl Sun Jul 3 19:47:39 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 04 Jul 2011 01:47:39 +0200 Subject: Problem!! In-Reply-To: References: Message-ID: <4e10ff9b$0$21805$e4fe514c@news2.news.xs4all.nl> On 4-7-2011 1:41, amir chaouki wrote: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? No, I misplaced my crystal ball. Irmen P.S. http://www.catb.org/~esr/faqs/smart-questions.html From drsalists at gmail.com Sun Jul 3 19:54:16 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 3 Jul 2011 16:54:16 -0700 Subject: Problem!! In-Reply-To: References: Message-ID: You'll probably want to give more detail about what your code is doing and what it should be doing. Mindreading is hard, especially when it's accurate. Usually the main difference between *ix and windows for text files is the line endings though - on *ix, you can open a file as text or binary, and things are the same. On windows, you need to read a text file as 'r' and a binary file as 'rb'. See also dos2unix and unix2dos. BTW, are you using a native windows python, or a cygwin python? Are you using python 2.x or 3.x? CPython, PyPy, Jython, Pyjamas, IronPython...? On Sun, Jul 3, 2011 at 4:41 PM, amir chaouki wrote: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Jul 3 19:54:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 3 Jul 2011 16:54:24 -0700 (PDT) Subject: Problem!! References: Message-ID: <62eb70bd-a15a-4ae2-8251-724d75ba77c4@fq4g2000vbb.googlegroups.com> On Jul 3, 6:41?pm, amir chaouki wrote: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? psst: you should show us the code first. :) From rosuav at gmail.com Sun Jul 3 19:54:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2011 09:54:28 +1000 Subject: Problem!! In-Reply-To: References: Message-ID: On Mon, Jul 4, 2011 at 9:41 AM, amir chaouki wrote: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? If you share your code, we may be able to help. Alternatively, here's a few differences to look at: 1) Filenames - if you have a literal for your file name, "/home/foobar/file" will work, but "c:\path\newfile.txt" won't - backslash is a special character. Make it a raw string: r"c:\path\newfile.txt" - that will work. 2) End of line characters. If you divide the contents of the file on the "\n" character, and then try to work with the end of each line, you may find that the string has a "\r" character at the end. 3) What Irmen de Jong said. :) Chris Angelico From chaouki.amir at gmail.com Sun Jul 3 19:58:24 2011 From: chaouki.amir at gmail.com (amir chaouki) Date: Sun, 3 Jul 2011 16:58:24 -0700 (PDT) Subject: Problem!! References: Message-ID: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> the problem is when i use the seek function on windows it gives me false results other then the results on *ux. the file that i work with are very large about 10mb. From ben+python at benfinney.id.au Sun Jul 3 20:12:20 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 04 Jul 2011 10:12:20 +1000 Subject: Problem!! References: Message-ID: <87liwekior.fsf@benfinney.id.au> amir chaouki writes: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? Please compose a new message, with a descriptive ?Subject? field, example code that we can run, and your expectations for what the code should do. -- \ ?In general my children refuse to eat anything that hasn't | `\ danced on television.? ?Erma Bombeck | _o__) | Ben Finney From invalid at invalid.invalid Sun Jul 3 20:34:06 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 4 Jul 2011 00:34:06 +0000 (UTC) Subject: Problem!! References: Message-ID: On 2011-07-03, amir chaouki wrote: > i have written code on linux for parsing text files and it works great > but when i try to run it on windows it goes crazy, do you have any > idea??? Yes. -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From miloshzorica at gmail.com Sun Jul 3 20:57:25 2011 From: miloshzorica at gmail.com (milosh zorica) Date: Sun, 3 Jul 2011 21:57:25 -0300 Subject: Problem!! In-Reply-To: References: Message-ID: filenames and the crlf / eof thing come to my mind first linux and windows handle files all different On Sun, Jul 3, 2011 at 9:34 PM, Grant Edwards wrote: > On 2011-07-03, amir chaouki wrote: > >> i have written code on linux for parsing text files and it works great >> but when i try to run it on windows it goes crazy, do you have any >> idea??? > > Yes. > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! LOOK!! ?Sullen > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?at ? ? ? ? ? ? ? American teens wearing > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?gmail.com ? ? ? ? ? ?MADRAS shorts and "Flock of > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Seagulls" HAIRCUTS! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Milosh Zorica http://www.linkedin.com/in/miloshzorica | www.coroflot.com/miloshz http://tangoinabox.co.uk Tango in a Box - Online Media Production, the Tango Principles Applied - Born in Argentina, Growing up Globally +1 310 601 4396 | +44 20 8144 5294 | +54 9 11 3515 7187 From johnjsal at gmail.com Sun Jul 3 23:24:07 2011 From: johnjsal at gmail.com (John Salerno) Date: Sun, 3 Jul 2011 20:24:07 -0700 (PDT) Subject: Why won't this decorator work? References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: On Jul 3, 1:01?pm, "OKB (not okblacke)" wrote: > subsequent calls to it will behave differently. ?If you want ALL calls > to your method to roll a die to get a random number, and then use that > random number, why not just roll the die inside the method itself: I thought maybe it would be cleaner if the roll function was something separate, but I suppose it could go inside the move method. It just seemed like two different things that needed to be separated. From johnjsal at gmail.com Sun Jul 3 23:25:51 2011 From: johnjsal at gmail.com (John Salerno) Date: Sun, 3 Jul 2011 20:25:51 -0700 (PDT) Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> Message-ID: <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> On Jul 3, 1:06?pm, "OKB (not okblacke)" wrote: > > Yeah, I considered that, but I just hate the way it looks when the > > line wraps around to the left margin. I wanted to line it all up > > under the opening quotation mark. The wrapping may not be as much > > of an issue when assigning a variable like this, but I especially > > don't like triple-quoted strings that wrap around inside function > > definitions. That seems to completely throw off the indentation. Do > > people still use triple-quotes in that situation? > > ? ? ? ? I do, because I use an editor that intelligently indents wrapped > text to the same indent level as the beginning of the line, instead of > wrapping it all the way back to the margin. But isn't wrapped text something different than text that is purposely split across multiple lines with a newline character? That's usually the case when I need to split up a long string. From wuwei23 at gmail.com Mon Jul 4 01:06:12 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 3 Jul 2011 22:06:12 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> Message-ID: <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> rantingrick wrote: > But why must we have > completely different languages just for that those two approaches? Because monocultures die. Because having broader diversity leads to more evolutionary leaps. Because the implementations are so fundamentally different. Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore different implementations. Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore different syntax & semantics. Because learning different approaches expands your appreciation of & informs your understanding of both. From xahlee at gmail.com Mon Jul 4 02:36:08 2011 From: xahlee at gmail.com (Xah Lee) Date: Sun, 3 Jul 2011 23:36:08 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) Message-ID: OMG, emacs lisp beats perl/python again! Hiya all, another little emacs lisp tutorial from the tiny Xah's Edu Corner. ?Emacs Lisp: Processing HTML: Transform Tags to HTML5 ?figure? and ?figcaption? Tags? xahlee.org/emacs/elisp_batch_html5_tag_transform.html plain text version follows. ------------------------------------------ Emacs Lisp: Processing HTML: Transform Tags to HTML5 ?figure? and ?figcaption? Tags Xah Lee, 2011-07-03 Another triumph of using elisp for text processing over perl/python. ---------------------------- The Problem -------------- Summary I want batch transform the image tags in 5 thousand html files to use HTML5's new ?figure? and ?figcaption? tags. I want to be able to view each change interactively, while optionally give it a ?go ahead? to do the whole job in batch. Interactive eye-ball verification on many cases lets me be reasonably sure the transform is done correctly. Yet i don't want to spend days to think/write/test a mathematically correct program that otherwise can be finished in 30 min with human interaction. -------------- Detail HTML5 has the following new tags: ?figure? and ?figcaption?. They are used like this:
my cat
my cat!
(For detail, see: HTML5 ?figure? ? ?figurecaption? Tags Browser Support) On my website, i used a similar structure. They look like this:
my cat

my cat!

So, i want to replace them with the HTML5's new tags. This can be done with a regex. Here's the ?find? regex:
?\([^?

\([^<]+?\)

?
Here's the replacement string:
\2
\5
Then, you can use ?find-file? and dired's ?dired-do-query-replace- regexp? to work on your 5 thousand pages. Nice. (See: Emacs: Interactively Find ? Replace String Patterns on Multiple Files.) However, the problem here is more complicated. The image file may be jpg or png or gif. Also, there may be more than one image per group. Also, the caption part may also contain complicated html. Here's some examples:
my cat my cat

my 2 cats

jamie's cat

jamie's cat! Her blog is http://example.com/jamie/

So, a solution by regex is out. ---------------------------- Solution The solution is pretty simple. Here's the major steps: Use ?find-lisp-find-files? to traverse a dir. For each file, open it. Search for the string
Use ?sgml-skip-tag-forward? to jump to its closing tag. Save the positions of these tag begin/end positions. Ask user if she wants to replace. If so, do it. (using ?delete- region? and ?insert?) Repeat. Here's the code: ;; -*- coding: utf-8 -*- ;; 2011-07-03 ;; replace image tags to use html5's ?figure? and ?figcaption? tags. ;; Example. This: ;;
?
;; should become this ;;
?
;; do this for all files in a dir. ;; rough steps: ;; find the
;; use sgml-skip-tag-forward to move to the ending tag. ;; save their positions. (defun my-process-file (fpath) "process the file at fullpath FPATH ..." (let (mybuff p1 p2 p3 p4 ) (setq mybuff (find-file fpath)) (widen) (goto-char 0) ;; in case buffer already open (while (search-forward "
" nil t) (progn (setq p2 (point) ) (backward-char 17) ; beginning of ?div? tag (setq p1 (point) ) (forward-char 1) (sgml-skip-tag-forward 1) ; move to the closing tag (setq p4 (point) ) (backward-char 6) ; beginning of the closing div tag (setq p3 (point) ) (narrow-to-region p1 p4) (when (y-or-n-p "replace?") (progn (delete-region p3 p4 ) (goto-char p3) (insert "") (delete-region p1 p2 ) (goto-char p1) (insert "
") (widen) ) ) ) ) (when (not (buffer-modified-p mybuff)) (kill-buffer mybuff) ) ) ) (require 'find-lisp) (let (outputBuffer) (setq outputBuffer "*xah img/figure replace output*" ) (with-output-to-temp-buffer outputBuffer (mapc 'my-process-file (find-lisp-find-files "~/web/xahlee_org/ emacs/" "\\.html$")) (princ "Done deal!") ) ) Seems pretty simple right? The ?p1? and ?p2? variables are the positions of start/end of
. The ?p3? and ?p4? is the start/end of it's closing tag . We also used a little trick with ?widen? and ?narrow-to-region?. It lets me see just the part that i'm interested. It narrows to the beginning/end of the div.img. This makes eye-balling a bit easier. The real time-saver is the ?sgml-skip-tag-forward? function from ?html- mode?. Without that, one'd have to write a mini-parser to deal with html's nested ways to be able to locate the proper ending tag. Using the above code, i can comfortably eye-ball and press ?y? at the rate of about 5 per second. That makes 300 replacements per minute. I have 5000+ files. If we presume there are 6k replacement to be made, then at 5 per second means 20 minutes sitting there pressing ?y?. Quite tiresome. So, now, the next step is simply to remove the asking (y-or-n-p "replace?"). Or, if i'm absolutely paranoid, i can make emacs write into a log buffer for every replacement it makes (together with the file path). When the batch replacement is done (probably under 3 minutes), i can simply scan thru the log to see if any replacement went wrong. For how to do that, see: Emacs Lisp: Multi-Pair String Replacement with Report. But what about replacing

?

with
?? I simply copy and pasted the above code into a new file, just made changes in 4 places. So, the replacing figcaption part is considered a separete batch job. Of course, one could spend extra hour or so to make the code do them both in one pass, but is that one extra hour of thinking ? coding worthwhile for this one-time job? I ? Emacs, do you? --------------------------------- PS perl and python solution welcome. I haven't looked at perl or python's html parser libs for 5+ years. Though, 2 little requirement: 1. it must be correct, of course. Cannot tolerate the possiblility that maybe one out of a thousand replacement it introduced a mismatched tag. (but you can assume that all the input html files are w3c valid) 2. it must not change the formatting of the html pages. i.e. adding/ removing spaces or tabs. Xah From nobody at nowhere.net.no Mon Jul 4 03:16:34 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 04 Jul 2011 15:16:34 +0800 Subject: Problem!! References: <4e10ff9b$0$21805$e4fe514c@news2.news.xs4all.nl> Message-ID: Irmen de Jong wrote: > No, I misplaced my crystal ball. I'm waiting mine, brand new in HD :D, with remote control :D :D -- goto /dev/null From greg.ewing at canterbury.ac.nz Mon Jul 4 03:36:54 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 19:36:54 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> Message-ID: <97d8spFg2nU1@mid.individual.net> rantingrick wrote: > I agree however i see merit in both approaches. But why must we have > completely different languages just for that those two approaches? We have different languages because different people have different ideas about what a language should be like. Ruby people like user defined control structures; Python people regard user defined control structures as an anti-feature. It's fundamentally impossible for one language to satisfy both sets of people. -- Greg From greg.ewing at canterbury.ac.nz Mon Jul 4 04:22:37 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:22:37 +1200 Subject: Why won't this decorator work? In-Reply-To: References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <97dbigF4d1U1@mid.individual.net> OKB (not okblacke) wrote: > A decorator basically modifies a function/method, so that ALL > subsequent calls to it will behave differently. Furthermore, usually a decorator is used when for some reason you *can't* achieve the same effect with code inside the function itself. For example, the classmethod() and staticmethod() decorators return descriptors that have different magical effects from a standard function object when looked up in a class or instance. Since that magic happens *before* the function is called, you can't do the same thing using an ordinary function. In this case, an ordinary function is quite sufficient, and there is no need to involve a decorator. -- Greg From hv at tbz-pariv.de Mon Jul 4 04:31:35 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 04 Jul 2011 10:31:35 +0200 Subject: HeaderParseError Message-ID: <97dc37F7gaU1@mid.individual.net> Hi, I get a HeaderParseError during decode_header(), but Thunderbird can display the name. >>> from email.header import decode_header >>> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header raise HeaderParseError email.errors.HeaderParseError How can I parse this in Python? Thomas Same question on Stackoverflow: http://stackoverflow.com/questions/6568596/headerparseerror-in-python -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From greg.ewing at canterbury.ac.nz Mon Jul 4 04:33:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:33:52 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: References: Message-ID: <97dc7iF9eiU1@mid.individual.net> rantingrick wrote: > Unlike most GUI libraries the Tkinter developers thought is would > "just wonderful" if the root GUI window just sprang into existence if > the programmer "somehow" forgot to create one. IMO the real problem here is the existence of a privileged "root" window at all. No GUI platform I know of has any such concept (except for a "desktop" window that represents the whole screen, which is not the same thing). All top-level windows should have equal status. -- Greg From greg.ewing at canterbury.ac.nz Mon Jul 4 04:43:35 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:43:35 +1200 Subject: Virtual functions are virtually invisible! In-Reply-To: References: Message-ID: <97dcpqFdndU1@mid.individual.net> rantingrick wrote: > what concerns me is the fact that virtual methods in derived > classes just blend in to the crowd. > I think we really need some > sort of visual cue in the form of forced syntactical notation (just > like the special method underscores). If you're suggesting that it should be impossible to override a method unless it is specially marked somehow in the base class, I think that would be a bad idea. One of the principles behind the design of Eiffel is that classes should *always* be open to modification in any way by a subclass. The reason is that the author of a class library can't anticipate all the ways people might want to use it. Consequently Eiffel has no equivalent of C++'s "private" declaration -- everything is at most "protected". It also has no equivalent of Java's "final". I like the fact that Python doesn't have these either. -- Greg From rosuav at gmail.com Mon Jul 4 04:44:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2011 18:44:48 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <97dc7iF9eiU1@mid.individual.net> References: <97dc7iF9eiU1@mid.individual.net> Message-ID: On Mon, Jul 4, 2011 at 6:33 PM, Gregory Ewing wrote: > rantingrick wrote: > >> Unlike most GUI libraries the Tkinter developers thought is would >> "just wonderful" if the root GUI window just sprang into existence if >> the programmer "somehow" forgot to create one. > > IMO the real problem here is the existence of a privileged > "root" window at all. No GUI platform I know of has any > such concept (except for a "desktop" window that represents > the whole screen, which is not the same thing). All top-level > windows should have equal status. I don't know Tkinter, but from the look of the example code, he's creating a Label that's not attached to a window, and then packing it into nothing. The toolkit kindly creates him a window. Is that the "root GUI window" that he means? A basic top-level window? Chris Angelico From greg.ewing at canterbury.ac.nz Mon Jul 4 04:48:16 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:48:16 +1200 Subject: Problem!! In-Reply-To: References: <4e10ff9b$0$21805$e4fe514c@news2.news.xs4all.nl> Message-ID: <97dd2jFfs7U1@mid.individual.net> TheSaint wrote: > On 4-7-2011 1:41, amir chaouki wrote: > >> No, I misplaced my crystal ball. > > I'm waiting mine, brand new in HD :D, with remote control :D :D The new digital models are great. But there's a distressing tendency for visions to come with DRM protection these days, so you can only share them with at most 5 other users. :-( -- Greg From fetchinson at googlemail.com Mon Jul 4 04:59:19 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 4 Jul 2011 10:59:19 +0200 Subject: web hosting, first hand experiences? In-Reply-To: <4E10E5BD.6050502@googlemail.com> References: <4E10E5BD.6050502@googlemail.com> Message-ID: >> Hi folks, I know this comes up regularly but the thing is that the >> quality of service changes also quite regularly with many of the >> hosting companies. What's currently the best option for shared hosting >> of a turbogears application? I'm thinking of dreamhost and webfaction >> does anyone have any recent experiences with these two? Or others? >> >> Cheers, >> Daniel >> > > Hi Daniel, > > I can wholeheartedly recommend WebFaction. I currently have an account > running 3 different CherryPy applications (so TurboGears shouldn't pose > any problems), and apart from initial teething problems, they have been > running for months without interruption. As well as an excellent > control panel, they give you full Linux command-line access to your > site(s). The level of support is as good as you will get anywhere > (short of having experts with you in the office!), and they know a huge > amount about Python web applications. Nothing seems to be too much > trouble for them. They also provide a 60-day money-back guarantee, so > you can try-before-you-buy. > > Best wishes, > Alan Harris-Reid Thanks for all the responses, based on the feedback I'll go with webfaction I guess. They were my first choice anyway but wanted to double check with people in the know about their current situation. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From __peter__ at web.de Mon Jul 4 05:51:41 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jul 2011 11:51:41 +0200 Subject: HeaderParseError References: <97dc37F7gaU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > I get a HeaderParseError during decode_header(), but Thunderbird can > display the name. > >>>> from email.header import decode_header >>>> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header > raise HeaderParseError > email.errors.HeaderParseError > > > How can I parse this in Python? Trying to decode as much as possible: >>> s = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>> for n in range(len(s), 0, -1): ... try: t = s[:n].decode("base64") ... except: pass ... else: break ... >>> n, t (49, 'Anmeldung Netzanschluss S\x19\x1c\x9a[\x99\xcc\xdc\x0b\x9a\x9c\x19') >>> print t.decode("iso-8859-1") Anmeldung Netzanschluss S[?? >>> s[n:] 'w==?=' The characters after "...Netzanschluss " look like garbage. What does Thunderbird display? From swavijay at gmail.com Mon Jul 4 06:06:14 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Mon, 4 Jul 2011 15:36:14 +0530 Subject: Sending email in python Message-ID: Hi All, I read through the smtplib and email modules of python and have come up with a simple program to send a email as an attachment. This module sends out an email but not as an attachment but in the body of the email. Any problem with this code? any insight would be greatly appreciated. import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText testfile = 'test.txt' msg = MIMEMultipart() msg['Subject'] = 'Email with Attachment' msg['From'] = 'swavijay at gmail.com' msg['To'] = 'swavijay at gmail.com' with open(testfile,'rb') as f: # Open the files in binary mode. Let the MIMEImage class automatically # guess the specific image type. img = MIMEText(f.read()) f.close() msg.attach(img) try: s = smtplib.SMTP('localhost') s.sendmail(msg['From'],[msg['To']],msg.as_string()) print 'Email with attachment sent successfully' s.quit() except: print 'Email with attachment could not be sent !!' -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Mon Jul 4 06:38:39 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 04 Jul 2011 12:38:39 +0200 Subject: HeaderParseError In-Reply-To: References: <97dc37F7gaU1@mid.individual.net> Message-ID: <97djhfF10kU1@mid.individual.net> On 04.07.2011 11:51, Peter Otten wrote: > Thomas Guettler wrote: > >> I get a HeaderParseError during decode_header(), but Thunderbird can >> display the name. >> >>>>> from email.header import decode_header >>>>> > decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header >> raise HeaderParseError >> email.errors.HeaderParseError >> >> >> How can I parse this in Python? > > Trying to decode as much as possible: > >>>> s = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>>> for n in range(len(s), 0, -1): > ... try: t = s[:n].decode("base64") > ... except: pass > ... else: break > ... >>>> n, t > (49, 'Anmeldung Netzanschluss S\x19\x1c\x9a[\x99\xcc\xdc\x0b\x9a\x9c\x19') >>>> print t.decode("iso-8859-1") > Anmeldung Netzanschluss S[?? > >>>> s[n:] > 'w==?=' > > The characters after "...Netzanschluss " look like garbage. What does > Thunderbird display? Hi Peter, Thunderbird shows this: Anmeldung Netzanschluss S?dring3p.jpg Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From __peter__ at web.de Mon Jul 4 07:20:42 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jul 2011 13:20:42 +0200 Subject: HeaderParseError References: <97dc37F7gaU1@mid.individual.net> <97djhfF10kU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > On 04.07.2011 11:51, Peter Otten wrote: >> Thomas Guettler wrote: >> >>> I get a HeaderParseError during decode_header(), but Thunderbird can >>> display the name. >>> >>>>>> from email.header import decode_header >>>>>> >> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib64/python2.6/email/header.py", line 101, in >>> decode_header >>> raise HeaderParseError >>> email.errors.HeaderParseError >> The characters after "...Netzanschluss " look like garbage. What does >> Thunderbird display? > > Hi Peter, Thunderbird shows this: > > Anmeldung Netzanschluss S?dring3p.jpg >>> a = u"Anmeldung Netzanschluss S?dring3p.jpg".encode("iso-8859-1").encode("base64") >>> b = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>> for i, (x, y) in enumerate(zip(a, b)): ... if x != y: print i, x, y ... 33 / _ 52 ? >>> b.decode("base64") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/encodings/base64_codec.py", line 42, in base64_decode output = base64.decodestring(input) File "/usr/lib/python2.6/base64.py", line 321, in decodestring return binascii.a2b_base64(s) binascii.Error: Incorrect padding >>> b.replace("_", "/").decode("base64") 'Anmeldung Netzanschluss S\xfcdring3p.jpg' Looks like you encountered a variant of base64 that uses "_" instead of "/" for chr(63). The wikipedia page http://en.wikipedia.org/wiki/Base64 calls that base64url. You could try and make the email package accept that with a monkey patch like the following: #untested import binascii def a2b_base64(s): return binascii.a2b_base64(s.replace("_", "/")) from email import base64mime base64mime.a2b_base64 = a2b_base64 Alternatively monkey-patch the binascii module before you import the email package. From k.sahithi2862 at gmail.com Mon Jul 4 08:38:03 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Mon, 4 Jul 2011 05:38:03 -0700 (PDT) Subject: ONLY FOR MEN` Message-ID: <3ec7c780-7243-4fe5-a6fb-009347f05ab0@q14g2000prh.googlegroups.com> FOR FAST UPDATED IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com/ PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html TAPSEE SISTER HOT STILLS FOR U http://allyouwants.blogspot.com/2011/06/tapsee-sister-shagun-pannu-hot-photo.html NAMITHA LATEST HOT PHOTO STILLS http://allyouwants.blogspot.com/2011/06/namithas-latest-stills-from-her.html FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html From rantingrick at gmail.com Mon Jul 4 11:19:40 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:19:40 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> Message-ID: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> On Jul 4, 3:33?am, Gregory Ewing wrote: > IMO the real problem here is the existence of a privileged > "root" window at all. No GUI platform I know of has any > such concept (except for a "desktop" window that represents > the whole screen, which is not the same thing). All top-level > windows should have equal status. I dunno, it's natural to create a parent-child hierarchy when GUI programming with any library. So i am not completely sure what you are implying here? When you close the main application widow you would expect all child windows to close. Or likewise when you iconify the main window you would expect the other windows to do the same. Sure you could do this yourself by sending messages to all the other windows but Tkinter does this for you automatically. And how does Tkinter know which windows to configure? A parent-child relationship that's how. >>> a = set(dir(Tkinter.Toplevel)) >>> b = set(dir(Tkinter.Tk)) >>> len(a), len(b) (222, 226) >>> a.difference(b) set(['_setup', '_do']) You say "root" windows are bad however any parent-child relationship has to BEGIN somewhere. For Tkinter the beginning of this dynasty is an instance of the Tkinter.Tk[1] window from which all other windows and widgets are made children. HOWEVER any of the windows ARE in fact instances of Tk.Toplevel[1]. So they ARE all equal because they all have the same methods available to them. >>> import Tkinter >>> Tkinter.Tk.__doc__ 'Toplevel widget of Tk which represents mostly the main window\n of an appliation. It has an associated Tcl interpreter.' >>> import inspect >>> inspect.getmro(Tkinter.Tk) (, , ) >>> inspect.getmro(Tkinter.Toplevel) (, , , ) But let's dig a little deeper here. Your comment suggests that you "personally" need to create multiple windows for your applications. Is this correct? If so i pity any users of such application as they would be thoroughly confused. Most applications consist of one main window (a Tkinter.Tk instance). The only need for extra Toplevel windows is in the form of modal dialogs (use tkSimpleDialog.Dialog) or tool windows (use Tk.Toplevel with attribute '-toolwindow'=True). I don't see how your statements carry any weight here. Could you explain please? [1] http://effbot.org/tkinterbook/tkinter-application-windows.htm [2] http://effbot.org/tkinterbook/toplevel.htm From rantingrick at gmail.com Mon Jul 4 11:29:31 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:29:31 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> Message-ID: On Jul 4, 3:44?am, Chris Angelico wrote: > I don't know Tkinter, but from the look of the example code, he's > creating a Label that's not attached to a window, and then packing it > into nothing. The toolkit kindly creates him a window. Is that the > "root GUI window" that he means? A basic top-level window? Yes. But to be specific the "root" is an instance of Tkinter.Tk which is a toplevel that has a TCL interpreter attached. From robin at reportlab.com Mon Jul 4 11:35:22 2011 From: robin at reportlab.com (Robin Becker) Date: Mon, 04 Jul 2011 16:35:22 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: References: Message-ID: <4E11DDBA.7020201@chamonix.reportlab.co.uk> On 03/07/2011 23:21, Chris Angelico wrote: ......... > > var(0x14205359) x # Don't forget to provide an address where the > object will be located > x=42 ........ did you forget to specify the memory bank and computer (and presumably planet etc etc....) -molly-coddled-ly yrs- Robin Becker From rosuav at gmail.com Mon Jul 4 11:40:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 01:40:02 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 1:19 AM, rantingrick wrote: > But let's dig a little deeper here. Your comment suggests that you > "personally" need to create multiple windows for your applications. Is > this correct? If so i pity any users of such application as they would > be thoroughly confused. Most applications consist of one main window > (a Tkinter.Tk instance). The only need for extra Toplevel windows is > in the form of modal dialogs (use tkSimpleDialog.Dialog) or tool > windows (use Tk.Toplevel with attribute '-toolwindow'=True). Uhh, sorry. No. There are plenty of good reasons for one application to make multiple top-level windows, and if I ever find myself using a toolkit that makes this difficult, I'll either be hacking the toolkit or using a different one. I've been building GUI applications for far too long to not want features like that. ChrisA From rantingrick at gmail.com Mon Jul 4 11:45:35 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:45:35 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: oops. should have used symmetric_difference! >>> a.symmetric_difference(b) set(['_w', '_setup', 'report_callback_exception', '_do', '__getattr__', 'loadtk', '_loadtk', 'readprofile']) From rantingrick at gmail.com Mon Jul 4 11:46:27 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:46:27 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Jul 4, 10:40?am, Chris Angelico wrote: > Uhh, sorry. No. There are plenty of good reasons for one application > to make multiple top-level windows, and if I ever find myself using a > toolkit that makes this difficult, I'll either be hacking the toolkit > or using a different one. I've been building GUI applications for far > too long to not want features like that. And those reasons are...? From rosuav at gmail.com Mon Jul 4 12:01:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 02:01:49 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 1:46 AM, rantingrick wrote: > On Jul 4, 10:40?am, Chris Angelico wrote: > >> Uhh, sorry. No. There are plenty of good reasons for one application >> to make multiple top-level windows, and if I ever find myself using a >> toolkit that makes this difficult, I'll either be hacking the toolkit >> or using a different one. I've been building GUI applications for far >> too long to not want features like that. > > And those reasons are...? As varied as the applications that call on them. One example that springs to mind: Our database front end has "table view" and "record view", where you get one table view and from that you can view as many records as you like. Users may choose to effectively switch from one view to the other, or they may open up two or more record views and have them and the table view all on screen simultaneously. This is not a modal dialog; it's not even a modeless dialog - it's a completely stand-alone window that can be moved around the Z order independently of the parent. There's a definite ownership based on process, though; terminate the process (by closing the table view) and it must close all record views first. I've done other applications where this has not been the case - where all top-level windows are truly equal - but not in this instance. As an aside, that particular program is one that we are currently using (I glance over and can see it running on one of our terminals here), and the interface has not changed since about 2002 (actually earlier - 2002 had a major code rewrite without much UI change). Multiple top-level windows fulfills the Law of Least Astonishment admirably, and has done so for a decade. Chris Angelico From rantingrick at gmail.com Mon Jul 4 12:35:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 09:35:13 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> Message-ID: <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> On Jul 4, 12:06?am, alex23 wrote: > rantingrick wrote: > > But why must we have > > completely different languages just for that those two approaches? > > Because monocultures die. That's an interesting statement Alex (even though you parrot it constantly). So what IS a mono culture exactly? Lemme see... """A single, homogeneous culture without diversity or dissension. """ Interesting. Would you consider the Python community to be a monoculture? We are working towards a singular goal so i would say so. We should be working towards the language that is best for all but instead we are working towards the language that is best for US. How about the Ruby community? Here's a good one; How about the programming community? These groups would ALL classify as monocultures Alex. So why are they NOT dying? Well maybe they are and you just cannot see past your own nose (it does get fairly long from time to time you know). I believe (unlike most people) that nature is striving for perfection NOT for diversity. Diversity is just a byproduct of feeble attempts to GUESS the correct answer. Here is a thought exercise for the advanced reader...Which is more efficient; Numerous groups working to create languages that satisfy their selfish needs OR one group of all the bright minds working to destroy multiplicity and bring about the one true language that meets the needs of productivity? In order to achieve perfection we must propagate unity within the system and we must destroy multiplicity with a vengeance. We must unite to defeat multiplicity and in doing so we create innovation. That is the job of intelligent agents, to BRING ORDER TO THE NATURAL CHAOS OF THIS UNIVERSE! Your natural instincts are of propagating diversity (read as selfishness) HOWEVER the future exists only in unity. What do you think will be the eventual outcome of the human existence Alex? Since you have no imagination i will tell you, a singular intelligence. However an intelligence that is the product of many "intelligent agents". A unity intelligence if you will. Just think of it as a botnet alex, i am sure you have plenty of experience in this area! > Because having broader diversity leads to more evolutionary leaps. Do you think that if we combine all the worthwhile attributes of the high level languages that somehow everyone is just going to accept that forever? No, of course not. HOWEVER instead of splitting off into sects (and damaging our hive mind capabilities) we need to focus our efforts on one goal... CREATING THE BEST LANGUAGE WE CAN AT ANY ONE TIME IN HISTORY... and we will all learn TOGETHER not APART. Diversity only propagates multiplicity and slows our evolution Alex. It is selflessness on a grand scale. > Because the implementations are so fundamentally different. In the big picture that's untrue. Between say Ruby and Python you a few LARGE differences and many SMALL differences (and even some replication). I propose that we combine the Ruby and Python languages using all the best ideas, however dropping the multiplicity. > Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > different implementations. Why can they not explore within the hive mind? Why must they hide their explorations from the greater group. SELFISHNESS Here is another thought exercise for the advanced reader. Remember in the old days when furniture was crafted by hand? Not only was the furniture EXPENSIVE it was also scarce to come by. Why was this the case. Because human nature is to be selfish. And our selfishness slows evolution. But one day some very intelligent chap realized that he could build furniture not only faster but cheaper by using the assembly line. Now we have furniture stores on practically every corner at prices almost anyone can afford. Yes i realize "some" of the products are not of good quality but that is a result of economics (and greed) not unity. > Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > different syntax & semantics. We should have nailed down syntax and semantics long ago alex! This should have been step one. No instead we have groupA, groupB, and groupC still fighting about what is best for their selfish needs without concerning themselves wit the big picture. It's not what is best for ME, NO, it's what is best for US. * What syntax is most widely intuitive? * What semantics are the best for productivity? * etc... > Because learning different approaches expands your appreciation of & > informs your understanding of both. Yes, and i agree. But instead of learning in small groups we need to learn together. Of course we are going to make mistakes along the way. Heck we may even have to re write the whole spec a time or two. But i would argue that the chances of making mistakes decrease as the number of agents increase. I dunno, have you ever heard of a little thing called Open Source Software. Where people from all over the world maintain a piece of software. AMAZING HUH? Just imagine if we combined all the best people from all the current languages. There is your diversity Alex, however sadly, you have no imagination to see it. From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Jul 4 12:37:22 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Mon, 4 Jul 2011 16:37:22 +0000 (UTC) Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: John Salerno wrote: > On Jul 3, 1:06?pm, "OKB (not okblacke)" > wrote: > >> > Yeah, I considered that, but I just hate the way it looks when the >> > line wraps around to the left margin. I wanted to line it all up >> > under the opening quotation mark. The wrapping may not be as much >> > of an issue when assigning a variable like this, but I especially >> > don't like triple-quoted strings that wrap around inside function >> > definitions. That seems to completely throw off the indentation. Do >> > people still use triple-quotes in that situation? >> >> ? ? ? ? I do, because I use an editor that intelligently indents >> wrapped text to the same indent level as the beginning of the line, >> instead of wrapping it all the way back to the margin. > > But isn't wrapped text something different than text that is purposely > split across multiple lines with a newline character? That's usually > the case when I need to split up a long string. Well, what I'm saying is I use an editor that lets me make the lines as long as I want, and it still wraps them right, so I never explicitly hit enter to break a line except at the end of a string (or paragraph). -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From rantingrick at gmail.com Mon Jul 4 13:09:25 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 10:09:25 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Jul 4, 11:01?am, Chris Angelico wrote: > On Tue, Jul 5, 2011 at 1:46 AM, rantingrick wrote: > > On Jul 4, 10:40?am, Chris Angelico wrote: > > >> Uhh, sorry. No. There are plenty of good reasons for one application > >> to make multiple top-level windows, and if I ever find myself using a > >> toolkit that makes this difficult, I'll either be hacking the toolkit > >> or using a different one. I've been building GUI applications for far > >> too long to not want features like that. > > > And those reasons are...? > > As varied as the applications that call on them. One example that > springs to mind: Our database front end has "table view" and "record > view", where you get one table view and from that you can view as many > records as you like. Users may choose to effectively switch from one > view to the other, or they may open up two or more record views and > have them and the table view all on screen simultaneously. > This is not > a modal dialog; it's not even a modeless dialog - it's a completely > stand-alone window that can be moved around the Z order independently > of the parent. You can do the exact same thing with Tkinter's windows. > There's a definite ownership based on process, though; > terminate the process (by closing the table view) and it must close > all record views first. I've done other applications where this has > not been the case - where all top-level windows are truly equal - but > not in this instance. Tkinters Toplevels ARE equal! However in this case you should spawn a new instance of the application "opened" at that particular table view. It's as simple as a few command line arguments in your script. It's like a text editor, you never want a "New" command that resets the current document or an open command that resets the current document and loads the file into the existing editor. Each application instance should only create one document and stick with it until it is closed. Instead you want to spawn a new instance of the editor and tell the editor (via command line arguments) to load file data (if applicable). Simple command line arguments (of which you should be using anyway) are the key here. All part of proper software design. From rosuav at gmail.com Mon Jul 4 13:19:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:19:24 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 2:35 AM, rantingrick wrote: > I believe (unlike most people) that nature is striving for perfection > NOT for diversity. Diversity is just a byproduct of feeble attempts to > GUESS the correct answer. Here is a thought exercise for the advanced > reader...Which is more efficient; Numerous groups working to create > languages that satisfy their selfish needs OR one group of all the > bright minds working to destroy multiplicity and bring about the one > true language that meets the needs of productivity? You assume that there is one right answer. I'm not sure whether this is provably wrong or just utterly unfounded, but I see no reason to believe that it is so. > In order to achieve perfection we must propagate unity within the > system and we must destroy multiplicity with a vengeance. We must > unite to defeat multiplicity and in doing so we create innovation. > That is the job of intelligent agents, to BRING ORDER TO THE NATURAL > CHAOS OF THIS UNIVERSE! You join a long line of Lawful Evil villains who have made that statement. Look at such as Darth Vader, is that your goal? Bringing order to the universe even if it means choking it to death? Yes, humans will tend to bring orderliness to what used to be chaotic. But this cannot be the ultimate goal; order is but a means to an end. What end? What IS the end of programming? Is it not productivity? > What do you think will be the eventual outcome of the human existence > Alex? Since you have no imagination i will tell you, a singular > intelligence. However an intelligence that is the product of many > "intelligent agents". A unity intelligence if you will. Just think of > it as a botnet alex, i am sure you have plenty of experience in this > area! Thanks. Mind if I borrow your crystal ball for a moment? Seems to be a good one, since you can see *with certainty* the eventual outcome of all humans. I can't help thinking, though, that you're aligning yourself with villains again - in this case the Borg. > Do you think that if we combine all the worthwhile attributes of the > high level languages that somehow everyone is just going to accept > that forever? No, of course not. HOWEVER instead of splitting off into > sects (and damaging our hive mind capabilities) we need to focus our > efforts on one goal... CREATING THE BEST LANGUAGE WE CAN AT ANY ONE > TIME IN HISTORY... and we will all learn TOGETHER not APART. Diversity > only propagates multiplicity and slows our evolution Alex. It is > selflessness on a grand scale. Once again, you assume that there is one ultimate language, just waiting to be discovered/developed. One language which will be perfect in every way, for every purpose. > Why can they not explore within the hive mind? Why must they hide > their explorations from the greater group. SELFISHNESS If they explore anything that the whole hive isn't doing, they're making that disagreement again. Suppose we had that one language that I described earlier - the "clean slate representation" (CSR, but that's just syntactic sugar - if you'll pardon the awful pun) one where the only thing you have is "define operator". We then, as a single unified collective hive mind unity, develop a Standard Library for this language. Putting "#include std" or "import std" or whatever at the top of your code gives you a fairly normal set of things you can do. Well and good; we all use the same language. As soon as anyone explores anything within that language that hasn't yet been done, he has created a new dialect - a new language, if you will. It's right back with what you are ripping on, except that we now call it the same language. > We should have nailed down syntax and semantics long ago alex! This > should have been step one. No instead we have groupA, groupB, and > groupC still fighting about what is best for their selfish needs > without concerning themselves wit the big picture. It's not what is > best for ME, NO, it's what is best for US. Actually no. It's still about what's best for ME. I can't think of what would be best for you - you're the best one to think about that. Open source actually encourages and allows selfishness in ways that are far too awkward else; groupA can code to groupA's needs, then groupB adds code to that to make it do what groupB needs, and offers their enhancements back to the world, meaning that groupC need only code what groupC needs. > ?* What syntax is most widely intuitive? > ?* What semantics are the best for productivity? > ?* etc... These are subjective questions. I happen to be able to work very well with a bracey language, but other people can't. To me, Pike was incredibly intuitive, because it has so many similarities to languages I already know. To someone who knows only lisp, that would not be the case. Incidentally, your questions cross-multiply too: What semantics are more intuitive, and what syntax is best for productivity? Four good questions. > Yes, and i agree. But instead of learning in small groups we need to > learn together. Do you mean literally? Huge classrooms good, individual/small-group learning bad? That's provably empirically wrong. But if not that, then what? > Of course we are going to make mistakes along the way. > Heck we may even have to re write the whole spec a time or two. Yep, and code will be written for older versions of the spec. The way you're talking, it'd likely be a LOT more than Py2 vs Py3, with lots of installations and lots of programmers preferring to stick to the old language. Or are you planning to somehow force everyone to upgrade to the latest? > But i > would argue that the chances of making mistakes decrease as the number > of agents increase. I dunno, have you ever heard of a little thing > called Open Source Software. Where people from all over the world > maintain a piece of software. AMAZING HUH? Just imagine if we combined > all the best people from all the current languages. There is your > diversity Alex, however sadly, you have no imagination to see it. I'd say all the best people for Language X are already there. And all the best people for Language Y are already _there_. There's a lot of people who would be good in multiple communities, and guess what? They're already IN multiple communities. These things have a way of sorting themselves out. There cannot be one perfect language for everything, unless that language is so flexible that it is nothing. I retract my earlier statement that the "universal language" is C; no, it goes back further. The universal language is a text editor where you write your source code. You then run it through the universal compiler called "make", which figures out what to do with your source. You then run it on the universal hardware... oh. Well, make can figure out the hardware too, so we'll pretend it's universal. Is this one language? At work, I have SciTE holding several files in separate tabs - they might be C++, Python, Lua, Javascript, Pike, the Makefile, and a plain text file where I keep my notes. SciTE edits all of them (although it's less intelligent with the languages it doesn't know). In any of them, I can hit F7 to compile the current file and deploy it to my test-box. Does that mean they're all one language? Different languages have different purposes. As I found out recently, trying to use Python in a situation where you need to sandbox user-supplied code is a bad idea; I ended up with a p0wned test-box and a lot of egg on my face, and it's only because the Python community is intelligent adults that we didn't have some rather nasty consequences. (That box failed the test, but it was an incredibly successful test. We learned the painful truth that we needed to hear.) Has anyone ever used a very-high-level language (like Python or Ruby or Lua) to write, say, a video driver? There is a place for the languages that take most of the work away from the programmer, and a place for languages that basically give you the hardware and say "have fun". There will never be a universal language that does both jobs perfectly. *returns the crystal ball* Chris Angelico From rosuav at gmail.com Mon Jul 4 13:21:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:21:08 +1000 Subject: Anyone want to critique this program? In-Reply-To: References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 2:37 AM, OKB (not okblacke) wrote: > ? ? ? ?Well, what I'm saying is I use an editor that lets me make the > lines as long as I want, and it still wraps them right, so I never > explicitly hit enter to break a line except at the end of a string (or > paragraph). In this instance, I believe the OP was paragraphing his text. Is there a convenient way to do that in a triple-quoted string? My personal inclination would be to simply back-tab it. It looks ugly, but at least it works, and doesn't require a run-time re-parse. The run-time translation is good for docstrings, though (which are syntactically the same thing as this situation). ChrisA From liu.liuwei.wei at gmail.com Mon Jul 4 13:33:31 2011 From: liu.liuwei.wei at gmail.com (=?GB2312?B?s8m2vMbf1tAyMDAyvLY3sOBftPO80ra8ysfM7LLFoas=?=) Date: Mon, 4 Jul 2011 10:33:31 -0700 (PDT) Subject: i have configured proxy but fiddler can't capture python's network requests Message-ID: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> here's my code. I've change the port from 8888 to 1111. import urllib2 proxy_support = urllib2.ProxyHandler({'http':'http://127.0.0.1:1111'}) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) urllib2.install_opener(opener) content = urllib2.urlopen('http://www.google.com').read() print content The weird thing is: 1. If I close fiddler, python throws error when running Traceback (most recent call last): File "C:\Users\Micky\test.py", line 5, in content = urllib2.urlopen('http://www.google.com').read() File "D:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "D:\Python27\lib\urllib2.py", line 394, in open response = self._open(req, data) File "D:\Python27\lib\urllib2.py", line 412, in _open '_open', req) File "D:\Python27\lib\urllib2.py", line 372, in _call_chain result = func(*args) File "D:\Python27\lib\urllib2.py", line 1199, in http_open return self.do_open(httplib.HTTPConnection, req) File "D:\Python27\lib\urllib2.py", line 1174, in do_open raise URLError(err) URLError: 2. If I open fiddler, everything works great. But I can't see the traffic in fiddler. And if I change port from 1111 to any other number, it works find too. Any clues? From rosuav at gmail.com Mon Jul 4 13:41:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:41:44 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 3:09 AM, rantingrick wrote: > On Jul 4, 11:01?am, Chris Angelico wrote: >> This is not >> a modal dialog; it's not even a modeless dialog - it's a completely >> stand-alone window that can be moved around the Z order independently >> of the parent. > > You can do the exact same thing with Tkinter's windows. I didn't say Tkinter couldn't do this; I said that it was a good thing to be able to do, which you earlier decried. > However in this case you should spawn a new instance of the > application "opened" at that particular table view. It's as simple as > a few command line arguments in your script. No! Definitely not. Initializing the application includes logging in to the database. Suppose the user had to log in again... or, worse, suppose I transmitted the username and password via command line arguments. No, forcing programmers into a particular coding model is a bad idea. Let the individual programmer decide what tool is best for what job. > It's like a text editor, you never want a "New" command that resets > the current document or an open command that resets the current > document and loads the file into the existing editor. Each application > instance should only create one document and stick with it until it is > closed. What, never? Well, hardly ever! (As per HMS Pinafore, if you're wondering.) Actually, I quite frequently do want exactly that. Replace the current buffer with a new document. Keeping the previous document involves one of two choices (maybe more, but I can't think of any off hand): * Leave the other document visible on the screen, cluttering things up and forcing the user to switch to the other window, close it, and then return to his work; or * Have the new window completely and exactly mask the old one, making it unobvious that the previous document is actually still open, leaving enormous possibilities for confusion. Audacity takes the first option (at least, the Windows version that I used five years ago did). You choose New or Open, it brings up another window. This astonished me when I first saw it (strike one), annoys me 85% of the time and is useful only 15% (strike two), and tends to get in the way of rapid keyboard-oriented navigation (strike three and out). I'd much rather Audacity kept all its "stuff" in one window, unless I explicitly asked it for another window. For another example, look at where web browsers are going. By your description, one instance of a browser should work with precisely one "document" (which in this case would be a web page). That's how browsers were in the early days, but by the early 2000s most browsers had some form of tabs, letting you keep that application in one window. > Instead you want to spawn a new instance of the editor and tell the > editor (via command line arguments) to load file data (if applicable). > Simple command line arguments (of which you should be using anyway) > are the key here. All part of proper software design. Of course I could spawn a new instance. But why? Why do it? And if I have to have a completely new copy of all the editor's state, this is hopelessly inefficient on memory and startup work. Why should File|Open incur such a cost? (Ameliorated if you fork() but that has its own consequences.) But the memory cost is nothing compared to the extra interference it puts on "mindspace". I currently have precisely two slots in mindspace for web browsers: Chrome and Firefox. Chrome currently has about a dozen tabs up; Firefox about the same, but most of them are long-term status reports that I keep handy. If I had to have 20-30 separate windows, I would not be able to use alt-tab to find the one I want, but would have to use some other kind of "window picker". How would you write a user-friendly picker that can cope with myriad instances of everything? My guess is that it'd use some kind of tree structure with applications at one level and windows at the next. Is this not exactly what we already have? Chris Angelico From georg at python.org Mon Jul 4 13:48:50 2011 From: georg at python.org (Georg Brandl) Date: Mon, 04 Jul 2011 19:48:50 +0200 Subject: [RELEASED] Python 3.2.1 rc 2 Message-ID: <4E11FD02.3040205@python.org> On behalf of the Python development team, I am pleased to announce the second release candidate of Python 3.2.1. Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a testing release: Please consider trying Python 3.2.1 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) From rosuav at gmail.com Mon Jul 4 13:50:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:50:28 +1000 Subject: i have configured proxy but fiddler can't capture python's network requests In-Reply-To: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> References: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> Message-ID: 2011/7/5 ????2002?7?_??????? : > 2. If I open fiddler, everything works great. But I can't see the > traffic in fiddler. And if I change port from 1111 to any other > number, it works find too. > It sounds to me like the traffic's going through fiddler, but you're just not seeing any log entries. The reactions from the Python end are exactly what I'd expect. Look at fiddler's documentation to see if you can enable verbose logging, or something of the sort. Chris Angelico From tim at johnsons-web.com Mon Jul 4 14:11:33 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 10:11:33 -0800 Subject: Testing if a global is defined in a module Message-ID: <20110704181133.GH1971@johnsons-web.com> Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. ## A module has been imported, and we call `getmembers' members = inspect.getmembers(mod) ## While iterating thru `members', we test to see ## if an object is defined in the module. for m in members: obj = m[1] res = inspect.getmodule(obj) ## It appears that getmodule returns None for ## all but functions and classes. Example, for a module name `mvcInstall', when a class name `Install' that is defined in the module is passed as an argument to inspect.getmodule, the values returned is something like "" Likewise for functions defined in the module. ** But ** when global variables such as strings, booleans, integers are passed as an argument to getmodule, the value returned is `None'. What else can I do here? thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From StefanMandl at web.de Mon Jul 4 15:13:56 2011 From: StefanMandl at web.de (S.Mandl) Date: Mon, 4 Jul 2011 12:13:56 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: Nice. I guess that XSLT would be another (the official) approach for such a task. Is there an XSLT-engine for Emacs? -- Stefan From rantingrick at gmail.com Mon Jul 4 15:30:52 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 12:30:52 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> On Jul 4, 12:41?pm, Chris Angelico wrote: > For another example, look at where web browsers are going. By your > description, one instance of a browser should work with precisely one > "document" (which in this case would be a web page). That's how > browsers were in the early days, but by the early 2000s most browsers > had some form of tabs, letting you keep that application in one > window. Umm, if you want to see where things are "going" you should learn about the inner workings of chrome which actually spawns a new process for every tab created; which has the benefit of avoiding application lock up when one page decides to crash. > I currently have precisely two slots in mindspace for web browsers: > Chrome and Firefox. Chrome currently has about a dozen tabs up; > Firefox about the same, but most of them are long-term status reports > that I keep handy. If I had to have 20-30 separate windows, I would > not be able to use alt-tab to find the one I want, but would have to > use some other kind of "window picker". How would you write a > user-friendly picker that can cope with myriad instances of > everything? psst: it's called a notebook in GUI jargon. Again, study up on chrome internals. From rantingrick at gmail.com Mon Jul 4 15:40:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 12:40:18 -0700 (PDT) Subject: Testing if a global is defined in a module References: Message-ID: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> On Jul 4, 1:11?pm, Tim Johnson wrote: > Using Python 2.6 on ubuntu 10.04. > inspect module : > I want to 'inspect' a module and get a list of all > functions, classes and global variables in that module. > > ## A module has been imported, and we call `getmembers' > members = inspect.getmembers(mod) > > ## While iterating thru `members', we test to see > ## if an object is defined in the module. > for m in members: > ? obj = m[1] > ? res = inspect.getmodule(obj) > ## It appears that getmodule returns None for > ## all but functions and classes. > > Example, for a module name `mvcInstall', when a class > name `Install' that is defined in the module > is passed as an argument to inspect.getmodule, the > values returned is something like > " '/home/tim/prj/cgi/libraries/python/mvcInstall.py'>" > Likewise for functions defined in the module. > > ** But ** when global variables such as strings, booleans, > integers are passed as an argument to getmodule, the > value returned is `None'. > > What else can I do here? > thanks > -- > Tim > tim at johnsons-web dot com or akwebsoft dot comhttp://www.akwebsoft.com Well if you follow the python style guide (and most accepted styles for global notation) then it's a trial exercise. You don't even have to import anything!!! :) >>> GLOBAL_STR = 'str' >>> GLOBAL_FLOAT = 1.33333 >>> GLoBaL_Bs = '' >>> dir() ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', '__name__', '__package__', 'item'] >>> for item in dir(): if item.isupper(): print 'Found Global!', item Found Global! GLOBAL_FLOAT Found Global! GLOBAL_STR ;-) From aly.tawfik at gmail.com Mon Jul 4 15:44:48 2011 From: aly.tawfik at gmail.com (Aly Tawfik) Date: Mon, 4 Jul 2011 12:44:48 -0700 (PDT) Subject: Compiling Python 3.2 on Cygwin fails References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> Message-ID: <8759432d-6b53-4021-8992-2213624762f0@u30g2000vby.googlegroups.com> On Jun 20, 12:44?pm, sewpafly wrote: > I was able to a little further by changing 2 lines in Makefile.pre.in. > > On line 170, changed: > ? ? DLLLIBRARY= @DLLLIBRARY@ > to: > ? ? DLLLIBRARY= libpython$(VERSION).dll > > On line 509 it had: > ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) > > which I changed to: > ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) > > Compile finishes with: > Python build finished, but the necessary bits to build these modules > were not found: > _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter > nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd > To find the necessary bits, look in setup.py in detect_modules() for > the module's name. > > Failed to build these modules: > _curses ? ? ? ? ? ?_curses_panel > > But 'make test' returns many errors. > > I'm thinking I'll try Python 3.1 instead. Yes! I am facing the same problem. I, too, will try to install Python 3.1.4 instead. Did it work for you? From aly.tawfik at gmail.com Mon Jul 4 15:49:41 2011 From: aly.tawfik at gmail.com (Aly Tawfik) Date: Mon, 4 Jul 2011 12:49:41 -0700 (PDT) Subject: Compiling Python 3.2 on Cygwin fails References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> Message-ID: <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> On Jun 20, 12:44?pm, sewpafly wrote: > I was able to a little further by changing 2 lines in Makefile.pre.in. > > On line 170, changed: > ? ? DLLLIBRARY= @DLLLIBRARY@ > to: > ? ? DLLLIBRARY= libpython$(VERSION).dll > > On line 509 it had: > ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) > > which I changed to: > ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) > > Compile finishes with: > Python build finished, but the necessary bits to build these modules > were not found: > _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter > nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd > To find the necessary bits, look in setup.py in detect_modules() for > the module's name. > > Failed to build these modules: > _curses ? ? ? ? ? ?_curses_panel > > But 'make test' returns many errors. > > I'm thinking I'll try Python 3.1 instead. I, too, am facing the same problem. Which version of Python 3.1 did you install, and did it work? Thanks! From python at mrabarnett.plus.com Mon Jul 4 15:53:47 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 04 Jul 2011 20:53:47 +0100 Subject: [Python-ideas] Allow isinstance second argument to be a set of types In-Reply-To: References: <4E11656B.4050908@canterbury.ac.nz> <20110704172843.50c5b445@pitrou.net> <1309802125.3688.54.camel@localhost.localdomain> Message-ID: <4E121A4B.2040008@mrabarnett.plus.com> On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote: > Hi, > > 2011/7/4 Antoine Pitrou: >> Le lundi 04 juillet 2011 ? 10:52 -0700, Gregory P. Smith a ?crit : >>> note that a fast lookup implies exact type and not subclass making my >>> point silly... at which point you're back to iterating so I suspect >>> supporting arbitrary iterables is actually how this will be >>> implemented regardless. >> >> Indeed. Note that the tuple case should remain fast, and therefore >> special-cased (or the general list/tuple case, since the difference in C >> is rather small). > > Arbitrary iterables, arbitrarily nested... > beware of objects which are also their first element, like str('a')... > Probably not arbitrarily nested, just a type (type(t) is type) or an iterable yielding types. Anything else would raise an exception. From clp2 at rebertia.com Mon Jul 4 16:09:52 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 4 Jul 2011 13:09:52 -0700 Subject: [Python-ideas] Allow isinstance second argument to be a set of types In-Reply-To: <4E121A4B.2040008@mrabarnett.plus.com> References: <4E11656B.4050908@canterbury.ac.nz> <20110704172843.50c5b445@pitrou.net> <1309802125.3688.54.camel@localhost.localdomain> <4E121A4B.2040008@mrabarnett.plus.com> Message-ID: On Mon, Jul 4, 2011 at 12:53 PM, MRAB wrote: > On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote: >>> Le lundi 04 juillet 2011 ? 10:52 -0700, Gregory P. Smith a ?crit : >>>> >>>> note that a fast lookup implies exact type and not subclass making my >>>> point silly... at which point you're back to iterating so I suspect >>>> supporting arbitrary iterables is actually how this will be >>>> implemented regardless. >> >> Arbitrary iterables, arbitrarily nested... >> beware of objects which are also their first element, like str('a')... >> > Probably not arbitrarily nested, just a type (type(t) is type) or an > iterable yielding types. Anything else would raise an exception. What about a type that is itself iterable (via metaclass magic)? Gotta consider the wacky edge cases. Cheers, Chris From tim at johnsons-web.com Mon Jul 4 16:30:39 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 12:30:39 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <20110704203039.GJ1971@johnsons-web.com> * rantingrick [110704 12:00]: > On Jul 4, 1:11?pm, Tim Johnson wrote: > > Well if you follow the python style guide (and most accepted styles > for global notation) then it's a trial exercise. You don't even have > to import anything!!! :) > > >>> GLOBAL_STR = 'str' > >>> GLOBAL_FLOAT = 1.33333 > >>> GLoBaL_Bs = '' > >>> dir() > ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', > '__name__', '__package__', 'item'] > >>> for item in dir(): > if item.isupper(): > print 'Found Global!', item Thanks for the reply: *but* dir() will also show globals from other modules imported by the target module. So I would need a way to distinguish between those imported and those defined in print(dir(targetmodule)) => ['Install', 'TestAddresses', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] where 'TestAddresses' is a member of an imported module and 'usingCgi' is the only data variable defined in regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From clp2 at rebertia.com Mon Jul 4 17:03:32 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 4 Jul 2011 14:03:32 -0700 Subject: Testing if a global is defined in a module In-Reply-To: <20110704181133.GH1971@johnsons-web.com> References: <20110704181133.GH1971@johnsons-web.com> Message-ID: On Mon, Jul 4, 2011 at 11:11 AM, Tim Johnson wrote: > Using Python 2.6 on ubuntu 10.04. > inspect module : > I want to 'inspect' a module and get a list of all > functions, classes and global variables in that module. You meant "first defined in" that module. > Example, for a module name `mvcInstall', when a class > name `Install' that is defined in the module > is passed as an argument to inspect.getmodule, the > values returned is something like > " '/home/tim/prj/cgi/libraries/python/mvcInstall.py'>" > Likewise for functions defined in the module. > > ** But ** when global variables such as strings, booleans, > integers are passed as an argument to getmodule, the > value returned is `None'. > > What else can I do here? Look at the names in the module's import statements using the `ast` module, and exclude those from the set of names defined in the module. Won't work for `from foo import *`, but that's bad practice and should be refactored anyway. Cheers, Chris -- http://rebertia.com From rantingrick at gmail.com Mon Jul 4 17:30:16 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 14:30:16 -0700 (PDT) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: On Jul 4, 3:30?pm, Tim Johnson wrote: > > ? Thanks for the reply: *but* > ? dir() will also show globals from other modules imported > ? by the target module. So I would need a way to distinguish between > ? those imported and those defined in Okay, then do some processing on the source. You can use regexps or the module mentioned earlier by Chris. From tim at johnsons-web.com Mon Jul 4 17:39:36 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 13:39:36 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <20110704181133.GH1971@johnsons-web.com> Message-ID: <20110704213936.GK1971@johnsons-web.com> * Chris Rebert [110704 13:16]: > > > > What else can I do here? > > Look at the names in the module's import statements using the `ast` > module, and exclude those from the set of names defined in the module. > Won't work for `from foo import *`, but that's bad practice and should > be refactored anyway. I'm completely new to the `ast' module, so I will have to research that one. Thanks for the tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From rosuav at gmail.com Mon Jul 4 17:43:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 07:43:55 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 5:30 AM, rantingrick wrote: > Umm, if you want to see where things are "going" you should learn > about the inner workings of chrome which actually spawns a new process > for every tab created; which has the benefit of avoiding application > lock up when one page decides to crash. There is still one application. There's a single process which is the master; all the other processes die if the master dies. Chrome's isolation of tab-groups has nothing to do with the GUI design question of whether one top-level window is allowed to do more than one thing, which you claimed it should not. >> How would you write a >> user-friendly picker that can cope with myriad instances of >> everything? > > psst: it's called a notebook in GUI jargon. Again, study up on chrome > internals. No, that would not be what it would be called. Also, a notebook is a very specific widget, and it's not quite identical to Chrome's or Firefox's tabbed browsing setup; but again, that has nothing to do with the case. The question is one of UI design. ChrisA From tim at johnsons-web.com Mon Jul 4 17:59:13 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 13:59:13 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <20110704215913.GL1971@johnsons-web.com> * rantingrick [110704 13:47]: > On Jul 4, 3:30?pm, Tim Johnson wrote: > > > > ? Thanks for the reply: *but* > > ? dir() will also show globals from other modules imported > > ? by the target module. So I would need a way to distinguish between > > ? those imported and those defined in > > Okay, then do some processing on the source. You can use regexps or > the module mentioned earlier by Chris. I think I'm making this unnecessarily complicated. I had used something like: from spam import TestAddresses ## just for grins Which is something that I almost never do in practice. Also, you pointed out the UC naming convention, which I was unacquainted with, being self-employed, self-taught and a one-man crew who doesn't spend as much time as he should reading PEPs. I'm going to go for the predicate test as second argument to getmembers with something like: def isdata(self,obj,name): """Check if an object is of a type that probably means it's data.""" return (not (inspect.ismodule(obj) or inspect.isclass(obj) or inspect.isroutine(obj) or inspect.isframe(obj) or inspect.istraceback(obj) or inspect.iscode(obj))) and name.issupper() ## Untested code thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From steve+comp.lang.python at pearwood.info Mon Jul 4 19:13:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:13:25 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Tim Johnson wrote: > dir() will also show globals from other modules imported > by the target module. So I would need a way to distinguish between > those imported and those defined in Why would you want to do that? Importing *is* a definition in . Consider these two code snippets: #1 from math import pi #2 import math tau = 2*math.pi del math Why do you think it is necessary to distinguish pi from tau? Both names are local to the current namespace. > print(dir(targetmodule)) => > ['Install', 'TestAddresses', '__builtins__', '__doc__', > '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', > 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', > 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] > where 'TestAddresses' is a member of an imported module and You are mistaken. TestAddresses is *not* a member of an imported module. It is a member of the current module, which may or may not happen to point to the same object as the other module as well. > 'usingCgi' is the only data variable defined in It seems to me that your approach here is unnecessarily complex and fragile. I don't know what problem you are trying to solve, but trying to solve it by intraspecting differences that aren't differences is surely the wrong way to do it. -- Steven From steve+comp.lang.python at pearwood.info Mon Jul 4 19:24:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:24:00 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 4, 12:06?am, alex23 wrote: >> rantingrick wrote: >> > But why must we have >> > completely different languages just for that those two approaches? >> >> Because monocultures die. > > That's an interesting statement Alex (even though you parrot it > constantly). So what IS a mono culture exactly? Lemme see... > > """A single, homogeneous culture without diversity or dissension. > """ > > Interesting. Would you consider the Python community to be a > monoculture? We are working towards a singular goal so i would say so. We are? Certainly not. Some people want to make Python more dynamic. Some want it to be less dynamic. Some care about integrating it with Java or .Net, some don't care about either. Some are interested in clever optimization tricks, some oppose adding any more complexity. Some want it to be faster, and are happy to throw more memory at it to do so. Some want it to use less memory, because on embedded devices and smart phones memory is the bottleneck, not time. Some only program in Python. Some treat Python as merely one language out of many that they use. Some come to Python from the C/C++ community, and their wants are influenced by C. Some come to Python from Lisp, Scheme or Haskell, and their wants are influenced by functional programming ideas. Some have never programmed before, and don't know want they want. > We should be working towards the language that is best for all but Define "best for all", and try not to make it "what Rick wants". No, Python is not a monoculture. There are the Stackless, Jython, PyPy and IronPython sub-cultures, all with their own needs, wants and desires. There are sub-cultures for embedded devices and smart phones, sub-cultures for those who use Python as a teaching language, for web development, for GUI development, and for system administration. There are the Numpy and Scipy sub-cultures, sub-cultures in the fields of linguistics and biology. > I believe (unlike most people) that nature is striving for perfection > NOT for diversity. Nature isn't striving for anything. Rick, you think that you're an iconoclast bravely swimming against the tide of wrong-headed public opinion, but what you believe is not new and it is not a minority view. It is old, obsolete, and the vast majority of people with no modern biology education believe something like it. It is, essentially, just the Victorian concept of the "Great Chain of Being" -- not that it was unique to the Victorians, of course. > Diversity is just a byproduct of feeble attempts to > GUESS the correct answer. Here is a thought exercise for the advanced > reader...Which is more efficient; Numerous groups working to create > languages that satisfy their selfish needs OR one group of all the > bright minds working to destroy multiplicity and bring about the one > true language that meets the needs of productivity? The first: numerous groups. Anything else is false efficiency. If you think otherwise, you have seriously missed the point. Efficiency requires that all needs are met first. "The most efficient way to build a house" is NOT "Don't build a house, live in a cardboard box, it's cheaper". Who cares if it is cheaper or not, it's not a house, and doesn't meet the required needs. Since needs are frequently in opposition (e.g. the speed/memory trade-off), a single "true language" must be a compromise language that leaves nobody happy. Or some dictator (Rick?) declares that such-and-such a set of features is, by definition, the "perfect" language and those who want something else have to miss out. Imagine a world where *every* shop was Walmart. That would be good for Walmart, but terrible for everyone else. That's Rick's plan for programming. Screw that. We don't want "the perfect language", because there is no such thing and there is no point in wanting square circles or five-sided triangles or invisible pink unicorns. And even if we did, we wouldn't want YOUR idea of the perfect language. Rick, stop trying to "help" the community with these over-reaching grand schemes that nobody but you wants, that always involve you telling everyone else that they have to build the system you think you want. Go do something useful. -- Steven From tim at johnsons-web.com Mon Jul 4 19:26:47 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 15:26:47 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110704232647.GM1971@johnsons-web.com> * Steven D'Aprano [110704 15:18]: > > You are mistaken. TestAddresses is *not* a member of an imported module. It > is a member of the current module, which may or may not happen to point to > the same object as the other module as well. You are correct. I mispoke or misapplied. See my last post. > > > 'usingCgi' is the only data variable defined in > > It seems to me that your approach here is unnecessarily complex and fragile. > I don't know what problem you are trying to solve, but trying to solve it > by intraspecting differences that aren't differences is surely the wrong > way to do it. See my last post... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From steve+comp.lang.python at pearwood.info Mon Jul 4 19:30:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:30:12 +1000 Subject: Problem!! References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results What do you mean "false results"? What does this even mean? Please show us: * what you do * what result you expect * what result you actually get -- Steven From steve+comp.lang.python at pearwood.info Mon Jul 4 19:33:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:33:04 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> Tim Johnson wrote: >> It seems to me that your approach here is unnecessarily complex and >> fragile. I don't know what problem you are trying to solve, but trying to >> solve it by intraspecting differences that aren't differences is surely >> the wrong way to do it. > See my last post... Yes, but what are you actually *trying to do*? "Detecting data members" is not an end in itself. Why do you think you need to detect data members? -- Steven From tim at johnsons-web.com Mon Jul 4 20:01:31 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 16:01:31 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110705000131.GN1971@johnsons-web.com> * Steven D'Aprano [110704 15:48]: > Tim Johnson wrote: > > >> It seems to me that your approach here is unnecessarily complex and > >> fragile. I don't know what problem you are trying to solve, but trying to > >> solve it by intraspecting differences that aren't differences is surely > >> the wrong way to do it. > > See my last post... > > > Yes, but what are you actually *trying to do*? "Detecting data members" is > not an end in itself. Why do you think you need to detect data members? Steven, I'm building a documentation system. I have my own MVC framework and the goal is to have a documentation module for each project. Thanks again for the clarifications. I always learn a lot from you. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From ben+python at benfinney.id.au Mon Jul 4 20:03:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jul 2011 10:03:49 +1000 Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: <8762nhk2ze.fsf@benfinney.id.au> Chris Angelico writes: > In this instance, I believe the OP was paragraphing his text. What is ?paragraphing?? > Is there a convenient way to do that in a triple-quoted string? Did I answer this earlier in the thread (also at )? > My personal inclination would be to simply back-tab it. It looks ugly, > but at least it works, and doesn't require a run-time re-parse. Readability counts. Why is ?doesn't require a run-time re-parse? more valuable than readability? -- \ ?Because of the impropriety of entertaining guests of the | `\ opposite sex in the bedroom, it is suggested that the lobby be | _o__) used for this purpose.? ?hotel, Zurich | Ben Finney From rosuav at gmail.com Mon Jul 4 20:08:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 10:08:26 +1000 Subject: Testing if a global is defined in a module In-Reply-To: <20110705000131.GN1971@johnsons-web.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: > ?Steven, I'm building a documentation system. I have my own MVC framework > ?and the goal is to have a documentation module for each project. > Is there a reason for not using Doxygen / Autodoc / etc, or at least something in the same style? They work from specially-formatted comments in the source code, rather than the compiled module object. ChrisA From drsalists at gmail.com Mon Jul 4 20:09:44 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 4 Jul 2011 17:09:44 -0700 Subject: Problem!! In-Reply-To: <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: It turned out that switching to binary I/O made seek do what he was expecting. I'm guessing the transparent crlf to lf conversions in windows text I/O get seek() a bit perplexed, because it transparently changes the number of bytes. On Mon, Jul 4, 2011 at 4:30 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > amir chaouki wrote: > > > the problem is when i use the seek function on windows it gives me > > false results > > What do you mean "false results"? What does this even mean? > > Please show us: > > * what you do > * what result you expect > * what result you actually get > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jul 4 20:11:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 10:11:41 +1000 Subject: Anyone want to critique this program? In-Reply-To: <8762nhk2ze.fsf@benfinney.id.au> References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> <8762nhk2ze.fsf@benfinney.id.au> Message-ID: On Tue, Jul 5, 2011 at 10:03 AM, Ben Finney wrote: > Chris Angelico writes: > >> In this instance, I believe the OP was paragraphing his text. > > What is ?paragraphing?? If you look at the original code, you'll see embedded newlines used to create multiple paragraphs. Hence, paragraphing as opposed to simply wrapping in order to keep his source lines <80 chars. >> My personal inclination would be to simply back-tab it. It looks ugly, >> but at least it works, and doesn't require a run-time re-parse. > > Readability counts. Why is ?doesn't require a run-time re-parse? more > valuable than readability? Readability definitely counts. But having a string literal require an extra call to make it what you want also costs readability. It's like pushing your literals off to an i18n file - what you gain in flexibility, you lose in simplicity. ChrisA From tim at johnsons-web.com Mon Jul 4 22:01:03 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 18:01:03 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <20110705020103.GO1971@johnsons-web.com> * Chris Angelico [110704 16:19]: > On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: > > ?Steven, I'm building a documentation system. I have my own MVC framework > > ?and the goal is to have a documentation module for each project. > > > > Is there a reason for not using Doxygen / Autodoc / etc, or at least > something in the same style? They work from specially-formatted > comments in the source code, rather than the compiled module object. I want this as a component of my system. It will be bound to a relational data-structure-based 'core' that defines relationships between all files in the project. :) It's called *collateral* And yes, I have worked with comment-based systems, including my own, that worked with multi-language projects. Best regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From davea at ieee.org Mon Jul 4 22:26:53 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 04 Jul 2011 22:26:53 -0400 Subject: Problem!! In-Reply-To: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: <4E12766D.6030001@ieee.org> On 01/-10/-28163 02:59 PM, amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results other then the results on *ux. the file that i work with > are very large about 10mb. > If you still care about this problem, you should take some of the other suggestions to heart; post some code, state what you expected, and what actually happened, and how they're different. But my crystal ball says you're trying to do a seek on a text file, which has restrictions. Once you've called it a text file, you're telling the system to translate cr/lf pairs into lf, which changes the apparent size. So seek has no way to reproduce what reading lines does. To quote the docs at http://docs.python.org/library/stdtypes.html : "If the file is opened in text mode (without 'b'), only offsets returned by tell() are legal. Use of other offsets causes undefined behavior." DaveA -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Mon Jul 4 22:31:01 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 4 Jul 2011 19:31:01 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: rantingrick wrote: > I believe (unlike most people) that nature is striving for perfection Your belief is wrong. "Nature" doesn't "strive" for _anything_. Things in the world are either fit enough to continue their existence or not. As circumstances change, some things that were once suitably fit for the environment are no longer so and are replaced. Same with ideas. There is no "perfection", there is only "what works best now". > What do you think will be the eventual outcome of the human existence > Alex? Since you have no imagination i will tell you, a singular > intelligence. Firstly: cite some kind of evidence that this "will be the eventual outcome" or admit you're talking shit. Secondly: I can imagine humanity evolving into a great many things and something as limited as a 'botnet' is certainly nothing to be proud of as a species. > It is selflessness on a grand scale. I don't really know if you're a troll, have no self-reflective capability, delusionally believe what you're spouting, or are on or off medication, but sometimes your hypocrisy is just funny as hell. >> Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore >> different implementations. > Why can they not explore within the hive mind? Why must they hide > their explorations from the greater group. SELFISHNESS You mean like how Guido hid the Python code base and never let anyone else touch or influence it in any way? Rick, you remind me a lot of Bill Hicks yelling, "You are free to do as we tell you! YOU ARE FREE TO DO AS WE TELL YOU!!" Using terms like "hive mind" kinda shows that I'm wasting my time pushing the value of diversity to you. > * What syntax is most widely intuitive? > * What semantics are the best for productivity? You're inability to recognise the importance of the context in which a language is used explains your misguided position a lot. What if a particular language syntax is the best fit for the way 52% of the population think? What about the other 48%? What if it's a 80/20 split? 90/10? 99/1? At what point are you prepared to sacrifice the needs and best interests of others for your quest for mythical perfection? No need to answer that last one, we already know the answer: from the very beginning. From wuwei23 at gmail.com Mon Jul 4 22:36:25 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 4 Jul 2011 19:36:25 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <4fb6c152-0bb5-4497-b182-14518f18d5eb@s33g2000prg.googlegroups.com> rantingrick wrote: > CREATING THE BEST LANGUAGE WE CAN AT ANY ONE > TIME IN HISTORY... Incidentally, Umberto Eco's "The Search for the Perfect Language" pretty readily exposes this desire as a lingering vestige of the Biblical belief in the one true language that was spoken by God. It also covers in some depth the persistent failure to ever create such a language. Fools, history, rinse & repeat. From ian.g.kelly at gmail.com Tue Jul 5 00:28:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jul 2011 22:28:42 -0600 Subject: Testing if a global is defined in a module In-Reply-To: <20110705000131.GN1971@johnsons-web.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On Mon, Jul 4, 2011 at 6:01 PM, Tim Johnson wrote: >> Yes, but what are you actually *trying to do*? "Detecting data members" is >> not an end in itself. Why do you think you need to detect data members? > > ?Steven, I'm building a documentation system. I have my own MVC framework > ?and the goal is to have a documentation module for each project. It sounds like what you really want is to detect the names *exported* by the module, then. Why not do it the same way Python does it? If the module defines an "__all__" attribute, then it is taken to be a sequence of strings which are the exported names. Otherwise, the exported names are taken to be all the names in the module dict that don't begin with an underscore. Cheers, Ian From gagsl-py2 at yahoo.com.ar Tue Jul 5 00:51:49 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 05 Jul 2011 01:51:49 -0300 Subject: from module import * using __import__? References: Message-ID: En Sat, 02 Jul 2011 16:52:11 -0300, Dan Stromberg escribi?: > Is there a decent way of running "from import *"? Perhaps > using > __import__? > > Does it mean using the copy module or adding an element to globals() > somehow? > > Yes, I think I do have a good use for this: importing either pure python > or > cython versions of a module into a single namespace that can provide the > same interface (transparent to the caller), whether C extension modules > are > viable in the current interpreter or not. So you have a stub module that > provides one or the other, depending on availability and suitability. See pickle.py in Python 3 as an example: the slow (pure Python) code resides in pickle.py; the fast (C code) in _pickle.so (on Windows, a built-in module). Near the end of pickle.py, there is a line "from _pickle import *" which, if successful, overrides (replaces) any previous definitions; if not, the ImportError is trapped and the previously defined Python code remains valid. Unlike the 2.x series, where you should decide to "import cPickle" or "import pickle" (or attempt both, cathcing the ImportError), here you only have to "import pickle" in your code; if the fast module is present, it is automatically loaded and used; else, the slow but compatible version is used. You don't even have to know that an alternative implementation exists. -- Gabriel Genellina From lucio.wal at gmail.com Tue Jul 5 02:28:49 2011 From: lucio.wal at gmail.com (victor lucio) Date: Tue, 5 Jul 2011 01:28:49 -0500 Subject: Embedding a thin python Message-ID: Hi All, I would like to remove some modules for embedding a thin python. how to do that? I would be grateful for your suggestions -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane at harobed.org Tue Jul 5 03:36:59 2011 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Tue, 05 Jul 2011 09:36:59 +0200 Subject: =?windows-1252?Q?imp=2Efind=5Fmodule_don=27t_found_my_mo?= =?windows-1252?Q?dule_but_standard_import_statement_can_impo?= =?windows-1252?Q?rt_this_module=85_why_=3F?= Message-ID: Hi, I would like import some module dynamically. First, I install "js.jquery" $ pip install js.jquery Here, I would like import "js" module. >>> import imp >>> imp.find_module("js") Traceback (most recent call last): File "", line 1, in ImportError: No module named js >>> import js >>> I can't found module with "imp.find_module" but I can import it with standard "import" statement. Where is my mistake ? Regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From gandalf at shopzeus.com Tue Jul 5 04:02:13 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 05 Jul 2011 10:02:13 +0200 Subject: wx MenuItem - icon is missing Message-ID: <4E12C505.3020300@shopzeus.com> def onPopupMenu(self,evt): menu = wx.Menu() for title,bitmap in self.getPopupMenuItems(): item = wx.MenuItem(None,-1,title) if bitmap: item.SetBitmap(bitmap) menu.AppendItem(item) menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) self.PopupMenu( menu, evt.GetPoint()) menu.Destroy() I have read somewhere that under GTK, I have to assign the bitmap before Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu item icons are not showing up in Ubuntu. On Windows 7, everything is fine. What am I doing wrong? System: Ubuntu 11 amd64 Python: 2.7.1+ wx.__version__ '2.8.11.0' Thanks, Laszlo From nobody at nowhere.com Tue Jul 5 04:14:13 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 05 Jul 2011 09:14:13 +0100 Subject: Problem!! References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: On Sun, 03 Jul 2011 16:58:24 -0700, amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results other then the results on *ux. the file that i work with > are very large about 10mb. This is probably an issue with how the underlying C functions behave on Windows, related to the CRLF<->LF conversions when a file is opened in text mode. The Python library documention for the .seek() method says: > If the file is opened in text mode (without 'b'), only offsets returned > by tell() are legal. Use of other offsets causes undefined behavior. IOW, you can't use computed offsets with files opened in text mode (although in practice this will work for platforms other than Windows). If you want to use computed offsets, open the file in binary mode and strip the trailing CRs yourself. And 10MB isn't "very large"; it's not even "large". You normally only start running into problems with files which are 2GiB (2,147,483,648 bytes) or more (i.e. if you can't fit the size into a signed 32-bit integer). From anddimario at gmail.com Tue Jul 5 04:52:57 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Tue, 5 Jul 2011 10:52:57 +0200 Subject: Secure ssl connection with wrap_socket Message-ID: Hi, I'm a new python user and I'm writing a small web service with ssl. I want use a self-signed certificate like in wiki: http://docs.python.org/dev/library/ssl.html#certificates I've used wrap_socket, but if i try to use cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: urllib2.URLError: It works only with CERT_NONE (the default) but with this option i could access to the service in insicure mode. Have you some suggestions for my service? Thanks. Regards. -- Andrea Di Mario From greg.ewing at canterbury.ac.nz Tue Jul 5 07:11:15 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2011 23:11:15 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <97g9qlFootU1@mid.individual.net> rantingrick wrote: > You say "root" windows are bad however any parent-child relationship > has to BEGIN somewhere. There's no need for *toplevel* windows to be children of anything, though. > HOWEVER any of the windows ARE in fact > instances of Tk.Toplevel[1]. So they ARE all equal because they all > have the same methods available to them. No, they're not -- the root window is special, because if you kill it, the whole application exits. Often that is inconvenient. -- Greg From greg.ewing at canterbury.ac.nz Tue Jul 5 07:14:24 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2011 23:14:24 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <97ga0jFq2lU1@mid.individual.net> rantingrick wrote: > Most applications consist of one main window > (a Tkinter.Tk instance). You've obviously never used a Macintosh. On the Mac, it's perfectly normal for an application to open multiple documents, each in its own window, with no one window being the "main" window. Any of them can be closed (or even *all* of them) and the application continues to run until you explicitly quit it. -- Greg From rantingrick at gmail.com Tue Jul 5 07:42:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 04:42:39 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> Message-ID: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> On Jul 4, 2:36?am, Gregory Ewing wrote: > We have different languages because different people have different > ideas about what a language should be like. Ruby people like user > defined control structures; Python people regard user defined > control structures as an anti-feature. It's fundamentally > impossible for one language to satisfy both sets of people. I was thinking more about this comment and it occurred to me that Python does have user controlled data structures. Just because there is no "top level syntax" like ruby does not mean these do not exists. You only have to look below the surface. Take the sort methods of lists for example... >>> lst = [ (100, 0), (25, 2), (10,1), ] >>> lst [(100, 0), (25, 2), (10, 1)] >>> lst.sort() >>> lst [(10, 1), (25, 2), (100, 0)] >>> lst.sort(lambda x,y: cmp(x[1], y[1])) >>> lst [(100, 0), (10, 1), (25, 2)] ...that looks like a "user defined control" structure to me. So how can an anti-feature become part of the language proper? (devils advocate here) :) I leave the discovery of other user defined control structures for the advanced readers. From hv at tbz-pariv.de Tue Jul 5 08:02:32 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Tue, 05 Jul 2011 14:02:32 +0200 Subject: HeaderParseError In-Reply-To: References: <97dc37F7gaU1@mid.individual.net> <97djhfF10kU1@mid.individual.net> Message-ID: <97gcqoFfd1U1@mid.individual.net> On 04.07.2011 13:20, Peter Otten wrote: > Thomas Guettler wrote: > >> On 04.07.2011 11:51, Peter Otten wrote: >>> Thomas Guettler wrote: >>> >>>> I get a HeaderParseError during decode_header(), but Thunderbird can >>>> display the name. >>>> >>>>>>> from email.header import decode_header >>>>>>> >>> Hi, I created a ticket: http://bugs.python.org/issue12489 Thomas G?ttler -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From ulrich.eckhardt at dominolaser.com Tue Jul 5 08:50:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 05 Jul 2011 14:50:11 +0200 Subject: embedding: how do I redirect print output? Message-ID: Hi! I'm trying to add some scripting capabilities to an application. Since it is a GUI application, I need some way to display output from Python. For 3.x, where "print" is a function, I'd just exchange this function with one that redirects the output to a log window, right. However, I'm using 2.6 here, where that can't work. So, what I was thinking was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly replace "sys.stdin" with something that causes meaningful errors if some code tries to use it, but that last point is just icing on the cake. What seems cumbersome is that I'll need to write something that supports the file interface using C, which is still a bit awkward. I'm wondering, isn't there an easier way to achieve this? How would you do it? Thank you! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From philip at semanchuk.com Tue Jul 5 08:50:23 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 5 Jul 2011 08:50:23 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E12C505.3020300@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> Message-ID: <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> On Jul 5, 2011, at 4:02 AM, Laszlo Nagy wrote: > def onPopupMenu(self,evt): > menu = wx.Menu() > for title,bitmap in self.getPopupMenuItems(): > item = wx.MenuItem(None,-1,title) > if bitmap: > item.SetBitmap(bitmap) > menu.AppendItem(item) > menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) > self.PopupMenu( menu, evt.GetPoint()) > menu.Destroy() > > I have read somewhere that under GTK, I have to assign the bitmap before Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu item icons are not showing up in Ubuntu. On Windows 7, everything is fine. What am I doing wrong? > > System: Ubuntu 11 amd64 > Python: 2.7.1+ > wx.__version__ '2.8.11.0' Hi Laszlo, Two suggestions -- 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. 2. Ask on the wxPython mailing list. Good luck Philip From ericsnowcurrently at gmail.com Tue Jul 5 09:44:00 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 5 Jul 2011 07:44:00 -0600 Subject: =?windows-1252?Q?Re=3A_imp=2Efind=5Fmodule_don=27t_found_my_module_but_standa?= =?windows-1252?Q?rd_import_statement_can_import_this_module=85_why_=3F?= In-Reply-To: References: Message-ID: On Tue, Jul 5, 2011 at 1:36 AM, St?phane Klein wrote: > Hi, > > I would like import some module dynamically. > To import a module dynamically, you can use the built-in __import__ function: module = __import__("js") Even better, use importlib's import_module, which is available in 2.7/3.2. A backport is available on PyPI. module = importlib.import_module("js") -eric > First, I install "js.jquery" > > $ pip install js.jquery > > Here, I would like import "js" module. > >>>> import imp >>>> imp.find_module("js") > Traceback (most recent call last): > ?File "", line 1, in > ImportError: No module named js >>>> import js >>>> > > I can't found module with "imp.find_module" but I can import it with > standard "import" statement. > > Where is my mistake ? > > Regards, > Stephane > -- > St?phane Klein > blog: http://stephane-klein.info > Twitter: http://twitter.com/klein_stephane > pro: http://www.is-webdesign.com > > -- > http://mail.python.org/mailman/listinfo/python-list > From stephane at harobed.org Tue Jul 5 09:47:11 2011 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Tue, 05 Jul 2011 15:47:11 +0200 Subject: =?windows-1252?Q?Re=3A_imp=2Efind=5Fmodule_don=27t_found_?= =?windows-1252?Q?my_module_but_standard_import_statement_can?= =?windows-1252?Q?_import_this_module=85_why_=3F?= In-Reply-To: References: Message-ID: Le 05/07/2011 15:44, Eric Snow a ?crit : > On Tue, Jul 5, 2011 at 1:36 AM, St?phane Klein wrote: >> Hi, >> >> I would like import some module dynamically. >> > > To import a module dynamically, you can use the built-in __import__ function: > > module = __import__("js") > > Even better, use importlib's import_module, which is available in > 2.7/3.2. A backport is available on PyPI. > > module = importlib.import_module("js") > Thanks ! It's work very well. Regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From michael at stroeder.com Tue Jul 5 10:02:39 2011 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Tue, 05 Jul 2011 16:02:39 +0200 Subject: ANN: python-ldap 2.4.1 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.1 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.1 2011-07-05 Changes since 2.4.0: Modules: * New LDAP option OPT_X_TLS_PACKAGE available in OpenLDAP 2.4.26+ to determine the name of the SSL/TLS package OpenLDAP was built with Lib/ * ldap.modlist.modifyModlist(): New key-word argument case_ignore_attr_types used to define attribute types for which comparison of old and new values should be case-insensitive * Minor changes to which data is sent to debug output for various trace levels * Now tag [1] is used in ldap.extop.dds.RefreshResponse in compliance with RFC 2589 (fix available for OpenLDAP ITS#6886) * New sub-module ldap.controls.sessiontrack implements request control as described in draft-wahl-ldap-session (needs pyasn1_modules) From calderone.jeanpaul at gmail.com Tue Jul 5 10:08:59 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 5 Jul 2011 07:08:59 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: Message-ID: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> On Jul 5, 4:52?am, Andrea Di Mario wrote: > Hi, I'm a new python user and I'm writing a small web service with ssl. > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > I've used wrap_socket, but if i try to use > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > urllib2.URLError: specified for verification of other-side certificates.> > > It works only with CERT_NONE (the default) but with this option i > could access to the service in insicure mode. > > Have you some suggestions for my service? > Also specify some root certificates to use in verifying the peer's certificate. Certificate verification works by proceeding from a collection of "root" certificates which are explicitly trusted. These are used to sign other certificates (which may in turn be used to sign others, which in turn...). The process of certificate verification is the process of following the signatures from the certificate in use by the server you connect to back up the chain until you reach a root which you have either decided to trust or not. If the signatures are all valid and the root is one you trust, then you have established a connection to a trusted entity. If any signature is invalid, or the root is not one you trust, then you have not. The root certificates are also called the "ca certificates" or "certificate authority certificates". `wrap_socket` accepts a `ca_certs` argument. See http://docs.python.org/library/ssl.html#ssl-certificates for details about that argument. Jean-Paul From invalid at invalid.invalid Tue Jul 5 10:11:56 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 14:11:56 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Chris Angelico wrote: > On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: >>>Steven, I'm building a documentation system. I have my own MVC >>>framework and the goal is to have a documentation module for each >>>project. >> > > Is there a reason for not using Doxygen / Autodoc / etc, or at least > something in the same style? They work from specially-formatted > comments in the source code, rather than the compiled module object. Because those specially-formatted comments are wrong. -- Grant Edwards grant.b.edwards Yow! I have many CHARTS at and DIAGRAMS.. gmail.com From t at jollybox.de Tue Jul 5 10:18:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:18:20 +0200 Subject: embedding: how do I redirect print output? In-Reply-To: References: Message-ID: <4E131D2C.5010904@jollybox.de> On 07/05/2011 02:50 PM, Ulrich Eckhardt wrote: > I'm trying to add some scripting capabilities to an application. Since it is > a GUI application, I need some way to display output from Python. For 3.x, > where "print" is a function, I'd just exchange this function with one that > redirects the output to a log window, right. > > However, I'm using 2.6 here, where that can't work. So, what I was thinking > was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly > replace "sys.stdin" with something that causes meaningful errors if some > code tries to use it, but that last point is just icing on the cake. > > What seems cumbersome is that I'll need to write something that supports the > file interface using C, which is still a bit awkward. I'm wondering, isn't > there an easier way to achieve this? How would you do it? You can mess with low-level file descriptors. Example: # create new stdout: fout = file('out.txt', 'w') # close stdout (fd 1) import os os.close(1) # use fout as new stdout os.dup2(fout.fileno(), 1) # test. This will end up in out.txt print "Testing." # do the same for stdin (0) and stderr (2) # - EOF - However, I suggest you consider isolating your scripts from you main program and run them in a separate interpreter. You can provide dummy modules that communicate with your application via sockets to the scripts. Setting the standard files in the child process is easy: the Popen constructor takes stdin/stdout/stderr arguments. -T From drobinow at gmail.com Tue Jul 5 10:25:15 2011 From: drobinow at gmail.com (David Robinow) Date: Tue, 5 Jul 2011 10:25:15 -0400 Subject: Compiling Python 3.2 on Cygwin fails In-Reply-To: <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> Message-ID: On Mon, Jul 4, 2011 at 3:49 PM, Aly Tawfik wrote: > On Jun 20, 12:44?pm, sewpafly wrote: >> I was able to a little further by changing 2 lines in Makefile.pre.in. >> >> On line 170, changed: >> ? ? DLLLIBRARY= @DLLLIBRARY@ >> to: >> ? ? DLLLIBRARY= libpython$(VERSION).dll >> >> On line 509 it had: >> ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) >> >> which I changed to: >> ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) >> >> Compile finishes with: >> Python build finished, but the necessary bits to build these modules >> were not found: >> _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter >> nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd >> To find the necessary bits, look in setup.py in detect_modules() for >> the module's name. >> >> Failed to build these modules: >> _curses ? ? ? ? ? ?_curses_panel >> >> But 'make test' returns many errors. >> >> I'm thinking I'll try Python 3.1 instead. > > I, too, am facing the same problem. Which version of Python 3.1 did > you install, and did it work? Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > Cygwin is not really a supported platform. Reverting to Python 3.1 won't help at all. Download the 2.6.5 source version (i.e., click the Src box) using cygwin setup. Apply the included patches [some don't apply cleanly any more]. That will get you most of the way there. There are a few other issues the details of which I don't remember. I'm not sure why there hasn't been a cygwin distribution lately. You might ask on the cygwin mailing list. [Ultimately somebody with an interest in cygwin will need to get active in python development. I've been meaning to do this but life gets in the way.] DR From t at jollybox.de Tue Jul 5 10:25:29 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:25:29 +0200 Subject: Embedding a thin python In-Reply-To: References: Message-ID: <4E131ED9.3000408@jollybox.de> On 07/05/2011 08:28 AM, victor lucio wrote: > Hi All, > > I would like to remove some modules for embedding a thin python. > how to do that? > I would be grateful for your suggestions > > > Start your favourite file manager and delete them. From steve+comp.lang.python at pearwood.info Tue Jul 5 10:25:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 00:25:58 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> Message-ID: <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Gregory Ewing wrote: > rantingrick wrote: >> Most applications consist of one main window >> (a Tkinter.Tk instance). > > You've obviously never used a Macintosh. On the Mac, it's > perfectly normal for an application to open multiple > documents, each in its own window, with no one window > being the "main" window. Any of them can be closed (or > even *all* of them) and the application continues to run > until you explicitly quit it. Or a Linux GUI. I have kwrite running with 15 open windows. The application doesn't exit until the last window is closed, and no window is privileged over the others. Even in Windows, the sort of MDI interface Rick seems to be describing is less common now than it used to be -- possibly even rare. http://en.wikipedia.org/wiki/Multiple_document_interface -- Steven From t at jollybox.de Tue Jul 5 10:35:27 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:35:27 +0200 Subject: from module import * using __import__? In-Reply-To: References: Message-ID: <4E13212F.2030005@jollybox.de> On 07/02/2011 09:52 PM, Dan Stromberg wrote: > > Is there a decent way of running "from import *"? Perhaps > using __import__? > > Does it mean using the copy module or adding an element to globals() > somehow? Yes, exactly. That's what `from x import *` does: Get the module, and then add all members to the global namespace. def import_all_from (module_name): mod = __import__(module_name) for member_name in dir(mod): globals()[member_name] = getattr(mod, member_name) Of course, don't do this, do what Gabriel said. -T From steve+comp.lang.python at pearwood.info Tue Jul 5 10:36:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 00:36:43 +1000 Subject: embedding: how do I redirect print output? References: Message-ID: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Ulrich Eckhardt wrote: > Hi! > > I'm trying to add some scripting capabilities to an application. Since it > is a GUI application, I need some way to display output from Python. For > 3.x, where "print" is a function, I'd just exchange this function with one > that redirects the output to a log window, right. > > However, I'm using 2.6 here, where that can't work. So, what I was > thinking was to redirect "sys.stdout" and "sys.stderr" to a log window and > possibly replace "sys.stdin" with something that causes meaningful errors > if some code tries to use it, but that last point is just icing on the > cake. > > What seems cumbersome is that I'll need to write something that supports > the file interface using C, which is still a bit awkward. I'm wondering, > isn't there an easier way to achieve this? How would you do it? Why do you think it needs to be in C? As far as I can tell, so long as it quacks like a file object (that is, has a write method), it should work. >>> import StringIO, sys >>> class Test: ... def __init__(self): ... self.out = sys.stdout ... self.log = StringIO.StringIO() ... def write(self, text): ... self.log.write(text.upper()) ... self.out.write(''.join(reversed(text))) ... >>> fake_out = Test() >>> sys.stdout = fake_out >>> print "Hello world" dlrow olleH >>> print "Goodbye cruel world!!!" !!!dlrow leurc eybdooG >>> sys.stdout = sys.__stdout__ >>> fake_out.log.getvalue() 'HELLO WORLD\nGOODBYE CRUEL WORLD!!!\n' -- Steven From t at jollybox.de Tue Jul 5 10:49:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:49:20 +0200 Subject: can I package a distutil based python app in deb? In-Reply-To: <4E07737C.7090900@gmail.com> References: <4E07737C.7090900@gmail.com> Message-ID: <4E132470.7080609@jollybox.de> On 06/26/2011 07:59 PM, hackingKK wrote: > Hello all, > I guess the subject line says it all. > I want to package a python app to deb. > I have 3 interesting issues with it. > 1, I would want it to run on Ubuntu 10.04, Ubuntu 10.10, Ubuntu 11.04 > and Debian 5. > 2, the package depends on another python package which is also distutil > based. > 3, The second package needs to run in a virtual environment. > This means that I not only have to figure out the dependencies but also > have the deb to include a script to get the virtual environment script, > then create one for the package, then download all dependencies (Pylons > 0.9.7 in this case along with report lab) and finally put the package > into this virtual environment. > Is this all possible? Yes, it is possible. Refer to , particularly the New Maintainer's Guide: From t at jollybox.de Tue Jul 5 11:05:11 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 17:05:11 +0200 Subject: module problem on windows 64bit In-Reply-To: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> References: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> Message-ID: <4E132827.90101@jollybox.de> On 06/27/2011 06:59 PM, miamia wrote: > Hello, > > on 32-bit windows everything works ok but on 64-bit win I am getting > this error: > Traceback (most recent call last): > File "app.py", line 1040, in do_this_now > File "kinterbasdb\__init__.pyc", line 119, in > File "kinterbasdb\_kinterbasdb.pyc", line 12, in > File "kinterbasdb\_kinterbasdb.pyc", line 10, in __load > ImportError: DLL load failed: This application has failed to start > because the application configuration is incorrect. Reinstalling the > application may fix this problem. > > How to get it work on 64bit windows as well? many thanks A process can only link to a shared library compiled for the same architecture as the process. In layman's terms: A 32-bit DLL won't work with a 64-bit program. It looks like this package is attempting to load a 32-bit DLL. That's not going to work. Either procure a 64-bit version of the DLL, or use a 32-bit version of Python. From rosuav at gmail.com Tue Jul 5 11:17:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 01:17:30 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:25 AM, Steven D'Aprano wrote: > Gregory Ewing wrote: > >> You've obviously never used a Macintosh. On the Mac, it's >> perfectly normal for an application to open multiple >> documents, each in its own window, with no one window >> being the "main" window. Any of them can be closed (or >> even *all* of them) and the application continues to run >> until you explicitly quit it. > > Or a Linux GUI. I have kwrite running with 15 open windows. The application > doesn't exit until the last window is closed, and no window is privileged > over the others. It's actually quite easy to implement this, even if you _are_ forced to have one primary window. You just have an invisible primary whose sole purpose is to "be the application", and then everything else is secondary windows. Kinda defeats the purpose of forcing applications to have one primary window, though. To my thinking, there will always be one primary *thread*, and GUI facilities are secondary to the process, never the other way around. When the main thread exits, the process ends. ChrisA From rosuav at gmail.com Tue Jul 5 11:20:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 01:20:07 +1000 Subject: embedding: how do I redirect print output? In-Reply-To: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:36 AM, Steven D'Aprano wrote: >>>> print "Hello world" > dlrow olleH > You, sir, have a warped and twisted mind. And I love it!! Now to secretly put code into some module somewhere and wait for people to start tearing their hair out.... wait, did I say that out loud? ChrisA From steve+comp.lang.python at pearwood.info Tue Jul 5 11:26:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 01:26:06 +1000 Subject: Implicit initialization is EXCELLENT Message-ID: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> This is not strictly Python, although it is peripherally relevant. Some month or three ago, I read an article or blog post about API design, specifically the wrong-headedness of insisting that callers manually initialise instances using a separate step after creation. The argument goes, if your API looks something like this: instance = Spaminator(extra_truffles=False) instance.activate() instance.nom_nom_nom() => prints "yummy spam, the food of the Gods!!!" chances are that you are doing it wrong and your users will hate you. Why force the user to manually "flip the switch" (so to speak)? It's not like they can possibly avoid it: another_instance = Spaminator(with_extra_cheese=True) another_instance.nom_nom_nom() => raises InactiveInstanceError("you must activate the instance first") What? No! Just activate yourself! Exceptions to this rule are if the Spaminator has side-effects (e.g. files, in which case the user may want finer control in when they are opened and closed), or if there are meaningful operations you can perform on an inactive Spaminator. Python generally follows this design. Apart from files, I can't easily think off the top of my head of any types that require a separate open/start/activate call before they are usable. It's also relevant to tkinter, which will implicitly create a root window for you when needed. Since you can't do anything without a root window, I don't see the benefit in forcing the user to do so. When they need to learn about root windows, they will in their own good time. Now, I have an ulterior motive in raising this issue... I can't find the original article I read! My google-fu has failed me (again...). I don't suppose anyone can recognise it and can point me at it? -- Steven From tim at johnsons-web.com Tue Jul 5 11:30:30 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 5 Jul 2011 07:30:30 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <20110705153029.GP1971@johnsons-web.com> * Ian Kelly [110704 20:37]: > > It sounds like what you really want is to detect the names *exported* > by the module, then. i Yes! > Why not do it the same way Python does it? If > the module defines an "__all__" attribute, then it is taken to be a > sequence of strings which are the exported names. Otherwise, the > exported names are taken to be all the names in the module dict that > don't begin with an underscore. :) Oh here we go again. Another python feature I didn't know about or have forgotten. Thanks very much for that. Good tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From pruebauno at latinmail.com Tue Jul 5 11:33:09 2011 From: pruebauno at latinmail.com (nn) Date: Tue, 5 Jul 2011 08:33:09 -0700 (PDT) Subject: Implicit initialization is EVIL! References: Message-ID: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> On Jul 4, 11:35?am, Robin Becker wrote: > On 03/07/2011 23:21, Chris Angelico wrote: > ......... > > > var(0x14205359) x ? # Don't forget to provide an address where the > > object will be located > > x=42 > > ........ > did you forget to specify the memory bank and computer (and presumably planet > etc etc....) > -molly-coddled-ly yrs- > Robin Becker Ah, I see we have a mainframe programmer among us ... :-) From invalid at invalid.invalid Tue Jul 5 11:43:02 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 15:43:02 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Tim Johnson wrote: > * Ian Kelly [110704 20:37]: >> >> It sounds like what you really want is to detect the names *exported* >> by the module, then. i > Yes! >> Why not do it the same way Python does it? If >> the module defines an "__all__" attribute, then it is taken to be a >> sequence of strings which are the exported names. Otherwise, the >> exported names are taken to be all the names in the module dict that >> don't begin with an underscore. > > :) Oh here we go again. Another python feature I didn't know about > or have forgotten. You could probably implement at least two more languages using nothing but Python features I don't know about or have forgotten. :) Yet I still manage to get a lot accomplished using Python. -- Grant Edwards grant.b.edwards Yow! I don't know WHY I at said that ... I think it gmail.com came from the FILLINGS in my rear molars ... From kb1pkl at aim.com Tue Jul 5 12:04:32 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 05 Jul 2011 12:04:32 -0400 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <1309881085-sup-1096@dalek> Excerpts from rantingrick's message of Tue Jul 05 07:42:39 -0400 2011: > > I was thinking more about this comment and it occurred to me that > Python does have user controlled data structures. Just because there > is no "top level syntax" like ruby does not mean these do not exists. > You only have to look below the surface. Take the sort methods of > lists for example... > > >>> lst = [ > (100, 0), > (25, 2), > (10,1), > ] > >>> lst > [(100, 0), (25, 2), (10, 1)] > >>> lst.sort() > >>> lst > [(10, 1), (25, 2), (100, 0)] > >>> lst.sort(lambda x,y: cmp(x[1], y[1])) > >>> lst > [(100, 0), (10, 1), (25, 2)] > > ...that looks like a "user defined control" structure to me. So how > can an anti-feature become part of the language proper? (devils > advocate here) :) > How is giving the sort method a function by which to determine the relative value of objects a control structure? Do you know what a control structure is? It's something that you use to modify control flow: if foo <= bar: foo += 1 else: bar += 1 That's a control structurem the "if-else". I don't know what Ruby calls a control structure, but that's what it is. for and while are in there too. When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? We'll call that argument srt, here's a sample (naive) implementation: def sort(key): lst = self.internal_list for n in range(len(self.internal_list) - 1): for i in range(len(self.internal_list) - 1): if srt(lst[i], lst[i+1]) < 0: lst[i], lst[i+1] = lst[i+1], lst[i] Untested, probably doesn't work either. See what's in there? An if. Nothing "user-defined" at all. Sure, WHAT the if does is user-controlled with the key, but that doesn't make that particular if a new control structure, and it certainly doesn't make the key a control structure. You can pass a key to a sort even in C and that certainly doesn't have user defined control structures. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From robin at reportlab.com Tue Jul 5 12:23:42 2011 From: robin at reportlab.com (Robin Becker) Date: Tue, 05 Jul 2011 17:23:42 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> References: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> Message-ID: <4E133A8E.7020602@chamonix.reportlab.co.uk> On 05/07/2011 16:33, nn wrote: ...... > Ah, I see we have a mainframe programmer among us ... :-) so long since I manipulated the switches of that old pdp-8 -anciently yrs- Robin Becker From k.sahithi2862 at gmail.com Tue Jul 5 12:28:50 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 5 Jul 2011 09:28:50 -0700 (PDT) Subject: VIDEOS FOR HOT GUYS Message-ID: <253bb1c2-3493-4ce4-9849-8d6bb13be2bb@f39g2000prb.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From wm at localhost.localdomain Tue Jul 5 12:35:22 2011 From: wm at localhost.localdomain (Waldek M.) Date: Tue, 5 Jul 2011 18:35:22 +0200 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): > Because those specially-formatted comments are wrong. ... because? Not in sarcasm mode; just curious why you don't like them. Br. Waldek From steve+comp.lang.python at pearwood.info Tue Jul 5 13:36:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 03:36:24 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Waldek M. wrote: > Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): >> Because those specially-formatted comments are wrong. > > ... because? > Not in sarcasm mode; just curious why you don't like them. Because unless you are extremely disciplined, code and the comments describing them get out of sync. Quote: "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. " --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 -- Steven From salmig99 at gmail.com Tue Jul 5 14:14:11 2011 From: salmig99 at gmail.com (sal migondis) Date: Tue, 5 Jul 2011 11:14:11 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> On Jul 4, 10:31?pm, alex23 wrote: > rantingrick wrote: > > I believe (unlike most people) that nature is striving for perfection > > Your belief is wrong. "Nature" doesn't "strive" for _anything_. Things > in the world are either fit enough to continue their existence or not. > As circumstances change, some things that were once suitably fit for > the environment are no longer so and are replaced. Same with ideas. > There is no "perfection", there is only "what works best now". How could a belief be wrong? > > What do you think will be the eventual outcome of the human existence > > Alex? Since you have no imagination i will tell you, a singular > > intelligence. All from the land of creationism. > Firstly: cite some kind of evidence that this "will be the eventual > outcome" or admit you're talking shit. > > Secondly: I can imagine humanity evolving into a great many things and > something as limited as a 'botnet' is certainly nothing to be proud of > as a species. > > > It is selflessness on a grand scale. > > I don't really know if you're a troll, Beats me... I think everybody else does.. > have no self-reflective > capability, delusionally believe what you're spouting, or are on or > off medication, but sometimes your hypocrisy is just funny as hell. > > >> Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > >> different implementations. > > Why can they not explore within the hive mind? Why must they hide > > their explorations from the greater group. SELFISHNESS > > You mean like how Guido hid the Python code base and never let anyone > else touch or influence it in any way? > > Rick, you remind me a lot of Bill Hicks yelling, "You are free to do > as we tell you! YOU ARE FREE TO DO AS WE TELL YOU!!" Using terms like > "hive mind" kinda shows that I'm wasting my time pushing the value of > diversity to you. Now you're taking a troll as an excuse for your own trolling. > No need to answer that last one, we already know the answer: from the > very beginning. In the beginning was a singularity... and Albert Einstein was a chain- smoker. Sal. From steveo at syslang.net Tue Jul 5 14:31:07 2011 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 05 Jul 2011 14:31:07 -0400 Subject: Question about how to get line buffering from paramiko Message-ID: <4E13586B.4040109@syslang.net> I'm writing a program that uses paramiko to run a lot of commands over ssh. Some of the commands take time to run and they write to stdout and stderr as a normal part of their operation so that we can see progress happening. I can't seem to get the output from the remote commands (which is input to me) to be line buffered. If I run the commands using ssh, they line buffer nicely. If I run them through paramiko, they end up fully buffered. I stole this code I found as a base. The code that I got looked like the execute_capture method (below). I added the execute method so that I could poll for the result from both stderr and stdout. Note that I am calling channel.get_pty, but that doesn't change the fact that the results are not line buffered. Can anyone suggest a way to solve this? The code I'm using follows: #! /usr/bin/python """ Friendly Python SSH2 interface using paramiko """ import os import sys import tempfile import paramiko import select from collections import namedtuple ExecStatus = namedtuple('ExecStatus', 'status stdout stderr') class Connection(object): """ Connects and logs into the specified hostname. Arguments that are not given are guessed from the environment. """ def __init__(self, host, username = None, private_key = None, password = None, port = 22, blocking_cmds = True, verbose = False, ): self._sftp_live = False self._sftp = None if not username: username = os.environ['LOGNAME'] # Log to a temporary file if requested. if verbose: self.templog = tempfile.mkstemp('.txt', 'ssh-')[1] paramiko.util.log_to_file(self.templog) else: self.templog = False # Begin the SSH transport. self._transport = paramiko.Transport((host, port)) self._tranport_live = True # Authenticate the transport. if password: # Using Password. self._transport.connect(username = username, password = password) else: # Use Private Key. if not private_key: # Try to use default key. if os.path.exists(os.path.expanduser('~/.ssh/id_rsa')): private_key = '~/.ssh/id_rsa' elif os.path.exists(os.path.expanduser('~/.ssh/id_dsa')): private_key = '~/.ssh/id_dsa' else: raise TypeError, "You have not specified a password or key." private_key_file = os.path.expanduser(private_key) rsa_key = paramiko.RSAKey.from_private_key_file(private_key_file) self._transport.connect(username = username, pkey = rsa_key) def _sftp_connect(self): """Establish the SFTP connection.""" if not self._sftp_live: self._sftp = paramiko.SFTPClient.from_transport(self._transport) self._sftp_live = True def get(self, remotepath, localpath = None): """Copies a file between the remote host and the local host.""" if not localpath: localpath = os.path.split(remotepath)[1] self._sftp_connect() self._sftp.get(remotepath, localpath) def put(self, localpath, remotepath = None): """Copies a file between the local host and the remote host.""" if not remotepath: remotepath = os.path.split(localpath)[1] self._sftp_connect() self._sftp.put(localpath, remotepath) def execute(self, command): """ Execute the given commands on a remote machine. Return value is exit status of the remote command. """ # This execute method is similar to execute_capture below. The # difference is that this method gets the stdout and stderr of # the runnning command and forwards it on to the correct # channel within this process. # To do this, we use the poll(2) system call which comes from # the select package. def _write(fd, chan, syschan): """ _write internal method to check an fd from the list of fds for a POLLIN event, read the data that's there, and if there's anything there, then write it to the correct channel. Return True if there was something to read. """ ret = False if fd[1] & select.POLLIN: if fd[0] == chan.channel.fileno(): ss = chan.readline() ret = len(ss) != 0 if ret: # No need to strip and then print with a newline. # because every line is newline terminated. print >> syschan, ss[:-1] return ret # Open a channel of type session. Same as open_channel('session') channel = self._transport.open_session() # Calling get_pty does get us a pty # If the 2nd arg is 1, then it should be line buffered. Apparently, # in this context, line buffering refers to output to the process, # not input from the process. channel.get_pty() # Run command on the session of type channel. This returns immediately. channel.exec_command(command) # Get the stdout and stderr file descriptors. In this context, makefile # has nothing to do with the make utility. It's about making # file descriptors. stdout = channel.makefile('rb', 1) stderr = channel.makefile_stderr('rb', 1) # Create a polling object. We really only care about POLLIN events. po = select.poll() po.register(stdout.channel, select.POLLIN) po.register(stderr.channel, select.POLLIN) # Set found_output tto True to start the loop. Set it to False # as an initial value inside the loop, and OR the value on if any data # got written by either channel. found_output = True while found_output == True: found_output = False fds = po.poll() for fd in fds: found_output |= _write(fd, stdout, sys.stdout) found_output |= _write(fd, stderr, sys.stderr) status = channel.recv_exit_status() channel.close() return status def execute_capture(self, command): """ Execute the given commands on a remote machine. Return value is a 3-tuple: exit status, stdout and stderr Output is not written out. """ # Open a channel of type session. Same as open_channel('session') channel = self._transport.open_session() # Run command on the session of type channel. This returns immediately. channel.exec_command(command) # Collect stdout and stderr into lists. # The alternative would be to harvest the 3-tuple std{in,out,err} # of file descriptors returned by exec_command. stdout = channel.makefile('rb', -1).readlines() stderr = channel.makefile_stderr('rb', -1).readlines() # Not well documented, but recv_exit_status will block until # the command completes. Return value is the exit status. status = channel.recv_exit_status() channel.close() return ExecStatus(status, stdout, stderr) def close_transport(self): # Close the SSH Transport. if self._tranport_live: self._transport.close() self._tranport_live = False def close_sftp(self): # Close SFTP Connection. if self._sftp_live: self._sftp.close() self._sftp_live = False def close(self): """Closes the connection and cleans up.""" self.close_transport() self.close_sftp() # start the ball rolling. if __name__ == "__main__": def proc_exec(cmd): status = myssh.execute(cmd) print "Just ran %s with exit status %d"%(cmd, status) # Another choice is to call # def proc_exec(cmd): # run = myssh.execute_capture(cmd) # print "Just ran %s with exit status %d"%(cmd, status) # if run.stdout: # print "output:\n", ''.join(run.stdout)[:-1] # if run.stderr: # print "error:\n", ''.join(run.stderr)[:-1] # Little test when called directly. # Set these to your own details. myssh = Connection('host', username='user') proc_exec('pwd') proc_exec('false') proc_exec('xxx.sh') proc_exec('cd sorr; pwd') proc_exec('pwd') proc_exec('tty') myssh.close() -- 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 enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Jul 5 15:04:46 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 05 Jul 2011 21:04:46 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e136051$0$18782$ba4acef3@reader.news.orange.fr> Hi! +1 @-salutations -- Michel Claveau From ian.g.kelly at gmail.com Tue Jul 5 15:17:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2011 13:17:25 -0600 Subject: emacs lisp text processing example (html5 figure/figcaption) In-Reply-To: References: Message-ID: On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > So, a solution by regex is out. Actually, none of the complications you listed appear to exclude regexes. Here's a possible (untested) solution:
((?:\s*[^)+) \s*

((?:[^<]|<(?!/p>))+)

\s*
and corresponding replacement string:
\1
\2
I don't know what dialect Emacs uses for regexes; the above is the Python re dialect. I assume it is translatable. If not, then the above should at least work with other editors, such as Komodo's "Find/Replace in Files" command. I kept the line breaks here for readability, but for completeness they should be stripped out of the final regex. The possibility of nested HTML in the caption is allowed for by using a negative look-ahead assertion to accept any tag except a closing

. It would break if you had nested

tags, but then that would be invalid html anyway. Cheers, Ian From mwilson at the-wire.com Tue Jul 5 15:27:39 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 05 Jul 2011 15:27:39 -0400 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: [ ... ] > Python generally follows this design. Apart from files, I can't easily > think off the top of my head of any types that require a separate > open/start/activate call before they are usable. It's also relevant to > tkinter, which will implicitly create a root window for you when needed. > Since you can't do anything without a root window, I don't see the benefit > in forcing the user to do so. When they need to learn about root windows, > they will in their own good time. In wx, many of the window classes have Create methods, for filling in various attributes in "two-step construction". I'm not sure why, because it works so well to just supply all the details when the class is called and an instance is constructed. Maybe there's some C++ strategy that's being supported there. Mel. From stefaan.himpe at gmail.com Tue Jul 5 15:31:44 2011 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Tue, 05 Jul 2011 21:31:44 +0200 Subject: Implicit initialization is EXCELLENT In-Reply-To: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hello, I agree with the contents of this post. I see a similar problem with API's requiring to initialize all kinds of data using setters/properties instead of receiving it in the initializer (or constructor). > Python generally follows this design. Apart from files, I can't easily think > off the top of my head of any types that require a separate > open/start/activate call before they are usable. database connections, network connections, spawning expensive processes/threads, things that benefit from lazy evaluation... > Now, I have an ulterior motive in raising this issue... I can't find the > original article I read! My google-fu has failed me (again...). I don't > suppose anyone can recognise it and can point me at it? My sarcasm detector warns me not to add a link, although perhaps it's time for recalibration (after all, summer season started) :-) Best regards, Stefaan. From gandalf at shopzeus.com Tue Jul 5 15:32:37 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 05 Jul 2011 21:32:37 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> Message-ID: <4E1366D5.6030208@shopzeus.com> > 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. import sys import wx from wx.lib.embeddedimage import PyEmbeddedImage img = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAAAAAAAD5Q7t/AAAA" "CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QYGDS8dXc5KpwAAADV0RVh0Q29tbWVudAAo" "YykgMjAwNCBKYWt1YiBTdGVpbmVyCgpDcmVhdGVkIHdpdGggVGhlIEdJTVCQ2YtvAAAB+klE" "QVQ4y52TwWpTQRSGvzkzwV7S1pI2CFptC3VhUkjabsSlrxBKF0UQdONW3BsK7sQnUPA9pLos" "WtskzW3AgopKi6jtxYQSY3LnuEi8pYsidjbD8M98c/7/zJil5dJDoMzZRtksLZf0zt3bZzr9" "7Olz3N/F5tbLUze2Wkek0wHtdgdrhaGhcywu3AQ4BjSbB6cCPrzfw1ohOmzRbB5x/cZcoiWA" "mZm5UwFTUzmMMagqxhiMMYlmlpZLGjXbPLh/77/8rz56wqULmX4F3W6P8upjfnU6fVUV/QdA" "RI4t3FpZ4dXaC7yHi5OTfN3fx/uYkfNjtH5GqPcE6RGMCNHhASKG/g0eFwQBla03XJ2dRVUJ" "w5B8Po+1ljAMyeVyiAiNRgPFsDhfJJVK0e12qdUrSLvdxsceVU1CAojjGDB0Oh289wB4Vay1" "6GBOLFyZmuH1+joYw0Q2y85OA+9jxjLjvNvdBVXGMhMoUKvVEkgC+PzpI8VioW+h0SCXu4Zz" "jnq9znyxiIhQrdZwzlEoFJIqNysbyCB2nHN47/G9HtZanHOISNJ3EQP0S0+lUie7MHl5msrm" "W8Awns2yXa/jrCU9PMx2GGJUGQoCfg/aPDo6ShRFJ1/i/MICANZa4ulpDGBE0EGARoS9vS98" "//GNw+hgEHIfUK5WN878nf8AhFzLEABZzNIAAAAASUVORK5CYII=") class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='Popup image test', pos=wx.DefaultPosition, size=(200, 200), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) lst = wx.ListCtrl(self,-1,style=wx.LC_REPORT) lst.InsertColumn(0, "Column 01") for i in range(100): lst.InsertStringItem(sys.maxint, "Right click me %s"%i) lst.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onPopupMenu, lst) self.Bind(wx.EVT_CLOSE, self.OnClose) def OnClose(self, event): self.Destroy() def onPopupMenu(self,evt): global img menu = wx.Menu() item = wx.MenuItem(None,-1,u"Test") item.SetBitmap(img.GetBitmap()) menu.AppendItem(item) #menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) self.PopupMenu( menu, evt.GetPoint()) menu.Destroy() app = wx.App() frame = MyFrame(None) frame.Show() app.MainLoop() Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. Thanks L From xahlee at gmail.com Tue Jul 5 15:46:20 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 12:46:20 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: <77912925-c870-43ac-b405-68ded8748d05@34g2000pru.googlegroups.com> On Jul 5, 12:17?pm, Ian Kelly wrote: > On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > > So, a solution by regex is out. > > Actually, none of the complications you listed appear to exclude > regexes. ?Here's a possible (untested) solution: > >

> ((?:\s*[^ height="[0-9]+">)+) > \s*

((?:[^<]|<(?!/p>))+)

> \s*
> > and corresponding replacement string: > >
> \1 >
\2
>
> > I don't know what dialect Emacs uses for regexes; the above is the > Python re dialect. ?I assume it is translatable. ?If not, then the > above should at least work with other editors, such as Komodo's > "Find/Replace in Files" command. ?I kept the line breaks here for > readability, but for completeness they should be stripped out of the > final regex. > > The possibility of nested HTML in the caption is allowed for by using > a negative look-ahead assertion to accept any tag except a closing >

. ?It would break if you had nested

tags, but then that would > be invalid html anyway. > > Cheers, > Ian that's fantastic. Thanks! I'll try it out. Xah From xahlee at gmail.com Tue Jul 5 15:47:21 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 12:47:21 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: On Jul 4, 12:13?pm, "S.Mandl" wrote: > Nice. I guess that XSLT would be another (the official) approach for > such a task. > Is there an XSLT-engine for Emacs? > > -- Stefan haven't used XSLT, and don't know if there's one in emacs... it'd be nice if someone actually give a example... Xah From xahlee at gmail.com Tue Jul 5 16:37:18 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 13:37:18 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: On Jul 5, 12:17?pm, Ian Kelly wrote: > On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > > So, a solution by regex is out. > > Actually, none of the complications you listed appear to exclude > regexes. ?Here's a possible (untested) solution: > >

> ((?:\s*[^ height="[0-9]+">)+) > \s*

((?:[^<]|<(?!/p>))+)

> \s*
> > and corresponding replacement string: > >
> \1 >
\2
>
> > I don't know what dialect Emacs uses for regexes; the above is the > Python re dialect. ?I assume it is translatable. ?If not, then the > above should at least work with other editors, such as Komodo's > "Find/Replace in Files" command. ?I kept the line breaks here for > readability, but for completeness they should be stripped out of the > final regex. > > The possibility of nested HTML in the caption is allowed for by using > a negative look-ahead assertion to accept any tag except a closing >

. ?It would break if you had nested

tags, but then that would > be invalid html anyway. > > Cheers, > Ian emacs regex supports shygroup (the ?(?:?)?) but it doesn't support the negative assertion ??!?? though. but in anycase, i can't see how this part would work

((?:[^<]|<(?!/p>))+)

? Xah From bahamutzero8825 at gmail.com Tue Jul 5 17:01:57 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 16:01:57 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: <4E137BC5.2080401@gmail.com> On 2011.07.05 01:14 PM, sal migondis wrote: > How could a belief be wrong? Beliefs aren't subjective. One's taste in music, for example, is largely subjective and can't be right or wrong, but a belief (which has to do with facts) certainly can be. > > > What do you think will be the eventual outcome of the human existence > > > Alex? Since you have no imagination i will tell you, a singular > > > intelligence. > > All from the land of creationism. That's from rantingrick, not alex23. > > No need to answer that last one, we already know the answer: from the > > very beginning. > > In the beginning was a singularity... and Albert Einstein was a chain- > smoker. Either you're taking that statement out of context, or you're making an esoteric joke. If it's not the latter, I suggest you read the sentence before it. From gordon at panix.com Tue Jul 5 17:02:49 2011 From: gordon at panix.com (John Gordon) Date: Tue, 5 Jul 2011 21:02:49 +0000 (UTC) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Stefaan Himpe writes: > > Now, I have an ulterior motive in raising this issue... I can't find the > > original article I read! My google-fu has failed me (again...). I don't > > suppose anyone can recognise it and can point me at it? > My sarcasm detector warns me not to add a link, although perhaps it's > time for recalibration (after all, summer season started) :-) He's not asking for a link to the "Implicit initialization is EVIL" thread; he's asking for a link to the original article he read elsewhere which praised the bendfists of implicit initialization. -- 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 bahamutzero8825 at gmail.com Tue Jul 5 17:04:18 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 16:04:18 -0500 Subject: embedding: how do I redirect print output? In-Reply-To: References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E137C52.9020905@gmail.com> On 2011.07.05 10:20 AM, Chris Angelico wrote: > You, sir, have a warped and twisted mind. > > And I love it!! > > Now to secretly put code into some module somewhere and wait for > people to start tearing their hair out.... wait, did I say that out > loud? from pytroll import print From klica_sk8 at hotmail.com Tue Jul 5 17:25:22 2011 From: klica_sk8 at hotmail.com (miguel olivares varela) Date: Tue, 5 Jul 2011 14:25:22 -0700 Subject: write file Message-ID: Hi, i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. this is my an example of source file: [test.csv] Name;Lastname;Age;ContractDate;PhoneNumber John;Smith;20110128 105840;33611111111 Mike;Brown;20110128 105842;33622222222 James;Ryan;20110128 105850;33633333333 Barry;Jackson;20110128 105847;33644444444 [here my code:] import sys import csv import os import glob import time dir_cdr = "/tmp" #loop to find files csv in a directory and read thoses files for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): file_source = open(cdr_files_in, 'r') reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) try: for data in reader: if data: firstname = data[0] lastname = data[1] date_source = data[2] phone = data[3] #Date to epoch timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) fout = open("out.csv", "w") print >>fout, lastname, firstname, timestamp, phone fout.close() sys.exit() file_source.close() except csv.Error, e: print e file_source.close() sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) [out.csv] Smith John 1296208720 33611111111 Could you help me? Best Regards, Miguel -------------- next part -------------- An HTML attachment was scrubbed... URL: From StefanMandl at web.de Tue Jul 5 17:30:13 2011 From: StefanMandl at web.de (S.Mandl) Date: Tue, 5 Jul 2011 14:30:13 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: > haven't used XSLT, and don't know if there's one in emacs... > > it'd be nice if someone actually give a example... > Hi Xah, actually I have to correct myself. HTML is not XML. If it were, you could use a stylesheet like this:
which applied to this document:

Just having fun

with all the
my cat my cat

my 2 cats

cats here:

Just fooling around

jamie's cat

jamie's cat! Her blog is http://example.com/jamie/

would yield:

Just having fun

with all the
my cat my cat
my 2 cats
cats here:

Just fooling around

jamie's cat
jamie's cat! Her blog is http://example.com/jamie/
But well, as you don't have XML as input ... there really was no point to my remark. Best, Stefan From drsalists at gmail.com Tue Jul 5 17:37:07 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Jul 2011 14:37:07 -0700 Subject: write file In-Reply-To: References: Message-ID: What's date_cdr supposed to be? Is your exception handler doing unusual things with sys.exit? Did you try to run this? When I try to run it, it fails to compile. You might want to try opening your output file once and writing to it repeatedly, then close()ing it after all your writes are completed. Or use "with": http://effbot.org/zone/python-with-statement.htm On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela < klica_sk8 at hotmail.com> wrote: > > Hi, > > i got a csv file that i need to modify and create a new one, i have no > problem to read mi 'test.cvs' which is the source file but when i try to > create a new one with the modifications i only got the first row in my > 'out.csv' file. I think there is somethng wrong in my loop because i can't > put into the rest. > > > this is my an example of source file: > [test.csv] > Name;Lastname;Age;ContractDate;PhoneNumber > John;Smith;20110128 105840;33611111111 > Mike;Brown;20110128 105842;33622222222 > James;Ryan;20110128 105850;33633333333 > Barry;Jackson;20110128 105847;33644444444 > > > [here my code:] > > import sys > import csv > import os > import glob > import time > > dir_cdr = "/tmp" > #loop to find files csv in a directory and read thoses files > for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): > file_source = open(cdr_files_in, 'r') > reader = csv.reader(file_source, delimiter=';', > quoting=csv.QUOTE_NONE) > try: > for data in reader: > if data: > firstname = data[0] > lastname = data[1] > date_source = data[2] > phone = data[3] > #Date to epoch > > timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) > fout = open("out.csv", "w") > print >>fout, lastname, firstname, > timestamp, phone > fout.close() > sys.exit() > file_source.close() > except csv.Error, e: > print e > file_source.close() > sys.exit('file %s, line %d: %s' % (file_source, > reader.line_num, e) > > [out.csv] > Smith John 1296208720 33611111111 > > > Could you help me? > > Best Regards, > Miguel > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean.m.ochoa at gmail.com Tue Jul 5 17:52:49 2011 From: sean.m.ochoa at gmail.com (bitcycle) Date: Tue, 5 Jul 2011 14:52:49 -0700 (PDT) Subject: How do twisted and multiprocessing.Process create zombies? Message-ID: In python, using twisted loopingcall, multiprocessing.Process, and multiprocessing.Queue; is it possible to create a zombie process. And, if so, then how? From gordon at panix.com Tue Jul 5 17:58:01 2011 From: gordon at panix.com (John Gordon) Date: Tue, 5 Jul 2011 21:58:01 +0000 (UTC) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In John Gordon writes: > which praised the bendfists of implicit initialization. Wow, that's quite a typo! I meant "benefits", of course. -- 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 benjamin.kaplan at case.edu Tue Jul 5 18:09:09 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 5 Jul 2011 15:09:09 -0700 Subject: write file In-Reply-To: References: Message-ID: On Jul 5, 2011 2:28 PM, "miguel olivares varela" wrote: > > > Hi, > > i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. > > > > [here my code:] > > import sys > import csv > import os > import glob > import time > > dir_cdr = "/tmp" > #loop to find files csv in a directory and read thoses files > for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): > file_source = open(cdr_files_in, 'r') > reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) > try: > for data in reader: > if data: > firstname = data[0] > lastname = data[1] > date_source = data[2] > phone = data[3] > #Date to epoch > timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) > fout = open("out.csv", "w") > print >>fout, lastname, firstname, timestamp, phone Do you understand what these next two lines are doing? They are closing the file and then exiting the program. I'm pretty sure that's not what you want to do here. > fout.close() > sys.exit() > file_source.close() > except csv.Error, e: > print e > file_source.close() > sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) > > [out.csv] > Smith John 1296208720 33611111111 > > > Could you help me? > > Best Regards, > Miguel > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Jul 5 18:09:46 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2011 16:09:46 -0600 Subject: emacs lisp text processing example (html5 figure/figcaption) In-Reply-To: References: Message-ID: On Tue, Jul 5, 2011 at 2:37 PM, Xah Lee wrote: > but in anycase, i can't see how this part would work >

((?:[^<]|<(?!/p>))+)

It's not that different from the pattern ?alt="[^"]+"? earlier in the regex. The capture group accepts one or more characters that either aren't '<', or that are '<' but are not immediately followed by '/p>'. Thus it stops capturing when it sees exactly '

' without consuming the '<'. Using my regex with the example that you posted earlier demonstrates that it works: >>> import re >>> s = '''
... jamie's cat ...

jamie's cat! Her blog is http://example.com/jamie/

...
''' >>> print re.sub(pattern, replace, s)
jamie's cat
jamie's cat! Her blog is http://example.com/jamie/
Cheers, Ian From klica_sk8 at hotmail.com Tue Jul 5 18:09:53 2011 From: klica_sk8 at hotmail.com (miguel olivares varela) Date: Tue, 5 Jul 2011 15:09:53 -0700 Subject: write file In-Reply-To: References: , Message-ID: What's date_cdr supposed to be? It was a mistake it should be date_source Is your exception handler doing unusual things with sys.exit? Not really Did you try to run this? When I try to run it, it fails to compile. it compiles i have no problems with the compilation. The issue is the result 'out.csv', what i want is to save all the modified rows from 'test.csv' into 'out.csv' but i only can save the firs row. You might want to try opening your output file once and writing to it repeatedly, then close()ing it after all your writes are completed. Or use "with": http://effbot.org/zone/python-with-statement.htm On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela wrote: Hi, i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. this is my an example of source file: [test.csv] Name;Lastname;Age;ContractDate;PhoneNumber John;Smith;20110128 105840;33611111111 Mike;Brown;20110128 105842;33622222222 James;Ryan;20110128 105850;33633333333 Barry;Jackson;20110128 105847;33644444444 [here my code:] import sys import csv import os import glob import time dir_cdr = "/tmp" #loop to find files csv in a directory and read thoses files for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): file_source = open(cdr_files_in, 'r') reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) try: for data in reader: if data: firstname = data[0] lastname = data[1] date_source = data[2] phone = data[3] #Date to epoch timestamp=int(time.mktime(time.strptime(date_source, "%Y%m%d %H%M%S"))) fout = open("out.csv", "w") print >>fout, lastname, firstname, timestamp, phone fout.close() sys.exit() file_source.close() except csv.Error, e: print e file_source.close() sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) [out.csv] Smith John 1296208720 33611111111 Could you help me? Best Regards, Miguel -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 5 18:35:01 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:35:01 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: On Jul 5, 11:04?am, Corey Richardson wrote: > How is giving the sort method a function by which to determine the relative > value of objects a control structure? Do you know what a control structure is? > It's something that you use to modify control flow: > > if foo <= bar: > ? ? ? ? foo += 1 > else: > ? ? ? ? bar += 1 Interesting, corey. Very interesting. However the fun is yet to come so stay tuned... > That's a control structurem the "if-else". I don't know what Ruby calls a > control structure, but that's what it is. for and while are in there too. > When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? So are you suggesting that a control structure must have at minimum one of "for", "while", or "if"? Okay, i listening. Go on... > We'll call that argument srt, here's a sample (naive) implementation: > > def sort(key): > ? ? ? ? lst = self.internal_list > ? ? ? ? for n in range(len(self.internal_list) - 1): > ? ? ? ? ? ? ? ? for i in range(len(self.internal_list) - 1): > ? ? ? ? ? ? ? ? ? ? ? ? if srt(lst[i], lst[i+1]) < 0: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lst[i], lst[i+1] = lst[i+1], lst[i] > > See what's in there? An if. Yes there IS and "if" in there and IF you look closely enough you may see two "for"'s also. So by your own definition this (naive) code qualifies as a control structure. Interesting Corey, very interesting. But wait just a second Corey. My statement has nothing to do with sort. sort is just the vehicle. My statement is that the cmp argument to sort IS a user defined control structure (the code block to be exact). It doesn't matter that the code is contained in a function object. That's like saying a cake is not a cake because it was packaged in a shoe box instead of a cake box. > Sure, WHAT the if does is user-controlled with the > key, Well as long as you can admit that fact. > but that doesn't make that particular if a new control structure, Oh i see. Change the rules as we go eh? > and > it certainly doesn't make the key a control structure. You can pass a key > to a sort even in C and that certainly doesn't have user defined control > structures. What the hell does C have to do with Python Corey? One thing is for sure, i always get a giggle from your self defeating posts. You're the best enemy a person could have. Thank you. *bows* From rosuav at gmail.com Tue Jul 5 18:36:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:36:56 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 4:14 AM, sal migondis wrote: > On Jul 4, 10:31?pm, alex23 wrote: >> rantingrick wrote: >> > What do you think will be the eventual outcome of the human existence >> > Alex? Since you have no imagination i will tell you, a singular >> > intelligence. > > All from the land of creationism. I don't see the connection between creationism and a Borg-like "singularity of intelligence" where we all lose individuality. But this is now decidedly off-topic for a Python mailing list. ChrisA From rantingrick at gmail.com Tue Jul 5 18:38:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:38:49 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 5, 10:17?am, Chris Angelico wrote: > It's actually quite easy to implement this, even if you _are_ forced > to have one primary window. You just have an invisible primary whose > sole purpose is to "be the application", and then everything else is > secondary windows. Kinda defeats the purpose of forcing applications > to have one primary window, though. > > To my thinking, there will always be one primary *thread*, and GUI > facilities are secondary to the process, never the other way around. > When the main thread exits, the process ends. Chris are you playing devils advocate (for my team). I am confused? :-) From invalid at invalid.invalid Tue Jul 5 18:39:11 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 22:39:11 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Waldek M. wrote: > Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): >> Because those specially-formatted comments are wrong. > > ... because? In my experience, they're wrong because somebody changes the code and not the comments. > Not in sarcasm mode; just curious why you don't like them. There've been too many times when I couldn't trust them. -- Grant Edwards grant.b.edwards Yow! I'm totally DESPONDENT at over the LIBYAN situation gmail.com and the price of CHICKEN ... From rantingrick at gmail.com Tue Jul 5 18:42:17 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:42:17 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> Message-ID: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> On Jul 5, 11:00?am, Web Dreamer wrote: > What he means is that On Mac, if you close "all" windows, the application is > still running. Then that is NOT closing windows that is only ICONIFIYING/HIDING them. Let's use the correct lingo people! From rosuav at gmail.com Tue Jul 5 18:45:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:45:00 +1000 Subject: Testing if a global is defined in a module In-Reply-To: <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 3:36 AM, Steven D'Aprano wrote: > > Because unless you are extremely disciplined, code and the comments > describing them get out of sync. Quote: > > "At Resolver we've found it useful to short-circuit any doubt and just > refer to comments in code as 'lies'. " > --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 And yet, as I have found out by trying to embed V8 (Google's Javascript engine), those little comments can (a) prove the difference between a bug and a misfeature, and (b) be all the documentation there is. Okay, it's not QUITE the latter, but most things are not documented outside of the source, and I greatly appreciate those little comments! ChrisA From rantingrick at gmail.com Tue Jul 5 18:47:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:47:09 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> Message-ID: <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> On Jul 5, 6:14?am, Gregory Ewing wrote: > rantingrick wrote: > > Most applications consist of one main window > > (a Tkinter.Tk instance). > > You've obviously never used a Macintosh. On the Mac, it's > perfectly normal for an application to open multiple > documents, each in its own window, with no one window > being the "main" window. Any of them can be closed (or > even *all* of them) and the application continues to run > until you explicitly quit it. And how do you EXPLICITY quit the application? Because the interface for window management(on windows box) is three buttons "minimize", "maximize", and "destroy". If closing the window only "hides" the window then you are just "managing" a window's "visibility". We are talking about destroying GUI processes here. From rosuav at gmail.com Tue Jul 5 18:49:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:49:36 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 8:35 AM, rantingrick wrote: > You're the > best enemy a person could have. Thank you. *bows* Compliments are made to be returned, and this one is particularly well suited. *bow* Chris Angelico From rosuav at gmail.com Tue Jul 5 19:20:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 09:20:53 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 8:42 AM, rantingrick wrote: > Chris are you playing devils advocate (for my team). I am confused? :-) I say whatever I choose to say. Don't pigeon-hole me into "on your team" or "not on your team" or "devil's advocate" or whatever. And at two in the morning, "whatever I choose to say" can be quite random. :) > On Jul 5, 11:00?am, Web Dreamer wrote: > >> What he means is that On Mac, if you close "all" windows, the application is >> still running. > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > Let's use the correct lingo people! Actually, it IS closing those windows. Why wouldn't it be? 1) User presses Alt-F4, or clicks the X, or opens the system menu and chooses 'Close Window'. 2) Windowing manager sends a message to the appropriate thread's queue (on MS Windows, that's WM_CLOSE; not sure how on Linux as I haven't bothered to dig that deep - interface layers like Tkinter and GTK don't count). 2a) Toolkit passes message to application code, if applicable. 3) Application destroys this window, leaving the other windows alive. The memory used by that window can be reclaimed. Handles to its objects are no longer valid. The window really is closed. The application might not have terminated, but that window has not been minimized - the *window* is closed. > And how do you EXPLICITY quit the application? Because the interface > for window management(on windows box) is three buttons "minimize", > "maximize", and "destroy". If closing the window only "hides" the > window then you are just "managing" a window's "visibility". We are > talking about destroying GUI processes here. Presumably you would right-click it and choose "Exit" or something. Up to the application. If all else fails, kill -9 it. The interface for window management does not actually have "destroy", it has "close". The normal handling of a close message is to destroy the window; and in many applications, once all windows have been destroyed, the process terminates. These are three quite separate concepts. The separation of "close" and "destroy" is most easily seen in "Are you sure" prompts - you send a Close signal to the window, but the application queries you before going through with the destruction. And even once the last window has been destroyed, that has nothing to do with process termination. I could conceivably write a program that sits invisibly in the background until a network message arrives. Upon receipt of such a message, the program initializes the GUI subsystem and opens a window. When the user closes the window, the program flushes all GUI code out of memory and waits for the next message. While it's waiting, is there any "main window" that exists but has just been hidden? No. But is the application still running? Of course! Completely separate. ChrisA From python.list at tim.thechases.com Tue Jul 5 19:21:02 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 05 Jul 2011 18:21:02 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <4E139C5E.2020003@tim.thechases.com> On 07/05/2011 05:35 PM, rantingrick wrote: > One thing is for sure, i always get a giggle from your self > defeating posts. You're the best enemy a person could have. > Thank you. *bows* Every time I see a rantingrick post, it's like watching the Black Knight scene from the Holy Grail yet again. You know what's going to happen; you know he has a purposeless fight; you know he's going to laughably lose; and you know he's going to *think* that he is invincible & has won. ARTHUR: What are you going to do, bleed on me? BLACK KNIGHT: I'm invincible! ARTHUR: You're a looney. Sigh...ready for an intermission... -tkc From philip at semanchuk.com Tue Jul 5 19:33:47 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 5 Jul 2011 19:33:47 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E1366D5.6030208@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> Message-ID: On Jul 5, 2011, at 3:32 PM, Laszlo Nagy wrote: > >> 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. > [code sample snipped] > > Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. I get different results than you. Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- Traceback (most recent call last): File "x.py", line 46, in onPopupMenu item = wx.MenuItem(None,-1,u"Test") File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu Hope this helps more than it confuses. Cheers Philip From rantingrick at gmail.com Tue Jul 5 19:47:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 16:47:53 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> On Jul 5, 6:20?pm, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 8:42 AM, rantingrick wrote: > [...] > > On Jul 5, 11:00?am, Web Dreamer wrote: > >> What he means is that On Mac, if you close "all" windows, the application is > >> still running. > > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > > Let's use the correct lingo people! > > Actually, it IS closing those windows. Why wouldn't it be? > [...] > The memory used by that window can be reclaimed. Handles to its > objects are no longer valid. The window really is closed. The > application might not have terminated, but that window has not been > minimized - the *window* is closed. And you need the OS to that for you!?!? Are you joking? > I could conceivably write a program that sits invisibly in the > background until a network message arrives. Upon receipt of such a > message, the program initializes the GUI subsystem and opens a window. > When the user closes the window, the program flushes all GUI code out > of memory and waits for the next message. While it's waiting, is there > any "main window" that exists but has just been hidden? No. But is the > application still running? Of course! Completely separate. And so could i using Tkinter and it's "supposedly" flawed window hierarchy. Remind me again why we are discussing this? From rosuav at gmail.com Tue Jul 5 19:54:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 09:54:09 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 9:47 AM, rantingrick wrote: >> > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. >> > Let's use the correct lingo people! >> >> Actually, it IS closing those windows. Why wouldn't it be? >> [...] >> The memory used by that window can be reclaimed. Handles to its >> objects are no longer valid. The window really is closed. The >> application might not have terminated, but that window has not been >> minimized - the *window* is closed. > > And you need the OS to that for you!?!? Are you joking? > To do what for me? Close windows? Reclaim memory? Terminate applications? I don't understand your bogglement. ChrisA From rantingrick at gmail.com Tue Jul 5 20:15:44 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 17:15:44 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> Message-ID: <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> On Jul 5, 6:54?pm, Chris Angelico wrote: > To do what for me? Close windows? Reclaim memory? Terminate > applications? I don't understand your bogglement. ClaimA: I made claim that Tkinter's window hierarchy is not only normal, but justified in modern GUI programming. ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's system of window management was superior and did not need such a "window hierarchy" simply because; 1. You can create a program that twiddles it's thumbs (using very little memory) until a message is received. 2. Upon receiving a message the program can open a GUI window. 3. When the user closes the GUI window (definition of "close" is not nailed down yet!) the program will free the GUI memory and start twiddling it's thumbs again until the next message arrives. 4. rinse and repeat until you are happy. It's obvious that yours and my claims are contradicting. So with that said, at what point does Tkinter or Windows fail in this example you provide? Because, i can recreate the exact same functionality on a windows box without need of the underlying window manager's help. 1. What is your point? 2. And how does it prove my position incorrect? From rosuav at gmail.com Tue Jul 5 20:34:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 10:34:08 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 10:15 AM, rantingrick wrote: > On Jul 5, 6:54?pm, Chris Angelico wrote: > >> To do what for me? Close windows? Reclaim memory? Terminate >> applications? I don't understand your bogglement. > > ClaimA: I made claim that Tkinter's window hierarchy is not only > normal, but justified in modern GUI programming. > > ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's > system of window management was superior and did not need such a > "window hierarchy" simply because; I never said "better". I just said that it's possible to create an application that *to the user* has no main window, even though *to the system* it does. And I'm also pointing out that in most good toolkits, there's no "main window", but instead a "main thread". > 1. You can create a program that twiddles it's thumbs (using very > little memory) until a message is received. > 2. Upon receiving a message the program can open a GUI window. > 3. When the user closes the GUI window (definition of "close" is not > nailed down yet!) the program will free the GUI memory and start > twiddling it's thumbs again until the next message arrives. > 4. rinse and repeat until you are happy. Again, pointing out that it's possible, not that it's good. (Most messenger programs will have a means of *sending* messages too, which makes a good basis for a main window.) It's not efficient to keep loading up GUI libraries and discarding them again. But it's possible, and it would mean that you genuinely have multiple equal main windows. > It's obvious that yours and my claims are contradicting. So with that > said, at what point does Tkinter or Windows fail in this example you > provide? Because, i can recreate the exact same functionality on a > windows box without need of the underlying window manager's help. Actually, everything you do requires the underlying window manager, otherwise you're just painting your own pixels on the screen. And I never said that this model was possible in some and not others. (Although it's a bit harder with Windows; there's no explicit call to finalize windowing, so most likely the application will hold GUI memory until termination.) ChrisA From stefan_ml at behnel.de Tue Jul 5 20:47:55 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 06 Jul 2011 02:47:55 +0200 Subject: How do twisted and multiprocessing.Process create zombies? In-Reply-To: References: Message-ID: bitcycle, 05.07.2011 23:52: > In python, using twisted loopingcall, multiprocessing.Process, and multiprocessing.Queue; is it possible to create a zombie process. And, if so, then how? I think it's best to consult your local Voodoo master on the matter of zombie creation processes. That being said, there are far too many zombies around already, so please don't add to that. Stefan From rantingrick at gmail.com Tue Jul 5 21:07:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:07:43 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 4, 6:24?pm, Steven D'Aprano wrote: > rantingrick wrote: > Some people want to make Python more dynamic. Some want it to be less > dynamic. Some care about integrating it with Java or .Net, some don't care > about either. Some are interested in clever optimization tricks, some > oppose adding any more complexity. > > Some want it to be faster, and are happy to throw more memory at it to do > so. Some want it to use less memory, because on embedded devices and smart > phones memory is the bottleneck, not time. > > Some only program in Python. Some treat Python as merely one language out of > many that they use. > > Some come to Python from the C/C++ community, and their wants are influenced > by C. Some come to Python from Lisp, Scheme or Haskell, and their wants are > influenced by functional programming ideas. Some have never programmed > before, and don't know want they want. And are any of them getting what they want? No. And they should not. (stay tuned for the reason "why not") > Define "best for all", and try not to make it "what Rick wants". You want features? And remember i am talking about scripting/glue level languages here. Something to replace Python, Ruby, Perl, JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- our-problems" pipe dream language. * Intuitive syntax. * Productivity friendly. * Complex enough to solve large problems but simple enough for simple problems (that does include extending into C when needed) * Multi paradigm (problem * Promotes a culture of code readability (because people read source; not just machines!). * there is always more. * we all know this list steven! > No, Python is not a monoculture. There are the Stackless, Jython, PyPy and > IronPython sub-cultures, all with their own needs, wants and desires. There > are sub-cultures for embedded devices and smart phones, sub-cultures for > those who use Python as a teaching language, for web development, for GUI > development, and for system administration. There are the Numpy and Scipy > sub-cultures, sub-cultures in the fields of linguistics and biology. Hmm. Just think how far ahead we would be if these folks would stop trying to support petty differences and focus on a singular Python language? But let's not kid ourselves here! This problem is far bigger than python. Selfishness infests every group of humans on this planet. Why do we need multiple OS's? Just so one can say "\" is the proper file path sep and someone else can say "/" is the proper one! Are you kidding me? Look at the multiplicity. Look at the asinine nature of it all and for once in your life join the group that is the future of human evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello! > Nature isn't striving for anything. > [...] > what you believe is not new and it is > not a minority view. It is old, obsolete, Before you go out babbling about "concepts" you should understand what these "concepts" are; or at least at the minimum read the freaking Wiki! My statements are in no way remotely related to "Great Chain of Being" and this feeble attempt to prove so is obviously another one of your half stuffed straw-men arguments. > and the vast majority of people > with no modern biology education believe something like it. You sure presume to know quite a lot about "uneducated people". Do you know these folks personally? Do you chit-chat with them on the subway or whilst sharing a Frappuccino? > Since needs are frequently in opposition (e.g. the speed/memory trade-off), > a single "true language" must be a compromise language that leaves nobody > happy. Oh Steven, that's just your fear of unity acting out again. Yes, what's good for the group will not *always* be good for you, or me, or xah lee! But what matters is progress. Not your selfish needs Steven. > Or some dictator (Rick?) declares that such-and-such a set of > features is, by definition, the "perfect" language and those who want > something else have to miss out. I have never held myself out as some sort of dictator. These decisions must be made in a democratic manner. This is FUD. > Imagine a world where *every* shop was Walmart. That would be good for > Walmart, but terrible for everyone else. That's Rick's plan for > programming. You know Steven, wal-mart is a very successful company. And wal-mart meets the needs of the many. Again you fail to see the truth behind the curtain. If (as you say) wal-mart really is such a bad company and it's existence is hurting "the many"... then explain to the class (if you can) why wal mart is the most successful retail chain in the history of the world? We are listening... Do you realize that without customers buying products that wal-mart could never get to this pinnacle of retail success? If you are correct, then people buy from wal-mart even though wal-mart is "bad" for them. Please explain this reversal of reality Steven because i think you are watching too much MTV and it's rotting your brain. > Go do something useful. Well i might just go to wal-mart! From rantingrick at gmail.com Tue Jul 5 21:10:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:10:43 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> Message-ID: On Jul 5, 7:34?pm, Chris Angelico wrote: > Actually, everything you do requires the underlying window manager, > otherwise you're just painting your own pixels on the screen. And I > never said that this model was possible in some and not others. > (Although it's a bit harder with Windows; there's no explicit call to > finalize windowing, so most likely the application will hold GUI > memory until termination.) Ah ha. I think we are getting somewhere now. Everything up to this point has been mostly exposition :-) From dustin299 at gmail.com Tue Jul 5 21:30:57 2011 From: dustin299 at gmail.com (Dustin Cheung) Date: Tue, 5 Jul 2011 18:30:57 -0700 Subject: web browsing short cut In-Reply-To: References: Message-ID: Hey, I am looking into Tkinter. But i am not sure if it will actually work. This maybe a crazy idea but i was wondering if i can put a web browser in the frame. I have tried to use Tkinter to resize and place the windows to certain areas of the screen but that's not working or the way im approaching this problem is completely wrong. I want to make a program that will have websites displayed in specific areas of the screen. I was planning on using the program on the big screen. So is it possible to put the web browser inside the frame in Tkinter? On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert wrote: > On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung wrote: > > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > > and re-sizes them to display on different areas on the screen. I looked > > around but i had no luck. Is that possible with python? if so can someone > > point to to the right direction? Here is what I came up with so far.. > > The window positioning+resizing bit will likely require using > platform-specific APIs. Since you appear to be on Windows, the > relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 > ). You would use it to invoke some COM API that does window > positioning+resizing. I am unable to give more details as I'm on a > Mac. > > Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? > > Cheers, > Chris > -- Dustin Cheung -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 5 21:53:23 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:53:23 -0700 (PDT) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> On Jul 5, 10:26?am, Steven D'Aprano wrote: > This is not strictly Python, although it is peripherally relevant. > > Some month or three ago, I read an article or blog post about API design, > specifically the wrong-headedness of insisting that callers manually > initialise instances using a separate step after creation. > > The argument goes, if your API looks something like this: > > instance = Spaminator(extra_truffles=False) > instance.activate() > instance.nom_nom_nom() > => prints "yummy spam, the food of the Gods!!!" > > chances are that you are doing it wrong and your users will hate you. Why > force the user to manually "flip the switch" (so to speak)? It's not like > they can possibly avoid it: I completely agree! > Exceptions to this rule are if the Spaminator has side-effects (e.g. files, > in which case the user may want finer control in when they are opened and > closed), or if there are meaningful operations you can perform on an > inactive Spaminator. Agreed again! > It's also relevant to > tkinter, which will implicitly create a root window for you when needed. WRONG. Oh wait, of course, you are correct! YES! Maybe we should have library modules import only when needed! i mean, who needs those pesky import statements anyways! Sure it will slow down run time BUT WHO CARES! My gawd, you just opened my mind to so many possibilities! Why stop at library modules, if it is not there just download the source at run time! Guido really dropped the ball on this one folks. > Since you can't do anything without a root window, I don't see the benefit > in forcing the user to do so. The reason is simple. It's called order. It's called learning from day one how the order of things exists. Widgets are part of windows, not the other way around. Saving a few keystrokes is not acceptable if you jumble the understanding of a new student. To understand and use Tkinter properly you must understand the order of window->widget. > When they need to learn about root windows, > they will in their own good time. So you would start drivers education class with road construction? Or the history of the internal combustion engine? Who cares about actually *driving* the car. From rosuav at gmail.com Tue Jul 5 22:31:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 12:31:02 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 11:07 AM, rantingrick wrote: > On Jul 4, 6:24?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Define "best for all", and try not to make it "what Rick wants". > > You want features? And remember i am talking about scripting/glue > level languages here. Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", ?"single-answer-to-all- > our-problems" pipe dream language. > > ?* Intuitive syntax. Subjective. > ?* Productivity friendly. Depends heavily on the task at hand. HQ9+ is extremely productivity friendly if you're trying to write a quine. > ?* Complex enough to solve large problems but simple enough for simple > problems (that does include extending into C when needed) Subjective. Any Turing-complete language is technically complex enough to solve large problems, but would you care to write a web browser in Ook? > ?* Multi paradigm (problem ? > ?* Promotes a culture of code readability (because people read source; > not just machines!). from __future__ import braces # this'll make it more readable for C programmers >> No, Python is not a monoculture. There are the Stackless, Jython, PyPy and >> etc etc > > Hmm. Just think how far ahead we would be if these folks would stop > trying to support petty differences and focus on a singular Python > language? Imagine how much faster we'd all reach our destinations if whenever I push my car's accelerator, it moves every car in the world the same distance in the same direction! > This problem is far bigger than python. Selfishness infests every > group of humans on this planet. Why do we need multiple OS's? Just so > one can say "\" is the proper file path sep and someone else can say > "/" is the proper one! Are you kidding me? I've said for a while that Microsoft could do far worse than to turn Windows into a GUI that sits on top of a Unix-derived kernel. They won't do it, though, because it would be tantamount to admitting both that Unix is superior to Windows, AND that Apple got it right. However, if the entire world moved to one kernel, that would be a spof. That's why the DNS root servers don't all run the same software; if a flaw were found in BIND that brought everything down, there would still be three root servers (two of them anycasted) which would be unaffected. There's another good reason for diversity, too. Suppose you know only one language, and you want to verify that your program is producing correct results. What do you do? You're forced to do the job manually. If you have a completely different system, you could verify it against that - for instance, check your Python program by implementing equivalent functionality in Lua. > Look at the multiplicity. Look at the asinine nature of it all and for > once in your life join the group that is the future of human > evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello! You can't know what the future of human evolution is, unless it involves time travel. >> Since needs are frequently in opposition (e.g. the speed/memory trade-off), >> a single "true language" must be a compromise language that leaves nobody >> happy. > > Oh Steven, that's just your fear of unity acting out again. Yes, > what's good for the group will not *always* be good for you, or me, or > xah lee! But what matters is progress. Not your selfish needs Steven. And there you have the nub. Your idea of a perfect language is one that won't always be good for any particular person. This is where diversity comes to the fore. I'm currently using Google's V8 engine as my scripting engine, but I need it to be slightly different - so I modified it. I have offered the patch back to the community, and it may or may not end up being accepted, but that is immaterial. Right here, right now, I am running a modified V8, and it works FOR ME. What you're saying is that "progress" is more important than any individual... >> Or some dictator (Rick?) declares that such-and-such a set of >> features is, by definition, the "perfect" language and those who want >> something else have to miss out. > > I have never held myself out as some sort of dictator. These decisions > must be made in a democratic manner. This is FUD. ... which is exactly what many dictators have said. However, that is immaterial. Democracy DOES NOT WORK. Plain and simple. You cannot build a programming language democratically. Python has a BDFL. Open Office has had a variety of owners, and when enough people dislike the current owner, the project forks (eg LibreOffice). Savoynet is run by Marc Shepherd, who took over in 1998. All the best commanders listen to people, but ultimately, they make the decisions. Even in USA politics, where people talk proudly of living in a democracy, what you actually have is a President who wields a lot of power. >> Imagine a world where *every* shop was Walmart. That would be good for >> Walmart, but terrible for everyone else. That's Rick's plan for >> programming. > > You know Steven, wal-mart is a very successful company. And wal-mart > meets the needs of the many. They're cheap, ubiquitous, and convenient. They are NOT the ideal for every situation. Of course they're successful - that's because they buy and sell things at a profit. Steven never recommended abolishing Walmart, just said that it would be bad for people if Walmart were the only shop anywhere. > Again you fail to see the truth behind > the curtain. If (as you say) wal-mart really is such a bad company and > it's existence is hurting "the many"... then explain to the class (if > you can) why wal mart is the most successful retail chain in the > history of the world? Success just means they're able to make money. Fake pharmaceuticals companies can make money too; they send out roughly twelve million emails for every sale they get, but it's still a rip-roaring business. I doubt you would want all businesses in the world to follow THAT model. Walmart may and may not be hurting "the many". They certainly are not serving "the all". Other shops are also able to make a profit, which strongly suggests that they, too, are wanted. > Do you realize that without customers buying products that wal-mart > could never get to this pinnacle of retail success? If you are > correct, then people buy from wal-mart even though wal-mart is "bad" > for them. Please explain this reversal of reality Steven because i > think you are watching too much MTV and it's rotting your brain. If Steven is correct, then people buy from other shops because they are better for them than Walmart is. And that means that trying to unify ALL shopping under the one company name will be a disaster. I hope I make myself clear? ChrisA From rosuav at gmail.com Tue Jul 5 22:44:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 12:44:52 +1000 Subject: Implicit initialization is EXCELLENT In-Reply-To: <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 11:53 AM, rantingrick wrote: > So you would start drivers education class with road construction? Or > the history of the internal combustion engine? Who cares about > actually *driving* the car. > I believe that starting driver ed with some basics of how an internal combustion engine works would be a Good Thing. If you're going to be in control of a ton of steel that's capable of moving at a hundred kays, you ought to know at least a bit about what provides the kinetic energy. There's a difference between comprehension and jumping through hoops. In your driver ed example, I don't believe that the accelerator pedal should be replaced with a flexible fuel-line that the driver squeezes to control flow to the engine; but on the other hand, I don't think the brake pedal should be replaced by a single button saying "stop car" either. Arrogance is a normal part of designing programming languages (see Larry Wall's comments regarding Perl, for instance). But arrogance to the extent of forcing your views on programmers is generally resented, and with good reason. If you force too much on people, they'll go elsewhere. ChrisA From mozbugbox at yahoo.com.au Tue Jul 5 23:12:47 2011 From: mozbugbox at yahoo.com.au (Just Fill Bugs) Date: Wed, 06 Jul 2011 11:12:47 +0800 Subject: Should ctypes handle mis-matching structure return ABI between mingw and MSVC? Message-ID: According the Bug 36834 of gcc, there is a mis-matching between mingw and MSVC when a struct was returned by value from a C function. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834 Should ctypes handle this situation automatically somehow? A ctypes discussion on 2009: http://thread.gmane.org/gmane.comp.python.ctypes.user/4439 From rantingrick at gmail.com Tue Jul 5 23:45:06 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 20:45:06 -0700 (PDT) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Jul 5, 9:44?pm, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 11:53 AM, rantingrick wrote: > > So you would start drivers education class with road construction? Or > > the history of the internal combustion engine? Who cares about > > actually *driving* the car. > > I believe that starting driver ed with some basics of how an internal > combustion engine works would be a Good Thing. If you're going to be > in control of a ton of steel that's capable of moving at a hundred > kays, you ought to know at least a bit about what provides the kinetic > energy. How about kinetic energy itself? If you know *what* produces power to induce kinetic energy into the vehicle but not *how* the laws of physics govern kinetic energy; what damn good is that going to do for you? How about some basics of safe/defensive driving? How about considering the good of the many instead of the you? > There's a difference between comprehension and jumping through hoops. Likewise for priorities and acting aloof. > If you force too much on people, they'll go > elsewhere. Why all this running away with tail between legs? Do these these people have extremely small eggs? I wish they would stand firm and put up a fight instead they're just cowards spewing more endless tripe. From latheefb2 at gmail.com Tue Jul 5 23:45:47 2011 From: latheefb2 at gmail.com (http://123maza.com/65/chill155/) Date: Tue, 5 Jul 2011 20:45:47 -0700 (PDT) Subject: hai Message-ID: http://123maza.com/65/chill155/ From rosuav at gmail.com Tue Jul 5 23:54:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 13:54:22 +1000 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 1:45 PM, rantingrick wrote: >> If you force too much on people, they'll go >> elsewhere. > > ?Why all this running away with tail between legs? > ?Do these these people have extremely small eggs? > ?I wish they would stand firm and put up a fight > ?instead they're just cowards spewing more endless tripe. Standing up and fighting takes effort. It's a lot easier - and a lot more time-efficient - to ignore idiots and trolls and just get some work done. I think I'll do that, right now. Chris Angelico From bahamutzero8825 at gmail.com Wed Jul 6 00:13:36 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 23:13:36 -0500 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E13E0F0.20705@gmail.com> On 2011.07.05 09:31 PM, Chris Angelico wrote: > I've said for a while that Microsoft could do far worse than to turn > Windows into a GUI that sits on top of a Unix-derived kernel. They > won't do it, though, because it would be tantamount to admitting both > that Unix is superior to Windows, AND that Apple got it right. In my experience, it's been the GUIs that are awful and the backend stuff that's been good in Windows. Yes, the NT kernel still has some long standing bugs, but MS has done well with things that matter to sysadmins. chkdsk, for example, has been around for ages, but I still don't know of anything that really beats it. It's certainly saved my ass on several occasions. MS also bought the Sysinternals suite of software, and those programs continue to be very good. I've only had a small amount of experience with it so far, but Powershell seems to be an excellent tool for admin scripting since it interfaces with WMI so well. When it comes to things that interface with your average idiot, however, MS consistently drops the ball. The new interface design they've imposed on their office suite and Explorer is not only just plain bad, but it's infectious (and it's the reason the Firefox and Thunderbird default GUI configurations look horrendous). Another area MS fails it is sensible defaults. They put tons of effort into increasing security in the kernel, but don't use the security features (I'll try to come up with more detail on this later). Explorer /still/ hides known extensions by default, which /still/ makes it easier for bad people to get their victims to execute malware. What I think is that MS should focus on the kernel and encourage others to do their GUIs. From rosuav at gmail.com Wed Jul 6 00:25:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 14:25:56 +1000 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: <4E13E0F0.20705@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 2:13 PM, Andrew Berg wrote: > On 2011.07.05 09:31 PM, Chris Angelico wrote: >> I've said for a while that Microsoft could do far worse than to turn >> Windows into a GUI that sits on top of a Unix-derived kernel. They >> won't do it, though, because it would be tantamount to admitting both >> that Unix is superior to Windows, AND that Apple got it right. > In my experience, it's been the GUIs that are awful and the backend > stuff that's been good in Windows. Suppose I gave you a computer that had GNOME ported to Windows, and used the purplish palette that Ubuntu 10.10 uses, and had a Windows port of bash as its most convenient terminal. Members of this list will doubtless have no problem duck-typing that as a Linux box (to the extent of being quite surprised on seeing something that functions differently). What is Microsoft selling? They're a company, which means they need to keep selling stuff year after year. What's saleable in Windows? Is it the kernel? Maybe, but only by its specs. Far more saleable is the user-facing parts of the system. Sell them a pretty new GUI with transparent windows. Sell 'em a fancy new Office that looks and feels different. Sell a development package that lets programmers use these same facilities in their own code. (And of course, sell them bug fixes, by declaring end-of-life on older products and forcing everyone to move up. But that's different.) Since XP, the Windows kernel has been mostly reliable. I've had programs go wrong, and (eventually) managed to kill the process, upon which everything cleans up fairly nicely. Not that that's really a boast-worthy feature; I'd call it mandatory these days. The main reason I would recommend unifying kernels is simplicity. Let Microsoft play with, and sell, pretty GUIs and pretty apps. Let someone else worry about what's underneath. As an advantage, it would then become possible to buy a copy of Windows, run it *under Linux*, and treat it like a VMWare window. But it's not likely to happen, and I'm not 100% convinced it'd really be a good idea (see DNS root servers argument from earlier). It would make cross-compilation a lot easier, though! Chris Angelico From bahamutzero8825 at gmail.com Wed Jul 6 00:53:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 23:53:33 -0500 Subject: Microsoft GUIs In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: <4E13EA4D.3040504@gmail.com> On 2011.07.05 11:25 PM, Chris Angelico wrote: > Suppose I gave you a computer that had GNOME ported to Windows, and > used the purplish palette that Ubuntu 10.10 uses, and had a Windows > port of bash as its most convenient terminal. Members of this list > will doubtless have no problem duck-typing that as a Linux box (to the > extent of being quite surprised on seeing something that functions > differently). I would love to see a fully functional KDE running on Windows (this is being worked on, but development has been slow and rough). I was talking about GUI design, though, not just the aesthetics of a window manager and widgets. A recent version of bash working on Windows would be nice too, but IMO, MS should be actively promoting PowerShell. It's not that PowerShell is a superior scripting language to bash, but that it's integrated with WMI and is therefore much more convenient for admin stuff. > What is Microsoft selling? They're a company, which means they need to > keep selling stuff year after year. What's saleable in Windows? Is it > the kernel? Maybe, but only by its specs. Far more saleable is the > user-facing parts of the system. Sell them a pretty new GUI with > transparent windows. Sell 'em a fancy new Office that looks and feels > different. Sell a development package that lets programmers use these > same facilities in their own code. I think the reason MS has been creating good sysadmin tools lately is that it's feeling competition from Linux/Unix server solutions. If they can make a Windows domain admin's job easier, they're more likely to sell their OS. As for the end-user side of Windows (and their office suite), AFAICT, they're still pretty complacent with their market share and only change things up for the sake of difference. Since the GUI is the most noticeable part of the software, that's what gets changed. > Since XP, the Windows kernel has been mostly reliable. I've had > programs go wrong, and (eventually) managed to kill the process, upon > which everything cleans up fairly nicely. Not that that's really a > boast-worthy feature; I'd call it mandatory these days. I agree. > Let > Microsoft play with, and sell, pretty GUIs and pretty apps. I completely disagree. MS sucks at making GUIs. From drsalists at gmail.com Wed Jul 6 01:03:04 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Jul 2011 22:03:04 -0700 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: <4E13E0F0.20705@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: On Tue, Jul 5, 2011 at 9:13 PM, Andrew Berg wrote: > On 2011.07.05 09:31 PM, Chris Angelico wrote: > > I've said for a while that Microsoft could do far worse than to turn > > Windows into a GUI that sits on top of a Unix-derived kernel. They > > won't do it, though, because it would be tantamount to admitting both > > that Unix is superior to Windows, AND that Apple got it right. > Supposedly when Microsoft sold Xenix to SCO, Microsoft signed a legal document that barred them from competing in the *ix space. I do not know if it remains in effect now or not. > In my experience, it's been the GUIs that are awful and the backend > stuff that's been good in Windows. I disagree. The stuff endusers tend to use is polished to some extent, but the backend is verging on hideous. If a developer complains about the ugly internal structure "yeah, but you say that just because you're a computer person / geek." > Yes, the NT kernel still has some > long standing bugs, but MS has done well with things that matter to > sysadmins. chkdsk, for example, has been around for ages, but I still > don't know of anything that really beats it. How about FreeBSD's ability to check a filesystem while it's in use? > I've only had a small > amount of experience with it so far, but Powershell seems to be an > excellent tool for admin scripting since it interfaces with WMI so well. > I worked with PowerShell for about a year (after an acquisition by Microsoft), before eagerly diving back to Python. Here are some of my notes about the problems in PowerShell: 1) If you have a script that expects an array, and you don?t declare it as an array (type declarations are generally optional in PS), things will work fine until you get an array of length 1. Then your code breaks. 1.5) If you have a function that returns an array, you must return it with ,@{$a} to make it always be an array in the caller - it's ostensibly novice friendly, but it seems both novice and sophisticate hostile. 2) Options can be abbreviated, which may cause problems for what-was-working code on PowerShell upgrades, when something that was unique becomes ambiguous due to the addition of a new option having a common prefix with another option. 3) You can throw a string exception in PowerShell; this is disallowed in C# because it?s considered a poor practice. They?re deprecated in Python 2.x too - not sure if they were removed in Python 3. 4) Empty strings and nulls are kind of conflated, which is perhaps simpler in a way in native powershell stuff, but when you call something like a COM method that expects the two to be different, you run into problems that appear to require C# to get around. 5) If you try to invoke an external command having an option with double quotes and blanks in it, the single option will be converted into n+1 options, where n is the number of blanks inside double quotes. Granted, this is probably a problem that PowerShell inherited from one of its dependencies 6) no generators. C#, a supposedly lower-level language, has generators, but generators are a really nice high-level construct 7) Not a big deal, but what's up with the not operator? You Always seem to have to parenthesize, whether using ! or -not 8) If you pass an array of arrays, for EG 2x10, from one host to another using invoke-command, you actually end up with a single 20 element array 9) If you foreach ($foo in $bar), and $bar is empty, you still enter the script block once for $null 10) Sometimes you need comma separated parameters in parens. Sometimes you can't have them. When you can't have them and you're passing to a function that accepts multiple arguments, you end up with the 1st having an array of your arguments, and the 2..nth having $null. That's pretty far from the principle of least surprise 11) To pipe a 2-d array, you need to first convert it to a 3-d array, where the outermost array-ing is a single element - using the comma operator out front. Then send it into the pipeline as a 2-d array 12) DarkYellow is white and DarkMagenta is dark bluish. "It?s a feature. The default colours used by PowerShell are not in the standard console palette. To get the desired colours, we redefine DarkYellow and DarkMagenta and use them instead." 13) ?continue? is not really supported for a Foreach-Object loop, but at least return does what you'd expect continue to do 14) ?break? doesn?t do what it looks like it does in a foreach-object. It?s ending the script like ?continue?. 15) Sometimes foreach is foreach. Sometimes it's foreach-object. 16) break inside a foreach inside a pipeline breaks the whole pipeline > When it comes to things that interface with your average idiot, however, > MS consistently drops the ball. The new interface design they've imposed > on their office suite and Explorer is not only just plain bad, but it's > infectious (and it's the reason the Firefox and Thunderbird default GUI > configurations look horrendous). Hmmmm. Wonder why that is? > Another area MS fails it is sensible > defaults. They put tons of effort into increasing security in the > kernel, but don't use the security features (I'll try to come up with > more detail on this later). The newer security features in Windows are extremely baroque. Communication about them is lacking, even inside the company. I literally think it's more secure to use traditional *ix permissions despite the obvious effort Microsoft has put in on security - *ix permissions aren't as comprehensive, but they're also a simple model that works better. Sometime when you're in a puckish mood, ask a Microsoft expert how many different kinds of "delegation" Windows has, and what they're each good for. It's kind of like asking a *ix expert how many IOCTL's there are, and what they are each for. (Linux has moved away from IOCTL quite a bit because there were far too many in *ix historically). > Explorer /still/ hides known extensions by > default, which /still/ makes it easier for bad people to get their > victims to execute malware. What I think is that MS should focus on the > kernel and encourage others to do their GUIs. Oh my. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed Jul 6 01:29:43 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 00:29:43 -0500 Subject: Microsoft GUIs In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: <4E13F2C7.40704@gmail.com> On 2011.07.06 12:03 AM, Dan Stromberg wrote: > I disagree. The stuff endusers tend to use is polished to some > extent, but the backend is verging on hideous. If a developer > complains about the ugly internal structure "yeah, but you say that > just because you're a computer person / geek." Admittedly, I haven't tried to do a whole lot of development with the Windows APIs, and I certainly haven't tried to develop any software that's heavily tied to the kernel, so I could be wrong in this area. Could you elaborate? > > Yes, the NT kernel still has some > long standing bugs, but MS has done well with things that matter to > sysadmins. chkdsk, for example, has been around for ages, but I still > don't know of anything that really beats it. > > > How about FreeBSD's ability to check a filesystem while it's in use? Actually, I meant in Windows, as in there aren't any 3rd-party tools that really trump chkdsk for repairing NTFS volumes. I should've clarified that. However, that sounds like an awesome feature (though I'm not going to switch to FreeBSD just for that). > > I've only had a small > amount of experience with it so far, but Powershell seems to be an > excellent tool for admin scripting since it interfaces with WMI so > well. > > > I worked with PowerShell for about a year (after an acquisition by > Microsoft), before eagerly diving back to Python. Here are some of my > notes about the problems in PowerShell: Did you encounter these issues with PowerShell 2? I know MS put a lot of work into fixing and adding features to PowerShell 1, but like I said, I haven't had much experience with it. From bahamutzero8825 at gmail.com Wed Jul 6 01:37:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 00:37:55 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4E137BC5.2080401@gmail.com> Message-ID: <4E13F4B3.4070907@gmail.com> On 2011.07.06 12:26 AM, Dennis Lee Bieber wrote: > On Tue, 05 Jul 2011 16:01:57 -0500, Andrew Berg > declaimed the following in > gmane.comp.python.general: > > > On 2011.07.05 01:14 PM, sal migondis wrote: > > > How could a belief be wrong? > > Beliefs aren't subjective. One's taste in music, for example, is > > largely subjective and can't be right or wrong, but a belief (which has > > to do with facts) certainly can be. > > Pardon???? > > Most "beliefs" that I've encountered do their best to ignore any > facts that contradict the belief. "Facts" imply testable evidence, > hypotheses, eventual theorems... I didn't say people were objective. A belief is quite similar to a statement of fact. Whether the statement is true or false or even objectively reached isn't relevant to the definition. From rosuav at gmail.com Wed Jul 6 01:43:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 15:43:38 +1000 Subject: Microsoft GUIs In-Reply-To: <4E13EA4D.3040504@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> <4E13EA4D.3040504@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 2:53 PM, Andrew Berg wrote: >> Let Microsoft play with, and sell, pretty GUIs and pretty apps. > I completely disagree. MS sucks at making GUIs. > I never said they were good at making GUIs. I said they were good at selling GUIs. Dan is right about the ugliness of the Windows APIs. There are innumerable anomalies between otherwise-similar functions, weird behaviours that may and may not have historical precedent, and enough hair-pulling fuel to turn you bald in a week. Also, and possibly more serious, the security features that Windows has mostly seem to have been monkey-patched in; and there are ridiculous vulnerabilities just waiting to be exploited. The WM_TIMER message can be sent by any process to any process, and one of its parameters is the address of a callback - and voila, other process starts executing code at that address. And this works even if the program doesn't use timers. ChrisA From rosuav at gmail.com Wed Jul 6 01:47:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 15:47:05 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 3:26 PM, Dennis Lee Bieber wrote: > On Wed, 6 Jul 2011 12:31:02 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: >> Democracy DOES NOT WORK. Plain and simple. You cannot build a >> programming language democratically. >> > ? ? ? ?Uhm... COBOL and Ada may be close... They were committee/competition > where the best (compromise) aspect was selected for inclusion... And are they what you would call good languages? A committee isn't the same as democracy, although it is related. If you have two people making a decision, you potentially pull things in two directions. If you have two million people making a decision, you tear it to pieces. Vision for a language (or any other project) cannot come from a mandate from the masses. I'm waiting for my aquatic ceremony before I start building a language. ChrisA From phlip2005 at gmail.com Wed Jul 6 01:54:50 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 5 Jul 2011 22:54:50 -0700 (PDT) Subject: Does hashlib support a file mode? Message-ID: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Pythonistas: Consider this hashing code: import hashlib file = open(path) m = hashlib.md5() m.update(file.read()) digest = m.hexdigest() file.close() If the file were huge, the file.read() would allocate a big string and thrash memory. (Yes, in 2011 that's still a problem, because these files could be movies and whatnot.) So if I do the stream trick - read one byte, update one byte, in a loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit CPU. So that's the same problem; it would still be slow. So now I try this: sum = os.popen('sha256sum %r' % path).read() Those of you who like to lie awake at night thinking of new ways to flame abusers of 'eval()' may have a good vent, there. Does hashlib have a file-ready mode, to hide the streaming inside some clever DMA operations? Prematurely optimizingly y'rs -- Phlip http://bit.ly/ZeekLand From wm at localhost.localdomain Wed Jul 6 02:00:38 2011 From: wm at localhost.localdomain (Waldek M.) Date: Wed, 6 Jul 2011 08:00:38 +0200 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1pvghkmjff37$.dlg@localhost.localdomain> Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): > Because unless you are extremely disciplined, code and the comments > describing them get out of sync. [...] True, but that gets far worse with external docs. Do you have in mind any better replacement? Br. Waldek From greg.ewing at canterbury.ac.nz Wed Jul 6 02:12:16 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 18:12:16 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: <97icm3Ft0eU1@mid.individual.net> rantingrick wrote: >>What he means is that On Mac, if you close "all" windows, the application is >>still running. > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. No, the windows really are closed. They no longer exist in any way. The application is still running, though, and its menu bar will appear if you bring it to the front (in MacOSX this is done by clicking on its dock icon; in classic MacOS it was done by selecting from the menu of running applications that was available in the top right corner of the screen). -- Greg From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:24:25 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:24:25 +0200 Subject: embedding: how do I redirect print output? References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5dbde8-fcm.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Why do you think it [sink for use as sys.stdout] needs to be in C? As > far as I can tell, so long as it quacks like a file object (that is, > has a write method), it should work. Good point & thanks for the example fish! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From gandalf at shopzeus.com Wed Jul 6 02:25:37 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 06 Jul 2011 08:25:37 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> Message-ID: <4E13FFE1.1080303@shopzeus.com> >> Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. > > I get different results than you. > > Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. > > Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- > > Traceback (most recent call last): > File "x.py", line 46, in onPopupMenu > item = wx.MenuItem(None,-1,u"Test") > File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ > _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) > wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu I guess I'll have to write to the wxPython mailing list. Seriously, adding a simple menu to something is supposed to be platform independent, but we got four different results on four systems. :-( Thank you for trying out though. From greg.ewing at canterbury.ac.nz Wed Jul 6 02:29:03 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 18:29:03 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> Message-ID: <97idliF4ecU1@mid.individual.net> rantingrick wrote: > And how do you EXPLICITY quit the application? Using its "Quit" menu command. But that's Mac-specific, and not central to the discussion. On Linux and Windows, an application will usually exit when its last window is closed. Either way, there is no need for a privileged main window. -- Greg From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Jul 6 02:37:47 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 06 Jul 2011 08:37:47 +0200 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: Am 06.07.2011 07:54 schrieb Phlip: > Pythonistas: > > Consider this hashing code: > > import hashlib > file = open(path) > m = hashlib.md5() > m.update(file.read()) > digest = m.hexdigest() > file.close() > > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) > > So if I do the stream trick - read one byte, update one byte, in a > loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit > CPU. So that's the same problem; it would still be slow. Yes. That is why you should read with a reasonable block size. Not too small and not too big. def filechunks(f, size=8192): while True: s = f.read(size) if not s: break yield s # f.close() # maybe... import hashlib file = open(path) m = hashlib.md5() fc = filechunks(file) for chunk in fc: m.update(chunk) digest = m.hexdigest() file.close() So you are reading in 8 kiB chunks. Feel free to modify this - maybe use os.stat(file).st_blksize instead (which is AFAIK the recommended minimum), or a value of about 1 MiB... > So now I try this: > > sum = os.popen('sha256sum %r' % path).read() This is not as nice as the above, especially not with a path containing strange characters. What about, at least, def shellquote(*strs): return " ".join([ "'"+st.replace("'","'\\''")+"'" for st in strs ]) sum = os.popen('sha256sum %r' % shellquote(path)).read() or, even better, import subprocess sp = subprocess.Popen(['sha256sum', path'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) sp.stdin.close() # generate EOF sum = sp.stdout.read() sp.wait() ? > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? AFAIK not. Thomas From clp2 at rebertia.com Wed Jul 6 02:44:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 5 Jul 2011 23:44:28 -0700 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 10:54 PM, Phlip wrote: > Pythonistas: > > Consider this hashing code: > > ?import hashlib > ?file = open(path) > ?m = hashlib.md5() > ?m.update(file.read()) > ?digest = m.hexdigest() > ?file.close() > > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) > > So if I do the stream trick - read one byte, update one byte, in a > loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit > CPU. So that's the same problem; it would still be slow. > > So now I try this: > > ?sum = os.popen('sha256sum %r' % path).read() > > Those of you who like to lie awake at night thinking of new ways to > flame abusers of 'eval()' may have a good vent, there. Indeed (*eyelid twitch*). That one-liner is arguably better written as: sum = subprocess.check_output(['sha256sum', path]) > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? Barring undocumented voodoo, no, it doesn't appear to. You could always read from the file in suitably large chunks instead (rather than byte-by-byte, which is indeed ridiculous); see io.DEFAULT_BUFFER_SIZE and/or the os.stat() trick referenced therein and/or the block_size attribute of hash objects. http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE http://docs.python.org/library/hashlib.html#hashlib.hash.block_size Cheers, Chris -- http://rebertia.com From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:45:44 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:45:44 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: <5lcde8-p6n.ln1@satorlaser.homedns.org> rantingrick wrote: > On Jul 5, 10:26 am, Steven D'Aprano > Since you can't do anything without a root window, I don't see the >> benefit in forcing the user to do so [create one explicitly]. > > The reason is simple. It's called order. It's called learning from day > one how the order of things exists. Widgets are part of windows, not > the other way around. Saving a few keystrokes is not acceptable if you > jumble the understanding of a new student. To understand and use > Tkinter properly you must understand the order of window->widget. > >> When they need to learn about root windows, >> they will in their own good time. > > So you would start drivers education class with road construction? Or > the history of the internal combustion engine? Who cares about > actually *driving* the car. Ahem, you are the one that suggests that in order to drive a car you should first build a road, not Steven! That said, why should I care about the choices and steps I have for creating main windows and the possibilities I get from doing this myself? A basic default main window is enough for me! Further, choice implies I can make wrong choices, too, so forcing someone to make a decision might cause errors. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:49:51 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:49:51 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mel wrote: > In wx, many of the window classes have Create methods, for filling in > various attributes in "two-step construction". I'm not sure why, because > it works so well to just supply all the details when the class is called > and an instance is constructed. Maybe there's some C++ strategy that's > being supported there. Just guessing, is it legacy, C-with-classes code rather than C++ code perhaps? Haven't looked at wx for a while. Such code typically lacks understanding of exceptions, which are the only way to signal failure from e.g. constructors. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From greg.ewing at canterbury.ac.nz Wed Jul 6 03:05:07 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 19:05:07 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <97ifp6FjfuU1@mid.individual.net> rantingrick wrote: > I was thinking more about this comment and it occurred to me that > Python does have user controlled data structures. Just because there > is no "top level syntax" like ruby does not mean these do not exists. Syntax is what it's really about, though. There's no clear dividing line, but when Guido says he's opposed to "user defined syntax" he's talking about things like Lisp macros, which let you effectively extend the grammar with new keywords and syntactic structures. Compared to that, Python's grammar is very much fixed. Anything you want to do has to be done within the existing framework of function calls, attribute references etc. If Python truly had user-defined syntax, it wouldn't have been necessary to modify the compiler to implement features such as list comprehensions and with-statements -- those features could have been implemented, with the *same syntax* or something close to it, in the base language. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 6 03:15:29 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 19:15:29 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <97igcjFntvU1@mid.individual.net> rantingrick wrote: > Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- > our-problems" pipe dream language. So it's just a "single-answer-to-all-our-glue-programming" pipe dream language, then? :-) -- Greg From timbovaird at gmail.com Wed Jul 6 03:39:57 2011 From: timbovaird at gmail.com (TimB) Date: Wed, 6 Jul 2011 00:39:57 -0700 (PDT) Subject: Error while downloading webpages Message-ID: Hi everyone, new to python. I'm attempting to download a large amount of webpages (about 600) to disk and for some reason a few of them fail. I'm using this in a loop where pagename and urlStr change each time: import urllib try: urllib.urlretrieve(urlStr, 'webpages/'+pagename+'.htm') except IOError: print 'Cannot open URL %s for reading' % urlStr str1 = 'error!' Out of all the webpages, it does not work for these three: http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b http://exoplanet.eu/planet.php?p1=HAT-P-27/WASP-40&p2=b http://exoplanet.eu/planet.php?p1=HAT-P-30/WASP-51&p2=b giving "Cannot open URL http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b for reading" etc. however copying and pasting the URL from the error message successfully opens in firefox it successfully downloads the 500 or so other pages such as: http://exoplanet.eu/planet.php?p1=HD+88133&p2=b I guess it has something to do with the forward slash in the names (e.g. HAT-P-30/WASP-51 compared to HD+88133 in the examples above) Is there a way I can fix this? Thanks. From timbovaird at gmail.com Wed Jul 6 03:43:14 2011 From: timbovaird at gmail.com (TimB) Date: Wed, 6 Jul 2011 00:43:14 -0700 (PDT) Subject: Error while downloading webpages References: Message-ID: <39972319-f4f5-47be-91fd-803a017c9c33@e17g2000prj.googlegroups.com> On Jul 6, 5:39?pm, TimB wrote: > Hi everyone, new to python. I'm attempting to download a large amount > of webpages (about 600) to disk and for some reason a few of them > fail. > > I'm using this in a loop where pagename and urlStr change each time: > import urllib > ? ? try: > ? ? ? ? urllib.urlretrieve(urlStr, 'webpages/'+pagename+'.htm') > ? ? except IOError: > ? ? ? ? print 'Cannot open URL %s for reading' % urlStr > ? ? ? ? str1 = 'error!' > > Out of all the webpages, it does not work for these three:http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=bhttp://exoplanet.eu/planet.php?p1=HAT-P-27/WASP-40&p2=bhttp://exoplanet.eu/planet.php?p1=HAT-P-30/WASP-51&p2=b > giving "Cannot open URLhttp://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b > for reading" etc. > > however copying and pasting the URL from the error message > successfully opens in firefox > > it successfully downloads the 500 or so other pages such as:http://exoplanet.eu/planet.php?p1=HD+88133&p2=b > > I guess it has something to do with the forward slash in the names > (e.g. HAT-P-30/WASP-51 compared to HD+88133 in the examples above) > > Is there a way I can fix this? Thanks. sorry, I was attempting to save the page to disk with the forward slash in the name, disreguard From ramp99 at gmail.com Wed Jul 6 03:49:36 2011 From: ramp99 at gmail.com (Rama Rao Polneni) Date: Wed, 6 Jul 2011 13:19:36 +0530 Subject: Not able to store data to dictionary because of memory limitation Message-ID: Hi All, I am facing a problem when I am storing cursor fetched(Oracle 10G) data in to a dictionary. As I don't have option to manipulate data in oracle10G, I had to stick to python to parse the data for some metrics. After storing 1.99 GB data in to the dictionary, python stopped to store the remaining data in to dictionary. Memory utilization is 26 GB/34GB. That means, still lot memory is left as unutilized. Can please share your experices/ideas to resolve this issue. Is this prople mbecasue of large memory utlization. Is there any alternate solution to resolve this issue. Like splitting the dictionaries or writing the data to hard disk instead of writing to memory. How efficiently we can use memory when we are going for dictionaries. Thanks in advacne, Rama From t at jollybox.de Wed Jul 6 04:02:19 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 06 Jul 2011 10:02:19 +0200 Subject: web browsing short cut In-Reply-To: References: Message-ID: <4E14168B.5080107@jollybox.de> On 07/06/2011 03:30 AM, Dustin Cheung wrote: > I am looking into Tkinter. But i am not sure if it will actually work. > This maybe a crazy idea but i was wondering if i can put a web browser > in the frame. I have tried to use Tkinter to resize and place the > windows to certain areas of the screen but that's not working or the way > im approaching this problem is completely wrong. I want to make a > program that will have websites displayed in specific areas of the > screen. I was planning on using the program on the big screen. So is it > possible to put the web browser inside the frame in Tkinter? What you could do, in effect, is write your own web browser, using an existing rendering engine. I do not know which rendering engines are how easily used in Tkinter code (possibly none of them). This isn't a job for (traditional, cross-platform) Python. It *may* be possible with pyWin32. It may be easier with the Windows Script Host (which apparently can support Python). I personally would use browser-side JavaScript; it's certainly possible to open a popup of a specific size in JS, not sure about specific position on-screen. Maybe you have to write an extension for Firefox or Chrome. > > > On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert > wrote: > > On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung > wrote: > > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > > and re-sizes them to display on different areas on the screen. I > looked > > around but i had no luck. Is that possible with python? if so can > someone > > point to to the right direction? Here is what I came up with so far.. > > The window positioning+resizing bit will likely require using > platform-specific APIs. Since you appear to be on Windows, the > relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 > ). You would use it to invoke some COM API that does window > positioning+resizing. I am unable to give more details as I'm on a > Mac. > > Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? > > Cheers, > Chris > > > > > -- > Dustin Cheung > > From rosuav at gmail.com Wed Jul 6 04:33:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 18:33:51 +1000 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 5:49 PM, Rama Rao Polneni wrote: > Hi All, > > I am facing a problem when I am storing cursor fetched(Oracle 10G) > data in to a dictionary. > As I don't have option to manipulate data in oracle10G, I had to stick > to python to parse the data for some metrics. > > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. Is the data one row from the table, or could you work with it row-by-row? ChrisA From ulrich.eckhardt at dominolaser.com Wed Jul 6 04:35:44 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 10:35:44 +0200 Subject: Not able to store data to dictionary because of memory limitation References: Message-ID: Rama Rao Polneni wrote: > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. Question here: - Which Python? - "stopped to store" (you mean "stopped storing", btw), how does it behave? Hang? Throw exceptions? Crash right away? > Memory utilization is 26 GB/34GB. That means, still lot memory is left > as unutilized. 2GiB is typically the process limit for memory allocations on 32-bit systems. So, if you are running a 32-bit system or running a 32-bit process on a 64-bit system, you are probably hitting hard limits. With luck, you could extend this to 3GiB on a 32-bit system. > Is this proplem becasue of large memory utlization. I guess yes. > Is there any alternate solution to resolve this issue. Like splitting > the dictionaries or writing the data to hard disk instead of writing > to memory. If you have lost of equal strings, interning them might help, both in size and speed. Doing in-memory compression would be a good choice, too, like e.g. if you have string fields in the DB that can only contain very few possible values, converting them to an integer/enumeration. Otherwise, and this is a more general approach, prefer making a single sweep over the data. This means that you read a chunk of data, perform whatever operation you need on it, possibly write the results and then discard the chunk. This keeps memory requirements low. At first, it doesn't look as clean as reading the whole data in one step, calculations as a second and writing results as a third, but with such amounts of data as yours, it is the only viable step. Good luck, and I'd like to hear how you solved the issue! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rosuav at gmail.com Wed Jul 6 04:37:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 18:37:31 +1000 Subject: web browsing short cut In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 11:30 AM, Dustin Cheung wrote: > Hey, > I am looking into Tkinter. But i am not sure if it will actually work. This > maybe a crazy idea but i was wondering if i can put a web browser in the > frame. I have tried to use Tkinter to resize and place the windows to > certain areas of the screen but?that's?not working or the way im approaching > this problem is completely wrong. I want to make a program that will have > websites displayed in specific areas of the screen. I was planning on using > the program on the big screen. So is it possible to put the web browser > inside the frame in Tkinter? Thinking along a quite different line here, is it possible for you to use regular frames? Create an HTML file with: That should divide your screen four ways (if I haven't botched my HTML - ages since I've used frames). ChrisA From anddimario at gmail.com Wed Jul 6 04:44:16 2011 From: anddimario at gmail.com (AndDM) Date: Wed, 6 Jul 2011 01:44:16 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> Message-ID: <742ddcd0-37d1-4009-a82b-c12cd3b7c43f@b2g2000vbo.googlegroups.com> On Jul 5, 4:08?pm, Jean-Paul Calderone wrote: > On Jul 5, 4:52?am, Andrea Di Mario wrote: > > > Hi, I'm a new python user and I'm writing a small web service with ssl. > > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > > I've used wrap_socket, but if i try to use > > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > > urllib2.URLError: > specified for verification of other-side certificates.> > > > It works only with CERT_NONE (the default) but with this option i > > could access to the service in insicure mode. > > > Have you some suggestions for my service? > > Also specify some root certificates to use in verifying the peer's > certificate. ?Certificate verification works by proceeding from a > collection of "root" certificates which are explicitly trusted. ?These > are used to sign other certificates (which may in turn be used to sign > others, which in turn...). ?The process of certificate verification is > the process of following the signatures from the certificate in use by > the server you connect to back up the chain until you reach a root > which you have either decided to trust or not. ?If the signatures are > all valid and the root is one you trust, then you have established a > connection to a trusted entity. ?If any signature is invalid, or the > root is not one you trust, then you have not. > > The root certificates are also called the "ca certificates" or > "certificate authority certificates". ?`wrap_socket` accepts a > `ca_certs` argument. ?Seehttp://docs.python.org/library/ssl.html#ssl-certificates > for details about that argument. > > Jean-Paul Hi Jean-Paul, i thought that with self-signed certificate i shouldn't use ca_certs option. Now, i've created a ca-authority and i use this command: self.sock = ssl.wrap_socket(sock, certfile = "ca/certs/ myfriend.cert.pem", keyfile = "ca/private/myfriend.key.pem", ca_certs="/home/andrea/ca/certs/cacert.pem", cert_reqs=ssl.CERT_REQUIRED) When i use the some machine as client-server it works, but, when i use another machine as client, i've this: Traceback (most recent call last): ? File "loginsender.py", line 48, in ? ? handle = url_opener.open('https://debian.andrea.it:10700/%s+%s' % (DATA,IPIN)) ? File "/usr/lib/python2.6/urllib2.py", line 391, in open ? ? response = self._open(req, data) ? File "/usr/lib/python2.6/urllib2.py", line 409, in _open ? ? '_open', req) ? File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain ? ? result = func(*args) ? File "loginsender.py", line 33, in https_open ? ? return self.do_open(self.specialized_conn_class, req) ? File "/usr/lib/python2.6/urllib2.py", line 1145, in do_open ? ? raise URLError(err) urllib2.URLError: I see that i should create a certificate with server, client and ca autority, but i haven't clear the ca_certs option and which path i should use. Have you any suggestion? Thank. Regards. From gnarlodious at gmail.com Wed Jul 6 05:02:45 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 6 Jul 2011 02:02:45 -0700 (PDT) Subject: Extracting property getters from dir() results Message-ID: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Using introspection, is there a way to get a list of "property getters"? Does this: vars=property(getVars(), "Dump a string of variables and values") have some parsable feature that makes it different from other functions? Or would I need to use some naming scheme to parse them out? -- Gnarlie From ramp99 at gmail.com Wed Jul 6 05:05:44 2011 From: ramp99 at gmail.com (Rama Rao Polneni) Date: Wed, 6 Jul 2011 14:35:44 +0530 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: -------------------------------------------------------------------------------------------- Yes the data is from table. which is retrieved using some queries in to cx_oracel cursor. I am able to read the data row by row. One more information, I am Able to load the data in to dictionary by removing some some data from table. -Ram -------------------------------------------------------------------------------------------- > Is the data one row from the table, or could you work with it row-by-row? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -------------------------------------------------------------------------------------------- On 7/6/11, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 5:49 PM, Rama Rao Polneni wrote: >> Hi All, >> >> I am facing a problem when I am storing cursor fetched(Oracle 10G) >> data in to a dictionary. >> As I don't have option to manipulate data in oracle10G, I had to stick >> to python to parse the data for some metrics. >> >> After storing 1.99 GB data in to the dictionary, python stopped to >> store the remaining data in to dictionary. > > From lists at cheimes.de Wed Jul 6 05:35:18 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 11:35:18 +0200 Subject: Extracting property getters from dir() results In-Reply-To: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> References: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Message-ID: Am 06.07.2011 11:02, schrieb Gnarlodious: > Using introspection, is there a way to get a list of "property > getters"? > > Does this: > > vars=property(getVars(), "Dump a string of variables and values") > > have some parsable feature that makes it different from other > functions? Or would I need to use some naming scheme to parse them > out? dir() won't help you much here. The inspect module has several tools to make inspection easier. >>> import inspect >>> class Example(object): ... @property ... def method(self): ... return 1 ... >>> inspect.getmembers(Example, inspect.isdatadescriptor) [('__weakref__', ), ('method', )] inspect.getmembers() with isdatadescriptor predicate works only on classes, not on instances. >>> inspect.getmembers(Example(), inspect.isdatadescriptor) [] Property instances have the attributes fget, fset and fdel that refer to their getter, setter and delete method. >>> for name, obj in inspect.getmembers(Example, inspect.isdatadescriptor): ... if isinstance(obj, property): ... print name, obj, obj.fget ... method Christian From benjokal at gmail.com Wed Jul 6 05:44:07 2011 From: benjokal at gmail.com (Benji Benjokal) Date: Wed, 6 Jul 2011 05:44:07 -0400 Subject: Python Packaging Message-ID: Can someone show me how to package with py2exe? Every time I tried it says the file does not exist. Can you help? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From as at sci.fi Wed Jul 6 05:47:19 2011 From: as at sci.fi (Anssi Saari) Date: Wed, 06 Jul 2011 12:47:19 +0300 Subject: Does hashlib support a file mode? References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: Phlip writes: > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) I did a crc32 calculator like that and actually ran into some kind of string length limit with large files. So I switched to 4k blocks and the speed is about the same as a C implementation in the program cksfv. Well, of course crc32 is usually done with a table lookup, so it's always fast. I just picked 4k, since it's the page size in x86 systems and also a common block size for file systems. Seems to be big enough. io.DEFAULT_BUFFER_SIZE is 8k here. I suppose using that would be the proper way. From t at jollybox.de Wed Jul 6 06:48:02 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 06 Jul 2011 12:48:02 +0200 Subject: Python Packaging In-Reply-To: References: Message-ID: <4E143D62.3030103@jollybox.de> On 07/06/2011 11:44 AM, Benji Benjokal wrote: > > Can someone show me how to package with py2exe? > Every time I tried it says the file does not exist. If you show us how you're trying to do it, somebody may be able to spot your error. PS: http://www.catb.org/~esr/faqs/smart-questions.html From awilliam at whitemice.org Wed Jul 6 06:55:31 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 06 Jul 2011 06:55:31 -0400 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: <1309949732.3045.9.camel@linux-yu4c.site> On Tue, 2011-07-05 at 22:54 -0700, Phlip wrote: > Pythonistas > Consider this hashing code: > import hashlib > file = open(path) > m = hashlib.md5() > m.update(file.read()) > digest = m.hexdigest() > file.close() > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) Yes, the simple rule is do not *ever* file.read(). No matter what the year this will never be OK. Always chunk reading a file into reasonable I/O blocks. For example I use this function to copy a stream and return a SHA512 and the output streams size: def write(self, in_handle, out_handle): m = hashlib.sha512() data = in_handle.read(4096) while True: if not data: break m.update(data) out_handle.write(data) data = in_handle.read(4096) out_handle.flush() return (m.hexdigest(), in_handle.tell()) > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? Chunk it to something close to the block size of your underlying filesystem. From exxontechnical at gmail.com Wed Jul 6 07:21:50 2011 From: exxontechnical at gmail.com (covai exxon) Date: Wed, 6 Jul 2011 04:21:50 -0700 (PDT) Subject: hiiiiiiiiiiii see this webpage Message-ID: http://123maza.com/65/papaya846/ From steve+comp.lang.python at pearwood.info Wed Jul 6 07:44:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:44:21 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 5, 11:04?am, Corey Richardson wrote: > >> How is giving the sort method a function by which to determine the >> relative value of objects a control structure? Do you know what a control >> structure is? It's something that you use to modify control flow: >> >> if foo <= bar: >> foo += 1 >> else: >> bar += 1 > > Interesting, corey. Very interesting. However the fun is yet to come > so stay tuned... > >> That's a control structurem the "if-else". I don't know what Ruby calls a >> control structure, but that's what it is. for and while are in there too. >> When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? > > So are you suggesting that a control structure must have at minimum > one of "for", "while", or "if"? A control structure is a structure which controls the program flow. Control structures include: * jumps (goto, gosub, comefrom, exceptions, break, continue) * loops (for, while, repeat...until) * conditional branches (if, case/switch) There may be others, although I can't think of any of hand. Jumping, looping and branching pretty much covers all the bases, I think. It excludes expressions such as ternary-if, because that doesn't control program flow, it's just an expression. A function which includes a control structure inside it is not itself a control structure, in the same way that the existence of bones inside you does not make you a bone. [...] > Yes there IS and "if" in there and IF you look closely enough you may > see two "for"'s also. So by your own definition this (naive) code > qualifies as a control structure. I see what you did there. First you put words into Cory's mouth that he did not say, they you try to criticise him based on those words -- YOUR words. No Rick, that's your definition, not Cory's. Please do not treat us as stupid. > But wait just a second Corey. My statement has nothing to do with > sort. sort is just the vehicle. My statement is that the cmp argument > to sort IS a user defined control structure (the code block to be > exact). The cmp argument to sort is not a control structure because it is not a structure and it does not control the program flow. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:44:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:44:31 +1000 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> Stefaan Himpe wrote: >> Now, I have an ulterior motive in raising this issue... I can't find the >> original article I read! My google-fu has failed me (again...). I don't >> suppose anyone can recognise it and can point me at it? > > My sarcasm detector warns me not to add a link, although perhaps it's > time for recalibration (after all, summer season started) :-) No! I was serious. I've spent *ages* trying to find the link to the article... if you know it, please share. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:45:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:45:32 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> sal migondis wrote: > How could a belief be wrong? I believe you are a small glass of beer. Are you *actually* a small glass of beer in reality? If so, my belief is right. If you are a human being, then my belief is wrong. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:46:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:46:36 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e144b1d$0$29982$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: >> Define "best for all", and try not to make it "what Rick wants". > > You want features? And remember i am talking about scripting/glue > level languages here. Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- > our-problems" pipe dream language. > > * Intuitive syntax. Intuitive to who? Newbies? Then you get a language like Hypertalk, that experienced programmers hate. Experienced C programmers? Then you get something like Java. Forth programmers? Then you get something like Arc, that nobody except Paul Graham uses. (Not literally, no offence to anyone who likes Arc.) System administrators? They you get something like Perl. ("It's like bash scripting only better!") Mathematicians? Then you get something like Haskell. Non-programmers? Then you could get anything from Inform7, to Applescript, to Resolver's Python-in-a-spreadsheet, to Pascal, to FoxPro, to Flash, to Javascript, to Mathematica... depending on *which* non-programmers you are aiming at. > * Productivity friendly. That covers everything from Excel to Lisp, depending on who you ask. > * Complex enough to solve large problems but simple enough for simple > problems (that does include extending into C when needed) But if you are designing the "perfect language", what do you need C for? C will no longer exist, except in museums, because Rick's perfect language will be used for everything. > * Multi paradigm (problem Which is guaranteed to annoy those who believe that paradigms A, C, D and E are harmful and should be avoided... the only problem is that there is no broad agreement on which paradigm B is non-harmful. > * Promotes a culture of code readability (because people read source; > not just machines!). Define readability. Hypertalk, Python, Inform7 and Pascal are all readable, in radically different ways. >> No, Python is not a monoculture. There are the Stackless, Jython, PyPy >> and IronPython sub-cultures, all with their own needs, wants and desires. >> There are sub-cultures for embedded devices and smart phones, >> sub-cultures for those who use Python as a teaching language, for web >> development, for GUI development, and for system administration. There >> are the Numpy and Scipy sub-cultures, sub-cultures in the fields of >> linguistics and biology. > > Hmm. Just think how far ahead we would be if these folks would stop > trying to support petty differences and focus on a singular Python > language? These are not "petty differences", but real differences that are important to people who have actually work to do. A sushi chef needs a different sort of knife to a brain surgeon, both of which are different to that needed by a special forces soldier deep in enemy territory, which is different again to the sort of knife is needed by some guy working in a warehouse unpacking boxes. Different jobs need different tools. There is no perfect language because different tasks need different tools, and any compromise tool that tries to do everything will be weaker than a specialist tool. -- Steven From python.list at tim.thechases.com Wed Jul 6 07:58:45 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Jul 2011 06:58:45 -0500 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: <4E144DF5.2020208@tim.thechases.com> On 07/06/2011 02:49 AM, Rama Rao Polneni wrote: > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. > > Is there any alternate solution to resolve this issue. Like splitting > the dictionaries or writing the data to hard disk instead of writing > to memory. Without details on the specifics of what you're storing in your dictionary, you might investigate the anydbm module which would allow you to have a disk-backed dictionary, but it really only works for string->string mappings. You can use shelve/pickle to marshal other data-types into strings for use in such a mapping, but there are some odd edge-cases to be aware of (updating an instance of a class doesn't change the pickled object, so you have to intentionally re-store it after you change it; I've hit unexpected scoping issues with class-names; etc). But for the general case, it might do exactly what you need to remove the 2GB cap. -tkc From stefaan.himpe at gmail.com Wed Jul 6 08:44:45 2011 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Wed, 06 Jul 2011 14:44:45 +0200 Subject: Implicit initialization is EXCELLENT In-Reply-To: <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1NYQp.25969$Sr.25363@newsfe12.ams2> > No! I was serious. I've spent *ages* trying to find the link to the > article... if you know it, please share. Ok - I thought you were referring to some troll's rant with similar title. I'm probably way off, but were you referring to the RAII technique? http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization From rantingrick at gmail.com Wed Jul 6 09:41:52 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 06:41:52 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 6:44?am, Steven D'Aprano wrote: > A control structure is a structure which controls the program flow. Control > structures include: > > * jumps (goto, gosub, comefrom, exceptions, break, continue) > > * loops (for, while, repeat...until) > > * conditional branches (if, case/switch) ------------------------------------------- THIS CODE RESULTS IN A CONTROL STRUCTURE! --> lst.sort(lambda x,y: cmp(x[1], y[1])) ------------------------------------------- I am using a user defined spec as an argument to the cmp function. That spec then modifies the body of the compare function and creates a user defined control structure. You can argue all day that it is not a user defined control structure but no one is going to believe you. > A function which includes a control structure inside it is not itself a > control structure, Of course the FUNCTION is not a control structure (not directly). No wonder you are confused. It's the FUNCTION BODY that is the control structure. The function body that has been modified by my arguments to the cmp function. But in a way, you can say the function OWNS the code block so it is itself a control structure. Still confused? Read on... > in the same way that the existence of bones inside you > does not make you a bone. Bad analogy. See last comment. > I see what you did there. First you put words into Cory's mouth that he did > not say, they you try to criticise him based on those words -- YOUR words. I quoted Corey exactly. And why do you feel the need to answer for him? > The cmp argument to sort is not a control structure because it is not a > structure and it does not control the program flow. Again you lack simple reading and comprehension skills. It's not the argument that is the control structure itself. The argument is just the SPEC for creating a control structure. The control structure is the modified CODE BLOCK owned by the "CMP" function. The modified code block owned by the cmp function-- defined by the user through an argument spec-- controls the return value to the list sort method. USER DEFINED CONTROL STRUCTURE. Plain and simple. I don't think i can use any simpler terms to describe it. Give it up man and admit i am correct and you are wrong. From phlip2005 at gmail.com Wed Jul 6 09:47:02 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 06:47:02 -0700 (PDT) Subject: Does hashlib support a file mode? References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: <72286154-f71f-4f1c-8d53-18ae3eda9ecf@q14g2000prh.googlegroups.com> wow, tx y'all! I forgot to mention that hashlib itself is not required; I could also use Brand X. But y'all agree that blocking up the file in python adds no overhead to hashing each block in C, so hashlib in a loop it is! From rantingrick at gmail.com Wed Jul 6 09:51:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 06:51:30 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: On Jul 6, 1:12?am, Gregory Ewing wrote: > rantingrick wrote: > >>What he means is that On Mac, if you close "all" windows, the application is > >>still running. > > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > > No, the windows really are closed. They no longer exist > in any way. The application is still running, though, and > its menu bar will appear if you bring it to the front > (in MacOSX this is done by clicking on its dock icon; > in classic MacOS it was done by selecting from the menu > of running applications that was available in the top right > corner of the screen). Yes but what benefit does that gain over say, Tkinter's design (because that has been your argument). I see no benefit at all. I can destroy a GUI and still have a script run, but what's the point? If you design a GRAPHICAL user interface, then once the GRAPHICAL part is removed (window), why do need the main code to stick around? And if you do, that fact has nothing to do with Tkinter and window hierarchy. I think we've gone completely off topic here. Is this another community strawman contest? Are we mass producing these things now? From rosuav at gmail.com Wed Jul 6 09:52:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 23:52:40 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 11:41 PM, rantingrick wrote: > Give it up man and admit i am correct and you are wrong. > Sorry. A Lawful Good character cannot tell a lie. ChrisA From calderone.jeanpaul at gmail.com Wed Jul 6 09:53:09 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 6 Jul 2011 06:53:09 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> <742ddcd0-37d1-4009-a82b-c12cd3b7c43f@b2g2000vbo.googlegroups.com> Message-ID: On Jul 6, 4:44?am, AndDM wrote: > On Jul 5, 4:08?pm, Jean-Paul Calderone > wrote: > > > > > On Jul 5, 4:52?am, Andrea Di Mario wrote: > > > > Hi, I'm a new python user and I'm writing a small web service with ssl. > > > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > > > I've used wrap_socket, but if i try to use > > > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > > > urllib2.URLError: > > specified for verification of other-side certificates.> > > > > It works only with CERT_NONE (the default) but with this option i > > > could access to the service in insicure mode. > > > > Have you some suggestions for my service? > > > Also specify some root certificates to use in verifying the peer's > > certificate. ?Certificate verification works by proceeding from a > > collection of "root" certificates which are explicitly trusted. ?These > > are used to sign other certificates (which may in turn be used to sign > > others, which in turn...). ?The process of certificate verification is > > the process of following the signatures from the certificate in use by > > the server you connect to back up the chain until you reach a root > > which you have either decided to trust or not. ?If the signatures are > > all valid and the root is one you trust, then you have established a > > connection to a trusted entity. ?If any signature is invalid, or the > > root is not one you trust, then you have not. > > > The root certificates are also called the "ca certificates" or > > "certificate authority certificates". ?`wrap_socket` accepts a > > `ca_certs` argument. ?Seehttp://docs.python.org/library/ssl.html#ssl-certificates > > for details about that argument. > > > Jean-Paul > > Hi Jean-Paul, i thought that with self-signed certificate i shouldn't > use ca_certs option. Now, i've created a ca-authority and i use this > command: > > ?self.sock = ssl.wrap_socket(sock, certfile = "ca/certs/ > myfriend.cert.pem", keyfile = "ca/private/myfriend.key.pem", > ca_certs="/home/andrea/ca/certs/cacert.pem", > cert_reqs=ssl.CERT_REQUIRED) > > When i use the some machine as client-server it works, but, when i use > another machine as client, i've this: > > Traceback (most recent call last): > ? File "loginsender.py", line 48, in > ? ? handle = url_opener.open('https://debian.andrea.it:10700/%s+%s'% > (DATA,IPIN)) > ? File "/usr/lib/python2.6/urllib2.py", line 391, in open > ? ? response = self._open(req, data) > ? File "/usr/lib/python2.6/urllib2.py", line 409, in _open > ? ? '_open', req) > ? File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > ? ? result = func(*args) > ? File "loginsender.py", line 33, in https_open > ? ? return self.do_open(self.specialized_conn_class, req) > ? File "/usr/lib/python2.6/urllib2.py", line 1145, in do_open > ? ? raise URLError(err) > urllib2.URLError: 0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib> > > I see that i should create a certificate with server, client and ca > autority, but i haven't clear the ca_certs option and which path i > should use. > Have you any suggestion? You need to have the CA certificate on any machine that is going to verify the certificate used on the SSL connection. The path just needs to be the path to that CA certificate on the client machine. Jean-Paul From steve+comp.lang.python at pearwood.info Wed Jul 6 10:32:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 00:32:38 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > If you design a GRAPHICAL user interface, then once the GRAPHICAL part > is removed (window), why do need the main code to stick around? Open your mind to ideas that go beyond your simple window-centric paradigm! There is more to graphical user interfaces than windows! In the Mac OS GUI, an application can have a menubar and no windows. Windows come and go as needed, but the menubar stays until the users quits the application. In the Unix/Linux world, there is a graphical application called xkill which has no menus and no windows, all it has is a mouse cursor! No, it does not run in the background: it is a foreground app. An extreme case, but telling. There is no absolute need for any windows at all, let alone for one privileged window to rule all the others. -- Steven From gnarlodious at gmail.com Wed Jul 6 10:51:05 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 6 Jul 2011 07:51:05 -0700 (PDT) Subject: Extracting property getters from dir() results References: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Message-ID: <0fc2a5a5-986f-4b4a-bb9a-88835e29324c@y30g2000yqb.googlegroups.com> On Jul 6, 3:35?am, Christian Heimes wrote: Thank you! Exactly what I wanted. -- Gnarlie http://Gnarlodious.com From steve+comp.lang.python at pearwood.info Wed Jul 6 10:55:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 00:55:39 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e14776c$0$29998$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 6, 6:44?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> A control structure is a structure which controls the program flow. >> Control structures include: >> >> * jumps (goto, gosub, comefrom, exceptions, break, continue) >> >> * loops (for, while, repeat...until) >> >> * conditional branches (if, case/switch) > > ------------------------------------------- > THIS CODE RESULTS IN A CONTROL STRUCTURE! > > --> lst.sort(lambda x,y: cmp(x[1], y[1])) No it doesn't. How does it change the program flow? You call the sort method, it sorts, and execution continues at the next statement. Regardless of whether you supply a cmp function or not, the program flow is identical: ENTER SORT ROUTINE PERFORM SORTING EXIT SORT ROUTINE There is no control transferred. It is a linear program flow: in, do the job, out again. Since it doesn't modify the program flow, it is not a control structure. "Perform sorting" is a black box. It could have loops, branches, unconditional exists. It could have COMEFROM statements up the wazoo, if it were implemented in a language with COMEFROM (like Intercal). None of that matters two bits: the caller cannot use sort to modify the execution sequence around it, therefore it's not a control structure. No matter how much the sort routine jumps around internally, you can't use that change program flow around it. print surely is implemented with a loop: it has to loop over a string and write it to stdout. Would you say that therefore print is a control structure: ENTER PRINT STATEMENT PERFORM PRINTING EXIT PRINT STATEMENT One entry, one exit. -- Steven From mbadoiu at gmail.com Wed Jul 6 11:04:04 2011 From: mbadoiu at gmail.com (Mihai Badoiu) Date: Wed, 6 Jul 2011 11:04:04 -0400 Subject: interactive plots Message-ID: How do I do interactive plots in python? Say I have to plot f(x) and g(x) and I want in the plot to be able to click on f and make it disappear. Any python library that does this? thanks, --mihai -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Wed Jul 6 11:10:27 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 08:10:27 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 9:32?am, Steven D'Aprano wrote: > rantingrick wrote: > > If you design a GRAPHICAL user interface, then once the GRAPHICAL part > > is removed (window), why do need the main code to stick around? > > Open your mind to ideas that go beyond your simple window-centric paradigm! Correction: Window-Centric GUI paradigm! BIG DIFFERENCE. > There is more to graphical user interfaces than windows! OMG, you mean like, widgets? Whoa! Tell me more, Tell me more! > In the Mac OS GUI, an application can have a menubar and no windows. Windows > come and go as needed, but the menubar stays until the users quits the > application. That's just window visibility (whether by hiding or destroying) under the veil of a detached UI window manager bar and has nothing to do with window hierarchy. Your half stuffed straw men are leaking like a sieve Steven. > In the Unix/Linux world, there is a graphical application called xkill which > has no menus and no windows, all it has is a mouse cursor! No, it does not > run in the background: it is a foreground app. Wow nice corner case. Can you come up with at least five of them though? You and I both know that the vast majority of GUI's require visible windows. But wait! What is a GUI WINDOW exactly? I'll tell you in the simplest terms i can muster... GUI "windows" are an abstraction and nothing more. A GUI window is nothing more than an imaginary area of the screen that can be drawn to. This area has borders that define it. No not visible borders but two dimensional spacial borders. THAT'S IT! The area could be 1x1 pixels OR the entire screen space, OR even larger! Most time you want the user to see the boundaries of this abstraction (window) space and so the GUI library draws borders that represent this boundary. Your "supposedly" windowless xkill application is not windowless at all; THE WINDOW BOUNDARIES ARE JUST NOT DRAWN! The window is the entire screen space OR IS JUST THE DESKTOP SPACE (same thing) > An extreme case, but telling. There is no absolute need for any windows at > all, let alone for one privileged window to rule all the others. Again your fear of losing "imaginary" freedoms is acting out again. And your veiled attempts to link root GUI windows and Sauron (the great antagonist of LOTH) is quite entertaining. Next you'll suggest that root windows are really just a great eye, lidless, and wreathed in flame and that i am Saruman building an army of Orc followers hell bent on destroying the freedom to believe self serving fantasies. From vvnrk.vanapalli at gmail.com Wed Jul 6 11:12:04 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 08:12:04 -0700 (PDT) Subject: trouble creating tooltips using Wx in Tk canvas Message-ID: Hi all, Hi all, I am having a trouble creating tooltips. I am trying to embed a matplotlib graph inside a TkInter canvas. After some search over the net, I found out a way to create tooltips using the WXbackend. But when I embed my matplotlib figure inside a Tk and the tooltips are not getting displayed. The error I am getting is below. Traceback (most recent call last): File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100)) # needs to be added to getover the bug with tooltip. File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", line 771, in __init__ _misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) PyNoAppError: The wx.App object must be created first! I am not able to figure out the reason. I am trying to use IDLE for running the script using python 2.7. I tried running from commandline as well but still i face the same error. Following is the piece of code I have used. I created a simple 'sin' wave using matplotlib. and a button. Added them to a TkFrame. and then binded the code using self.f.canvas.mpl_connect('motion_notify_event',_onMotion) to '_onMotion' function, where I am printing the toooltip. Can somebody please help me solving the issue. Code I have used is below. #!/usr/apps/Python/bin/python import matplotlib, sys matplotlib.use('WXAgg') matplotlib.interactive(False) import numpy as np from numpy import arange, sin, pi import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import wx import Tkinter tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100)) # needs to be added to getover the bug with tooltip. def alt(): print 'My Button' def _onMotion(event): print "Xvalue:",event.xdata," Yvalue:",event.ydata tip= "Xvalue:{0}, Yvalue: {1}".format(event.xdata,event.ydata) tooltip.SetTip(tip) tooltip.Enable(True) class myClass(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) #global _onMotion self.parent=parent self.buildFigure() def buildFigure(self): self.f=plt.figure() self.f = plt.figure(figsize=(5,4)) self.a = self.f.add_subplot(111) self.t = np.array([0.01,0.02,0.03,0.04,0.05,0.07,0.09,1.7,1.9,2.3,2.5,2.7,2.9]) self.s = sin(2*pi*self.t) self.a.plot(self.t,self.s) self.dataPlot = FigureCanvasTkAgg(self.f, master=self) self.f.canvas.mpl_connect('motion_notify_event',_onMotion) self.dataPlot.get_tk_widget().pack(side='top', fill='both') self.toolbar = NavigationToolbar2TkAgg( self.dataPlot, self ) self.toolbar.update() self.toolbar.pack() self.btn=Tkinter.Button(self, text='btton',command=alt) self.btn.pack(ipadx=250) def alt (self): print 9 if __name__ == "__main__": app = myClass(None) app.title('Embedding in Tk') app.mainloop() From neilc at norwich.edu Wed Jul 6 11:13:22 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Jul 2011 15:13:22 GMT Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <97jcchF8akU2@mid.individual.net> On 2011-07-06, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 11:41 PM, rantingrick > wrote: >> Give it up man and admit i am correct and you are wrong. > > Sorry. A Lawful Good character cannot tell a lie. Lawful Good characters have a hard time coexisting with the Chaotic Neutrals. -- Neil Cerutti From rantingrick at gmail.com Wed Jul 6 11:33:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 08:33:46 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e14776c$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0fe80b69-c53f-4f04-84ea-e58fae5bdb79@k27g2000yqn.googlegroups.com> On Jul 6, 9:55?am, Steven D'Aprano wrote: > rantingrick wrote: > > ------------------------------------------- > > THIS CODE RESULTS IN A CONTROL STRUCTURE! > > > --> lst.sort(lambda x,y: cmp(x[1], y[1])) > > No it doesn't. > > How does it change the program flow? You call the sort method, it sorts, and > execution continues at the next statement. Regardless of whether you supply > a cmp function or not, the program flow is identical: Not identical. The sort called WITHOUT a cmp argument will sort in a predefined manner. The sort called WITH a cmp argument can modify the existing code block in a way that suits a users desired result. A USER DEFINED CONTROL STRUCTURE. Just because this realization breaks the mold of everything you hold dear about user defined control structures does not mean it is incorrect. For some reason you are religious about this subject. Could it be that you are wrong? > ENTER SORT ROUTINE > PERFORM SORTING > EXIT SORT ROUTINE True for the non-modified case. False for the modified one... ENTER SORT ROUTINE PERFORM SORTING BASED ON USER DEFINED CONTROL EXIT SORT ROUTINE > There is no control transferred. It is a linear program flow: in, do the > job, out again. Since it doesn't modify the program flow, it is not a > control structure. So you are telling me that calling cmp(itemsA[idx], itemsB[idx]) is exactly the same as cmp(itemsA[idx][-1], itemsB[idx[-1])? Please show proof of this in code. You have just witnessed the power of user defined control structures and it has rocked your little world. You believed UDCS to be evil, all the while oblivious to your own everyday usage of them. Now that's ironic. Cruel or poetic, you be the judge. > "Perform sorting" is a black box. It could have loops, branches, > unconditional exists. It could have COMEFROM statements up the wazoo, if it > were implemented in a language with COMEFROM (like Intercal). None of that > matters two bits: the caller cannot use sort to modify the execution > sequence around it, therefore it's not a control structure. No matter how > much the sort routine jumps around internally, you can't use that change > program flow around it. The "jumping"(sic) around is controlled by a user defined spec. The user is in control. The user made the definition. The cmp function just implemented it. > print surely is implemented with a loop: it has to loop over a string and > write it to stdout. Would you say that therefore print is a control > structure: > > ENTER PRINT STATEMENT > PERFORM PRINTING > EXIT PRINT STATEMENT Nope. Print only takes an argument and spits out the result to stdout.write. Print is an abstraction API for system.stdout.write, and nothing more. > One entry, one exit. As evident from all the BS you spew on a daily basis, apparently YOU have one entry and one exit! From philip at semanchuk.com Wed Jul 6 11:36:00 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 6 Jul 2011 11:36:00 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E13FFE1.1080303@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> Message-ID: <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> On Jul 6, 2011, at 2:25 AM, Laszlo Nagy wrote: > >>> Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. >> >> I get different results than you. >> >> Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. >> >> Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- >> >> Traceback (most recent call last): >> File "x.py", line 46, in onPopupMenu >> item = wx.MenuItem(None,-1,u"Test") >> File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ >> _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) >> wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu > I guess I'll have to write to the wxPython mailing list. Seriously, adding a simple menu to something is supposed to be platform independent, but we got four different results on four systems. :-( I can understand why it's frustrating but a menu items with icons on them aren't exactly common, so you're wandering into territory that's probably not so throughly explored (nor standard across platforms). Now that I think about it, I don't know that I've ever seen one under OSX, and I don't even know if it's supported at all. Me, I would start by addressing the error in the traceback. wx doesn't seem happy with an orphan menu item; why not create a wx.Menu and assign the menu item to that? It might solve your icon problem; you never know. In defense of wxPython, we have three wx apps in our project and they contain very little platform-specific code. To be fair, we've had to rewrite some code after we found that it worked on one platform but not another, but generally we're able to find code that works on all platforms. We have only a couple of places where we were forced to resort to this kind of thing: if wx.Platform == "__WXGTK__": do X elif wx.Platform == "__WXMAC__": do Y etc. > Thank you for trying out though. You're welcome. VirtualBox helped. bye Philip From phlip2005 at gmail.com Wed Jul 6 11:59:43 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 08:59:43 -0700 (PDT) Subject: Does hashlib support a file mode? References: mailman.697.1309951505.1164.python-list@python.org Message-ID: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Tx, all!. But... > For example I use this function to copy a stream and return a SHA512 and > the output streams size: > > ? ? def write(self, in_handle, out_handle): > ? ? ? ? m = hashlib.sha512() > ? ? ? ? data = in_handle.read(4096) > ? ? ? ? while True: > ? ? ? ? ? ? if not data: > ? ? ? ? ? ? ? ? break > ? ? ? ? ? ? m.update(data) > ? ? ? ? ? ? out_handle.write(data) > ? ? ? ? ? ? data = in_handle.read(4096) > ? ? ? ? out_handle.flush() > ? ? ? ? return (m.hexdigest(), in_handle.tell()) The operation was a success but the patient died. My version of that did not return the same hex digest as the md5sum version: def file_to_hash(path, m = hashlib.md5()): with open(path, 'r') as f: s = f.read(8192) while s: m.update(s) s = f.read(8192) return m.hexdigest() You'll notice it has the same control flow as yours. That number must eventually match an iPad's internal MD5 opinion of that file, after it copies up, so I naturally cannot continue working this problem until we see which of the two numbers the iPad likes! From steve+comp.lang.python at pearwood.info Wed Jul 6 12:11:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 02:11:28 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: >> In the Mac OS GUI, an application can have a menubar and no windows. >> Windows come and go as needed, but the menubar stays until the users >> quits the application. > > That's just window visibility (whether by hiding or destroying) under > the veil of a detached UI window manager bar and has nothing to do > with window hierarchy. If all the windows are destroyed, and the application still is running and active, where is your window hierarchy? The Dead Window Sketch ====================== (with apologies to Monty Python) Customer enters a pet shop. Customer: 'Ello, I wish to register a complaint. Owner: We're closin' for lunch. Customer: Never mind that, my lad. I wish to complain about this GUI window what I purchased not half an hour ago from this very boutique. Owner: Oh yes, the Norwegian Blue. What's wrong with it? Customer: I'll tell you what's wrong with it, my lad. It's deleted, that's what's wrong with it! Owner: No, no, it's resting! Customer: Look, matey, I know a deleted window when I see one, and I'm looking at one right now. Owner: No no it's not deleted, it's restin'! Remarkable window, the Norwegian Blue. Beautiful widgets! Customer: The widgets don't enter into it. It's completely destroyed. Owner: Nononono, no, no! It's resting! Customer: All right then, if it's restin', I'll wake it up! (shouting at the screen) 'Ello, Mister Wally Window! I've got a lovely fresh icon for you if you show... (owner hits the screen) Owner: There, it refreshed! Customer: No, it didn't, that was you hitting the screen! Owner: I never!! Customer: Yes, you did! Owner: I never, never did anything... Customer: (yelling and hitting the screen repeatedly) 'ELLO WINDOW!!! WAKEY WAKEY! This is your notification signal!!! (takes the window out of the screen and thumps its title bar on the counter. Throws it up in the air and watches it plummet to the floor.) Customer: Now that's what I call a dead window. Owner: No, no... No, it's stunned! Customer: STUNNED?!? Owner: Yeah! You stunned it, just as it was maximising! Norwegian Blues stun easily. Customer: Now look, mate, I've definitely 'ad enough of this! That window is definitely deleted, and when I purchased it not 'alf an hour ago, you assured me that its lack of an entry in the task bar was due to it bein' tired and shagged out following a long refresh! Owner: Well, it's... probably pining for the fjords. Customer: PININ' for the FJORDS?!?!?!? What kind of talk is that? Look, why did it fall flat on its back the moment I got it home? Owner: The Norwegian Blue prefers being minimised on its back! Remarkable bird, i'nit, squire? Lovely scroll bars! Customer: Look, I took the liberty of examining that window when I got it home, and I discovered the only reason that the window was still visible in the first place was that it had been NAILED there. (pause) Owner: Well, o'course it was nailed there! If I hadn't nailed that window down, it would have nuzzled up to those pixels, bent 'em apart with its cursor, and VOOM! Feeweeweewee! Customer: "VOOM"?!? Mate, this window wouldn't "voom" if you put four million volts through it! Its bleedin' memory is reclaimed! Owner: No no! It's pining! Customer: It's not pinin'! It's purged! This window is no more! It's pointer has ceased to be! It's expired and gone to meet the memory manager! Bereft of bytes, it rests in peace! If you hadn't nailed it to the screen it'd be a Flash animation in a browser by now! It's callbacks are now 'istory! Its ref count is zero! It's called the garbage collector, its blocks have been cleared, shuffled off this mortal coil, run down the curtain and joined the bleedin' choir invisibile!! THIS IS AN EX-WINDOW!! (pause) Owner: Well, I'd better replace it, then. (he takes a quick peek behind the counter) Owner: Sorry squire, I've had a look 'round the back of the shop, and uh, we're right out of windows. Customer: I see. I see, I get the picture. Owner: I got a DOS batch file. (pause) Customer: (sweet as sugar) Pray, does it talk? Owner: Yes. Customer: Right, I'll have that one then. -- Steven From rosuav at gmail.com Wed Jul 6 12:24:37 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 02:24:37 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 7, 2011 at 1:10 AM, rantingrick wrote: > On Jul 6, 9:32?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Open your mind to ideas that go beyond your simple window-centric paradigm! > > Correction: Window-Centric GUI paradigm! BIG DIFFERENCE. > >> There is more to graphical user interfaces than windows! > > OMG, you mean like, widgets? Whoa! Tell me more, Tell me more! Okay, Window-Centric GUI Paradigm. There's still more to it than windows and widgets and mouse cursors and so on. Underneath it all is CODE. In some graphical applications, the code is relatively trivial. A desktop calculator is just there to get input graphically and give output graphically. In those, once you destroy the window, you may as well terminate the application. But in others the code drastically outweighs the windowing work. I don't have a good example handy, but I have a bad example; our (antique) accounting package has an hours-long year end process that we do at the beginning of each July, and it chugs through its database work while painting a pretty animation of a hand scribing a book. It would be far more efficient to simply close the window and proceed with the work; but the window was necessary for collecting certain parameters from the user, prior to the start of the long job. There's more to a windowed program than its window. >> In the Mac OS GUI, an application can have a menubar and no windows. Windows >> come and go as needed, but the menubar stays until the users quits the >> application. > > That's just window visibility (whether by hiding or destroying) under > the veil of a detached UI window manager bar and has nothing to do > with window hierarchy. Your half stuffed straw men are leaking like a > sieve Steven. It can be implemented with window visibility. That's not the same thing. If I want to be in Sydney tomorrow, I want to cease existing here and begin existing there. That can be implemented by burning petrol in an internal combustion engine and turning some rubber wheels. If I turn up in Sydney tomorrow, and argue vehemently that I did not drive, are you going to insist that I did, or would you accept that perhaps I took a train instead? >> In the Unix/Linux world, there is a graphical application called xkill which >> has no menus and no windows, all it has is a mouse cursor! No, it does not >> run in the background: it is a foreground app. > > Wow nice corner case. Can you come up with at least five of them > though? You and I both know that the vast majority of GUI's require > visible windows. Five corner cases. Okay. One is xkill; if I can find four more, we run out of corners and they're not corner cases any more - is that it? 1) See above. 2) Win2VNC. Doesn't actually paint a window on the screen, it just watches where the mouse goes - move the mouse off the edge of the screen, and it wraps and hides it. Very cool. 3) Firewall software with a graphical config notebook. I think ZoneAlarm actually just hides its window, but that's not strictly necessary. (My preferred firewall setup, though, has no GUI at all - iptables etc is all I need.) 4) Clipboard Converter. An old app that I wrote a while ago that, whenever you copy anything to the clipboard, runs it through a script and puts the result back on the clipboard. Handier than you might think. 5) Hotkey manager. It watches for keystrokes and replaces them with other actions. Implemented as an input hook with injection facilities. Enjoy. > But wait! What is a GUI WINDOW exactly? > > I'll tell you in the simplest terms i can muster... GUI "windows" are > an abstraction and nothing more. *Everything* in a computer is an abstraction. People are fond of saying that computers only work with 1s and 0s - that's not strictly true, those numbers represent electrical signals. And those electrical signals represent data which usually carries information. It's turtles all the way down. > A GUI window is nothing more than an > imaginary area of the screen that can be drawn to. This area has > borders that define it. No not visible borders but two dimensional > spacial borders. THAT'S IT! The area could be 1x1 pixels OR the entire > screen space, OR even larger! Leaving off the "imaginary", all you're saying is that a window is a rectangular area of screen. That's not quite true; not all windows/widgets have a painting area. A window is an object - and that object can choose to request certain resources, including a portion of its parent window's painting area if desired. (A top-level window's parent is either a Screen or a Desktop, depending on your implementation.) > Most time you want the user to see the boundaries of this abstraction > (window) space and so the GUI library draws borders that represent > this boundary. Your "supposedly" windowless xkill application is not > windowless at all; THE WINDOW BOUNDARIES ARE JUST NOT DRAWN! The > window is the entire screen space OR IS JUST THE DESKTOP SPACE (same > thing) Boundaries have nothing to do with it being a window or not. The windowless xkill does NOT HAVE a window. If it had a borderless window that covered the entire desktop, you would not be able to click on any other window, thus making xkill ... somewhat useless. >> An extreme case, but telling. There is no absolute need for any windows at >> all, let alone for one privileged window to rule all the others. > > Again your fear of losing "imaginary" freedoms is acting out again. > And your veiled attempts to link root GUI windows and Sauron (the > great antagonist of LOTH) is quite entertaining. What, the One Ring is the only entity that ever wished to rule over all of something? *boggle* I regret that I am now in the position of following an awesome post with a somewhat mediocre one. Steven, the Dead Window Sketch is awesome! ChrisA From ryan.morrone at gmail.com Wed Jul 6 12:25:38 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Wed, 6 Jul 2011 09:25:38 -0700 (PDT) Subject: Javacv / google apps Message-ID: <1191548b-ec59-4b5b-84ec-d3b146bf12cf@glegroupsg2000goo.googlegroups.com> Hi, Is it possible to use JavaCV with Google apps engine? From __peter__ at web.de Wed Jul 6 12:26:09 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jul 2011 18:26:09 +0200 Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: Phlip wrote: > Tx, all!. But... > >> For example I use this function to copy a stream and return a SHA512 and >> the output streams size: >> >> def write(self, in_handle, out_handle): >> m = hashlib.sha512() >> data = in_handle.read(4096) >> while True: >> if not data: >> break >> m.update(data) >> out_handle.write(data) >> data = in_handle.read(4096) >> out_handle.flush() >> return (m.hexdigest(), in_handle.tell()) > > The operation was a success but the patient died. > > My version of that did not return the same hex digest as the md5sum > version: > > > def file_to_hash(path, m = hashlib.md5()): > > with open(path, 'r') as f: > > s = f.read(8192) > > while s: > m.update(s) > s = f.read(8192) > > return m.hexdigest() > > You'll notice it has the same control flow as yours. > > That number must eventually match an iPad's internal MD5 opinion of > that file, after it copies up, so I naturally cannot continue working > this problem until we see which of the two numbers the iPad likes! - Open the file in binary mode. - Do the usual dance for default arguments: def file_to_hash(path, m=None): if m is None: m = hashlib.md5() From gandalf at shopzeus.com Wed Jul 6 12:26:11 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 06 Jul 2011 18:26:11 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> Message-ID: <4E148CA3.1010106@shopzeus.com> > I can understand why it's frustrating but a menu items with icons on them aren't exactly common, so you're wandering into territory that's probably not so throughly explored (nor standard across platforms). Now that I think about it, I don't know that I've ever seen one under OSX, and I don't even know if it's supported at all. Maybe you are right, I'm not familiar with OS X. But they are common in GTK, Qt and Windows. > Me, I would start by addressing the error in the traceback. wx doesn't seem happy with an orphan menu item; why not create a wx.Menu and assign the menu item to that? It might solve your icon problem; you never know. I did create it: menu = wx.Menu() # wx.Menu created here. item = wx.MenuItem(None,-1,u"Test") item.SetBitmap(img.GetBitmap()) menu.AppendItem(item) # Item added to menu here. > In defense of wxPython, we have three wx apps in our project and they contain very little platform-specific code. To be fair, we've had to rewrite some code after we found that it worked on one platform but not another, but generally we're able to find code that works on all platforms. We have only a couple of places where we were forced to resort to this kind of thing: > > if wx.Platform == "__WXGTK__": > do X > elif wx.Platform == "__WXMAC__": > do Y > etc. Hmmm then probably I'll have to install other OS too. :-) From ian.g.kelly at gmail.com Wed Jul 6 12:26:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 10:26:48 -0600 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt wrote: > Mel wrote: >> In wx, many of the window classes have Create methods, for filling in >> various attributes in "two-step construction". ?I'm not sure why, because >> it works so well to just supply all the details when the class is called >> and an instance is constructed. ?Maybe there's some C++ strategy that's >> being supported there. > > Just guessing, is it legacy, C-with-classes code rather than C++ code > perhaps? Haven't looked at wx for a while. Such code typically lacks > understanding of exceptions, which are the only way to signal failure from > e.g. constructors. No, wx is C++ through and through. For the why of it, see: http://wiki.wxpython.org/TwoStageCreation The "More Details" section is particularly illuminating. From bahamutzero8825 at gmail.com Wed Jul 6 12:28:35 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 11:28:35 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E148D33.8030306@gmail.com> On 2011.07.06 11:11 AM, Steven D'Aprano wrote: > The Dead Window Sketch > ====================== As much as I hate it when people feed trolls, that was pretty funny. From mwilson at the-wire.com Wed Jul 6 12:36:33 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 06 Jul 2011 12:36:33 -0400 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt > wrote: >> Mel wrote: >>> In wx, many of the window classes have Create methods, for filling in >>> various attributes in "two-step construction". I'm not sure why, >>> because it works so well to just supply all the details when the class >>> is called and an instance is constructed. Maybe there's some C++ >>> strategy that's being supported there. >> >> Just guessing, is it legacy, C-with-classes code rather than C++ code >> perhaps? Haven't looked at wx for a while. Such code typically lacks >> understanding of exceptions, which are the only way to signal failure >> from e.g. constructors. > > No, wx is C++ through and through. For the why of it, see: > > http://wiki.wxpython.org/TwoStageCreation > > The "More Details" section is particularly illuminating. Yes, it is. Many thanks. From phlip2005 at gmail.com Wed Jul 6 12:49:10 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 09:49:10 -0700 (PDT) Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: > - Open the file in binary mode. I had tried open(path, 'rb') and it didn't change the "wrong" number. And I added --binary to my evil md5sum version, and it didn't change the "right" number! Gods bless those legacy hacks that will never die, huh? But I'm using Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that might explain why "binary mode" is a no-op. > - Do the usual dance for default arguments: > ? ? def file_to_hash(path, m=None): > ? ? ? ? if m is None: > ? ? ? ? ? ? m = hashlib.md5() Not sure why if that's what the defaulter does? I did indeed get an MD5-style string of what casually appeared to be the right length, so that implies the defaulter is not to blame... From tlikonen at iki.fi Wed Jul 6 12:55:53 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 06 Jul 2011 19:55:53 +0300 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrfv9wme.fsf@mithlond.arda> * 2011-07-06T06:41:52-07:00 * wrote: > I am using a user defined spec as an argument to the cmp function. > That spec then modifies the body of the compare function and creates a > user defined control structure. You can argue all day that it is not a > user defined control structure but no one is going to believe you. I won't argue all day, I'll just show you an example of a user defined control structure. This is like the standard (DOTIMES (VAR COUNT) BODY) macro expect that it executes BODY forms first forwards and then backwards. The iterator variable VAR goes first up from 0 and then down to 0. (defmacro ping-pong-iterator ((var count &optional result) &body body) `(progn (loop for ,var from 0 below ,count do (progn , at body)) (loop for ,var from (1- ,count) downto 0 do (progn ,@(reverse body)) finally (return ,result)))) CL-USER> (ping-pong-iterator (i 3 "ready") (format t "form 1: ~A~%" i) (format t "form 2: ~A~%" i) (format t "form 3: ~A~%" i) (format t "~%")) form 1: 0 form 2: 0 form 3: 0 form 1: 1 form 2: 1 form 3: 1 form 1: 2 form 2: 2 form 3: 2 form 3: 2 form 2: 2 form 1: 2 form 3: 1 form 2: 1 form 1: 1 form 3: 0 form 2: 0 form 1: 0 => "ready" From wm at localhost.localdomain Wed Jul 6 12:56:05 2011 From: wm at localhost.localdomain (Waldek M.) Date: Wed, 6 Jul 2011 18:56:05 +0200 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1a9lv7u7bfrdj$.dlg@localhost.localdomain> Dnia Wed, 6 Jul 2011 08:10:27 -0700 (PDT), rantingrick napisa?(a): >> In the Unix/Linux world, there is a graphical application called xkill which >> has no menus and no windows, all it has is a mouse cursor! No, it does not >> run in the background: it is a foreground app. > > Wow nice corner case. Can you come up with at least five of them > though? You and I both know that the vast majority of GUI's require > visible windows. - 90% of MS DOS games; should I list them here? ;-) - M$ Windows taskbar-only applications - Linux apps using framebuffer but not X One could argue that the second and the third case are - in one way or another - using windows. But not the first case, and I don't think you'd call them GUI-less. Br. Waldek From ian.g.kelly at gmail.com Wed Jul 6 12:59:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 10:59:52 -0600 Subject: interactive plots In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: > How do I do interactive plots in python? ?Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. ?Any > python library that does this? Matplotlib can be integrated with either wxPython or PyQt to create GUI applications with interactive plots. From __peter__ at web.de Wed Jul 6 13:06:13 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jul 2011 19:06:13 +0200 Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: Phlip wrote: >> - Open the file in binary mode. > > I had tried open(path, 'rb') and it didn't change the "wrong" number. > > And I added --binary to my evil md5sum version, and it didn't change > the "right" number! > > Gods bless those legacy hacks that will never die, huh? But I'm using > Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that > might explain why "binary mode" is a no-op. Indeed. That part was a defensive measure mostly meant to make your function Windows-proof. >> - Do the usual dance for default arguments: >> def file_to_hash(path, m=None): >> if m is None: >> m = hashlib.md5() > > Not sure why if that's what the defaulter does? I did indeed get an > MD5-style string of what casually appeared to be the right length, so > that implies the defaulter is not to blame... The first call will give you the correct checksum, the second: not. As the default md5 instance remembers the state from the previous function call you'll get the checksum of both files combined. From python.list at tim.thechases.com Wed Jul 6 13:37:39 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Jul 2011 12:37:39 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E149D63.3090108@tim.thechases.com> On 07/06/2011 11:24 AM, Chris Angelico wrote: > On Thu, Jul 7, 2011 at 1:10 AM, rantingrick wrote: >> Wow nice corner case. Can you come up with at least five of them >> though? You and I both know that the vast majority of GUI's require >> visible windows. > > Five corner cases. Okay. One is xkill; if I can find four more, we run > out of corners and they're not corner cases any more - is that it? > > 1) See above. > 2) Win2VNC. Doesn't actually paint a window on the screen, it just > watches where the mouse goes - move the mouse off the edge of the > screen, and it wraps and hides it. Very cool. > 3) Firewall software with a graphical config notebook. I think > ZoneAlarm actually just hides its window, but that's not strictly > necessary. (My preferred firewall setup, though, has no GUI at all - > iptables etc is all I need.) > 4) Clipboard Converter. An old app that I wrote a while ago that, > whenever you copy anything to the clipboard, runs it through a script > and puts the result back on the clipboard. Handier than you might > think. > 5) Hotkey manager. It watches for keystrokes and replaces them with > other actions. Implemented as an input hook with injection facilities. 6) possibly xneko (just mouse-cursor amusements) 7) screen-shot/print-screen software (several such as "scrot" don't have an actual window, just a process that interacts with the other windows) 8) AutoHotkey and other keystroke-monitors (or mouse-gesture-monitors) to expand text, send key-sequences, launch programs, reconfigure windows, signal changes in display-configuration, etc 9) other clipboard utilities such as xclip or multi-clipboard functionality 10) DPMI screen-savers (that only listen for key/mouse activity and send a blank-screen signal to the monitor after a given period of inactivity) I think there are sufficiently many edge cases this formerly-square room is starting to look round... > I regret that I am now in the position of following an awesome post > with a somewhat mediocre one. Steven, the Dead Window Sketch is > awesome! agreed :) -tkc From phlip2005 at gmail.com Wed Jul 6 13:38:10 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 10:38:10 -0700 (PDT) Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: > >> def file_to_hash(path, m=None): > >> if m is None: > >> m = hashlib.md5() > The first call will give you the correct checksum, the second: not. As the > default md5 instance remembers the state from the previous function call > you'll get the checksum of both files combined. Ouch. That was it. Python sucks. m = md5() looks like an initial assignment, not a special magic storage mode. Principle of least surprise fail, and principle of most helpful default behavior fail. From steve+comp.lang.python at pearwood.info Wed Jul 6 13:41:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 03:41:45 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e149e5a$0$29996$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > On 2011.07.06 11:11 AM, Steven D'Aprano wrote: >> The Dead Window Sketch >> ====================== > As much as I hate it when people feed trolls, that was pretty funny. Thanks. Re the troll-feeding, every few months I get a strange seizure in my brain that compels me to interact with rantingrick and try to treat him seriously. It never ends well, he always ends up back in my killfile. Call it the triumph of hope over experience. -- Steven From rosuav at gmail.com Wed Jul 6 13:46:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 03:46:28 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <4E149D63.3090108@tim.thechases.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4E149D63.3090108@tim.thechases.com> Message-ID: Five more good entries (though I think #8 and #9 are mostly covered already). But hey, we have at least an octagon to work in. On Thu, Jul 7, 2011 at 3:37 AM, Tim Chase wrote: > I think there are sufficiently many edge cases this formerly-square room is > starting to look round... The room is starting to look round? Eek, it might see us! *flees* ChrisA From nospam at torek.net Wed Jul 6 13:54:07 2011 From: nospam at torek.net (Chris Torek) Date: 6 Jul 2011 17:54:07 GMT Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: >> - Do the usual dance for default arguments: >> def file_to_hash(path, m=None): >> if m is None: >> m = hashlib.md5() [instead of def file_to_hash(path, m = hashlib.md5()): ] In article Phlip wrote: >Not sure why if that's what the defaulter does? For the same reason that: def spam(somelist, so_far = []): for i in somelist: if has_eggs(i): so_far.append(i) return munch(so_far) is probably wrong. Most beginners appear to expect this to take a list of "things that pass my has_eggs test", add more things to that list, and return whatever munch(adjusted_list) returns ... which it does. But then they *also* expect: result1_on_clean_list = spam(list1) result2_on_clean_list = spam(list2) result3_on_partly_filled_list = spam(list3, prefilled3) to run with a "clean" so_far list for *each* of the first two calls ... but it does not; the first call starts with a clean list, and the second one starts with "so_far" containing all the results accumulated from list1. (The third call, of course, starts with the prefilled3 list and adjusts that list.) >I did indeed get an MD5-style string of what casually appeared >to be the right length, so that implies the defaulter is not to >blame... In this case, if you do: print('big1:', file_to_hash('big1')) print('big2:', file_to_hash('big2')) you will get two md5sum values for your two files, but the md5sum value for big2 will not be the equivalent of "md5sum big2" but rather that of "cat big1 big2 | md5sum". The reason is that you are re-using the md5-sum-so-far on the second call (for file 'big2'), so you have the accumulated sum from file 'big1', which you then update via the contents of 'big2'. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From howe.steven at gmail.com Wed Jul 6 13:57:54 2011 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 06 Jul 2011 10:57:54 -0700 Subject: interactive plots In-Reply-To: References: Message-ID: <4E14A222.8000504@gmail.com> On 07/06/2011 09:59 AM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: >> How do I do interactive plots in python? Say I have to plot f(x) and g(x) >> and I want in the plot to be able to click on f and make it disappear. Any >> python library that does this? > Matplotlib can be integrated with either wxPython or PyQt to create > GUI applications with interactive plots. PyGTK interface too. From rantingrick at gmail.com Wed Jul 6 14:19:17 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 11:19:17 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> On Jul 6, 11:11?am, Steven D'Aprano wrote: > The Dead Window Sketch > ====================== > > [snip] ########################## The Roman Stawman Sketch ########################## [cmp.lang.python]: (The trolls are gathered and a righteous man speaks.) GRACCHUS: For your guidance TrollCaesar, the Senate has prepared a series of protocols to address the many problems in the community, beginning with basic understanding of USER DEFINED CONTROL STRUCTURES, which is already propagated wildly throughout the community and people are suffering gravely from a misunderstanding. So if TrollCaesar? (Obviously bored, Commodus is spinning his sword on its tip on the marble floor. He interrupts.) COMMODUS: Shhh. Don?t you see Gracchus? That?s the very problem, isn?t it? You've spent all your time at study, at books, learning and programming. All the while my self aggrandizing has been forgotten by the people. (He rises and brings his sword to rest across his shoulders. He begins to pace.) GRACCHUS: But comp.lang.python is the people, Sire, chosen from among the people, a place to "speak" for the people. COMMODUS: I doubt if many people know as much as you do Gracchus, or have such splendid code bases, Gaius. I think I understand my own people. GRACCHUS: Then perhaps TrollCaesar would be so kind as to teach us, out of his own extensive experience about the nature of USER DEFINED CONTROL STRUCTURES. (Laughter is heard from the other group members.) COMMODUS: I call it lies. The people are my children and I their father. I shall hold them to my bosom and embrace them tightly with lies and propaganda. GRACCHUS(interrupting): Have you ever embraced someone dying of exceptions, Sire? (Commodus stops pacing and turns to face Gracchus bringing his sword down from his shoulder.) COMMODUS: No, but if you interrupt me again, I assure you, that you shall! [INT. PALACE ? COMMODUS CHAMBERS]: (He is struggling to clear his conscience. Lucilla assists him.) COMMODUS: Who would deign to lecture me? LUCILLA: Commodus, the community has its uses. COMMODUS: What uses? All they do is talk. It should be just you and me, and Guido. LUCILLA: Don?t even think it. There has always been a community. COMMODUS: The community has changed. It takes an emperor to rule an empire. LUCILLA: Of course, but leave the people their (She hesitates, searching for the right word.) COMMODUS: Illusions? LUCILLA: Traditions. COMMODUS: My war against the righteous, they said it themselves, it achieved nothing. But the minions loved me! LUCILLA: Minions always love victories. COMMODUS: Why? They didn?t see all the work that went into stuffing those straw-men. LUCILLA: They care about the entertainment. COMMODUS: The Entertainment? Well what is that? LUCILLA: It?s a way to waste time, entertainment. Entertainment is a vision. COMMODUS: Exactly! A vision. Do you not see, Lucilla? I will give the people a vision, a false vision and they will love me for it. And they?ll soon forget the tedious sermonizing of a few honest group members. (He extends his hand to her and without hesitation, she accepts it. Commodus raises her hand to his lips and kisses it.) COMMODUS: I will give the people the greatest false vision of their lives... Strawmen! Legions of them! (A hand reaches out and opens a mail reader. It is Usenet. And a thread called the "Dead Window Sketch". The splendor of his false victory.) [EXT. Rome ? MARKET]: (Gaius approaches Gracchus at an outdoor caf? (starbucks). Gaius is waving a leaflet advertising ?Comp.lang.python.Gladiators_Violante.?) GAIUS: Straw-men. 150 days of Straw-men! GRACCHUS: He?s cleverer than I thought. GAIUS: Clever? The whole of cmp.lang.python would be laughing at him if they weren't so afraid of his forked tongue. GRACCHUS: Fear and wonder. A powerful combination. GAIUS: You really think the people will be seduced by that? GRACCHUS: I think he knows what comp.lang.python is. Comp.lang.python is the mob. He will conjure comedy for them and they will be distracted. He will take away their freedom to think with half stuffed straw-men, and still they will roar. The beating heart of comp.lang.python is not the halls of righteousness; it is the den of minions. He will give them tripe, and they will love him for it. From ian.g.kelly at gmail.com Wed Jul 6 14:32:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 12:32:59 -0600 Subject: trouble creating tooltips using Wx in Tk canvas In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth wrote: > Hi all, > Hi all, > > I am having a trouble creating tooltips. I am trying to embed a > matplotlib graph inside ?a TkInter canvas. After some search over the > net, I found out a way to create tooltips using the WXbackend. > But when I embed my matplotlib figure inside a Tk and ?the tooltips > are not getting displayed. That's pretty much what I would expect, since wxPython and Tkinter are completely different GUI libraries. Trying to use them together is a bit like trying to call a .NET function from Java -- maybe possible, but it's going to take a lot of work. > The error I am getting is below. > > Traceback (most recent call last): > ?File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in > > ? ?tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' > % (' '*100)) # needs to be added to getover the bug with tooltip. > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", > line 771, in __init__ > ? ?_misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) > PyNoAppError: The wx.App object must be created first! > > I am not able to figure out the reason. As it says, you haven't created the wx.App object necessary for pretty much all wxPython code. You could create one, but your tooltip still would not work correctly because you would be running the Tkinter event loop rather than the wxPython event loop. If you want to use the wxToolTip widget, then you should write your program to use wxPython only. Alternatively, googling for "tkinter tooltip" turns up a couple of recipes; you could try one of those. Cheers, Ian From bahamutzero8825 at gmail.com Wed Jul 6 14:36:25 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 13:36:25 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> Message-ID: <4E14AB29.30408@gmail.com> On 2011.07.06 01:19 PM, rantingrick wrote: > ########################## > The Roman Stawman Sketch > ########################## Nice try, but you have to use a Monty Python sketch (and you have to spell correctly :-P ). From bahamutzero8825 at gmail.com Wed Jul 6 14:42:12 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 13:42:12 -0500 Subject: Does hashlib support a file mode? In-Reply-To: References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: <4E14AC84.1090303@gmail.com> On 2011.07.06 12:38 PM, Phlip wrote: > Python sucks. m = md5() looks like an initial assignment, not a > special magic storage mode. Principle of least surprise fail, and > principle of most helpful default behavior fail. func() = whatever the function returns func = the function object itself (in Python, everything's an object) Maybe you have Python confused with another language (I don't know what exactly you mean by initial assignment). Typically one does not need more than one name for a function/method. When a function/method is defined, it gets created as a function object and occupies the namespace in which it's defined. From phlip2005 at gmail.com Wed Jul 6 15:07:56 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 12:07:56 -0700 (PDT) Subject: Does hashlib support a file mode? References: mailman.715.1309977744.1164.python-list@python.org Message-ID: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> On Jul 6, 11:42?am, Andrew Berg wrote: > On 2011.07.06 12:38 PM, Phlip wrote:> Python sucks. m = md5() looks like an initial assignment, not a > > special magic storage mode. Principle of least surprise fail, and > > principle of most helpful default behavior fail. > > func() = whatever the function returns > func = the function object itself (in Python, everything's an object) > > Maybe you have Python confused with another language (I don't know what > exactly you mean by initial assignment). Typically one does not need > more than one name for a function/method. When a function/method is > defined, it gets created as a function object and occupies the namespace > in which it's defined. If I call m = md5() twice, I expect two objects. I am now aware that Python bends the definition of "call" based on where the line occurs. Principle of least surprise. From ian.g.kelly at gmail.com Wed Jul 6 15:15:50 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 13:15:50 -0600 Subject: Implicit initialization is EVIL! In-Reply-To: <4E14AB29.30408@gmail.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: > On 2011.07.06 01:19 PM, rantingrick wrote: >> ########################## >> ?The Roman Stawman Sketch >> ########################## > Nice try, but you have to use a Monty Python sketch (and you have to > spell correctly :-P ). Seriously. The source he borrowed from is the movie Gladiator, which isn't even a comedy. From debatem1 at gmail.com Wed Jul 6 15:15:54 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 6 Jul 2011 15:15:54 -0400 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 3:07 PM, Phlip wrote: > On Jul 6, 11:42?am, Andrew Berg wrote: >> On 2011.07.06 12:38 PM, Phlip wrote:> Python sucks. m = md5() looks like an initial assignment, not a >> > special magic storage mode. Principle of least surprise fail, and >> > principle of most helpful default behavior fail. >> >> func() = whatever the function returns >> func = the function object itself (in Python, everything's an object) >> >> Maybe you have Python confused with another language (I don't know what >> exactly you mean by initial assignment). Typically one does not need >> more than one name for a function/method. When a function/method is >> defined, it gets created as a function object and occupies the namespace >> in which it's defined. > > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Python doesn't do anything to the definition of call. If you call hashlib.md5() twice, you get two objects: >>> import hashlib >>> m1 = hashlib.md5() >>> m2 = hashlib.md5() >>> id(m1) 139724897544712 >>> id(m2) 139724897544880 Geremy Condra From noway at nohow.com Wed Jul 6 15:30:18 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 15:30:18 -0400 Subject: Large number multiplication Message-ID: I was looking through the python source and noticed that long multiplication is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n log n). I was wondering if there was a reason the Karatsuba method was chosen over the FFT convolution method? -- Bill From python at mrabarnett.plus.com Wed Jul 6 15:34:28 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jul 2011 20:34:28 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: <4E14B8C4.6010107@mrabarnett.plus.com> On 06/07/2011 20:15, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: >> On 2011.07.06 01:19 PM, rantingrick wrote: >>> ########################## >>> The Roman Stawman Sketch >>> ########################## >> Nice try, but you have to use a Monty Python sketch (and you have to >> spell correctly :-P ). > > Seriously. The source he borrowed from is the movie Gladiator, which > isn't even a comedy. If it was from "Life of Brian", then it would be OK: What has Guido ever done for us...? :-) From vvnrk.vanapalli at gmail.com Wed Jul 6 15:35:59 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 12:35:59 -0700 (PDT) Subject: trouble creating tooltips using Wx in Tk canvas References: Message-ID: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> On Jul 6, 1:32?pm, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth wrote: > > Hi all, > > Hi all, > > > I am having a trouble creating tooltips. I am trying to embed a > > matplotlib graph inside ?a TkInter canvas. After some search over the > > net, I found out a way to create tooltips using the WXbackend. > > But when I embed my matplotlib figure inside a Tk and ?the tooltips > > are not getting displayed. > > That's pretty much what I would expect, since wxPython and Tkinter are > completely different GUI libraries. ?Trying to use them together is a > bit like trying to call a .NET function from Java -- maybe possible, > but it's going to take a lot of work. > > > The error I am getting is below. > > > Traceback (most recent call last): > > ?File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in > > > > ? ?tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' > > % (' '*100)) # needs to be added to getover the bug with tooltip. > > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", > > line 771, in __init__ > > ? ?_misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) > > PyNoAppError: The wx.App object must be created first! > > > I am not able to figure out the reason. > > As it says, you haven't created the wx.App object necessary for pretty > much all wxPython code. ?You could create one, but your tooltip still > would not work correctly because you would be running the Tkinter > event loop rather than the wxPython event loop. ?If you want to use > the wxToolTip widget, then you should write your program to use > wxPython only. ?Alternatively, googling for "tkinter tooltip" turns up > a couple of recipes; you could try one of those. > > Cheers, > Ian Thank you Ian for your insights to me on this. I will migrate to wxPython to achieve the functionality. From bahamutzero8825 at gmail.com Wed Jul 6 15:42:30 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 14:42:30 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: mailman.715.1309977744.1164.python-list@python.org <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <4E14BAA6.6070207@gmail.com> On 2011.07.06 02:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. You get two objects because you make the function run again. Of course, the first one is garbage collected if it doesn't have another reference. >>> m1 = hashlib.md5() >>> m2 = hashlib.md5() >>> m1 is m2 False Are you assuming Python acts like another language or is there something confusing in the docs or something else? From mwilson at the-wire.com Wed Jul 6 15:43:36 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 06 Jul 2011 15:43:36 -0400 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Actually, in def file_to_hash(path, m = hashlib.md5()): hashlib.md5 *is* called once; that is when the def statement is executed. Later on, when file_to_hash gets called, the value of m is either used as is, as the default parameter, or is replaced for the duration of the call by another object supplied by the caller. Mel. From ian.g.kelly at gmail.com Wed Jul 6 15:48:36 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 13:48:36 -0600 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 1:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. There is no definition-bending. The code: """ def file_to_hash(path, m = hashlib.md5()): # do stuff... file_to_hash(path1) file_to_hash(path2) """ does not call hashlib.md5 twice. It calls it *once*, at the time the file_to_hash function is defined. The returned object is stored on the function object, and that same object is passed into file_to_hash as a default value each time the function is called. See: http://docs.python.org/reference/compound_stmts.html#function From ian.g.kelly at gmail.com Wed Jul 6 16:02:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 14:02:04 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: > I was looking through the python source and noticed that long multiplication > is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n > log n). ?I was wondering if there was a reason the Karatsuba method was > chosen over the FFT convolution method? According to Wikipedia: """ In practice the Sch?nhage?Strassen algorithm starts to outperform older methods such as Karatsuba and Toom?Cook multiplication for numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). """ I think most Python users are probably not working with numbers that large, and if they are, they are probably using specialized numerical libraries anyway, so there would be little benefit in implementing it in core. From lists at cheimes.de Wed Jul 6 16:05:52 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 22:05:52 +0200 Subject: Large number multiplication In-Reply-To: References: Message-ID: Am 06.07.2011 21:30, schrieb Billy Mays: > I was looking through the python source and noticed that long > multiplication is done using the Karatsuba method (O(~n^1.5)) rather > than using FFTs O(~n log n). I was wondering if there was a reason the > Karatsuba method was chosen over the FFT convolution method? The Karatsuba algorithm uses just addition, subtraction and multiplication, so you don't need to resort to floats and have no rounding errors. On the other hand FFT are based on e, complex numbers or trigonometric functions (=floats), which mean you'll get rounding errors. We don't want rounding errors for large long multiplication. Christian From noway at nohow.com Wed Jul 6 16:15:06 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 16:15:06 -0400 Subject: Large number multiplication References: Message-ID: On 07/06/2011 04:05 PM, Christian Heimes wrote: > Am 06.07.2011 21:30, schrieb Billy Mays: >> I was looking through the python source and noticed that long >> multiplication is done using the Karatsuba method (O(~n^1.5)) rather >> than using FFTs O(~n log n). I was wondering if there was a reason the >> Karatsuba method was chosen over the FFT convolution method? > > The Karatsuba algorithm uses just addition, subtraction and > multiplication, so you don't need to resort to floats and have no > rounding errors. On the other hand FFT are based on e, complex numbers > or trigonometric functions (=floats), which mean you'll get rounding errors. > > We don't want rounding errors for large long multiplication. > > Christian > I believe it is possible to do FFTs without significant rounding error. I know that the GIMPS's Prime95 does very large multiplications using FFTs (I don't know if they use the integer based or double based version). I also know they have guards to prevent rounding errors so I don't think it would be impossible to implement. -- Bill From hobson42 at gmail.com Wed Jul 6 16:19:41 2011 From: hobson42 at gmail.com (Ian) Date: Wed, 06 Jul 2011 21:19:41 +0100 Subject: web browsing short cut In-Reply-To: References: Message-ID: <4E14C35D.80007@gmail.com> On 03/07/2011 02:21, Dustin Cheung wrote: > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > and re-sizes them to display on different areas on the screen. I > looked around but i had no luck. Is that possible with python? if so > can someone point to to the right direction? Here is what I came up > with so far.. > > I suggest you create a dummy page on your disk with an onload event that uses javascript to open, size and load all the windows you want. Then create a short cut to the dummy page. Regards Ian From noway at nohow.com Wed Jul 6 16:21:03 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 16:21:03 -0400 Subject: Large number multiplication References: Message-ID: On 07/06/2011 04:02 PM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: >> I was looking through the python source and noticed that long multiplication >> is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n >> log n). I was wondering if there was a reason the Karatsuba method was >> chosen over the FFT convolution method? > > According to Wikipedia: > > """ > In practice the Sch?nhage?Strassen algorithm starts to outperform > older methods such as Karatsuba and Toom?Cook multiplication for > numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). > """ > > I think most Python users are probably not working with numbers that > large, and if they are, they are probably using specialized numerical > libraries anyway, so there would be little benefit in implementing it > in core. You are right that not many people would gain significant use of it. The reason I ask is because convolution has a better (best ?) complexity class than the current multiplication algorithm. I do like the idea of minimizing reliance on external libraries, but only if the changes would be useful to all the regular users of python. I was more interested in finding previous discussion (if any) on why Karatsuba was chosen, not so much as trying to alter the current multiplication implementation. Side note: Are Numpy/Scipy the libraries you are referring to? -- Bill From ethan at stoneleaf.us Wed Jul 6 16:24:31 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 06 Jul 2011 13:24:31 -0700 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: mailman.715.1309977744.1164.python-list@python.org <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <4E14C47F.3020601@stoneleaf.us> Phlip wrote: >> On 2011.07.06 12:38 PM, Phlip wrote: >>> Python sucks. m = md5() looks like an initial assignment, not a >>> special magic storage mode. Principle of least surprise fail, and >>> principle of most helpful default behavior fail. >>> > > If I call m = md5() twice, I expect two objects. You didn't call md5 twice -- you called it once when you defined the function. Phlips naive code: --- def file_to_hash(path, m = hashlib.md5()): \---------------/ happens once, when def line is executed If you want separate md5 objects, don't create just one when you create the function, create one inside the function: def file_to_hash(path, m = None): if m is None: m = hashlib.md5() You should try the Principle of Learning the Language. ~Ethan~ From pavlovevidence at gmail.com Wed Jul 6 16:25:37 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 6 Jul 2011 13:25:37 -0700 (PDT) Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> On Wednesday, July 6, 2011 12:07:56 PM UTC-7, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Phlip: We already know about this violation of the least surprise principle; most of us acknowledge it as small blip in an otherwise straightforward and clean language. (Incidentally, fixing it would create different surprises, but probably much less common ones.) We've helped you with your problem, but you risk alienating those who helped you when you badmouth the whole language on account of this one thing, and you might not get such prompt help next time. So try to be nice. You are wrong about Python bending the definition of "call", though. Surprising though it be, the Python language is very explicit that the default arguments are executed only once, when creating the function, *not* when calling it. Carl Banks From ian.g.kelly at gmail.com Wed Jul 6 16:37:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 14:37:23 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 2:21 PM, Billy Mays wrote: > Side note: Are Numpy/Scipy the libraries you are referring to? I was thinking more of gmpy or mpmath, but I'm not personally well acquainted with any of them. From lists at cheimes.de Wed Jul 6 16:43:04 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 22:43:04 +0200 Subject: Large number multiplication In-Reply-To: References: Message-ID: Am 06.07.2011 22:15, schrieb Billy Mays: > I believe it is possible to do FFTs without significant rounding error. > I know that the GIMPS's Prime95 does very large multiplications using > FFTs (I don't know if they use the integer based or double based > version). I also know they have guards to prevent rounding errors so I > don't think it would be impossible to implement. It might work for medium large longs but how about really large longs like 5 * 1,000**10,000? I'm not familiar with FFT based multiplication but I guess that very large numbers are going to introduce rounding errors if floating points are involved. Python used to run on platforms without an FPU and floats. These days Python might still run on platforms with just an emulated FPU. Unless there is a way to implement FFT without floating point ops, an emulated or missing FPU makes FFT slower than Karatsuba. There might be one but I haven't learned a way in my numerics classes. Christian From phlip2005 at gmail.com Wed Jul 6 17:07:47 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 14:07:47 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> Message-ID: <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> On Jul 6, 1:25?pm, Carl Banks wrote: > We already know about this violation of the least surprise principle; most of us acknowledge it as small blip in an otherwise straightforward and clean language. Here's the production code we're going with - thanks again all: def file_to_hash(path, hash_type=hashlib.md5): """ Per: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ea1c46f77ac1738c """ hash = hash_type() with open(path, 'rb') as f: while True: s = f.read(8192) # CONSIDER: io.DEFAULT_BUFFER_SIZE if not s: break hash.update(s) return hash.hexdigest() Note the fix also avoids comparing to None, which, as usual, is also icky and less typesafe! (And don't get me started about the extra lines needed to avoid THIS atrocity! while s = f.read(8192): hash.update(s) ;) From jeremy at jeremysanders.net Wed Jul 6 17:25:56 2011 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Wed, 06 Jul 2011 22:25:56 +0100 Subject: interactive plots References: Message-ID: Mihai Badoiu wrote: > How do I do interactive plots in python? Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. > Any python library that does this? You could try veusz, which is a python module and plotting program combined. You can also embed it in a PyQt program. Jeremy From almar.klein at gmail.com Wed Jul 6 18:00:06 2011 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 7 Jul 2011 00:00:06 +0200 Subject: interactive plots In-Reply-To: References: Message-ID: On 6 July 2011 17:04, Mihai Badoiu wrote: > How do I do interactive plots in python? Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. Any > python library that does this? Visvis is a plotting toolkit that has good support for interactive use and picking: http://code.google.com/p/visvis/ I'll even give you an example: import visvis as vv # Create to lines, increase line width (lw) for easier clicking f = vv.plot([1,2,3,2], lc='r', lw=3) g = vv.plot([2,1,4,3], lc='b', lw=3) # Create callback function def deleteLine(event): event.owner.Destroy() # Enable picking and set callback for fg in [f, g]: fg.hitTest = True fg.eventMouseDown.Bind(deleteLine) Regards, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From almar.klein at gmail.com Wed Jul 6 18:03:19 2011 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 7 Jul 2011 00:03:19 +0200 Subject: interactive plots In-Reply-To: References: Message-ID: On 7 July 2011 00:00, Almar Klein wrote: > > > On 6 July 2011 17:04, Mihai Badoiu wrote: > >> How do I do interactive plots in python? Say I have to plot f(x) and g(x) >> and I want in the plot to be able to click on f and make it disappear. Any >> python library that does this? > > > Visvis is a plotting toolkit that has good support for interactive use and > picking: http://code.google.com/p/visvis/ > > I'll even give you an example: > > import visvis as vv > > > # Create to lines, increase line width (lw) for easier clicking > > f = vv.plot([1,2,3,2], lc='r', lw=3) > > g = vv.plot([2,1,4,3], lc='b', lw=3) > > > # Create callback function > > def deleteLine(event): > > event.owner.Destroy() > > # Enable picking and set callback > > for fg in [f, g]: > > fg.hitTest = True > > fg.eventMouseDown.Bind(deleteLine) > Except that the indentation got mangled when I pasted the code in. Sorry about that. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From vvnrk.vanapalli at gmail.com Wed Jul 6 18:05:48 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:05:48 -0700 (PDT) Subject: show() in pylab doesn't work if used twice Message-ID: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Hi all, I have been using python for just over a month now. I am writing a program to plot some graph using the show() twice in the same program. The code snippet is shown below. I am trying to plot a simple x vs y using ax.plot() then I get a figure displayed. I close the figure displayed and then the execution proceeds. Now If i try to call show second time with the updated values of x and y, the second figure does not appear on my desktop. but the second call to show() appears to work as the code also printed 'passed the second show' as well Can someone help me figure out what the problem here is.why is the second figure not coming up on the desktop. I am using python 2.7 . from pylab import * import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the first show()' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show()' From vvnrk.vanapalli at gmail.com Wed Jul 6 18:42:26 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:42:26 -0700 (PDT) Subject: multiple call to show not working in matplotlib Message-ID: <3a3d960b-b0f2-4d15-a0bd-1644e18fc106@s17g2000yqs.googlegroups.com> Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' Thanks Ravikanth From vvnrk.vanapalli at gmail.com Wed Jul 6 18:49:02 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:49:02 -0700 (PDT) Subject: multiple calls to show doesnot work for matplotlib Message-ID: Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' Thanks Ravikanth From mrunalu1 at gmail.com Wed Jul 6 19:10:44 2011 From: mrunalu1 at gmail.com (mru) Date: Wed, 6 Jul 2011 16:10:44 -0700 (PDT) Subject: multiple call to show not working in matplotlib Message-ID: Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' From steve+comp.lang.python at pearwood.info Wed Jul 6 19:15:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:15:29 +1000 Subject: multiple calls to show doesnot work for matplotlib References: Message-ID: <4e14ec92$0$29990$c3e8da3$5496439d@news.astraweb.com> Ravikanth wrote: > Hi, > > I am facing some problem. Yes, we heard you the first two times, there's no need to keep repeating the question over and over again. There is no Service Level Agreement for guaranteed response times for free advice over the Internet. Be patient, and hopefully somebody with an answer to your question will respond once they have read the question. Wait AT LEAST a day before reposting the question. In the meantime, you might like to Read the Fine Manual, which explains everything you need to know about using show(). http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show Does that answer your question? -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 19:16:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:16:35 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> Message-ID: <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: > Note the fix also avoids comparing to None, which, as usual, is also > icky and less typesafe! "Typesafe"? Are you trying to make a joke? -- Steven From dustin299 at gmail.com Wed Jul 6 19:16:45 2011 From: dustin299 at gmail.com (Dustin Cheung) Date: Wed, 6 Jul 2011 16:16:45 -0700 Subject: web browsing short cut In-Reply-To: <4E14C35D.80007@gmail.com> References: <4E14C35D.80007@gmail.com> Message-ID: Okay thanks for the help guys, ill keep you guys posted. On Wed, Jul 6, 2011 at 1:19 PM, Ian wrote: > On 03/07/2011 02:21, Dustin Cheung wrote: > >> Hey guys, >> >> I am new to python. I want to make a shortcut that opens my websites and >> re-sizes them to display on different areas on the screen. I looked around >> but i had no luck. Is that possible with python? if so can someone point to >> to the right direction? Here is what I came up with so far.. >> >> >> I suggest you create a dummy page on your disk with an onload event that > uses javascript to open, size and load all the windows you want. > > Then create a short cut to the dummy page. > > Regards > > Ian > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Dustin Cheung -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Jul 6 19:26:15 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 06 Jul 2011 18:26:15 -0500 Subject: show() in pylab doesn't work if used twice In-Reply-To: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> References: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Message-ID: On 7/6/11 5:05 PM, Ravikanth wrote: > Hi all, > > I have been using python for just over a month now. > I am writing a program to plot some graph using the show() twice in > the same program. The code snippet is shown below. Please use the matplotlib-users list for matplotlib questions. By the way, four versions of your message made it to this list. I'm sure the repetition was an honest mistake, but there may be things you can do to prevent it in the future. https://lists.sourceforge.net/lists/listinfo/matplotlib-users To answer your question, you are probably using an older version of matplotlib than 1.0.0. The ability to use show() more than once was only added in 1.0.0: http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show -- 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 vvnrk.vanapalli at gmail.com Wed Jul 6 19:31:33 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 16:31:33 -0700 (PDT) Subject: multiple calls to show doesnot work for matplotlib References: <4e14ec92$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f19a626-7d8b-4266-8c0a-8b63c64bd6ae@em7g2000vbb.googlegroups.com> On Jul 6, 6:15?pm, Steven D'Aprano wrote: > Ravikanth wrote: > > Hi, > > > I am facing some problem. > > Yes, we heard you the first two times, there's no need to keep repeating the > question over and over again. > > There is no Service Level Agreement for guaranteed response times for free > advice over the Internet. Be patient, and hopefully somebody with an answer > to your question will respond once they have read the question. Wait AT > LEAST a day before reposting the question. > > In the meantime, you might like to Read the Fine Manual, which explains > everything you need to know about using show(). > > http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show > > Does that answer your question? > > -- > Steven Hi Steven, I do understand that posting several times causes trouble. I did not see my post appear on the groups over in the groups site even after like 15 mints after posting. I thought I was posting it incorrectly. Thank you for your link. I will look through it. Regards, Ravikanth From steve+comp.lang.python at pearwood.info Wed Jul 6 19:40:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:40:44 +1000 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> <1NYQp.25969$Sr.25363@newsfe12.ams2> Message-ID: <4e14f27e$0$29971$c3e8da3$5496439d@news.astraweb.com> Stefaan Himpe wrote: > >> No! I was serious. I've spent *ages* trying to find the link to the >> article... if you know it, please share. > > Ok - I thought you were referring to some troll's rant with similar > title. I'm probably way off, but were you referring to the RAII technique? > > http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization Thanks Stefaan, but although it *sounds* like it should be from the title, that's not the idea I'm talking about. Despite the name, RAII is more about destructor/finalizer methods than initialisation. The blog post I'm looking for is not about finalizers, but about API design: don't make the caller give an explicit second activation call if you don't need to. -- Steven From nobody at nowhere.com Wed Jul 6 20:22:05 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:22:05 +0100 Subject: How do twisted and multiprocessing.Process create zombies? References: Message-ID: On Tue, 05 Jul 2011 14:52:49 -0700, bitcycle wrote: > In python, using twisted loopingcall, multiprocessing.Process, and > multiprocessing.Queue; is it possible to create a zombie process. And, if > so, then how? A zombie is a process which has terminated but hasn't been wait()ed on (aka "reaped") by its parent. Most libraries which create child processes make some effort to reap them. E.g. the subprocess module keeps a list of "orphaned" processes (those for which the Popen object was deleted while the underlying process was still alive), and polls the list periodically (specifically, whenever a new Popen object is created). From nobody at nowhere.com Wed Jul 6 20:25:31 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:25:31 +0100 Subject: Should ctypes handle mis-matching structure return ABI between mingw and MSVC? References: Message-ID: On Wed, 06 Jul 2011 11:12:47 +0800, Just Fill Bugs wrote: > According the Bug 36834 of gcc, there is a mis-matching between mingw and > MSVC when a struct was returned by value from a C function. > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834 > > Should ctypes handle this situation automatically somehow? I would expect this to be the responsibility of libffi rather than ctypes. From vvnrk.vanapalli at gmail.com Wed Jul 6 20:29:02 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 17:29:02 -0700 (PDT) Subject: show() in pylab doesn't work if used twice References: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Message-ID: On Jul 6, 6:26?pm, Robert Kern wrote: > On 7/6/11 5:05 PM, Ravikanth wrote: > > > Hi all, > > > I have been using python for just over a month now. > > I am writing a program to plot some graph using the ?show() twice in > > the same program. The code snippet is shown below. > > Please use the matplotlib-users list for matplotlib questions. By the way, four > versions of your message made it to this list. I'm sure the repetition was an > honest mistake, but there may be things you can do to prevent it in the future. > > ? ?https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > To answer your question, you are probably using an older version of matplotlib > than 1.0.0. The ability to use show() more than once was only added in 1.0.0: > > ? ?http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show > > -- > 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 Hi Robert, Thank you for the link. I did not see my post posted onto the groups after i sent my query, which usually does happen in a few minutes. So I thought i posted it wrongly and reposted it. My apologies for inconvenience. I'll make sure this does not repeat. Regards, Ravikanth From nobody at nowhere.com Wed Jul 6 20:33:06 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:33:06 +0100 Subject: Large number multiplication References: Message-ID: On Wed, 06 Jul 2011 22:05:52 +0200, Christian Heimes wrote: > On the other hand FFT are based on e, complex numbers or > trigonometric functions (=floats), which mean you'll get rounding errors. It's possible to perform a DFT over any field. Schoenhage-Strassen uses a DFT over a finite field (integers modulo N); it doesn't use floats. From kw at codebykevin.com Wed Jul 6 21:04:34 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 06 Jul 2011 21:04:34 -0400 Subject: trouble creating tooltips using Wx in Tk canvas In-Reply-To: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> References: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> Message-ID: <8709b$4e150668$4275d90a$21028@FUSE.NET> On 7/6/11 3:35 PM, Ravikanth wrote: >> As it says, you haven't created the wx.App object necessary for pretty >> much all wxPython code. You could create one, but your tooltip still >> would not work correctly because you would be running the Tkinter >> event loop rather than the wxPython event loop. If you want to use >> the wxToolTip widget, then you should write your program to use >> wxPython only. Alternatively, googling for "tkinter tooltip" turns up >> a couple of recipes; you could try one of those. >> >> Cheers, >> Ian > > Thank you Ian for your insights to me on this. > I will migrate to wxPython to achieve the functionality. Tooltips are trivial to create in Tkinter: http://tkinter.unpythonic.net/wiki/ToolTip --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rosuav at gmail.com Thu Jul 7 00:55:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 14:55:45 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: On Thu, Jul 7, 2011 at 5:15 AM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: >> On 2011.07.06 01:19 PM, rantingrick wrote: >>> ########################## >>> ?The Roman Stawman Sketch >>> ########################## >> Nice try, but you have to use a Monty Python sketch (and you have to >> spell correctly :-P ). > > Seriously. ?The source he borrowed from is the movie Gladiator, which > isn't even a comedy. Thanks, I was wondering where it was from. Unfortunately parodies tend to lose a lot if the reader doesn't know the original (although there are exceptions to that). ChrisA From ben+python at benfinney.id.au Thu Jul 7 01:10:56 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Jul 2011 15:10:56 +1000 Subject: The end to all language wars and the great unity API to come! References: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4E137BC5.2080401@gmail.com> Message-ID: <87r562iskf.fsf@benfinney.id.au> Dennis Lee Bieber writes: > On Tue, 05 Jul 2011 16:01:57 -0500, Andrew Berg > declaimed the following in > gmane.comp.python.general: > > > On 2011.07.05 01:14 PM, sal migondis wrote: > > > How could a belief be wrong? > > Beliefs aren't subjective. One's taste in music, for example, is > > largely subjective and can't be right or wrong, but a belief (which > > has to do with facts) certainly can be. > > Pardon???? By ?has to do with facts?, I understand Andrew to be saying that a belief is *about* facts. That is, a belief is the position that a factual claim is true. > Most "beliefs" that I've encountered do their best to ignore any > facts that contradict the belief. You seem to be ignoring beliefs that are not usually held dogmatically: that the sun will rise tomorrow, that the newspaper article one is reading is likely true, that one's lunch is not poison, etc. These are distinct from so-called ?beliefs? that are really opinions: that my daughter is the loveliest in the world, that wasabi is horrible, etc. > "Facts" imply testable evidence, hypotheses, eventual theorems... I'd say facts are claims about reality which have been independently verified to be true. Beliefs that are about facts are thereby correct or incorrect. -- \ ?Only the educated are free.? ?Epictetus, _Discourses_ | `\ | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Thu Jul 7 01:34:23 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Jul 2011 17:34:23 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: <97kur2FlkhU1@mid.individual.net> rantingrick wrote: > Yes but what benefit does that gain over say, Tkinter's design > (because that has been your argument). Like I said, it's a tangential issue. The important thing is that it's okay for an app to stay alive until its *last* top level window is closed. There doesn't have to be a special "main" window that kills the whole app when you close it. However, I think what the original complaint was really about is that when you create a non-toplevel widget in Tkinter you have to specify its parent (and if you don't, it assumes you want it to be a child of the main window). You can't create the widget first and specify its parent later. This is another API flaw that is seen distressingly often in GUI libraries. It's a nuisance, because it means you can't write code that creates a widget hierarchy bottom-up. For example, in PyGUI you can write things like dialog_contents = Column([ Label("Caution: Your underpants are on fire."), Row([Button("OK"), Button("Cancel")]) ]) There's no way you could write Row and Column functions for Tkinter that work like that -- they would have to take parent widgets as arguments, and you wouldn't be able to nest the calls. -- Greg From greg.ewing at canterbury.ac.nz Thu Jul 7 01:37:55 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Jul 2011 17:37:55 +1200 Subject: wx MenuItem - icon is missing In-Reply-To: References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> Message-ID: <97kv1mFmrkU1@mid.individual.net> Philip Semanchuk wrote: > I can understand why it's frustrating but a menu items with icons on them > aren't exactly common... Now that I think about it, I > don't know that I've ever seen one under OSX, and I don't even know if it's > supported at all. It's supported -- I've got FruitMenu running at the moment and it makes fairly heavy use of them. I agree that they don't seem to be used much anywhere else these days, though. -- Greg From ulrich.eckhardt at dominolaser.com Thu Jul 7 03:12:06 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 07 Jul 2011 09:12:06 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt > wrote: >> Mel wrote: >>> In wx, many of the window classes have Create methods, for filling in >>> various attributes in "two-step construction". [...] >> >> Just guessing, is it legacy, C-with-classes code rather than C++ code >> perhaps? Haven't looked at wx for a while. Such code typically lacks >> understanding of exceptions, which are the only way to signal failure >> from e.g. constructors. > > No, wx is C++ through and through. No namespaces. No templates but macros. No exceptions. No C++. Sorry, I beg to differ. BTW, they say themselves that they tolerate but not use exceptions, so they actually need two-stage construction if construction can fail, and for exactly the guessed legacy reasons. > http://wiki.wxpython.org/TwoStageCreation A C++ object is not a window, it is rather a proxy for managing the window. As such, it can be attached or detached from the underlying window, just like a std::fstream, so in this light it makes sense actually. Thanks for the link! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From cousinstanley at gmail.com Thu Jul 7 03:21:34 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 7 Jul 2011 07:21:34 +0000 (UTC) Subject: web browsing short cut References: Message-ID: Chris Angelico wrote: > > > > > > > > > > > > That should divide your screen four ways > ( if I haven't botched my HTML > - ages since I've used frames ). html !botched .... :-) An example of your frameset code http://csphx.net/fourpy.htm -- Stanley C. Kitching Human Being Phoenix, Arizona From kvaradhan3 at gmail.com Thu Jul 7 04:08:30 2011 From: kvaradhan3 at gmail.com (Kannan Varadhan) Date: Thu, 7 Jul 2011 01:08:30 -0700 (PDT) Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) Message-ID: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Hi Folks, Here is something I don't fully understand. 1 def DefaultTracer(fmt, *args): 2 fmt = 'in DefaultTracer ' + fmt 3 print(fmt % args) 4 pass 5 def myTracer(fmt, *args): 6 fmt = 'in myTracer ' + fmt 7 print(fmt % args) 8 9 class MyClass: 10 ClassDefaultTracer = DefaultTracer 11 def __init__(self): 12 self.InstanceTracer = MyClass.ClassDefaultTracer 13 def trace(self, fmt, *args): 14 self.InstanceTracer(fmt, *args) 15 16 17 DefaultTracer("Testing %s", 'at first') 18 myTracer("Testing %s", 'at first') 19 20 MyClass().trace('Using ClassDefaultTracer') 21 22 # override ClassDefaultTracer for all new instances 23 MyClass.ClassDefaultTracer = myTracer 24 MyClass().trace('Using Overridden ClassDefaultTracer') I want ClassDefaultTracer to store a reference to DefaultTracer and be used by instances of MyClass. Why does line20 give me the following error: $ python foo.py in DefaultTracer Testing at first in myTracer Testing at first Traceback (most recent call last): File "foo.py", line 20, in MyClass().trace('Using ClassDefaultTracer') File "foo.py", line 14, in trace self.InstanceTracer(fmt, *args) TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) Alternately, how can I achieve what I want, i.e. a class-wide default used by all instances created off it, but itself be changeable, so that once changed, the changed default would be used by subsequent newer instances of that class. Thanks, Kannan From ulrich.eckhardt at dominolaser.com Thu Jul 7 04:30:09 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 07 Jul 2011 10:30:09 +0200 Subject: Large number multiplication References: Message-ID: Billy Mays wrote: > On 07/06/2011 04:02 PM, Ian Kelly wrote: >> According to Wikipedia: >> >> """ >> In practice the Sch?nhage?Strassen algorithm starts to outperform >> older methods such as Karatsuba and Toom?Cook multiplication for >> numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). >> """ >> >> I think most Python users are probably not working with numbers that >> large, and if they are, they are probably using specialized numerical >> libraries anyway, so there would be little benefit in implementing it >> in core. > > You are right that not many people would gain significant use of it. Even worse, most people would actually pay for its use, because they don't use numbers large enough to merit the Sch?nhage?Strassen algorithm. > The reason I ask is because convolution has a better (best ?) complexity > class than the current multiplication algorithm. The "asymptotic complexity" of algorithms (I guess that's what you mean) is concerned with large up to infinite n elements in operations. The claim there always excludes any number of elements below n_0, where the complexity might be different, even though that is usually not repeatedly mentioned. In other words, lower complexity does not mean that something runs faster, only that for large enough n it runs faster. If you never realistically reach that limit, you can't reap those benefits. That said, I'm sure that the developers would accept a patch that switches to a different algorithm if the numbers get large enough. I believe it already doesn't use Karatsuba for small numbers that fit into registers, too. > I was more interested in finding previous discussion (if any) on why > Karatsuba was chosen, not so much as trying to alter the current > multiplication implementation. I would hope that such design decisions are documented in code or at least referenced from there. Otherwise the code is impossible to understand and argue about. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From washakie at gmail.com Thu Jul 7 04:59:35 2011 From: washakie at gmail.com (John [H2O]) Date: Thu, 7 Jul 2011 01:59:35 -0700 (PDT) Subject: more advanced learning resources (code structure, fundamentals) Message-ID: <32011481.post@talk.nabble.com> Hello, I've been programming in Python for a few years now. I have read most the typical learning resources, such as 'Dive Into Python', 'A Byte of Python', etc. In general I feel I have a good overview of the language. However, as I advanced toward trying to create more OO styled programs, I feel I am lacking some background on basic concepts. I have read 'Coding' and 'Beautiful Code', and while these provide good information on how to style and think about code, they haven't help me design classes, think about where and when to use inheritance, decorators, etc. The point is, most examples stop at demonstrating a single class, or show a trivial decorator example. What I am after is something that will help me design a program from scratch. What are the key points to the classes? Is it okay to reference or pass classes to instantiate a class? When would I want to use a decorator? How to decide which should be a static method, and if I need them at all? I know a lot of this would come from experience of working in a team, but unfortunately, I'm mostly running solo. I am starting to look more and more at source code too, which I find helpful, but the styles of programming vary significantly. Perhaps someone could say which modules have nice 'exemplary' code worth learning from? So, if someone has a good book or online reference, please point me to it. Other ideas too are most certainly welcome! Best, john -- View this message in context: http://old.nabble.com/more-advanced-learning-resources-%28code-structure%2C-fundamentals%29-tp32011481p32011481.html Sent from the Python - python-list mailing list archive at Nabble.com. From __peter__ at web.de Thu Jul 7 05:04:15 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 11:04:15 +0200 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: Kannan Varadhan wrote: > Here is something I don't fully understand. > > 1 def DefaultTracer(fmt, *args): > 2 fmt = 'in DefaultTracer ' + fmt > 3 print(fmt % args) > 4 pass > 5 def myTracer(fmt, *args): > 6 fmt = 'in myTracer ' + fmt > 7 print(fmt % args) > 8 > 9 class MyClass: > 10 ClassDefaultTracer = DefaultTracer > 11 def __init__(self): > 12 self.InstanceTracer = MyClass.ClassDefaultTracer > 13 def trace(self, fmt, *args): > 14 self.InstanceTracer(fmt, *args) > 15 > 16 > 17 DefaultTracer("Testing %s", 'at first') > 18 myTracer("Testing %s", 'at first') > 19 > 20 MyClass().trace('Using ClassDefaultTracer') > 21 > 22 # override ClassDefaultTracer for all new instances > 23 MyClass.ClassDefaultTracer = myTracer > 24 MyClass().trace('Using Overridden ClassDefaultTracer') > > I want ClassDefaultTracer to store a reference to DefaultTracer and be > used by instances of MyClass. Why does line20 give me the following > error: > > $ python foo.py > in DefaultTracer Testing at first > in myTracer Testing at first > Traceback (most recent call last): > File "foo.py", line 20, in > MyClass().trace('Using ClassDefaultTracer') > File "foo.py", line 14, in trace > self.InstanceTracer(fmt, *args) > TypeError: unbound method DefaultTracer() must be called with MyClass > instance as first argument (got str instance instead) Functions written in Python are also "descriptors", they have a __get__() method. The seemingly harmless whatever = MyClass.ClassDefaultTracer therefore results in something like whatever = MyClass.__dict__["ClassDefaultTracer"].__get__(None, MyClass) internally, and whatever becomes an "unbound method", essentially the DefaultTracer function wrapped in a check that its first argument is a MyClass instance. The simplest workaround is probably to spell out the dictionary access whatever = MyClass.__dict__["ClassDefaultTracer"] If you want inheritance to work properly you need something more invoved, perhaps (untested) f = self.ClassDefaultTracer try: f = f.im_func except AttributeError: pass self.InstanceTracer = f or you wrap the callable in a descriptor: >>> def DefaultTracer(*args): print args ... >>> class D(object): ... def __init__(self, f): ... self.f = f ... def __get__(self, *args): ... return self.f ... >>> class MyClass(object): ... old = DefaultTracer ... new = D(DefaultTracer) ... >>> MyClass.old >>> MyClass.new >>> m = MyClass() >>> m.old > >>> m.new Not pretty, but in Python 3 the problem is gone... > Alternately, how can I achieve what I want, i.e. a class-wide default > used by all instances created off it, but > itself be changeable, so that once changed, the changed default would > be used by subsequent newer instances of that class. From a24061 at ducksburg.com Thu Jul 7 05:47:50 2011 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 07 Jul 2011 10:47:50 +0100 Subject: bash: testing whether anyone is or has recently been logged in? References: Message-ID: <6vbge8x0pa.ln2@news.ducksburg.com> On 2011-04-20, Bill Marcum wrote: > On 2011-04-20, Adam Funk wrote: >> I'd appreciate any suggestions for testing (preferably from a bash >> script, although perl or python would be OK too) whether anyone is >> currently logged in, and whether anyone has been logged in during the >> past $N minutes. >> >> (The idea is to use this in a cron script that only does its job when >> the machine is not "in live use".) >> > A script could parse the output of "who", "w" or "last", and the stored > output from previous commands. [adding comp.lang.python] Here's what I came up with in python. If you call it with no arguments or with 0 as the argument, it gives a 0 exit code if no-one is logged in. If you call it with a non-zero argument N, it gives a 0 exit code if no-one has been logged in in the past N minutes. I welcome suggestions, corrections, &c. #v+ #!/usr/bin/python # -*- coding: utf-8 -*- import subprocess, re from dateutil.parser import * from sys import stdout, stderr, argv from datetime import datetime, timedelta from optparse import OptionParser oparser = OptionParser(usage="usage: %prog [options] [N]") oparser.add_option("-v", dest="verbose", default=False, action="store_true", help="Verbose output") (options, args) = oparser.parse_args() query = 0 try: if len(args) > 0: query = int(args[0]) except ValueError: stderr.write('Invalid argument %s\n' % argv[1]) exit(-1) if (options.verbose): stdout.write('query %i\n' % query) last_proc = subprocess.Popen(args=['last'], stdout=subprocess.PIPE) last_out = last_proc.stdout.read().split('\n') still_logged = re.compile(r'still logged in') line_pattern = re.compile(r'^\S+\s+\S+\s+\S+\s+(\S+\s+\S+\s+\S+) ..:.. - (..:..)\s+.*$') timestamps = []; minutes = 1 for line in last_out: if line.startswith('reboot'): pass elif still_logged.search(line): minutes = 0 if (options.verbose): stdout.write('still logged in\n') break else: matcher = line_pattern.match(line) # user term host Tue Apr 26 13:49 - 14:52 (01:02) if matcher: date_string = matcher.group(1) + ' ' + matcher.group(2) timestamp = parse(date_string) stdout.write('d> ' + date_string + ' --> ' + str(timestamp) + '\n') timestamps.append(timestamp) if len(timestamps) > 0: latest = max(timestamps) stderr.write(str(latest) + '\n') now = datetime.now() delta = now - latest minutes = delta.days * 24 * 60 + delta.seconds / 60 diff_value = query + 1 - minutes exit_value = max (0, diff_value) if (options.verbose): stdout.write('min %i\n' % minutes) stdout.write('diff %i\n' % diff_value) stdout.write('exit %i\n' % exit_value) exit(exit_value) #v- -- I worry that 10 or 15 years from now, [my daughter] will come to me and say 'Daddy, where were you when they took freedom of the press away from the Internet?' [Mike Godwin] http://www.eff.org/ From prakash.stack at gmail.com Thu Jul 7 05:58:25 2011 From: prakash.stack at gmail.com (prakash jp) Date: Thu, 7 Jul 2011 15:28:25 +0530 Subject: find max and min values from a column of a csv file Message-ID: Hi All , Could any one help to get max and min values from a specified column of a csv file. The* csv file is large* and hence the below code did go bad. *Alternate methods would be highly appreciated ** minimum.py*: import csv filename = "testLog_4.csv" f = open(filename) def col_min(mincname): with open(filename, 'rb') as f: reader = csv.reader(f, delimiter=",") #print reader #print mincname col_index = next(reader).index(mincname) #print col_index least = min(rec[col_index] for rec in reader) print least col_min(str("Server Latency")) col_min(str("Client Latency")) f.close() *maximum.py:* import csv filename = "testLog_4.csv" f = open(filename) def col_max(maxcname): with open(filename, 'rb') as f: reader = csv.reader(f, delimiter=",") #print reader #print cname col_index = next(reader).index(maxcname) #print col_index highest = max(rec[col_index] for rec in reader) print highest col_max(str("Server Latency")) col_max(str("Client Latency")) f.close() Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From washakie at gmail.com Thu Jul 7 06:38:04 2011 From: washakie at gmail.com (John [H2O]) Date: Thu, 7 Jul 2011 03:38:04 -0700 (PDT) Subject: find max and min values from a column of a csv file In-Reply-To: References: Message-ID: <32012126.post@talk.nabble.com> I think you would benefit from reading the data into a numpy array first, then using numpy min, max functions. prakash jp wrote: > > Hi All , > > Could any one help to get max and min values from a specified column of a > csv file. The* csv file is large* and hence the below code did go bad. > *Alternate > methods would be highly appreciated > ** > minimum.py*: > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_min(mincname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print mincname > col_index = next(reader).index(mincname) > #print col_index > least = min(rec[col_index] for rec in reader) > print least > > col_min(str("Server Latency")) > col_min(str("Client Latency")) > f.close() > > *maximum.py:* > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_max(maxcname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print cname > col_index = next(reader).index(maxcname) > #print col_index > highest = max(rec[col_index] for rec in reader) > print highest > > col_max(str("Server Latency")) > col_max(str("Client Latency")) > f.close() > > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/find-max-and-min-values-from-a-column-of-a-csv-file-tp32011861p32012126.html Sent from the Python - python-list mailing list archive at Nabble.com. From mwilson at the-wire.com Thu Jul 7 07:04:40 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 07 Jul 2011 07:04:40 -0400 Subject: more advanced learning resources (code structure, fundamentals) References: Message-ID: John [H2O] wrote: [ ... ] > What are the key points to the classes? Is it okay to reference or pass > classes to instantiate a class? Yes. The standard library does this in BaseHTTPServer (via its parent SocketServer.) Maybe looks abstruse at the outset, but it's the natural way to assign a fresh message handler to a new input message. Docs are via the Python Global Module Index, source is in some directory like /usr/lib/python2.6/SocketServer.py , .../BaseHTTPServer.py , etc. Mel. From as at sci.fi Thu Jul 7 07:29:38 2011 From: as at sci.fi (Anssi Saari) Date: Thu, 07 Jul 2011 14:29:38 +0300 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: Mel writes: > def file_to_hash(path, m = hashlib.md5()): > > hashlib.md5 *is* called once; that is when the def statement is executed. Very interesting, I certainly wasn't clear on this. So after that def, the created hashlib object is in the module's scope and can be accessed via file_to_hash.__defaults__[0]. From dmitrey15 at gmail.com Thu Jul 7 08:08:56 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Thu, 7 Jul 2011 05:08:56 -0700 (PDT) Subject: blist question Message-ID: hi all, I feel lack of native Python lists operations (e.g. taking N greatest elements with the involved key function and O(n) speed) and occasionally found blist http://pypi.python.org/pypi/blist/ Its entry says it is better than Python list. Did anyone ensure? Will it ever be merged into Python source code? D. From paul.nospam at rudin.co.uk Thu Jul 7 08:13:22 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 07 Jul 2011 13:13:22 +0100 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <87aacq70gt.fsf@no-fixed-abode.cable.virginmedia.net> Anssi Saari writes: > Mel writes: > >> def file_to_hash(path, m = hashlib.md5()): >> >> hashlib.md5 *is* called once; that is when the def statement is executed. > > Very interesting, I certainly wasn't clear on this. So after that def, > the created hashlib object is in the module's scope and can be > accessed via file_to_hash.__defaults__[0]. This also why you have to be a bit careful if you use e.g. [] or {} as a default argument - if you then modify these things within the function you might not end up with what you expect - it's the same list or dictionary each time the function is called. So to avoid that kind of thing you end up with code like: def foo(bar=None): if bar is None: bar = [] ... From __peter__ at web.de Thu Jul 7 08:33:25 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 14:33:25 +0200 Subject: find max and min values from a column of a csv file References: Message-ID: prakash jp wrote: > Could any one help to get max and min values from a specified column of a > csv file. The* csv file is large* and hence the below code did go bad. > *Alternate > methods would be highly appreciated > ** > minimum.py*: > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_min(mincname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print mincname > col_index = next(reader).index(mincname) > #print col_index > least = min(rec[col_index] for rec in reader) > print least > > col_min(str("Server Latency")) > col_min(str("Client Latency")) > f.close() I don't see a way to make this much faster as it is probably already i/o- bound. You can try and calculate all four extrema at once, so you have to iterate over the file only once: $ cat csv_minmax_chunked.py #!/usr/bin/env python import csv import locale from itertools import islice def make_key(index, type): def key(row): return type(row[index]) return key class Aggregator(object): def __init__(self, name, index, type, key=None): self.name = name self.index = index self.type = type or float self.getvalue = make_key(index, type) self.key = {"key": key} if key is not None else {} def __repr__(self): return "{0}(name={1}, index={2}, type={3}".format( type(self).__name__, self.name, self.index, self.type) def __str__(self): try: return "%s: %s...%s" % (self.name, self.min, self.max) except AttributeError: return "%s: (no values)" % self.name def update(self, rows): values = map(self.getvalue, rows) chunkmin = min(values, **self.key) chunkmax = max(values, **self.key) try: curmin = self.min curmax = self.max except AttributeError: self.min = chunkmin self.max = chunkmax else: self.min = min(curmin, chunkmin, **self.key) self.max = max(curmax, chunkmax, **self.key) def identity(s): return s convert = { "float": (float,), "int": (int,), "text": (lambda s: s, locale.strxfrm), "": (identity,) } def main(): locale.setlocale(locale.LC_ALL, "") import argparse parser = argparse.ArgumentParser() parser.add_argument("csvfile") parser.add_argument("columns", nargs="+") parser.add_argument("--chunksize", "-s", type=int, default=2**12) args = parser.parse_args() ntpairs = (column.partition(":")[::2] for column in args.columns) with open(args.csvfile, "rb") as instream: rows = csv.reader(instream) header = dict((name, index) for index, name in enumerate(next(rows))) aggregators = [ Aggregator( "{0}({1})".format(name, type or "str"), header[name], *convert[type]) for name, type in ntpairs] chunksize = args.chunksize while True: chunk = list(islice(rows, chunksize)) if not chunk: break for agg in aggregators: agg.update(chunk) for agg in aggregators: print agg if __name__ == "__main__": main() $ head sample.csv alpha,beta,gamma,delta 69,-454,460960,ELIJAH 92,796,278885,SUFFICIENCY 42,895,934523,PIONEERED 88,-213,360633,reassert 63,-518,327010,mcmahon 84,604,540764,deprecatory 83,117,621832,VEGETARIANISM'S 61,411,844243,tan 29,-147,982043,plushest $ ./csv_minmax_chunked.py sample.csv alpha:int beta:int beta gamma:float delta delta:text alpha(int): 0...99 beta(int): -1000...999 beta(str): -1...999 gamma(float): 0.0...999997.0 delta(str): AALIYAH...?tudes delta(text): a...ZYUGANOV'S From steve+comp.lang.python at pearwood.info Thu Jul 7 08:36:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 22:36:33 +1000 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: <4e15a853$0$29982$c3e8da3$5496439d@news.astraweb.com> Kannan Varadhan wrote: > Hi Folks, > > Here is something I don't fully understand. > > 1 def DefaultTracer(fmt, *args): > 2 fmt = 'in DefaultTracer ' + fmt > 3 print(fmt % args) > 4 pass > 5 def myTracer(fmt, *args): > 6 fmt = 'in myTracer ' + fmt > 7 print(fmt % args) Please don't post code with line numbers. That makes it difficult to copy and paste your function into an interactive session, so that we can run it and see what it does. [...] > I want ClassDefaultTracer to store a reference to DefaultTracer and be > used by instances of MyClass. Why does line20 give me the following > error: > > $ python foo.py > in DefaultTracer Testing at first > in myTracer Testing at first > Traceback (most recent call last): > File "foo.py", line 20, in > MyClass().trace('Using ClassDefaultTracer') > File "foo.py", line 14, in trace > self.InstanceTracer(fmt, *args) > TypeError: unbound method DefaultTracer() must be called with MyClass > instance as first argument (got str instance instead) Unfortunately you've run into a side-effect of one of the very few "Do What I Mean" aspects of Python: under many circumstances, storing a function in a class automatically turns it into a method. This is almost always what you want, but not this time. Here's a simple example: >>> def function(s): ... print s ... >>> class C(object): ... func = function ... print func, type(func) ... >>> print C.func, type(C.func) How to interpret this: The class block is an executable statement which is executed at runtime. During that execution, "print func" is called, and it sees func is an actual function object. After the block finishes executing, a class object (also called a type) is created. This is where the DWIM behaviour happens: function attributes are automatically turned into methods. That's normally what you want, but in this case, it gives you the surprising result: >>> C.func("hello world") Traceback (most recent call last): File "", line 1, in TypeError: unbound method function() must be called with C instance as first argument (got str instance instead) Instead of calling it from the class C, you can call it from an instance: >>> c = C() >>> c.func("hello world") Traceback (most recent call last): File "", line 1, in TypeError: function() takes exactly 1 argument (2 given) Two arguments? What? Where's the second argument??? But wait: *bound* methods automatically get the instance as their first argument. (When you define a method in the class, you write a function with "self" as the first argument.) A bound method is one that is called from an instance, not the class, and it gets the instance as first argument automatically: instance.method(args) # a bound method is translated by Python into: theclass = type(instance) theclass.method(instance, args) # an unbound method So if we do this, the method works: >>> c.func() # bound methods get the instance as first argument <__main__.C object at 0xb7f8fb6c> There are a couple of solutions to avoid this. One is to live with it: def function(self, s): # Define this as if it were a method. print s class C(object): func = function Now you can call: instance = C() # unbound method, you are responsible for supplying "self" C.func(instance, arg) # bound method, Python supplies "self" instance.func(arg) but of course now you can't call function(arg) from outside the class. Another solution is to use a staticmethod: def function(s): print s class C(object): func = staticmethod(function) A third is to disguise the function: class C(object): func = (function,) # In a tuple and then call C.func[0](arg) but that's hideous. Don't do that. Fourthly, the DWIM magic only happens when you store a function in the *class*, not if you do it in the instance: class C(object): def __init__(self): self.func = function but now you can't call C.func because it doesn't exist, you have to initialise an instance first. > Alternately, how can I achieve what I want, i.e. a class-wide default > used by all instances created off it, but > itself be changeable, so that once changed, the changed default would > be used by subsequent newer instances of that class. class C(object): default = staticmethod(function) def __init__(self): self.func = type(self).default ought to do it. -- Steven From paul.nospam at rudin.co.uk Thu Jul 7 08:38:04 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 07 Jul 2011 13:38:04 +0100 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> <4e15a853$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8762ne6zbn.fsf@no-fixed-abode.cable.virginmedia.net> Steven D'Aprano writes: > Please don't post code with line numbers. That makes it difficult to copy > and paste your function into an interactive session, so that we can run it > and see what it does. C-x r d From bahamutzero8825 at gmail.com Thu Jul 7 08:50:08 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 07:50:08 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E15AB80.50906@gmail.com> On 2011.07.06 06:16 PM, Steven D'Aprano wrote: > Phlip wrote: > > > Note the fix also avoids comparing to None, which, as usual, is also > > icky and less typesafe! > > "Typesafe"? Are you trying to make a joke? Maybe he has a duck phobia. Maybe he denies the existence of ducks. Maybe he doesn't like the sound of ducks. Maybe he just weighs the same as a duck. In any case, duck tolerance is necessary to use Python effectively. On a side note, it turns out there's no word for the fear of ducks. The closest phobia is anatidaephobia, which is the fear of being /watched/ by a duck. From __peter__ at web.de Thu Jul 7 08:50:33 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 14:50:33 +0200 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: Peter Otten wrote: > or you wrap the callable in a descriptor: > >>>> def DefaultTracer(*args): print args > ... >>>> class D(object): > ... def __init__(self, f): > ... self.f = f > ... def __get__(self, *args): > ... return self.f > ... After skimming over Steven's post: use staticmethod. No idea why I didn't think of that myself. From phlip2005 at gmail.com Thu Jul 7 09:11:19 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 06:11:19 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> > On 2011.07.06 06:16 PM, Steven D'Aprano wrote:> Phlip wrote: > > > > Note the fix also avoids comparing to None, which, as usual, is also > > > icky and less typesafe! > > > "Typesafe"? Are you trying to make a joke? No, I was pointing out that passing a type is more ... typesafe. From bahamutzero8825 at gmail.com Thu Jul 7 09:24:58 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 08:24:58 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> Message-ID: <4E15B3AA.4030106@gmail.com> On 2011.07.07 08:11 AM, Phlip wrote: > No, I was pointing out that passing a type is more ... typesafe. None is a type. >>> None.__class__ From phlip2005 at gmail.com Thu Jul 7 09:39:54 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 06:39:54 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> Message-ID: <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> On Jul 7, 6:24?am, Andrew Berg wrote: > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that passing a type is more ... typesafe. > > None is a type. I never said it wasn't. From bahamutzero8825 at gmail.com Thu Jul 7 09:58:48 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 08:58:48 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> Message-ID: <4E15BB98.2040804@gmail.com> On 2011.07.07 08:39 AM, Phlip wrote: > On Jul 7, 6:24 am, Andrew Berg wrote: > > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that passing a type is more ... typesafe. > > > > None is a type. > > I never said it wasn't. You are talking about this code, right? def file_to_hash(path, m=None): if m is None: m = hashlib.md5() What's not a type? The is operator compares types (m's value isn't the only thing compared here; even an separate instance of the exact same type would make it return False), and m can't be undefined. From invalid at invalid.invalid Thu Jul 7 10:18:32 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 7 Jul 2011 14:18:32 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> <1pvghkmjff37$.dlg@localhost.localdomain> Message-ID: On 2011-07-06, Waldek M. wrote: > Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): >> Because unless you are extremely disciplined, code and the comments >> describing them get out of sync. [...] > True, but that gets far worse with external docs. Do you have in mind > any better replacement? You write code that's easy to read, and you provide the language with introspection capabilities that allow you do do things like write a program that will list the symbols exported by a module. -- Grant Edwards grant.b.edwards Yow! Now that I have my at "APPLE", I comprehend COST gmail.com ACCOUNTING!! From python at bdurham.com Thu Jul 7 10:20:02 2011 From: python at bdurham.com (python at bdurham.com) Date: Thu, 07 Jul 2011 10:20:02 -0400 Subject: Tips/lessons learned for writing a Python powered DSL? Message-ID: <1310048402.8528.2149215773@webmail.messagingengine.com> Looking for tips and lessons learned (advice on what to do and not do) for writing a Python based DSL. Googling python dsl yields some wonderful content which I've just started to read. If there are specific articles or 3rd party libraries that you used to implement a DSL, I would appreciate hearing about them. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwoolcoc at gmail.com Thu Jul 7 10:40:39 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Thu, 7 Jul 2011 10:40:39 -0400 Subject: Tips/lessons learned for writing a Python powered DSL? In-Reply-To: <1310048402.8528.2149215773@webmail.messagingengine.com> References: <1310048402.8528.2149215773@webmail.messagingengine.com> Message-ID: For me, diving into the data model really helped me grasp some of the metaprogramming capabilities that python has, which is helping me as I am implementing my own DSL in python. http://docs.python.org/reference/datamodel.html On Thu, Jul 7, 2011 at 10:20 AM, wrote: > Looking for tips and lessons learned (advice on what to do and not do) for > writing a Python based DSL. > > Googling python dsl yields some wonderful content which I've just started > to read. If there are specific articles or 3rd party libraries that you used > to implement a DSL, I would appreciate hearing about them. > > Thank you, > Malcolm > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- --- Paul Woolcock -------------- next part -------------- An HTML attachment was scrubbed... URL: From toyze.rocha at gmail.com Thu Jul 7 11:21:12 2011 From: toyze.rocha at gmail.com (=?ISO-8859-1?Q?Ant=F3nio_Rocha?=) Date: Thu, 7 Jul 2011 16:21:12 +0100 Subject: Question- Getting Windows 64bits information Python 32bits Message-ID: Greetings I'm running Python (32b) in Windows7 (at 64bits) and I would like to know how can I check if my machine is a 32b or 64b in Python. Is it possible? I saw a few examples (like platform) but they only provide information about Python not the machine. Thanks Toze -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Thu Jul 7 11:46:56 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 10:46:56 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: References: Message-ID: <4E15D4F0.5040408@gmail.com> On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: > I'm running Python (32b) in Windows7 (at 64bits) and I would like to > know how can I check if my machine is a 32b or 64b in Python. Is it > possible? I saw a few examples (like platform) but they only provide > information about Python not the machine. os.environ['processor_architecture'] os.environ is a dictionary of system environment variables. That exact key probably only exists on Windows, but I'm there is a similar key on other platforms. From ian.g.kelly at gmail.com Thu Jul 7 11:49:10 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:49:10 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt wrote: > Even worse, most people would actually pay for its use, because they don't > use numbers large enough to merit the Sch?nhage?Strassen algorithm. As it stands, Karatsuba is only used for numbers greater than a specific threshold. Adding Sch?nhage?Strassen would just mean adding another threshold, below which Karatsuba would still be used. So at worst it would just add another comparison or two for numbers within the Karatsuba range. From ian.g.kelly at gmail.com Thu Jul 7 11:50:34 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:50:34 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 9:49 AM, Ian Kelly wrote: > On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt > wrote: >> Even worse, most people would actually pay for its use, because they don't >> use numbers large enough to merit the Sch?nhage?Strassen algorithm. > > As it stands, Karatsuba is only used for numbers greater than a > specific threshold. ?Adding Sch?nhage?Strassen would just mean adding > another threshold, below which Karatsuba would still be used. ?So at > worst it would just add another comparison or two for numbers within > the Karatsuba range. And I just realized that you said as much yourself further down in your message. My apologies for the needless lecturing. From ian.g.kelly at gmail.com Thu Jul 7 11:58:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:58:47 -0600 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 7, 2011 at 1:12 AM, Ulrich Eckhardt wrote: >>> Just guessing, is it legacy, C-with-classes code rather than C++ code >>> perhaps? Haven't looked at wx for a while. Such code typically lacks >>> understanding of exceptions, which are the only way to signal failure >>> from e.g. constructors. >> >> No, wx is C++ through and through. > > No namespaces. No templates but macros. No exceptions. No C++. > > Sorry, I beg to differ. BTW, they say themselves that they tolerate but not > use exceptions, so they actually need two-stage construction if construction > can fail, and for exactly the guessed legacy reasons. Ah, I think I misunderstood your meaning. By "C-with-classes" I thought you were referring to the practice of OOP in C, and my response was to the effect that building wx requires a C++ compiler, not just a C compiler. From nabble.com at bodrato.it Thu Jul 7 12:00:08 2011 From: nabble.com at bodrato.it (Parerga) Date: Thu, 7 Jul 2011 09:00:08 -0700 (PDT) Subject: Large number multiplication In-Reply-To: References: Message-ID: <32014454.post@talk.nabble.com> Hi, Billy Mays wrote: > >> On 07/06/2011 04:02 PM, Ian Kelly wrote: >> > On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: >> >> I was looking through the python source and noticed that long >> multiplication >> >> is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs >> O(~n >> >> log n). I was wondering if there was a reason the Karatsuba method >> was >> >> chosen over the FFT convolution method? > >> The reason I ask is because convolution has a better (best ?) complexity > Better complexity, yes. This means "smaller execution time for LARGE ENOUGH operands" Billy Mays wrote: > >> I was more interested in finding previous discussion (if any) on why >> Karatsuba was chosen, not so much as trying to alter the current >> multiplication implementation. > I'm not a python developer, but I worked on multiplication algorithms for GMP [ http://gmplib.org/ ], and I can guess the answer: - Karatsuba is (by far) simpler to implement, - FFT-based multiplication is (by far) slower than Karatsuba for numbers that are not huge. I try to attach a small graph http://old.nabble.com/file/p32014454/karaVSfft.pdf karaVSfft.pdf , with timings for multiplications of n-bits operands (with GMP, on my very old laptop) with Toom(2,2) (it's Karatsuba!) and the FFT-based computation. The first is faster than the latter up to 10000 bits (GMP uses some Toom for that size, to get the result even faster). Regards, Marco -- http://bodrato.it/software/toom.html -- View this message in context: http://old.nabble.com/Large-number-multiplication-tp32007815p32014454.html Sent from the Python - python-list mailing list archive at Nabble.com. From phil at brassy.net Thu Jul 7 12:33:16 2011 From: phil at brassy.net (Philip Reynolds) Date: Thu, 7 Jul 2011 17:33:16 +0100 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: <4E15D4F0.5040408@gmail.com> References: <4E15D4F0.5040408@gmail.com> Message-ID: <20110707163315.GA14053@brassy.net> On Thu, 07 Jul 2011, Andrew Berg wrote: > On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: > > I'm running Python (32b) in Windows7 (at 64bits) and I would like to > > know how can I check if my machine is a 32b or 64b in Python. Is it > > possible? I saw a few examples (like platform) but they only provide > > information about Python not the machine. > os.environ['processor_architecture'] > > os.environ is a dictionary of system environment variables. That exact > key probably only exists on Windows, but I'm there is a similar key on > other platforms. $ python -c 'import platform; print platform.architecture()' ('64bit', 'ELF') http://docs.python.org/library/platform.html Phil. From robert.kern at gmail.com Thu Jul 7 12:43:55 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 07 Jul 2011 11:43:55 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: <20110707163315.GA14053@brassy.net> References: <4E15D4F0.5040408@gmail.com> <20110707163315.GA14053@brassy.net> Message-ID: On 7/7/11 11:33 AM, Philip Reynolds wrote: > On Thu, 07 Jul 2011, Andrew Berg wrote: > >> On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: >>> I'm running Python (32b) in Windows7 (at 64bits) and I would like to >>> know how can I check if my machine is a 32b or 64b in Python. Is it >>> possible? I saw a few examples (like platform) but they only provide >>> information about Python not the machine. >> os.environ['processor_architecture'] >> >> os.environ is a dictionary of system environment variables. That exact >> key probably only exists on Windows, but I'm there is a similar key on >> other platforms. > > $ python -c 'import platform; print platform.architecture()' > ('64bit', 'ELF') > > http://docs.python.org/library/platform.html This is not what the OP is looking for. The OP wants to know what the CPU and OS are capable of, not what the Python executable is compiled for. platform.architecture() gives the latter. -- 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 stutzbach at google.com Thu Jul 7 13:03:25 2011 From: stutzbach at google.com (Daniel Stutzbach) Date: Thu, 7 Jul 2011 10:03:25 -0700 Subject: blist question In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 5:08 AM, dmitrey wrote: > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) and > occasionally found blist > http://pypi.python.org/pypi/blist/ > > Its entry says it is better than Python list. Did anyone ensure? > It has better performance for many operations. I made a very detailed performance comparison here (against Python 3.1): http://stutzbachenterprises.com/performance-blist Undoubtedly, you can find sequences of operations where Python's built-in list type has better performance by a constant factor. Python's built-in list type is more memory-efficient for small lists (blist's memory usage for small lists could be improved to be similar, but I haven't gotten around to making the necessary changes.) > Will it ever be merged into Python source code? > Seems unlikely. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Thu Jul 7 13:15:20 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Thu, 7 Jul 2011 12:15:20 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: References: Message-ID: 2011/7/7 Ant?nio Rocha > Greetings > > I'm running Python (32b) in Windows7 (at 64bits) and I would like to know > how can I check if my machine is a 32b or 64b in Python. Is it possible? I > saw a few examples (like platform) but they only provide information about > Python not the machine. > Thanks > Toze > Running CPython compiled for 32-bit on a Windows 7 64-bit machine gives the following: >>> platform.architecture() ('32bit', 'WindowsPE') >>> platform.machine() 'AMD64' This didn't used to be the case - it was corrected in http://bugs.python.org/issue7860 so you may need to upgrade to get accurate information if you have an older Python installed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.schoon at gmail.com Thu Jul 7 13:22:56 2011 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 7 Jul 2011 17:22:56 GMT Subject: Programming tips :-) Message-ID: <97m8bgFqq4U1@mid.individual.net> I just found the following url in my archives at work and thought you might enjoy it: http://thc.org/root/phun/unmaintain.html /Martin From peterirbizon at gmail.com Thu Jul 7 13:24:04 2011 From: peterirbizon at gmail.com (miamia) Date: Thu, 7 Jul 2011 10:24:04 -0700 (PDT) Subject: module problem on windows 64bit References: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> Message-ID: <682c2d6e-4564-4451-ae77-84638aa4d6c9@q17g2000vby.googlegroups.com> On Jul 5, 5:05?pm, Thomas Jollans wrote: > On 06/27/2011 06:59 PM, miamia wrote: > > > Hello, > > > on 32-bit windows everything works ok but on 64-bit win I am getting > > this error: > > Traceback (most recent call last): > > ? File "app.py", line 1040, in do_this_now > > ? File "kinterbasdb\__init__.pyc", line 119, in > > ? File "kinterbasdb\_kinterbasdb.pyc", line 12, in > > ? File "kinterbasdb\_kinterbasdb.pyc", line 10, in __load > > ImportError: DLL load failed: This application has failed to start > > because the application configuration is incorrect. Reinstalling the > > application may fix this problem. > > > How to get it work on 64bit windows as well? many thanks > > A process can only link to a shared library compiled for the same > architecture as the process. In layman's terms: A 32-bit DLL won't work > with a 64-bit program. It looks like this package is attempting to load > a 32-bit DLL. That's not going to work. Either procure a 64-bit version > of the DLL, or use a 32-bit version of Python. hello, it looks lite I solved it with files msvcp80.dll, Microsoft.VC80.CRT.manifest. I forgot to extract these files from firebird embedded pachage to my app folder. now it seems to be ok on both systems 32 and 64bit (so It wasn't 64bit issue as I thought). thank you From miki.tebeka at gmail.com Thu Jul 7 13:27:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 7 Jul 2011 10:27:30 -0700 (PDT) Subject: blist question In-Reply-To: Message-ID: Have you looked at http://docs.python.org/library/collections.html#collections.deque ? From rantingrick at gmail.com Thu Jul 7 13:29:58 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 7 Jul 2011 10:29:58 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> Message-ID: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> On Jul 7, 12:34?am, Gregory Ewing wrote: > rantingrick wrote: > > Yes but what benefit does that gain over say, Tkinter's design > > (because that has been your argument). > > Like I said, it's a tangential issue. Agreed. > The important thing is that it's okay for an app to stay > alive until its *last* top level window is closed. So your argument is: """ A window hierarchy is bad because if your application requires a user to open a gazillion windows (read as: designed poorly) --each representing completely different transactions-- and if you close the original window all the "other" windows will close too. Boo :(""" continuing... > There > doesn't have to be a special "main" window that kills the > whole app when you close it. So you prefer to close a gazillion windows one by one? If so, why not just code the GUI correctly from the start; by creating separate transactions? Thereby reducing the number of windows a user must juggle? FYI: You know the user complexity of a GUI increases exponentially by the number of windows present. > However, I think what the original complaint was really > about is that when you create a non-toplevel widget in Tkinter > you have to specify its parent (and if you don't, it assumes > you want it to be a child of the main window). Thats was MY complaint yes. On the grounds that widgets require windows NOT windows require widgets. This fact will confuse folks. > You can't > create the widget first and specify its parent later. > > This is another API flaw that is seen distressingly often > in GUI libraries. It's a nuisance, because it means you can't > write code that creates a widget hierarchy bottom-up. Actually you can! Stay tuned for enlightenment! > For > example, in PyGUI you can write things like > ? ?dialog_contents = Column([ > ? ? ?Label("Caution: Your underpants are on fire."), > ? ? ?Row([Button("OK"), Button("Cancel")]) > ? ?]) > > There's no way you could write Row and Column functions for > Tkinter that work like that -- they would have to take parent > widgets as arguments, and you wouldn't be able to nest the > calls. WRONG! A function or class structure can handle this just fine. And lends itself nicely to GUI programming. ## START CODE ## import Tkinter as tk class DumbDialog(tk.Toplevel): def __init__(self, master, **kw): w=tk.Label(master, text="Caution: Your underpants are on fire.") w.pack() w=tk.Button(master, text="OK").pack() w=tk.Button(master, text="Cancel").pack() print 'start script' root = tk.Tk() d = DumbDialog(root) root.mainloop() print 'continue script' root = tk.Tk() d = DumbDialog(root) root.mainloop() print 'end script' ## END CODE ## *school bell rings* From casevh at gmail.com Thu Jul 7 13:46:35 2011 From: casevh at gmail.com (casevh) Date: Thu, 7 Jul 2011 10:46:35 -0700 (PDT) Subject: Large number multiplication References: Message-ID: On Jul 7, 1:30?am, Ulrich Eckhardt wrote: > Billy Mays wrote: > > On 07/06/2011 04:02 PM, Ian Kelly wrote: > >> According to Wikipedia: > > >> """ > >> In practice the Sch?nhage?Strassen algorithm starts to outperform > >> older methods such as Karatsuba and Toom?Cook multiplication for > >> numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). > >> """ > > >> I think most Python users are probably not working with numbers that > >> large, and if they are, they are probably using specialized numerical > >> libraries anyway, so there would be little benefit in implementing it > >> in core. > > > You are right that not many people would gain significant use of it. > > Even worse, most people would actually pay for its use, because they don't > use numbers large enough to merit the Sch?nhage?Strassen algorithm. > > > The reason I ask is because convolution has a better (best ?) complexity > > class than the current multiplication algorithm. > > The "asymptotic complexity" of algorithms (I guess that's what you mean) is > concerned with large up to infinite n elements in operations. The claim > there always excludes any number of elements below n_0, where the complexity > might be different, even though that is usually not repeatedly mentioned. In > other words, lower complexity does not mean that something runs faster, only > that for large enough n it runs faster. If you never realistically reach > that limit, you can't reap those benefits. > > That said, I'm sure that the developers would accept a patch that switches > to a different algorithm if the numbers get large enough. I believe it > already doesn't use Karatsuba for small numbers that fit into registers, > too. > > > I was more interested in finding previous discussion (if any) on why > > Karatsuba was chosen, not so much as trying to alter the current > > multiplication implementation. > > I would hope that such design decisions are documented in code or at least > referenced from there. Otherwise the code is impossible to understand and > argue about. > > Cheers! > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932- Hide quoted text - > > - Show quoted text - A quick search on the Python issue tracker (bugs.python.org) yields the following issues: http://bugs.python.org/issue560379 http://bugs.python.org/issue4258 The issues also refer to discussion threads on the python-dev mailing list. casevh From postslot at gmail.com Thu Jul 7 14:18:08 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 11:18:08 -0700 (PDT) Subject: i get different answers based on run platform Message-ID: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> I have this simple palindrome program that yields different results depending on whether I run it from Windows or from IDLE. The answer is correct off IDLE, but why is this the case? Here's the code: def reverse(text): return text[::-1] def is_palindrome(text): return text==reverse(text) while True: something=input('enter text:') print(something) print(something[::-1]) if (is_palindrome(something)): print("yes, it is a palindrome") break else: print("no, it is not a palindrome") continue print ('done') Thanks for your help. From widebandwidth at gmail.com Thu Jul 7 14:18:18 2011 From: widebandwidth at gmail.com (high bandwidth) Date: Thu, 7 Jul 2011 14:18:18 -0400 Subject: making socket.getaddrinfo use cached dns In-Reply-To: References: Message-ID: I use cached dns lookups with pdnsd on my ubuntu machine to speed up web access as regular lookups can take 15-30 seconds. However, python's mechanize and urllib etc use socket.getaddrinfo, which seems not to be using dns cacheing or taking a long time because of ipv6 lookups. In either case, I subsequent access to the same site to be fast and not require lengthy calls to getaddrinfo. How can I get python to correctly use cached dns lookups and ipv4 only (at least in those cases where it is appropriate). As mentioned here: http://stackoverflow.com/questions/2014534/force-python-mechanize-urllib2-to-only-use-a-requests/2035686#2035686 It seems that many python libraries are hardcoded to look for both ipv6 and ipv4. Since ipv6 lookups are extremely slow at least for some users, perhaps the devs should carry over these optional arguments to higher level libraries like mechanize, urllib, httplib etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jul 7 14:24:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2011 04:24:12 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: On Fri, Jul 8, 2011 at 3:29 AM, rantingrick wrote: > So your argument is: > ? ?""" A window hierarchy is bad because if your application requires > a user to open a gazillion windows (read as: designed poorly) --each > representing completely different transactions-- and if you close the > original window all the "other" windows will close too. Boo :(""" Why should opening multiple windows AUTOMATICALLY equate to poor design? > So you prefer to close a gazillion windows one by one? If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. By "separate transactions" do you mean that the user can simultaneously perform multiple actions? Because that's best done with multiple separate interfaces - such as, multiple windows. Or do you really mean "sequential transactions"? That would not in any way be good design. >> For >> example, in PyGUI you can write things like > >> ? ?dialog_contents = Column([ >> ? ? ?Label("Caution: Your underpants are on fire."), >> ? ? ?Row([Button("OK"), Button("Cancel")]) >> ? ?]) >> > WRONG! A function or class structure can handle this just fine. And > lends itself nicely to GUI programming. You have to break your code into two pieces. Here's an alternative way of laying out a dialog, this taken from Pike-GTK2: mainwindow->add(GTK2.Vbox(0,0)->add(GTK2.HbuttonBox()->add(button("E_xit",window_destroy)->set_use_underline(1))->add(button("Set",setprops))->set_layout(GTK2.BUTTONBOX_SPREAD)))->show_all(); This program uses utility functions such as: //Helper function to create a button and give it an event. Useful because signal_connect doesn't return self. GTK2.Button button(mixed content,function clickevent,mixed|void arg) { GTK2.Button ret=GTK2.Button(content); ret->signal_connect("clicked",clickevent,arg); return ret; } I make no apologies for the braces in the code :) The 'button' function creates a button and assigns it an event. At this stage, the button has no parent; it won't be drawn anywhere. The GTK2.Button object is returned, and then added. It's added to the HbuttonBox which is then added to the Vbox which is only then added to the main window; although the code would work just fine if done in the other order. It's important here that objects are simply objects - they don't have to be built in a tree structure; and the window's layout is entirely in the one place, I don't have to put half of it into the window's constructor. ChrisA From rosuav at gmail.com Thu Jul 7 14:26:37 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2011 04:26:37 +1000 Subject: making socket.getaddrinfo use cached dns In-Reply-To: References: Message-ID: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth wrote: > I use cached dns lookups with pdnsd on my ubuntu machine to speed up web > access as regular lookups can take 15-30 seconds. However, python's > mechanize and urllib etc use socket.getaddrinfo, which seems not to be using > dns cacheing or taking a long time because of ipv6 lookups. In either case, > I subsequent access to the same site to be fast and not require lengthy > calls to getaddrinfo. How can I get python to correctly use cached dns > lookups and ipv4 only (at least in those cases where it is appropriate). One solution would be to do your own DNS lookups and then pass urllib an IP address. Is pdnsd set up to be your computer's primary resolver? (Is /etc/resolv.conf pointing to localhost?) If not, that might help. I've generally done my DNS caching using BIND, so I can't help with pdnsd specifically. ChrisA From bahamutzero8825 at gmail.com Thu Jul 7 14:36:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 13:36:55 -0500 Subject: Programming tips :-) In-Reply-To: <97m8bgFqq4U1@mid.individual.net> References: <97m8bgFqq4U1@mid.individual.net> Message-ID: <4E15FCC7.3020501@gmail.com> On 2011.07.07 12:22 PM, Martin Sch??n wrote: > I just found the following url in my archives at work and > thought you might enjoy it: > http://thc.org/root/phun/unmaintain.html That's awesome. > If a maintenance programmer can't quote entire Monty Python movies > from memory, he or she has *no* business being a programmer. :-D From gordon at panix.com Thu Jul 7 14:37:54 2011 From: gordon at panix.com (John Gordon) Date: Thu, 7 Jul 2011 18:37:54 +0000 (UTC) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: In <842fce9d-1b3f-434a-b748-a6dc4828c385 at h12g2000pro.googlegroups.com> linda writes: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: Your code contains debugging statements that print the value of the normal string and the reversed string. What do those statements print when you run your program under Windows? That should go a long way towards telling you what the problem is. (Perhaps Windows leaves a linefeed character hanging at the end of the input line, which upsets the palindromic balance?) By the way, I could not make your program work as you provided it; I had to replace input() with raw_input(). Does it really work for you this way? -- 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 bahamutzero8825 at gmail.com Thu Jul 7 14:42:04 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 13:42:04 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <4E15FDFC.3080506@gmail.com> On 2011.07.07 12:29 PM, rantingrick wrote: > So you prefer to close a gazillion windows one by one? If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. :-D Are you paid to troll? I must say, your technique of presenting semi-logical, but completely wrong arguments is admirable. Truly the work of a professional. From python at mrabarnett.plus.com Thu Jul 7 14:54:47 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 07 Jul 2011 19:54:47 +0100 Subject: i get different answers based on run platform In-Reply-To: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1600F7.5030107@mrabarnett.plus.com> On 07/07/2011 19:18, linda wrote: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: > > def reverse(text): > return text[::-1] > def is_palindrome(text): > return text==reverse(text) > while True: > something=input('enter text:') > print(something) > print(something[::-1]) > if (is_palindrome(something)): > print("yes, it is a palindrome") > break > else: > print("no, it is not a palindrome") > continue > print ('done') > > Thanks for your help. > Try printing ascii(something) too. There's a known bug in Python 3.2 where it leaves a training '\r', if that's what you're using (http://bugs.python.org/issue12435), fixed in Python 3.2.1. From ethan at stoneleaf.us Thu Jul 7 14:58:22 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 11:58:22 -0700 Subject: i get different answers based on run platform In-Reply-To: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1601CE.3070100@stoneleaf.us> linda wrote: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: > > def reverse(text): > return text[::-1] > def is_palindrome(text): > return text==reverse(text) > while True: > something=input('enter text:') try changing this to: something = input('enter text:').rstrip('\n') > print(something) > print(something[::-1]) > if (is_palindrome(something)): > print("yes, it is a palindrome") > break > else: > print("no, it is not a palindrome") > continue > print ('done') From python at mrabarnett.plus.com Thu Jul 7 14:59:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 07 Jul 2011 19:59:05 +0100 Subject: i get different answers based on run platform In-Reply-To: References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1601F9.6070506@mrabarnett.plus.com> On 07/07/2011 19:37, John Gordon wrote: > In<842fce9d-1b3f-434a-b748-a6dc4828c385 at h12g2000pro.googlegroups.com> linda writes: > >> I have this simple palindrome program that yields different results >> depending on whether I run it from Windows or from IDLE. The answer >> is correct off IDLE, but why is this the case? Here's the code: > > Your code contains debugging statements that print the value of the normal > string and the reversed string. What do those statements print when you > run your program under Windows? That should go a long way towards telling > you what the problem is. > > (Perhaps Windows leaves a linefeed character hanging at the end of the > input line, which upsets the palindromic balance?) > > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? > It's Python 3. Python 2's raw_input() has been renamed input() in Python 3 and Python 2's input() was never in Python 3 because it uses eval on the string, which usually undesirable. From ethan at stoneleaf.us Thu Jul 7 15:11:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 12:11:52 -0700 Subject: i get different answers based on run platform In-Reply-To: References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1604F8.3020000@stoneleaf.us> John Gordon wrote: > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? input() is the 3.x name for raw_input() ~Ethan~ From yorick.brunet at gmail.com Thu Jul 7 15:34:39 2011 From: yorick.brunet at gmail.com (yorick) Date: Thu, 7 Jul 2011 12:34:39 -0700 (PDT) Subject: Serial & reset of the device Message-ID: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Hello, I'm trying to access a hardware board of my company through a serial connection using a Python script and the pyserial module. I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). The board to which I'm trying to connect works correctly with serial as some other guys did some TCL scripts to manage it. My problem is that every time I open a new connection, the device is reset. I'd like to not have the device reset. The code is the following : handler = serial.Serial(port=self.portname, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stHello, I'm trying to access a hardware board of my company through a serial connection using a Python script and the pyserial module. I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). The board to which I'm trying to connect works correctly with serial as some other guys did some TCL scripts to manage it. My problem is that every time I open a new connection, the device is reset. I'd like to not have the device reset. The code is the following : handler = serial.Serial(port=self.portname, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=False) # here the device is reset ... handler.close() I found the following post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274205532 but I haven't tested it yet as I don't like the idea to change files managed by the system (and it is for Windows). Is there any possibility to not reset the device when opening the connection ? Thanks, Yorickopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=False) # here the device is reset ... handler.close() I found the following post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274205532 but I haven't tested it yet as I don't like the idea to change files managed by the system (and it is for Windows). Is there any possibility to not reset the device when opening the connection ? Thanks, Yorick From mrkwjc at gmail.com Thu Jul 7 16:08:37 2011 From: mrkwjc at gmail.com (ichi) Date: Thu, 7 Jul 2011 13:08:37 -0700 (PDT) Subject: multiprocessing.Manager().Namespace() and data copying Message-ID: Hi! I'm trying to share data between processes using multiprocessing.Manager and? creating shared Namespace. I have the following code: from multiprocessing import Manager from scipy import rand x = rand(5000, 5000) m = Manager() n = m.Namespace() n.x = x?? It seems that at n.x = x data is serialized and copied. It seems it is also? serialized and copied at x = n.x. Is there a way to omit this to have really? shared objects with Namespace? I need read only objects (not necessarily? arrays)... From AimeeG at sgainc.com Thu Jul 7 16:48:17 2011 From: AimeeG at sgainc.com (Aimee Gerzofsky) Date: Thu, 7 Jul 2011 16:48:17 -0400 Subject: FULL TIME PYTHON DEVELOPER OPPORTUNITY IN CHICAGO, IL Message-ID: <817109B09119D849A3B8FCFBBEAAA8E15294DA8A@sga3.sga.local> Python Developer Major financial clients is seeking a Python Developer for a full time position in Chicago, IL. The candidate will be a mid level developer responsible for contributing to all phases of the SDLC including analysis, design, development, QA, UAT, and tier-2 production support. The deliverables include real-time rules engines, real-time processing engines, real-time dashboards, and scheduled end of day reporting processes built on our cross-asset strategic trading and processing platform. Responsibilities: Required: * 5+ years Object Oriented Programming experience * 3+ years Python programming * Experience with Microsoft WPF UI programming a plus * 2+ years XML experience * Experience with SQL databases * Experience with NoSQL databases a plus * Working knowledge of Unix/Linux * Agile development life-cycle experience Preferred: * Financial experience a plus * Knowledge of Dodd-Frank regulations a huge plus * Knowledge of derivative products Contact me: aimee at sgainc.com if you or someone you know is interested. Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From postslot at gmail.com Thu Jul 7 17:09:11 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 14:09:11 -0700 (PDT) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> I tried something = input('enter text:').rstrip('\n') as suggested but the problem persists. BTW, the intermediate print commands agree and so are not an issue. The disagreement is in IDLE correctly identifying palindromes and Windows not. I do suspect it may be a trailing '\r' issue. Is there an easy fix or shall I wait for the new Python versions to be released? Thanks for helping. From postslot at gmail.com Thu Jul 7 17:37:14 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 14:37:14 -0700 (PDT) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> Message-ID: On Jul 7, 2:42?pm, Ethan Furman wrote: > linda wrote: > > I tried something = input('enter text:').rstrip('\n') as suggested but > > the problem persists. ?BTW, the intermediate print commands agree and > > so are not an issue. ?The disagreement is in IDLE correctly > > identifying palindromes and Windows not. ?I do suspect it may be a > > trailing '\r' issue. ?Is there an easy fix or shall I wait for the new > > Python versions to be released? ?Thanks for helping. > > My apologies -- change the '\n' to '\r' and that will hopefully do the > trick. > > ~Ethan~ Thanks Ethan--that did work :) From ethan at stoneleaf.us Thu Jul 7 17:42:45 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 14:42:45 -0700 Subject: i get different answers based on run platform In-Reply-To: <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> Message-ID: <4E162855.4000605@stoneleaf.us> linda wrote: > I tried something = input('enter text:').rstrip('\n') as suggested but > the problem persists. BTW, the intermediate print commands agree and > so are not an issue. The disagreement is in IDLE correctly > identifying palindromes and Windows not. I do suspect it may be a > trailing '\r' issue. Is there an easy fix or shall I wait for the new > Python versions to be released? Thanks for helping. My apologies -- change the '\n' to '\r' and that will hopefully do the trick. ~Ethan~ From python at rcn.com Thu Jul 7 18:46:16 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 7 Jul 2011 15:46:16 -0700 (PDT) Subject: blist question References: Message-ID: On Jul 7, 5:08?am, dmitrey wrote: > hi all, > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) Take a look at heapq.nlargest()... > and > occasionally found blisthttp://pypi.python.org/pypi/blist/ > Its entry says it is better than Python list. It should say: better in some respects and worse in others Do you honestly think that python's list implementation as a simple array of pointers can be beaten in every category of performance? > Did anyone ensure? > Will it ever be merged into Python source code? It was rejected as a replacement for the existing list implementation. There is some chance it will get accepted into the collections module someday. Raymond From clp2 at rebertia.com Thu Jul 7 20:36:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 7 Jul 2011 17:36:27 -0700 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> <1pvghkmjff37$.dlg@localhost.localdomain> Message-ID: On Thu, Jul 7, 2011 at 7:18 AM, Grant Edwards wrote: > On 2011-07-06, Waldek M. wrote: >> Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): > >>> Because unless you are extremely disciplined, code and the comments >>> describing them get out of sync. [...] > >> True, but that gets far worse with external docs. Do you have in mind >> any better replacement? > > You write code that's easy to read Reminded me of this excellent presentation: "Uncomment Your Code" https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw Cheers, Chris From steve+comp.lang.python at pearwood.info Thu Jul 7 21:25:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 11:25:14 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 7, 12:34?am, Gregory Ewing wrote: >> The important thing is that it's okay for an app to stay >> alive until its *last* top level window is closed. I partially disagree with Greg on this. This is not the only model: on the Apple Mac, or any system with a similar GUI design, the application can survive having the last window closed. There are other application types that don't need any window at all. So while it is common for closing the last window to exit the application, it is not a necessary requirement. >> There >> doesn't have to be a special "main" window that kills the >> whole app when you close it. > > So you prefer to close a gazillion windows one by one? Nonsense. Greg says nothing of the sort. Avoiding the anti-pattern "close a gazillion windows one by one" is why you have an application-wide Quit or Exit command, as opposed to a Close command which applies only to the current window. > If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. Don't assume that there is a one-to-one relationship between transactions (documents?) and windows. The relationship is actually many-to-many: windows can contain tabbed or notepad interfaces, or can be split into multiple panes, or both. Panes and tabs can be split into independent windows, or rejoined into one main window. E.g. I can have six Firefox windows open, each one with many different websites open in separate tabs. I have Close Tab, Close Window and Exit Firefox commands. In Konquorer, not only can I have multiple windows and multiple tabs, but I can split each tab into two or more panes, and display two views of the same document in the same tab, or two different documents in the one tab. This is especially useful when using it as a file manager. In older versions of Word (and possibly current, although I haven't tested it) you can open files multiple times. Each time opens in a new window, representing a new view of the one file. Edits in one window update all the others. This can be useful for, e.g. making edits to page 3 while simultaneously viewing page 303. An alternate UI for to split the one window into two panes, and scroll them independently. So a single file may have one or two panes, in one or more windows. So, you can have multiple documents in multiple windows, and there is no 1:1 relationship between them. -- Steven From steve+comp.lang.python at pearwood.info Thu Jul 7 21:46:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 11:46:12 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> Message-ID: <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > On 2011.07.07 08:39 AM, Phlip wrote: >> On Jul 7, 6:24 am, Andrew Berg wrote: >> > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that >> > passing a type is more ... typesafe. >> > >> > None is a type. >> >> I never said it wasn't. Unfortunately, it isn't. None is not a type, it is an instance. >>> isinstance(None, type) # is None a type? False >>> isinstance(None, type(None)) # is None an instance of None's type? True So None is not itself a type, although it *has* a type: >>> type(None) >>> isinstance(type(None), type) # is NoneType itself a type? True > You are talking about this code, right? > > def file_to_hash(path, m=None): > if m is None: > m = hashlib.md5() > > What's not a type? The is operator compares types (m's value isn't the > only thing compared here; even an separate instance of the exact same > type would make it return False), and m can't be undefined. The is operator does not compare types, it compares instances for identity. There is no need for is to ever care about the type of the arguments -- that's just a waste of time, since a fast identity (memory location) test is sufficient. This is why I initially thought that Phlip was joking when he suggested that "m is None" could be type-unsafe. It doesn't matter what type m has, "m is " will always be perfectly safe. -- Steven From greg.ewing at canterbury.ac.nz Thu Jul 7 21:58:42 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Jul 2011 13:58:42 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <97n6ilFpbkU1@mid.individual.net> rantingrick wrote: > So you prefer to close a gazillion windows one by one? If I want to close all the windows, I can use the application's "Quit" or "Exit" command, or whatever the platform calls it. (Note that if there is a separate instance of the application for each window -- as was suggested earlier -- then you don't have that option, and you have to close them one by one anyway.) >>There's no way you could write Row and Column functions for >>Tkinter that work like that -- they would have to take parent >>widgets as arguments, and you wouldn't be able to nest the >>calls. > > WRONG! A function or class structure can handle this just fine. > > class DumbDialog(tk.Toplevel): > def __init__(self, master, **kw): > w=tk.Label(master, text="Caution: Your underpants are on > fire.") > w.pack() > w=tk.Button(master, text="OK").pack() > w=tk.Button(master, text="Cancel").pack() Which is *exactly* what I said you would have to do in Tkinter! Each widget creation requires a separate statement, with the parent passed in at each step. This is nowhere near as convenient as the nested function call style. -- Greg From bahamutzero8825 at gmail.com Thu Jul 7 22:32:59 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 21:32:59 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E166C5B.8030100@gmail.com> On 2011.07.07 08:46 PM, Steven D'Aprano wrote: > None is not a type, it is an instance. > > >>> isinstance(None, type) # is None a type? > False > >>> isinstance(None, type(None)) # is None an instance of None's type? > True > > So None is not itself a type, although it *has* a type: > > >>> type(None) > > >>> isinstance(type(None), type) # is NoneType itself a type? > True I worded that poorly. None is (AFAIK) the only instance of NoneType, but I should've clarified the difference. > The is operator does not compare types, it compares instances for identity. > There is no need for is to ever care about the type of the arguments -- > that's just a waste of time, since a fast identity (memory location) test > is sufficient. "Compare" was the wrong word. I figured the interpreter doesn't explicitly compare types, but obviously identical instances are going to be of the same type. From phlip2005 at gmail.com Thu Jul 7 22:44:12 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 19:44:12 -0700 (PDT) Subject: Programming tips :-) References: <97m8bgFqq4U1@mid.individual.net> Message-ID: <5b0c982a-5b4c-4136-ba6f-e6223b713f99@s2g2000vbw.googlegroups.com> On Jul 7, 11:36?am, Andrew Berg wrote: > On 2011.07.07 12:22 PM, Martin Sch??n wrote:> I just found the following url in my archives at work and > > thought you might enjoy it: > >http://thc.org/root/phun/unmaintain.html > > That's awesome. That's "How To Write Unmaintainable Code" - a venerable classic. Compare these: http://c2.com/cgi/wiki?HowToPissOffYourPair http://c2.com/cgi/wiki?HelpSourceForgeSuck From phlip2005 at gmail.com Thu Jul 7 23:26:56 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 20:26:56 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> > I worded that poorly. None is (AFAIK) the only instance of NoneType, but > I should've clarified the difference.> The is operator does not compare types, it compares instances for identity. None is typesafe, because it's strongly typed. However, what's even MORE X-safe (for various values of X) is a method that takes LESS for its arguments. That's why I switched from passing an object to passing a type, because the more restrictive argument type is more typesafe. However, the MOST X-safe version so far simply passes a string, and uses hashlib the way it designs to be used: def file_to_hash(path, hash_type): hash = hashlib.new(hash_type) with open(path, 'rb') as f: while True: s = f.read(8192) if not s: break hash.update(s) return hash.hexdigest() From drsalists at gmail.com Fri Jul 8 00:22:58 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 7 Jul 2011 21:22:58 -0700 Subject: Serial & reset of the device In-Reply-To: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Message-ID: On Thu, Jul 7, 2011 at 12:34 PM, yorick wrote: > Hello, > > I'm trying to access a hardware board of my company through a serial > connection using a Python script and the pyserial module. > > I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- > serial with version 2.5.2, > http://pyserial.sourceforge.net/pyserial_api.html). > > The board to which I'm trying to connect works correctly with serial > as some other guys did some TCL scripts to manage it. > My problem is that every time I open a new connection, the device is > reset. I'd like to not have the device reset. A few suggestions: 1) You could try strace'ing the TCL, and then strace'ing the Python, and comparing - especially if you're comfortable with low-level I/O in C, but not only. Hunt for the open() call to the relevant device file, and other system calls near it. Even if you aren't that cozy with C, you could try putting the strace results on a website or ftp server, and posting links to them here. 2) Check and double check and triple check your line discipline parameters: bits per second, parity, word size, start/stop bits. 3) It's also possible the cable is bad (or merely inappropriate), especially if the TCL is accessing such a device over a different cable. There is no "one true serial (RS-232) cable standard" - RS-232 is a rather large collection of ways of doing communications, and they are frequently not compatible with one another. 4) One of the more likely causes of a reset of a device that is accessed serially, is sending it a break signal. There are official ways of sending a break, and accidental ways. Sometimes the two boil down to the same thing behind the scenes, but look very different in the code. A break signal is a longish sequence of unframed 0 bits (IE, with no start/stop bits separating one byte from another). An accidental way of sending a break, is to set your bits per second too low, and then sending a 0 byte - because those 8 0 bits at the too-low speed will look like a long series of unframed 0's from the perspective of the reader process that's running at the correct speed. So I guess the gist of point #4 (this point), is "make sure your bps is set correctly" and "check the device doc to see if a break signal causes a reset" 5) If the protocol layered over the serial communication is ASCII-based, you could try connecting to the device using something like minicom, to make sure the device is behaving as expected. If the device is speaking a binary protocol, this is unlikely to help much HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From eaglebalti at gmail.com Fri Jul 8 01:08:50 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Thu, 7 Jul 2011 22:08:50 -0700 (PDT) Subject: Hello Sweet Friends. Message-ID: <78af194e-3b51-49c4-ac4d-b238e01fa140@h17g2000yqn.googlegroups.com> I bring you a source of entertaintment.Just visit the following link and know about Bollywood actresses www.bollywoodactresseshotpictures.blogspot.com From nobody at nowhere.com Fri Jul 8 02:18:35 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 08 Jul 2011 07:18:35 +0100 Subject: making socket.getaddrinfo use cached dns References: Message-ID: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth wrote: >> I use cached dns lookups with pdnsd on my ubuntu machine to speed up >> web access as regular lookups can take 15-30 seconds. However, python's >> mechanize and urllib etc use socket.getaddrinfo, which seems not to be >> using dns cacheing or taking a long time because of ipv6 lookups. In >> either case, I subsequent access to the same site to be fast and not >> require lengthy calls to getaddrinfo. How can I get python to correctly >> use cached dns lookups and ipv4 only (at least in those cases where it >> is appropriate). To only query IPv4 addresses, pass socket.AF_INET as the third argument (family) to socket.getaddrinfo(). The default is AF_UNSPEC (= 0), which will return both IPv4 and IPv6 addresses. From mdickinson at enthought.com Fri Jul 8 03:31:10 2011 From: mdickinson at enthought.com (Mark Dickinson) Date: Fri, 8 Jul 2011 00:31:10 -0700 (PDT) Subject: Large number multiplication References: Message-ID: On Jul 7, 9:30?am, Ulrich Eckhardt wrote: > That said, I'm sure that the developers would accept a patch that switches > to a different algorithm if the numbers get large enough. I believe it > already doesn't use Karatsuba for small numbers that fit into registers, > too. I'm far from sure that such a patch would be accepted. :-) Indeed, Tim Peters has been heard to mention that if he were to do it all again, he probably wouldn't even have implemented Karatsuba [1]. Asymptotically fast integer multiplication is a specialist need that's already available in 3rd-party Python libraries (gmpy). IMO, it's not appropriate to include it in a general-purpose programming language, and the burden of maintaining such code would outweigh the benefits. One thing that has been considered in the past is making it possible to use GMP directly for Python's implementation of long integers; see Victor Stinner's efforts in this direction [2]. Licensing concerns, and the fact that Python's implementation is faster for small integers, ended up killing this issue. [1] http://mail.python.org/pipermail/python-dev/2008-November/083355.html [2] http://bugs.python.org/issue1814 -- Mark From steve+comp.lang.python at pearwood.info Fri Jul 8 03:42:47 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 17:42:47 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> Message-ID: <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but >> I should've clarified the difference.> The is operator does not compare >> types, it compares instances for identity. > > None is typesafe, because it's strongly typed. Everything in Python is strongly typed. Why single out None? Python has strongly-typed objects, dynamically typed variables, and a philosophy of preferring duck-typing over explicit type checks when possible. > However, what's even MORE X-safe (for various values of X) is a method > that takes LESS for its arguments. That's why I switched from passing > an object to passing a type, because the more restrictive argument > type is more typesafe. It seems to me that you are defeating duck-typing, and needlessly restricting what the user can pass, for dubious or no benefit. I still don't understand what problems you think you are avoiding with this tactic. > However, the MOST X-safe version so far simply passes a string, and > uses hashlib the way it designs to be used: > > def file_to_hash(path, hash_type): > hash = hashlib.new(hash_type) > with open(path, 'rb') as f: > while True: > s = f.read(8192) > if not s: break > hash.update(s) > return hash.hexdigest() There is no advantage to this that I can see. It limits the caller to using only hashes in hashlib. If the caller wants to provide her own hashing algorithm, your function will not support it. A more reasonable polymorphic version might be: def file_to_hash(path, hash='md5', blocksize=8192): # FIXME is md5 a sensible default hash? if isinstance(hash, str): # Allow the user to specify the hash by name. hash = hashlib.new(hash) else: # Otherwise hash must be an object that implements the # hashlib interface, i.e. a callable that returns an # object with appropriate update and hexdigest methods. hash = hash() with open(path, 'rb') as f: while True: s = f.read(blocksize) if not s: break hash.update(s) return hash.hexdigest() -- Steven From timr at probo.com Fri Jul 8 03:45:22 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 08 Jul 2011 00:45:22 -0700 Subject: Serial & reset of the device References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Message-ID: <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> yorick wrote: > >I'm trying to access a hardware board of my company through a serial >connection using a Python script and the pyserial module. > >I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- >serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). > >The board to which I'm trying to connect works correctly with serial >as some other guys did some TCL scripts to manage it. >My problem is that every time I open a new connection, the device is >reset. I'd like to not have the device reset. I'm not sure what that means. The RS-232 standard does not have the concept of "reset". What is it that triggers a device reset? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bpajith at gmail.com Fri Jul 8 04:41:34 2011 From: bpajith at gmail.com (Ajith Kumar) Date: Fri, 8 Jul 2011 14:11:34 +0530 Subject: Python for science experiments Message-ID: Hello, Just posting a link of a project using Python for doing science experiments. with regards ajith -- Dr. Ajith Kumar B.P. Scientist SG Inter-University Accelerator Centre Aruna Asaf Ali Marg New Delhi 110067 www.iuac.res.in Ph: (off) 91 11 26893955 (Ext.230) (res)91 11 26897867 (mob) 91 9868150852 -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.net.no Fri Jul 8 07:29:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 08 Jul 2011 19:29:44 +0800 Subject: Finding duplicated photo Message-ID: Hello, I came across the problem that Gwenview moves the photo from the camera memory by renaming them, but later I forgot which where moved. Then I tought about a small script in python, but I stumbled upon my ignorance on the way to do that. PIL can find similar pictures. I was thinking to reduce the foto into gray scale and resize them to same size, what algorithm should take place? Is PIL able to compare 2 images? -- goto /dev/null From noway at nohow.com Fri Jul 8 08:37:58 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 08:37:58 -0400 Subject: Finding duplicated photo References: Message-ID: On 07/08/2011 07:29 AM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > I recently wrote a program after reading an article ( http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html ) using the DCT method he proposes. It worked surprisingly well even with just the 64bit hash it produces. -- Bill From python.list at tim.thechases.com Fri Jul 8 08:58:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 08 Jul 2011 07:58:13 -0500 Subject: Serial & reset of the device In-Reply-To: <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> Message-ID: <4E16FEE5.5050807@tim.thechases.com> On 07/08/2011 02:45 AM, Tim Roberts wrote: > yorick wrote: >> I'm trying to access a hardware board of my company through a serial >> connection using a Python script and the pyserial module. >> >> The board to which I'm trying to connect works correctly with serial >> as some other guys did some TCL scripts to manage it. >> My problem is that every time I open a new connection, the device is >> reset. I'd like to not have the device reset. > > I'm not sure what that means. The RS-232 standard does not have the > concept of "reset". What is it that triggers a device reset? While not a "reset" per-se, it might be triggered by the RTS/CTS, DSR/DTR, or carrier-detect pins depending on the configuration. Without the code and with minimal pySerial experience, I don't know whether opening a serial-port in pySerial automatically lights up one of those aux. lines and unsignals it when the connection is closed. If the device expects a "power on" signal on one of those pins, I'd start by looking to see if pySerial's .close() drops the signal on those pins and if it offers a way to keep the signal high while releasing the port. Otherwise, you may have to open once, do all your work and only close the port when you're done (and the device can be reset) -tkc From phlip2005 at gmail.com Fri Jul 8 09:03:54 2011 From: phlip2005 at gmail.com (Phlip) Date: Fri, 8 Jul 2011 06:03:54 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0c552105-dd13-40d4-8265-d06097adda18@d22g2000yqn.googlegroups.com> On Jul 8, 12:42?am, Steven D'Aprano wrote: > Phlip wrote: > >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but > >> I should've clarified the difference.> The is operator does not compare > >> types, it compares instances for identity. > > > None is typesafe, because it's strongly typed. > > Everything in Python is strongly typed. Why single out None? You do understand these cheap shots are bad for conversations, right? I didn't single out None. When did you stop raping your mother? From invalid at invalid.invalid Fri Jul 8 09:56:12 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 8 Jul 2011 13:56:12 +0000 (UTC) Subject: Serial & reset of the device References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> Message-ID: On 2011-07-08, Tim Chase wrote: > On 07/08/2011 02:45 AM, Tim Roberts wrote: >> yorick wrote: >>> I'm trying to access a hardware board of my company through a serial >>> connection using a Python script and the pyserial module. >>> >>> The board to which I'm trying to connect works correctly with serial >>> as some other guys did some TCL scripts to manage it. My problem is >>> that every time I open a new connection, the device is reset. I'd >>> like to not have the device reset. >> >> I'm not sure what that means. The RS-232 standard does not have the >> concept of "reset". What is it that triggers a device reset? > > While not a "reset" per-se, it might be triggered by the RTS/CTS, > DSR/DTR, or carrier-detect pins depending on the configuration. > Without the code and with minimal pySerial experience, I don't > know whether opening a serial-port in pySerial automatically > lights up one of those aux. lines and unsignals it when the > connection is closed. On Unix, the serial port device driver generally turns DTR and RTS off when a port is closed and turns them on when it's opened. I don't know what Windows does. A quick glance through the pyserial sources shows that it turns on DTR and RTS when a port is opened, and does nothing with them when a port is closed. If you need RTS/DTR to stay in a known state, then open the port, set them to the state you want them, and keep the port open. -- Grant Edwards grant.b.edwards Yow! Remember, in 2039, at MOUSSE & PASTA will gmail.com be available ONLY by prescription!! From nobody at nowhere.net.no Fri Jul 8 10:14:54 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 08 Jul 2011 22:14:54 +0800 Subject: Finding duplicated photo References: Message-ID: Billy Mays wrote: > It worked surprisingly well even > with just the 64bit hash it produces. > I'd say that comparing 2 images reduced upto 32x32 bit seems too little to find if one of the 2 portrait has a smile referred to the other. I think it's about that mine and your suggestion are similar, but I'd like to scale pictures not less than 256x256 pixel. Also to take a wider case which the comparison involve a rotated image. -- goto /dev/null From noway at nohow.com Fri Jul 8 10:32:13 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 10:32:13 -0400 Subject: Finding duplicated photo References: Message-ID: On 07/08/2011 10:14 AM, TheSaint wrote: > Billy Mays wrote: > >> It worked surprisingly well even >> with just the 64bit hash it produces. >> > I'd say that comparing 2 images reduced upto 32x32 bit seems too little to > find if one of the 2 portrait has a smile referred to the other. > I think it's about that mine and your suggestion are similar, but I'd like > to scale pictures not less than 256x256 pixel. > Also to take a wider case which the comparison involve a rotated image. > Originally I thought the same thing. It turns out that doing a DCT on an image typically moves the more important data to the top left corner of the output. This means that most of the other data in the output an be thrown away since most of it doesn't significantly affect the image. The 32x32 is an arbitrary size, you can make it any square block that you want. Rotation is harder to find. You can always take a brute force approach by simply rotating the image a couple of times and try running the algorithm on each of the rotated pics. Image matching is a difficult problem. -- Bill From widebandwidth at gmail.com Fri Jul 8 10:40:34 2011 From: widebandwidth at gmail.com (high bandwidth) Date: Fri, 8 Jul 2011 10:40:34 -0400 Subject: making socket.getaddrinfo use cached dns Message-ID: my /etc/resolv.conf says: # Dynamic resolv.conf(5) file for glibc resolver(3) generated by > resolvconf(8) > # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN > nameserver 127.0.0.1 > search Dynex > But getaddrinfo still takes a lot of time for repeated queries. After installing BIND9 and starting it, getaddrinfo is almost instantaneous for repeated queries. Thanks! *Chris Angelico* rosuav at gmail.com wrote: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth > wrote: >* I use cached dns lookups with pdnsd on my ubuntu machine to speed up web*>* access as regular lookups can take 15-30 seconds. However, python's*>* mechanize and urllib etc use socket.getaddrinfo, which seems not to be using*>* dns cacheing or taking a long time because of ipv6 lookups. In either case,*>* I subsequent access to the same site to be fast and not require lengthy*>* calls to getaddrinfo. How can I get python to correctly use cached dns*>* lookups and ipv4 only (at least in those cases where it is appropriate).* One solution would be to do your own DNS lookups and then pass urllib an IP address. Is pdnsd set up to be your computer's primary resolver? (Is /etc/resolv.conf pointing to localhost?) If not, that might help. I've generally done my DNS caching using BIND, so I can't help with pdnsd specifically. ChrisA -------------- next part -------------- An HTML attachment was scrubbed... URL: From mapere.ali at gmail.com Fri Jul 8 10:45:51 2011 From: mapere.ali at gmail.com (Mapere Ali) Date: Fri, 8 Jul 2011 16:45:51 +0200 Subject: Python-list Digest, Vol 94, Issue 52 In-Reply-To: References: Message-ID: Hi, I need help with a python script to monitor my wireless router internet usage using a Mac address and then backup the report files on the server. i would also like to create login access on the website to have users checkout their bandwidth usage...Please help anyone I'm a newbie in Python.. Regards mapere I'v On 7/8/11, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > From t at jollybox.de Fri Jul 8 11:13:10 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 08 Jul 2011 17:13:10 +0200 Subject: Python-list Digest, Vol 94, Issue 52 In-Reply-To: References: Message-ID: <4E171E86.4090806@jollybox.de> On 07/08/2011 04:45 PM, Mapere Ali wrote: > Hi, > > I need help with a python script to monitor my wireless router > internet usage using a Mac address and then backup the report files on > the server. i would also like to create login access on the website to > have users checkout their bandwidth usage...Please help anyone > I'm a newbie in Python.. Try doing it yourself. Give it your best shot, one step at a time. Depending on how new you are to Python, you might want to go through a tutorial before embarking on your own project. The Python documentation (this will be very useful) is here: http://doc.python.org/ When you get stuck, come back here, show us what you've done and what the problem is, and we can help you with your (specific) problem. Also, if you ask questions here, you'll want to be able to respond to individual answers, so please subscribe to the actual list, not the digest. Have fun Thomas > > Regards > mapere > > I'v > On 7/8/11, python-list-request at python.org > wrote: >> Send Python-list mailing list submissions to >> python-list at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.python.org/mailman/listinfo/python-list >> or, via email, send a message with subject or body 'help' to >> python-list-request at python.org >> >> You can reach the person managing the list at >> python-list-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Python-list digest..." >> From t at jollybox.de Fri Jul 8 11:16:57 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 08 Jul 2011 17:16:57 +0200 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: <4E171F69.3090709@jollybox.de> On 07/08/2011 01:29 PM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > If Gwenview simply moves/renames the images, is it not enough to compare the actual files, byte by byte? From drsalists at gmail.com Fri Jul 8 11:29:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jul 2011 08:29:13 -0700 Subject: Finding duplicated photo In-Reply-To: <4E171F69.3090709@jollybox.de> References: <4E171F69.3090709@jollybox.de> Message-ID: On Fri, Jul 8, 2011 at 8:16 AM, Thomas Jollans wrote: > On 07/08/2011 01:29 PM, TheSaint wrote: > > Hello, > > > > I came across the problem that Gwenview moves the photo from the camera > > memory by renaming them, but later I forgot which where moved. > > Then I tought about a small script in python, but I stumbled upon my > > ignorance on the way to do that. > > > > PIL can find similar pictures. I was thinking to reduce the foto into > gray > > scale and resize them to same size, what algorithm should take place? > > Is PIL able to compare 2 images? > > > > If Gwenview simply moves/renames the images, is it not enough to compare > the actual files, byte by byte? > This'll detect duplicates pretty fast; it often doesn't even need to read a whole file once, while not sacrificing accuracy: http://stromberg.dnsalias.org/~dstromberg/equivalence-classes.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Jul 8 12:13:43 2011 From: davea at ieee.org (Dave Angel) Date: Fri, 08 Jul 2011 12:13:43 -0400 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: <4E172CB7.7060007@ieee.org> On 01/-10/-28163 02:59 PM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > If your real problem is identifying a renamed file amongst thousands of others, why not just compare the metadata? it'll be much faster. For example, if you only have one camera, the timestamp stored in the EXIF data would be pretty close, Some cameras also store their "shutter release number" in the metadata, which would be even better. One concern is whether Glenview or any other of your utilities discard the metadata. That would be a big mistake. Also, if Gwenview has no other features you're counting on, perhaps you should write your own "move the files from camera to computer" utility. that's what I did, and it renames and reorganises the files as it does, according to my conventions, not someone else's. One reason for the renaming is that my cameras only use 4 digit numbers, and these recycle every 10000 images. DaveA From sharanya9030 at gmail.com Fri Jul 8 12:21:52 2011 From: sharanya9030 at gmail.com (sharu) Date: Fri, 8 Jul 2011 09:21:52 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <144abcea-1553-4002-9516-9bd7b3577cd7@w4g2000yqm.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From rantingrick at gmail.com Fri Jul 8 13:30:20 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 8 Jul 2011 10:30:20 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <77ae91c9-b170-402a-81cf-264af825858a@e21g2000vbz.googlegroups.com> On Jul 7, 8:25?pm, Steven D'Aprano wrote: > rantingrick wrote: > > On Jul 7, 12:34?am, Gregory Ewing wrote: > >> The important thing is that it's okay for an app to stay > >> alive until its *last* top level window is closed. > > I partially disagree with Greg on this. This is not the only model: on the > Apple Mac, or any system with a similar GUI design, the application can > survive having the last window closed. There are other application types > that don't need any window at all. Yeah they call those "command line" programs. > So while it is common for closing the > last window to exit the application, it is not a necessary requirement. If a "root-window-hierarchy" type GUI needs to close any or all windows (or allow the user to do so) it can do this quite well. It's called logic (in programming circles). But the GUI by default exposes an interface to the user: * Close all windows by clicking the X of the ROOT window. * Close any window by clicking the X of THAT window. However, if (as you argue) you need the program to continue AFTER the root is closed well then, i have wonderful news for you... THAT CAN BE DONE!. You just create some logic to handle it. This is very simple ideas Steven. I am talking about CS 101 here. Do you need a tutor? > >> There > >> doesn't have to be a special "main" window that kills the > >> whole app when you close it. > > > So you prefer to close a gazillion windows one by one? > > Nonsense. Greg says nothing of the sort. > > Avoiding the anti-pattern "close a gazillion windows one by one" is why you > have an application-wide Quit or Exit command, as opposed to a Close > command which applies only to the current window. CRIKEY! That's what the ROOT window does you blankity-blank! Are you just arguing for the sake of arguing? Just because Apple removed the root-window's "window-management user-interface" (psst: that's the three buttons at the top of the root window (Minimize|Maximize|Close)) and nailed them on the desktop does not change anything. You are comparing a half dozen eggs and six eggs and then claiming them to be somehow different. There is no comparison! If i remove the steering wheel from a car and hook up some "remote- controlled" gearbox to the front wheel linkage how does that modification change anything about how the CAR itself interfaces with the road? I just simply moved around some of the interface elements from a user point of view. Someone is still driving the car; albeit from a remote location. They can go left, they can go right. And you claim that this "remote-window management user-interface" has some magical benefit over the "window-management user-interface". There is no benefit that is applicable to this argument. The only benefit in my version is driver safety, however safety is non applicable to this thread. And i would argue that as the safety of a driver increases the safety of the general public decreases due to the driver being "once removed" from the danger zone. Not that "safety" is applicable either. > > If so, why not > > just code the GUI correctly from the start; by creating separate > > transactions? Thereby reducing the number of windows a user must > > juggle? FYI: You know the user complexity of a GUI increases > > exponentially by the number of windows present. > > Don't assume that there is a one-to-one relationship between transactions > (documents?) and windows. The relationship is actually many-to-many: > windows can contain tabbed or notepad interfaces, or can be split into > multiple panes, or both. Panes and tabs can be split into independent > windows, or rejoined into one main window. Of course, and that is exactly why i suggested using a tabbed widget to an earlier confused GUI designer. > E.g. I can have six Firefox windows open, each one with many different > websites open in separate tabs. I have Close Tab, Close Window and Exit > Firefox commands. Yes. Firefox itself is the "root" window. Each tab is a transaction. What is your point? Proving yourself incorrect? > In Konquorer, not only can I have multiple windows and multiple tabs, but I > can split each tab into two or more panes, and display two views of the > same document in the same tab, or two different documents in the one tab. > This is especially useful when using it as a file manager. Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. > In older versions of Word (and possibly current, although I haven't tested > it) you can open files multiple times. Each time opens in a new window, > representing a new view of the one file. Edits in one window update all the > others. This can be useful for, e.g. making edits to page 3 while > simultaneously viewing page 303. An alternate UI for to split the one > window into two panes, and scroll them independently. So a single file may > have one or two panes, in one or more windows. [repeated from above] Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. > So, you can have multiple documents in multiple windows, and there is no 1:1 > relationship between them. [repeated from above] Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. I would argue to say that i am one of the most informed users in this group when it comes to GUI API design, GUI interface design, and GUI implementation via code. The fact that some of you wish to challenge me is quite amusing. Just admit you are wrong already. Geez! How many straw-men and David Copperfeild style misdirections are you willing to conjure in your feeble attempts to discredit me with tripe. From sridharr at activestate.com Fri Jul 8 13:32:28 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:32:28 -0700 Subject: ANN: ActivePython 2.7.2.5 is now available Message-ID: <7A37DA3F-DF69-415C-91F4-266A344E54CA@activestate.com> ActiveState is pleased to announce ActivePython 2.7.2.5, a complete, ready-to-install binary distribution of Python 2.7. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.7.2.5 ================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.7.2 (`release notes `__) - Security upgrade to openssl-0.9.8r - [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16 - Upgrade to pythonselect 1.3 which supports Windows - Upgrade to PyPM 1.3.4: - [Windows] `Bug #89474 `_: automatically expand %APPDATA%\Python\Scripts - Bug #90382: --no-ignore option to fail immediately for missing packages - Upgraded the following packages: - Distribute-0.6.19 - pip-1.0.1 - virtualenv-1.6.1 Noteworthy Changes & Bug Fixes ------------------------------ - PyPM: - Upgrade to six 1.0.0 - Bug #89540: `uninstall` command now properly removes symlinks - Bug #89648: shebang fixer skips symlinks - Include SQLAlchemy in the private area (pypm/external/{2,3}/sqlalchemy) What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From sridharr at activestate.com Fri Jul 8 13:36:07 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:36:07 -0700 Subject: ANN: ActivePython 2.6.7.20 is now available Message-ID: <9A72BB58-735D-4201-B978-168128268382@activestate.com> ActiveState is pleased to announce ActivePython 2.6.7.20, a complete, ready-to-install binary distribution of Python 2.6. http://www.activestate.com/activepython/downloads What's New in ActivePythonEE-2.6.7.20 ===================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.6.7 (`release notes `__) - Upgrade to pythonselect 1.3 which supports Windows - Upgrade to PyPM 1.3.4: - [Windows] `Bug #89474 `_: automatically expand %APPDATA%\Python\Scripts - Bug #90382: --no-ignore option to fail immediately for missing packages - Upgraded the following packages: - Distribute-0.6.19 - pip-1.0.1 - virtualenv-1.6.1 Noteworthy Changes & Bug Fixes ------------------------------ - PyPM: - Upgrade to six 1.0.0 - Bug #89540: `uninstall` command now properly removes symlinks - Bug #89648: shebang fixer skips symlinks What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From sridharr at activestate.com Fri Jul 8 13:39:34 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:39:34 -0700 Subject: ANN: ActivePython 2.5.6.10 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.5.6.10, a complete, ready-to-install binary distribution of Python 2.5. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.5.6.10 =================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.5.6 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - [Windows] Installer upgrade: automatically uninstall previous versions - Bug #87783 - [Linux] Include Tcl/Tk development files (`#40`_) - [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16 - Security upgrade to openssl-0.9.8r Noteworthy Changes & Bug Fixes ------------------------------ - [MacOSX] Fix uninstall on Snow Leopard (10.6) - Bug #87600: create a `idleX.Y` script on unix - [Windows] Renamed "python25.exe" to "python2.5.exe" (Unix like) - [Windows] Include "python2.exe" What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.5/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.5/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From salmig99 at gmail.com Fri Jul 8 15:05:03 2011 From: salmig99 at gmail.com (sal migondis) Date: Fri, 8 Jul 2011 12:05:03 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 7:45?am, Steven D'Aprano wrote: > sal migondis wrote: > > How could a belief be wrong? > I believe... Shifting from 'belief' to 'believe', the latter having a considerably wider semantic scope. After that, anything goes.. naturally. > you are a small glass of beer. Are you *actually* a small glass of > beer in reality? If so, my belief is right. If you are a human being, then > my belief is wrong. Are you a lawyer..? Sal. From ian.g.kelly at gmail.com Fri Jul 8 15:21:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jul 2011 13:21:00 -0600 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 8, 2011 at 1:05 PM, sal migondis wrote: >> I believe... > > Shifting from 'belief' to 'believe', the latter having a considerably > wider semantic scope. Wider how? Would you care to give an example of something that is believed but is not a belief? From g.rodola at gmail.com Fri Jul 8 15:22:31 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 8 Jul 2011 21:22:31 +0200 Subject: ANN: psutil 0.3.0 released Message-ID: Hi folks, I'm pleased to announce the 0.3.0 release of psutil: http://code.google.com/p/psutil === Major enhancements === * disk usage * mounted disk partitions * system per-cpu percentage utilization and times * per-process terminal * physical and virtual memory usage including percentage === New features by example === >>> import psutil >>> >>> for x in range(3): ... psutil.cpu_percent(percpu=True) ... [4.0, 34.2] [7.0, 8.5] [1.2, 9.0] >>> >>> psutil.phymem_usage() usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6) >>> psutil.virtmem_usage() usage(total=2097147904, used=4096, free=2097143808, percent=0.0) >>> >>> psutil.get_partitions() [partition(device='/dev/sda3', mountpoint='/', fstype='ext4'), partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')] >>> >>> psutil.disk_usage('/') usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) >>> >>> >>> psutil.Process(os.getpid()).terminal '/dev/pts/0' >>> Also, a new examples directory showing some examples usages: http://code.google.com/p/psutil/source/browse/#svn%2Ftrunk%2Fexamples For a complete list of features and bug fixes see: http://psutil.googlecode.com/svn/trunk/HISTORY === Links === * Home page: http://code.google.com/p/psutil * Source tarball: http://psutil.googlecode.com/files/psutil-0.3.0.tar.gz * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance. --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From bahamutzero8825 at gmail.com Fri Jul 8 16:18:37 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 08 Jul 2011 15:18:37 -0500 Subject: String concatenation vs. string formatting Message-ID: <4E17661D.6020307@gmail.com> Is it bad practice to use this > logger.error(self.preset_file + ' could not be stored - ' + > sys.exc_info()[1]) Instead of this? > logger.error('{file} could not be stored - > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) Other than the case where a variable isn't a string (format() converts variables to strings, automatically, right?) and when a variable is used a bunch of times, concatenation is fine, but somehow, it seems wrong. Sorry if this seems a bit silly, but I'm a novice when it comes to design. Plus, there's not really supposed to be "more than one way to do it" in Python. From gordon at panix.com Fri Jul 8 16:23:52 2011 From: gordon at panix.com (John Gordon) Date: Fri, 8 Jul 2011 20:23:52 +0000 (UTC) Subject: String concatenation vs. string formatting References: Message-ID: In Andrew Berg writes: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. Concatenation feels ugly/clunky to me. I prefer this usage: logger.error('%s could not be stored - %s' % \ (self.preset_file, sys.exc_info()[1])) -- 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 noway at nohow.com Fri Jul 8 16:57:09 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 16:57:09 -0400 Subject: String concatenation vs. string formatting References: Message-ID: On 07/08/2011 04:18 PM, Andrew Berg wrote: > Is it bad practice to use this >> logger.error(self.preset_file + ' could not be stored - ' + >> sys.exc_info()[1]) > Instead of this? >> logger.error('{file} could not be stored - >> {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. If it means anything, I think concatenation is faster. __TIMES__ a() - 0.09s b() - 0.09s c() - 54.80s d() - 5.50s Code is below: def a(v): out = "" for i in xrange(1000000): out += v return len(out) def b(v): out = "" for i in xrange(100000): out += v+v+v+v+v+v+v+v+v+v return len(out) def c(v): out = "" for i in xrange(1000000): out = "%s%s" % (out, v) return len(out) def d(v): out = "" for i in xrange(100000): out = "%s%s%s%s%s%s%s%s%s%s%s" % (out,v,v,v,v,v,v,v,v,v,v) return len(out) print "a", a('xxxxxxxxxx') print "b", b('xxxxxxxxxx') print "c", c('xxxxxxxxxx') print "d", d('xxxxxxxxxx') import profile profile.run("a('xxxxxxxxxx')") profile.run("b('xxxxxxxxxx')") profile.run("c('xxxxxxxxxx')") profile.run("d('xxxxxxxxxx')") From benjamin.kaplan at case.edu Fri Jul 8 17:23:08 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 8 Jul 2011 14:23:08 -0700 Subject: String concatenation vs. string formatting In-Reply-To: <4E17661D.6020307@gmail.com> References: <4E17661D.6020307@gmail.com> Message-ID: On Fri, Jul 8, 2011 at 1:18 PM, Andrew Berg wrote: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. > String formatting is the One Right Way here. It's fine to use string concatenation for a few things, but the operation is O(n^2) because each concat occurs one at a time: Python allocates space for a string the size of the first 2 things, copies the contents over. Then allocate a string the size of that string plus the third string and copy the contents over. It can get pretty slow if you're building a really big string With string formatting, Python creates a single string large enough to copy all the formatting arguements in and then copies the contents over once. Also, string formatting (especially using the new syntax like you are) is much clearer because there's less noise (the quotes all over the place and the plusses) and it's better for dealing with internationalization if you need to do that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Jul 8 17:38:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jul 2011 15:38:18 -0600 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> Message-ID: On Fri, Jul 8, 2011 at 3:23 PM, Benjamin Kaplan wrote: > String formatting is the One Right Way here.?It's fine to use string > concatenation for a few things, but?the operation is O(n^2) because each > concat occurs?one at a time: Python allocates space for a string the size of > the first 2 things, copies the contents over. Then?allocate a string the > size of that string plus the third string and copy the contents over. It can > get pretty slow if you're building a really big string?With string > formatting, Python?creates a single string large enough to copy all?the > formatting arguements in and then copies?the contents over once. This argument doesn't really fly, because a string formatting operation is typically used as an alternative for a constant number of concatenations, not O(n) concatenations. As such, either approach would be O(n) for a single instance. In the case that you do need to do O(n) concatenations, it is usually best to use a StringIO object, or to build a list and then call str.join. > Also, string formatting (especially using the new syntax like you are) is > much clearer because there's less noise (the quotes all over the place and > the plusses) and?it's better for dealing with internationalization if you > need to do that. This is the real reason to prefer string formatting over concatenation. It's also much less clutter to be able to use the %s placeholder rather than having to call str() on everything. From ben+python at benfinney.id.au Fri Jul 8 18:50:03 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 08:50:03 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <87box4ie04.fsf@benfinney.id.au> John Gordon writes: > I prefer this usage: > > logger.error('%s could not be stored - %s' % \ > (self.preset_file, sys.exc_info()[1])) That can be improved by learning two things: * The backslash-linebreak is ugly and fragile, and almost never needed, since Python knows to continue a statement if any bracketing syntax (parens, brackets, braces, triple quotes, etc.) is still open. So you can continue a statement over multiple lines by introducing some bracketing syntax at an appropriate place. In this case, you don't even need to add any bracketing syntax, since the function parens are still open. * The ?%? string formatting operator is superseded in current Python versions by the more flexible ?format? method of string objects. So: logger.error( '{0} could not be stored - {1}'.format( (self.preset_file, sys.exc_info()[1])) I usually prefer to use named placeholders instead of positional, but this duplicates your original. -- \ ?We have clumsy, sputtering, inefficient brains?. It is a | `\ *struggle* to be rational and objective, and failures are not | _o__) evidence for an alternative reality.? ?Paul Z. Myers, 2010-10-14 | Ben Finney From ben+python at benfinney.id.au Fri Jul 8 18:59:53 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 08:59:53 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <877h7sidjq.fsf@benfinney.id.au> Andrew Berg writes: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) This is not necessarily bad practice, but there are not many points in its favour. It's inflexible and makes the eventual formatting harder to discern. > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) With the caveat that the formatting of that line should be using PEP 8 indentation for clarity: logger.error( '{file} could not be stored - {error}'.format( file=self.preset_file, error=sys.exc_info()[1])) > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) If you don't specify a conversion in the placeholder, it will default to ?str?, yes. > and when a variable is used a bunch of times, concatenation is fine, I don't see any argument for concatenation there; using a variable a bunch of times works just fine with the ?format? method. > but somehow, it seems wrong. Sorry if this seems a bit silly, but I'm > a novice when it comes to design. Plus, there's not really supposed to > be "more than one way to do it" in Python. There is often more than one way to do it. The Zen of Python is explicit that there should be one obvious way to do it (and preferably only one). The ?OOW? in ?TOOWTDI? is not ?only one way?, but ?one obvious way?. The presence of multiple ways to format strings (the ?%? operator, the ?format? method) is for backward compatibility with code written before the current recommended ?format? method. Backward compatibility is a common reason for more than one way to do it in Python. It's just preferable that all but one of them should be non-obvious :-) -- \ ?The whole area of [treating source code as intellectual | `\ property] is almost assuring a customer that you are not going | _o__) to do any innovation in the future.? ?Gary Barnett | Ben Finney From drsalists at gmail.com Fri Jul 8 19:02:25 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jul 2011 16:02:25 -0700 Subject: String concatenation vs. string formatting In-Reply-To: <87box4ie04.fsf@benfinney.id.au> References: <87box4ie04.fsf@benfinney.id.au> Message-ID: On Fri, Jul 8, 2011 at 3:50 PM, Ben Finney wrote: > * The ?%? string formatting operator is superseded in current Python > versions by the more flexible ?format? method of string objects. > AFAIK, % formatting is the only kind of formatting that works portably across all of CPythons 2.5, 2.6, 2.7, 3.0, 3.1, 3.2; Pypy and Jython. So I'm still writing new code using %. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Jul 8 19:15:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 09:15:41 +1000 Subject: String concatenation vs. string formatting References: <87box4ie04.fsf@benfinney.id.au> Message-ID: <8739igicte.fsf@benfinney.id.au> Ben Finney writes: > logger.error( > '{0} could not be stored - {1}'.format( > (self.preset_file, sys.exc_info()[1])) > > I usually prefer to use named placeholders instead of positional, but > this duplicates your original. Ah, I see that the OP *did* use named placeholders. So, even better: logger.error( '{file} could not be stored - {error}'.format( file=self.preset_file, error=sys.exc_info()[1])) -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From bahamutzero8825 at gmail.com Fri Jul 8 19:29:40 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 08 Jul 2011 18:29:40 -0500 Subject: String concatenation vs. string formatting In-Reply-To: <877h7sidjq.fsf@benfinney.id.au> References: <877h7sidjq.fsf@benfinney.id.au> Message-ID: <4E1792E4.9030809@gmail.com> On 2011.07.08 05:59 PM, Ben Finney wrote: > With the caveat that the formatting of that line should be using PEP 8 > indentation for clarity: PEP 8 isn't bad, but I don't agree with everything in it. Certain lines look good in chunks, some don't, at least to me. It's quite likely I'm going to be writing 98%, if not more, of this project's code, so what looks good to me matters more than a standard (as long as the code works). Obviously, if I need to work in a team, then things change. > > and when a variable is used a bunch of times, concatenation is fine, I prefaced that sentence with "Other than the case", as in "except for the following case(s)". > There is often more than one way to do it. The Zen of Python is explicit > that there should be one obvious way to do it (and preferably only one). I meant in contrast to the idea of intentionally having multiple ways to do something, all with roughly equal merit. On 2011.07.08 04:38 PM, Ian Kelly wrote: > Also, string formatting (especially using the new syntax like you are) > is much clearer because there's less noise (the quotes all over the > place and the plusses) I don't find it that much clearer unless there are a lot of chunks. > and it's better for dealing with internationalization if you need to > do that. I hadn't thought of that. That's probably the best reason to use string formatting. Thanks, everyone. From mark at curphey.com Fri Jul 8 19:41:48 2011 From: mark at curphey.com (mark curphey) Date: Fri, 8 Jul 2011 16:41:48 -0700 Subject: CI and BDD with Python Message-ID: Moving to Python from Ruby, first time poster. Anyone any opinions (non-religious) on investing time in Lettuce (www.lettuce.it) or Freshen (https://github.com/rlisagor/freshen#readme) for their BDD ? And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? Cheers! Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From joey.zh.cn at gmail.com Fri Jul 8 20:14:29 2011 From: joey.zh.cn at gmail.com (Joey) Date: Fri, 8 Jul 2011 17:14:29 -0700 (PDT) Subject: meaning of numpy.fft coefficients Message-ID: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> the list generated by numpy is of form [ a+bi, c+di, ...] could anybody tell me the meaning of the coefficients a and b? I am very confused about fourier transform! information provided by numpy reference says Ak = Sum of a[m] * exp{-2*pi * i * m * k / n} for m from 0 to n-1 Which part is a and which part is b and what is the meaning of each part? Thx in adv. From kb1pkl at aim.com Fri Jul 8 20:52:23 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Fri, 08 Jul 2011 20:52:23 -0400 Subject: meaning of numpy.fft coefficients In-Reply-To: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> References: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> Message-ID: <1310172576-sup-7317@dalek> Excerpts from Joey's message of Fri Jul 08 20:14:29 -0400 2011: > the list generated by numpy is of form [ a+bi, c+di, ...] > > could anybody tell me the meaning of the coefficients a and b? I am > very confused about fourier transform! > a+bi is a typical complex number. a is the real part, b is the imaginary. Python uses j, >>> 4+5j (4+5j) http://en.wikipedia.org/wiki/Complex_number http://docs.python.org/library/stdtypes.html#typesnumeric -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From thorsten at thorstenkampe.de Sat Jul 9 00:23:42 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 9 Jul 2011 06:23:42 +0200 Subject: String concatenation vs. string formatting References: Message-ID: * John Gordon (Fri, 8 Jul 2011 20:23:52 +0000 (UTC)) > I prefer this usage: > > logger.error('%s could not be stored - %s' % \ > (self.preset_file, sys.exc_info()[1])) The syntax for formatting logging messages according to the documentation is: Logger.error(msg, *args) NOT Logger.error(msg % (*args)) Thorsten From stefan_ml at behnel.de Sat Jul 9 00:36:36 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 09 Jul 2011 06:36:36 +0200 Subject: CI and BDD with Python In-Reply-To: References: Message-ID: mark curphey, 09.07.2011 01:41: > And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? I warmly recommend Jenkins (i.e. Hudson) for anything CI. It gives you tons of plugins and configuration options together with full information awareness about your build status and dependencies through a nice web interface. The only reason to go native here is that it may become simpler to set up Python build and test jobs. But given that it's usually just a couple of shell commands that you write once, you'd miss more from the interface than what you gain from a quicker job setup. Stefan From steve+comp.lang.python at pearwood.info Sat Jul 9 00:41:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 14:41:45 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> <77ae91c9-b170-402a-81cf-264af825858a@e21g2000vbz.googlegroups.com> Message-ID: <4e17dc09$0$29966$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 7, 8:25?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> rantingrick wrote: >> > On Jul 7, 12:34?am, Gregory Ewing wrote: >> >> The important thing is that it's okay for an app to stay >> >> alive until its *last* top level window is closed. >> >> I partially disagree with Greg on this. This is not the only model: on >> the Apple Mac, or any system with a similar GUI design, the application >> can survive having the last window closed. There are other application >> types that don't need any window at all. > > Yeah they call those "command line" programs. Only idiots who don't understand that Graphical User Interface does not equal Window. I'm done with this conversation. Welcome to Killfile City, population rantingrick. See you in a few months. Try to have grown up by then. -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 00:44:48 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 14:44:48 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> <0c552105-dd13-40d4-8265-d06097adda18@d22g2000yqn.googlegroups.com> Message-ID: <4e17dcc0$0$29966$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: > On Jul 8, 12:42?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Phlip wrote: >> >> I worded that poorly. None is (AFAIK) the only instance of NoneType, >> >> but I should've clarified the difference.> The is operator does not >> >> compare types, it compares instances for identity. >> >> > None is typesafe, because it's strongly typed. >> >> Everything in Python is strongly typed. Why single out None? > > You do understand these cheap shots are bad for conversations, right? > > I didn't single out None. Phlip, I'm not an idiot, please don't pee on my leg and tell me it's raining. In the very sentence you quote above, you clearly and obviously single out None: "None is typesafe, because it's strongly typed." Yes, None is strongly typed -- like everything else in Python. I don't understand what point you are trying to make. Earlier you claimed that identity testing for None is type-unsafe (or at least *less* type-safe, whatever that means): "Note the fix also avoids comparing to None, which, as usual, is also icky and less typesafe!" then you say None is type-safe -- if there is a coherent message in your posts, it is too cryptic for me. > When did you stop raping your mother? What makes you think I've stopped? -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 01:12:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 15:12:39 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e17e348$0$29993$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > Is it bad practice to use this >> logger.error(self.preset_file + ' could not be stored - ' + >> sys.exc_info()[1]) > Instead of this? >> logger.error('{file} could not be stored - >> {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) Not exactly, but more or less. format() has type codes, just like % string interpolation: >>> '{0:d}'.format(1) '1' >>> '{0:d}'.format(None) Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code 'd' for object of type 'str' >>> '%d' % 1 '1' >>> '%d' % None Traceback (most recent call last): File "", line 1, in TypeError: %d format: a number is required, not NoneType If you don't give a type code, format converts any object to string (if possible). > and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. I don't like long chains of string concatenation, but short chains seem okay to me. One or two plus signs seems fine to my eyes, three at the most. Any more than that, I'd look at replacing it with % interpolation, the str.join() idiom, the string.Template class, or str.format. That's five ways of building strings. Of course, *repeated* string concatenation risks being slow -- not just a little slow, but potentially MASSIVELY slow, hundreds or thousands of times slower that alternatives. Fortunately recent versions of CPython tend to avoid this (which makes it all the more mysterious when the slow-down does strike), but other Pythons like Jython and IronPython may not. So it's best to limit string concatenation to one or two strings. And finally, if you're concatenating string literals, you can use implicit concatenation (*six* ways): >>> s = ("hello " ... "world" ... "!") >>> s 'hello world!' > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. On the contrary -- there are many different examples of "more than one way to do it". The claim that Python has "only one way" to do things comes from the Perl community, and is wrong. It is true that Python doesn't deliberately add multiple ways of doing things just for the sake of being different, or because they're cool, although of course that's a subjective judgement. (Some people think that functional programming idioms such as map and filter fall into that category, wrongly in my opinion.) In any case, it's clear that Python supports many ways of doing "the same thing", not all of which are exactly equivalent: # e.g. copy a list blist = list(alist) blist = alist[:] blist[:] = alist # assumes blist already exists blist = copy.copy(alist) blist = copy.deepcopy(alist) blist = []; blist.extend(alist) blist = [x for x in alist] # don't do this Hardly "only one way" :) -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 01:30:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 15:30:55 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > If it means anything, I think concatenation is faster. You are measuring the speed of an implementation-specific optimization. You'll likely get *very* different results with Jython or IronPython, or old versions of CPython, or even if you use instance attributes instead of local variables. It also doesn't generalise: only appends are optimized, not prepends. Worse, the optimization can be defeated by accidents of your operating system's memory management, so code that runs snappily and fast on one machine will run SLLLOOOOOOWWWWWWWWWWWWWWWLY on another. This is not a hypothetical risk. People have been burned by this in real life: http://www.gossamer-threads.com/lists/python/dev/771948 If you're interested in learning about the optimization: http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt -- Steven From ian.g.kelly at gmail.com Sat Jul 9 02:04:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Jul 2011 00:04:41 -0600 Subject: String concatenation vs. string formatting In-Reply-To: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 8, 2011 at 11:30 PM, Steven D'Aprano wrote: > Billy Mays wrote: > >> If it means anything, I think concatenation is faster. > > You are measuring the speed of an implementation-specific optimization. > You'll likely get *very* different results with Jython or IronPython, or > old versions of CPython, or even if you use instance attributes instead of > local variables. > > It also doesn't generalise: only appends are optimized, not prepends. Indeed: $ python -m timeit -s "v = 'x' * 10; out = ''" "out = out + v" 1000000 loops, best of 3: 6.59 usec per loop $ python -m timeit -s "v = 'x' * 10; out = ''" "out = v + out" 100000 loops, best of 3: 268 usec per loop Good to know. I had no idea such an optimization existed. Cheers, Ian From rosuav at gmail.com Sat Jul 9 02:16:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jul 2011 16:16:55 +1000 Subject: String concatenation vs. string formatting In-Reply-To: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 3:30 PM, Steven D'Aprano wrote: > It also doesn't generalise: only appends are optimized, not prepends. > > If you're interested in learning about the optimization: > > http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt >From that page: "Also, this is only for plain (byte) strings, not for Unicode strings; as of Python 2.4.2, Unicode string concatenation remains un-optimized." Has the same optimization been implemented for Unicode? The page doesn't mention Python 3 at all, and I would guess that the realloc optimization would work fine for both types of string. ChrisA From ian.g.kelly at gmail.com Sat Jul 9 02:29:38 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Jul 2011 00:29:38 -0600 Subject: String concatenation vs. string formatting In-Reply-To: References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 12:16 AM, Chris Angelico wrote: > Has the same optimization been implemented for Unicode? The page > doesn't mention Python 3 at all, and I would guess that the realloc > optimization would work fine for both types of string. Seems to be implemented for strs in 3.2, but not unicode in 2.7. From k.sahithi2862 at gmail.com Sat Jul 9 03:58:03 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 9 Jul 2011 00:58:03 -0700 (PDT) Subject: NEW HOT PHOTOS Message-ID: <594c3f69-2061-4ad4-b8b3-f5015e232e75@x12g2000yql.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From vinay_sajip at yahoo.co.uk Sat Jul 9 07:06:37 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 9 Jul 2011 11:06:37 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. In a logging context at least, using the form like logger.debug("formatting message with %s", "arguments") rather than logger.debug("formatting message with %s" % "arguments") means that the formatting is deferred by logging until it is actually needed. If the message never gets output because of the logging configuration in use, then the formatting is never done. This optimisation won't matter in most cases, but it will in some scenarios. By the way, logging primarily uses %-formatting instead of the newer {}-formatting, because it pre-dates {}-formatting. In more recent versions of Python, all of Python's three formatting styles are supported - see http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html Also by the way - Python doesn't say there shouldn't be more than one way to do things - just that there should be one *obvious* way (from the Zen of Python). Regards, Vinay Sajip From babedoudi at yahoo.fr Sat Jul 9 08:55:37 2011 From: babedoudi at yahoo.fr (=?ISO-8859-1?Q?R=E9mi?=) Date: Sat, 09 Jul 2011 14:55:37 +0200 Subject: HTTP Proxy : receive call on local socket takes a lot of time Message-ID: <4e184fca$0$18114$426a74cc@news.free.fr> Hi all, I am currently working on a HTTP Proxy. For maximum flexibility, I am implementing the proxy at a low level : I am using the SocketServer library. The server itself is very simple: class MyTCPServer(SocketServer.TCPServer): allow_reuse_address = 1 and the handler looks like: class MyTCPHandler(SocketServer.BaseRequestHandler): def handle(self): # Prints ip and port print "\n#### " + str(self.client_address) + " ####" requestParser = HTTPRequestParser() while True: # Get packet data = self.request.recv(4096) if data == '': break # Parse request packet if requestParser.got_new_chunk(data): break someStuff = "" self.request.send(someStuff) This is working fine, but I have a small performance issue. The proxy is targeted by Firefox. Sometimes the first receive call on the input socket takes a lot of time (up to 20s sometimes), which should not be as this is a communication of two local sockets. This is occurring maybe every 30 requests or so. When looking at the logs I noticed that this weird behavior happens when the client port is not contiguous to the previous ones. For example, handling the fourth request takes a lot of time: #### ('127.0.0.1', 49704) #### #### ('127.0.0.1', 49705) #### #### ('127.0.0.1', 49706) #### #### ('127.0.0.1', 49674) #### Do you have any idea what the problem could be ? I tried to manually close self.request request, but I still have the problem. Is it related to "allow_reuse_address = 1" ? Thanks for your help ! R?mi From jessrobe at gmail.com Sat Jul 9 14:24:30 2011 From: jessrobe at gmail.com (Jesse R) Date: Sat, 9 Jul 2011 11:24:30 -0700 (PDT) Subject: ctypes: point to buffer in structure Message-ID: Hey I've been trying to convert this to run through ctypes and i'm having a hard time typedef struct _SYSTEM_PROCESS_ID_INFORMATION { HANDLE ProcessId; UNICODE_STRING ImageName; } SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, *PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; to class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): _fields_ = [('pid', ctypes.c_ulong), ('imageName', ctypes.c_wchar_p)] processNameBuffer = ctypes.create_unicode_buffer(0x100) pidInfo = SYSTEM_PROCESS_ID_INFORMATION(pid, ctypes.byref(processNameBuffer)) status = ntdll.NtQuerySystemInformation(0x58, ctypes.byref(pidInfo), ctypes.sizeof(pidInfo), None) does anyone know how to get this working? From thinke365 at gmail.com Sat Jul 9 16:45:30 2011 From: thinke365 at gmail.com (smith jack) Date: Sun, 10 Jul 2011 04:45:30 +0800 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? Message-ID: from threading import Thread def calc(start, end): total = 0; for i in range(start, end + 1): total += i; print '----------------------result:', total return total t = Thread(target=calc, args=(1,100)) t.start() I have run this program for many times,and the result is always 5050, if there is any concurrency problem, the result should not be 5050, which is never met, anyhow I mean this program should get the wrong answer at some times, but this never happens, why? can concurrency without synchronize mechanism always get the right answer? any special case in python programming? From alex.kapps at web.de Sat Jul 9 17:17:29 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 09 Jul 2011 23:17:29 +0200 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? In-Reply-To: References: Message-ID: <4E18C569.10400@web.de> On 09.07.2011 22:45, smith jack wrote: > from threading import Thread > > def calc(start, end): > total = 0; > for i in range(start, end + 1): > total += i; > print '----------------------result:', total > return total > > t = Thread(target=calc, args=(1,100)) > t.start() > > I have run this program for many times,and the result is always 5050, > if there is any concurrency problem, the result should not be 5050, > which is never met, anyhow > I mean this program should get the wrong answer at some times, but > this never happens, why? > can concurrency without synchronize mechanism always get the right answer? > any special case in python programming? Why do you think, that there's a concurrency problem? All variables are local to the calc() function and all calc() invocations run in an own thread. No thread tries to access any shared data, so why should there be a concurrency problem? Concurrency is an issue, when two or more threads/processes try to access the same data, but in your program everything is local to the calc() function. From ericsnowcurrently at gmail.com Sat Jul 9 17:28:58 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 15:28:58 -0600 Subject: What makes functions special? Message-ID: A tracker issue [1] recently got me thinking about what makes functions special. The discussion there was regarding the distinction between compile time (generation of .pyc files for modules and execution of code blocks), [function] definition time, and [function] execution time. Definition time actually happens during compile time, but it has its own label to mark the contrast with execution time. So why do functions get this special treatment? Functions are a special case in Python for providing a more optimized execution of a code block in pure Python code. And how is that? When the function is defined, a code object is generated for the function body along with a few "static" details that will be used during execution. No other objects have code objects. No other objects in Python have this special optimization. Maybe I am missing something, or maybe it is super obvious, but isn't this a critical point? Is it just a CPython implementation detail that code objects should provide an optimization, or is it a specification of the language? From the docs, the code objects in of function objects are the latter, but the optimization expectation is not clearly indicated. Are there other motivations behind code objects that I am missing? Am I wrong about the optimization expectation? Thoughts? -eric [1] http://bugs.python.org/issue12374 From bahamutzero8825 at gmail.com Sat Jul 9 18:02:32 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 17:02:32 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> Message-ID: <4E18CFF8.1060908@gmail.com> On 2011.07.09 06:06 AM, Vinay Sajip wrote: > In a logging context at least, using the form like > > logger.debug("formatting message with %s", "arguments") > > rather than > > logger.debug("formatting message with %s" % "arguments") How would I do that with the newer formatting? I've tried: > logger.info('Binary preset file {file} successfully stored.', {file : > queue[0].preset_file}) (global name 'file' not defined) and > logger.info('Binary preset file {file} successfully stored.', > file=queue[0].preset_file) (unexpected keyword 'file') > By the way, logging primarily uses %-formatting instead of the newer > {}-formatting, because it pre-dates {}-formatting. In more recent versions of > Python, all of Python's three formatting styles are supported - see I've noticed. :-) > log_formatter = logging.Formatter('{asctime} - __main__ - {funcName} - > line {lineno} - {levelname} - {message}', style='{') From ben+python at benfinney.id.au Sat Jul 9 18:41:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 08:41:27 +1000 Subject: What makes functions special? References: Message-ID: <87sjqfgjqg.fsf@benfinney.id.au> Eric Snow writes: > A tracker issue [1] recently got me thinking about what makes > functions special. As you describe, functions are special for your scenario because a function definition needs to result in executable code as an object. > Definition time actually happens during compile time, but it has its > own label to mark the contrast with execution time. So why do > functions get this special treatment? You answer this question. > No other objects have code objects. No other objects in Python have > this special optimization. Yes. The two facts are directly related. > Maybe I am missing something, or maybe it is super obvious, but isn't > this a critical point? What is the crisis (?a stark change from one state to another?) that you're referring to by ?a critical point?? Yes, functions are different and are treated differently. What's your question? > From the docs, the code objects in of function objects are the latter, > but the optimization expectation is not clearly indicated. Are there > other motivations behind code objects that I am missing? Am I wrong > about the optimization expectation? What optimisation expectation? > Thoughts? I think yours need to be expressed more explicitly; I'm not seeing the issue that concerns you. -- \ ?The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.? ?Bill Gates, 1995-10-23 | _o__) | Ben Finney From ericsnowcurrently at gmail.com Sat Jul 9 19:16:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 17:16:19 -0600 Subject: What makes functions special? In-Reply-To: <87sjqfgjqg.fsf@benfinney.id.au> References: <87sjqfgjqg.fsf@benfinney.id.au> Message-ID: On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: > Eric Snow writes: > >> A tracker issue [1] recently got me thinking about what makes >> functions special. > > As you describe, functions are special for your scenario because a > function definition needs to result in executable code as an object. > >> Definition time actually happens during compile time, but it has its >> own label to mark the contrast with execution time. So why do >> functions get this special treatment? > > You answer this question. > >> No other objects have code objects. No other objects in Python have >> this special optimization. > > Yes. The two facts are directly related. > >> Maybe I am missing something, or maybe it is super obvious, but isn't >> this a critical point? > > What is the crisis (?a stark change from one state to another?) that > you're referring to by ?a critical point?? > > Yes, functions are different and are treated differently. What's your > question? > >> From the docs, the code objects in of function objects are the latter, >> but the optimization expectation is not clearly indicated. Are there >> other motivations behind code objects that I am missing? Am I wrong >> about the optimization expectation? > > What optimisation expectation? > >> Thoughts? > > I think yours need to be expressed more explicitly; I'm not seeing the > issue that concerns you. > My point is that functions are special in Python because they provide a built in optimization via the special execution of code objects. I would like to know if it is really that big a deal, and if the optimized execution of code objects is a CPython implementation detail or a specification of the language. -eric > -- > ?\ ? ? ? ??The reason we come up with new versions is not to fix bugs. | > ?`\ ? ? ? ? ? ? ? ? ? ? It's absolutely not.? ?Bill Gates, 1995-10-23 | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat Jul 9 20:21:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Jul 2011 17:21:28 -0700 Subject: What makes functions special? In-Reply-To: References: Message-ID: On 7/9/2011 2:28 PM, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Not true. For main modules, execution of each statement immediately follows compilation, but not for other modules, where compilation and caching of code objects may happen years before the function object is created. > Functions are a special case in Python for providing a more optimized > execution of a code block in pure Python code. And how is that? When > the function is defined, a code object is generated for the function > body along with a few "static" details that will be used during > execution. No other objects have code objects. No other objects in > Python have this special optimization. A .pyc file is a serialized code object for a module. As for the rest, I am not sure what you are asking. Terry Reedy From johnjsal at gmail.com Sat Jul 9 20:26:50 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 9 Jul 2011 17:26:50 -0700 (PDT) Subject: How can I make a program automatically run once per day? Message-ID: I have a script that does some stuff that I want to run every day for maybe a week, or a month. So far I've been good about running it every night, but is there some way (using Python, of course) that I can make it automatically run at a set time each night? From ben+python at benfinney.id.au Sat Jul 9 20:38:28 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 10:38:28 +1000 Subject: What makes functions special? References: <87sjqfgjqg.fsf@benfinney.id.au> Message-ID: <87mxgngebf.fsf@benfinney.id.au> Eric Snow writes: > On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: > > Eric Snow writes: > >> No other objects have code objects. No other objects in Python have > >> this special optimization. > > > > Yes. The two facts are directly related. [?] > > Yes, functions are different and are treated differently. What's > > your question? > > My point is that functions are special in Python because they provide > a built in optimization via the special execution of code objects. Functions are special because they define a code object. > I would like to know if it is really that big a deal Is *what* really that big a deal? Perhaps this could be clearer if you'd describe what it is that surprises you, and how you'd expect it to be different. > and if the optimized execution of code objects is a CPython > implementation detail or a specification of the language. I don't know that it's a specification. But functions result in code objects, and other statements don't; I am not seeing why treating them differently is surprising. -- \ ?I see little commercial potential for the Internet for at | `\ least ten years.? ?Bill Gates, 1994 | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Jul 9 20:40:17 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 10:40:17 +1000 Subject: How can I make a program automatically run once per day? References: Message-ID: <87iprbge8e.fsf@benfinney.id.au> John Salerno writes: > is there some way (using Python, of course) that I can make it > automatically run at a set time each night? You need to use whatever facilities your operating system has for scheduled events. That's unrelated to the language you use for implementing the program. On a Unix-like system (e.g. GNU+Linux), you could create a ?cron? job entry. -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From bahamutzero8825 at gmail.com Sat Jul 9 20:49:14 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 19:49:14 -0500 Subject: How can I make a program automatically run once per day? In-Reply-To: References: Message-ID: <4E18F70A.2010309@gmail.com> On 2011.07.09 07:26 PM, John Salerno wrote: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? I would use the OS to worry about scheduling (cron/Windows Task Scheduler/whatever), but in Python, you could probably use a while True loop, time.sleep() (to specify how often to check the time) and a datetime.time or datetime.now object (e.g. datetime.now().hour). From alex.kapps at web.de Sat Jul 9 21:00:57 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 10 Jul 2011 03:00:57 +0200 Subject: How can I make a program automatically run once per day? In-Reply-To: References: Message-ID: <4E18F9C9.8090006@web.de> On 10.07.2011 02:26, John Salerno wrote: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? Use your operating system's facilities to run timed jobs. Unix/Linux: Cron jobs Windows: Scheduled Tasks Mac: don't know, but probably Cron too From ericsnowcurrently at gmail.com Sat Jul 9 21:10:55 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 19:10:55 -0600 Subject: What makes functions special? In-Reply-To: References: Message-ID: On Sat, Jul 9, 2011 at 6:21 PM, Terry Reedy wrote: > On 7/9/2011 2:28 PM, Eric Snow wrote: >> >> A tracker issue [1] recently got me thinking about what makes >> functions special. ?The discussion there was regarding the distinction >> between compile time (generation of .pyc files for modules and >> execution of code blocks), [function] definition time, and [function] >> execution time. ?Definition time actually happens during compile time, > > Not true. For main modules, execution of each statement immediately follows > compilation, but not for other modules, where compilation and caching of > code objects may happen years before the function object is created. > So for non-main modules the function definition happens during module compilation, and for all other code blocks (__main__, exec, etc.) it happens during execution of the code block? >> Functions are a special case in Python for providing a more optimized >> execution of a code block in pure Python code. ?And how is that? ?When >> the function is defined, a code object is generated for the function >> body along with a few "static" details that will be used during >> execution. ?No other objects have code objects. ?No other objects in >> Python have this special optimization. > > A .pyc file is a serialized code object for a module. > I hadn't thought of it like that. Nice insight. In that case, do [non-main] module definition and execution time have the same logical separation as function phases do? > As for the rest, I am not sure what you are asking. > Yeah, I have a real knack for communicating. :) Mostly I am just trying to put together more pieces of the Python puzzle. In this case I was trying to find out if the optimized execution of code objects for functions is a part of the language or just an implementation detail. -eric > Terry Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > From ericsnowcurrently at gmail.com Sat Jul 9 21:28:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 19:28:02 -0600 Subject: What makes functions special? In-Reply-To: <87mxgngebf.fsf@benfinney.id.au> References: <87sjqfgjqg.fsf@benfinney.id.au> <87mxgngebf.fsf@benfinney.id.au> Message-ID: On Sat, Jul 9, 2011 at 6:38 PM, Ben Finney wrote: > Eric Snow writes: > >> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: >> > Eric Snow writes: >> >> No other objects have code objects. No other objects in Python have >> >> this special optimization. >> > >> > Yes. The two facts are directly related. > [?] > >> > Yes, functions are different and are treated differently. What's >> > your question? >> >> My point is that functions are special in Python because they provide >> a built in optimization via the special execution of code objects. > > Functions are special because they define a code object. > Right. But the point is that the code objects (in CPython at least) allow a special execution of the function body. What does that special execution give us? I am guessing a sufficient performance increase. Is there anything else? And do other Python implementations do anything special with code objects? I am not questioning why it was done a certain way, but rather trying to understand how Python works. >> I would like to know if it is really that big a deal > > Is *what* really that big a deal? > > Perhaps this could be clearer if you'd describe what it is that > surprises you, and how you'd expect it to be different. > I don't have any unexpected failure that I ran into or anything like that. I am just trying to learn more about the ins and outs of Python and that tracker issue got me thinking. And I know that there are plenty of people on this list that know a lot more about Python than I do. :) So I thought I would ask (in my own obscure way) if I was understanding the definition/execution model correctly. Sorry for any confusion. -eric >> and if the optimized execution of code objects is a CPython >> implementation detail or a specification of the language. > > I don't know that it's a specification. But functions result in code > objects, and other statements don't; I am not seeing why treating them > differently is surprising. > > -- > ?\ ? ? ? ? ??I see little commercial potential for the Internet for at | > ?`\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? least ten years.? ?Bill Gates, 1994 | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > From bruce at whealton.info Sat Jul 9 21:32:00 2011 From: bruce at whealton.info (Bruce Whealton) Date: Sat, 9 Jul 2011 21:32:00 -0400 Subject: Newbie help - Programming the Semantic Web with Python Message-ID: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Hello, So, I got this book on Programming the Semantic Web about the same time I started learning Python. The code seems to be developed for python 2.7 and not 3, I believe. The code is here: http://semprog.com/content/the-book/ I tried to run simpletriple.py from inside eclipse with PYDEV. The first thing it has a problem with is this line: def add(self, (sub, pred, obj)): I think the problem is with the parentheses before the sub. I removed those and that seemed to fix that error or make it go away. I don?t remember how I figured that out, It should be on the Errata page for sure. Then it has a problem with this line: print list(g.triples((None, None, None))) If I was using python 3, it would require () around the thing that is going to be printed, right? Maybe python 2.7 doesn?t like this line for the same reason. The book suggests that from IDLE, I can just use >>>from simplegraph import SimpleGraph That means it is going to look for a file named simplegraph.py but where will it be looking? I guess I would have to have it in the same folder as the python interpreter or one of the PATH directories, right? Thanks, Bruce ++++++++++++++++++++++++++++++++++++++++++++++++++ Bruce Whealton, Owner Future Wave Designs FOAF: http://whealton.info/BruceWhealtonJr/foaf.rdf Vcard: http://whealton.info/BruceWhealtonJr/brucewhealtonvcard.html Web Design and Development http://FutureWaveDesigns.com http://futurewavedesigns.com/wordpress/ Web Technology wiki: http://futurewavedesigns.com/w/ ++++++++++++++++++++++++++++++++++++++++++++++++++ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: wlEmoticon-smile[1].png Type: image/png Size: 1041 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Sat Jul 9 21:34:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2011 11:34:50 +1000 Subject: What makes functions special? References: Message-ID: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > Mostly I am just > trying to put together more pieces of the Python puzzle. In this case > I was trying to find out if the optimized execution of code objects > for functions is a part of the language or just an implementation > detail. You keep using that phrase, "optimized execution of code objects for functions", but I have no idea what that means. The best I can think of is that you are thinking along these lines... "Suppose we have the source code to a function: def spam(n): return "SPAM"*n To execute this, Python currently compiles the function into a code block, and then when you call spam(n) elsewhere, Python executes the already compiled code block. Suppose instead an implementation of Python did not pre-compile the function. Each time you called spam(n), the implementation would have to locate the source code and interpret it on the spot. Would that be allowed?" If that's your question, then I would call that a Python interpreter using c.1960 technology (as opposed to a byte-code compiler, which all the main implementations currently are). If that were the *only* difference, then I see no reason why it wouldn't be allowed as an implementation of Python. A horribly slow implementation, but still an implementation. However, I doubt that would be the only difference. Given such a simple-minded Python interpreter, it would be hard to provide expected Python language features such as compiled code objects, closures, etc. You would have to fake them somehow. Provided you could fake them sufficiently well, then the lack of a byte-code compiler is just a quality of implementation issue. If that's *not* your question, them I'm stumped. -- Steven From cs at zip.com.au Sat Jul 9 21:58:59 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 10 Jul 2011 11:58:59 +1000 Subject: How can I make a program automatically run once per day? In-Reply-To: <4E18F9C9.8090006@web.de> References: <4E18F9C9.8090006@web.de> Message-ID: <20110710015859.GA26678@cskk.homeip.net> On 10Jul2011 03:00, Alexander Kapps wrote: | On 10.07.2011 02:26, John Salerno wrote: | >I have a script that does some stuff that I want to run every day for | >maybe a week, or a month. So far I've been good about running it every | >night, but is there some way (using Python, of course) that I can make | >it automatically run at a set time each night? | | Use your operating system's facilities to run timed jobs. | | Unix/Linux: Cron jobs | Windows: Scheduled Tasks | Mac: don't know, but probably Cron too Yep. Macs are UNIX, BSD derived. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ USENET: Post to exotic, distant machines. Meet exciting, unusual people. And flame them. - Dan Sorenson, z1dan at exnet.iastate.edu, DoD #1066 From johnjsal at gmail.com Sat Jul 9 22:01:27 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 9 Jul 2011 19:01:27 -0700 (PDT) Subject: How can I make a program automatically run once per day? References: Message-ID: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Thanks everyone! I probably should have said something like "Python, if possible and efficient, otherwise any other method" ! :) I'll look into the Task Scheduler. Thanks again! From phlip2005 at gmail.com Sat Jul 9 22:05:25 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 19:05:25 -0700 (PDT) Subject: CI and BDD with Python References: Message-ID: On Jul 8, 9:36?pm, Stefan Behnel wrote: > mark curphey, 09.07.2011 01:41: > > > And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? I'm kind'a partial to Morelia for BDD. Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted opinion. "BDD" means "your customer gives you requirements as sentences, and you make them into executable statements." That's what Cucumber does, which Morelia learns from. And BDD and CI are orthogonal. BDD should be part of a complete TDD test suite, and your CI tool should run that. I still like CruiseControl.rb - even though it has bugs when it sees too many git integrations. Hudson had way too many features, and CCrb mildly presumes you know how to operate its .cruise/projects folder manually! From rosuav at gmail.com Sat Jul 9 22:10:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2011 12:10:31 +1000 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton wrote: problem with is this line: > ??? def add(self, (sub, pred, obj)): > I think the problem is with the parentheses before the sub.? I removed those and that seemed to fix that error or make it go away.? I don?t remember how I figured that out, ? It should be on the Errata page for sure. > Then it has a problem with this line: > ??? print list(g.triples((None, None, None))) > If I was using python 3, it would require () around the thing that is going to be printed, right?? Maybe python 2.7 doesn?t like this line for the same reason. > The issue there is with tuple unpacking. To match the older syntax, don't touch the call, but change the definition thus: def add(self, args): (sub, pred, obj)=args Or, of course, simply list the arguments directly, rather than in a tuple; but that requires changing every call (if it's a small program that may not be a problem). You're right about needing parentheses around the print() call; in Python 2 it's a statement, but in Python 3, print is a function like any other. Regarding the module search path, this may help: http://docs.python.org/dev/tutorial/modules.html#the-module-search-path Chris Angelico From ericsnowcurrently at gmail.com Sat Jul 9 22:33:10 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 20:33:10 -0600 Subject: What makes functions special? In-Reply-To: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 7:34 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> Mostly I am just >> trying to put together more pieces of the Python puzzle. ?In this case >> I was trying to find out if the optimized execution of code objects >> for functions is a part of the language or just an implementation >> detail. > > You keep using that phrase, "optimized execution of code objects for > functions", but I have no idea what that means. > > The best I can think of is that you are thinking along these lines... > > "Suppose we have the source code to a function: > > def spam(n): > ? ?return "SPAM"*n > > To execute this, Python currently compiles the function into a code block, > and then when you call spam(n) elsewhere, Python executes the already > compiled code block. > Yeah, that's pretty much it. Is that all there is to it? I was saying optimized, but I guess there isn't much special optimization going on then. Thanks for taking the time. -eric > Suppose instead an implementation of Python did not pre-compile the > function. Each time you called spam(n), the implementation would have to > locate the source code and interpret it on the spot. Would that be > allowed?" > > If that's your question, then I would call that a Python interpreter using > c.1960 technology (as opposed to a byte-code compiler, which all the main > implementations currently are). > > If that were the *only* difference, then I see no reason why it wouldn't be > allowed as an implementation of Python. A horribly slow implementation, but > still an implementation. > > However, I doubt that would be the only difference. Given such a > simple-minded Python interpreter, it would be hard to provide expected > Python language features such as compiled code objects, closures, etc. You > would have to fake them somehow. Provided you could fake them sufficiently > well, then the lack of a byte-code compiler is just a quality of > implementation issue. > > If that's *not* your question, them I'm stumped. > > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From mark at curphey.com Sat Jul 9 22:39:06 2011 From: mark at curphey.com (mark curphey) Date: Sat, 9 Jul 2011 19:39:06 -0700 Subject: CI and BDD with Python In-Reply-To: References: Message-ID: Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) over the last few days and Lettuce appears to be the most "actively" maintained and closest to a cucumber-like implementation IMHO. I have decided to adopt it for now. I played with a few CI servers but Jenkins (Hudson) is tough to beat IMHO but I am sure this is just my personal preference. Anyways thanks for the help. Cheers, Mark On Jul 9, 2011, at 7:05 PM, Phlip wrote: > On Jul 8, 9:36 pm, Stefan Behnel wrote: >> mark curphey, 09.07.2011 01:41: >> >>> And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? > > I'm kind'a partial to Morelia for BDD. > > Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted > opinion. "BDD" means "your customer gives you requirements as > sentences, and you make them into executable statements." That's what > Cucumber does, which Morelia learns from. > > And BDD and CI are orthogonal. BDD should be part of a complete TDD > test suite, and your CI tool should run that. > > I still like CruiseControl.rb - even though it has bugs when it sees > too many git integrations. Hudson had way too many features, and CCrb > mildly presumes you know how to operate its .cruise/projects folder > manually! > -- > http://mail.python.org/mailman/listinfo/python-list From bahamutzero8825 at gmail.com Sat Jul 9 22:44:47 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 21:44:47 -0500 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: <4E19121F.4010203@gmail.com> On 2011.07.09 08:32 PM, Bruce Whealton wrote: > Hello, > So, I got this book on Programming the Semantic Web about > the same time I started learning Python. The code seems to be > developed for python 2.7 and not 3, I believe. If you're going to learn Python 3, I suggest learning from a book that deals with Python 3 (if there's not an updated text for the area you're dealing with, go with something that teaches the basics). Once you have the basics down and you know the common differences, then it will be much easier to learn from a text that's based on Python 2 (you'll stumble a whole lot less when trying to learn from such texts). You'll also find some things in Python 3 that have been added to recent versions of Python 2 that the text may not cover (e.g., the old % string formatting syntax vs. the new format() string method). > If I was using python 3, it would require () around the thing that is > going to be printed, right? That's not really the right way to think of the print() function. The print statement has some very arbitrary syntax that could cause unexpected behavior if simply put in the print() function. The print function has parameters for optional behavior rather than odd syntax. In the simplest cases, print and print() are extremely similar, but print() has a bunch of functionality that is either difficult/annoying to decipher (for humans, not the interpreter) or simply doesn't exist in print. From pavlovevidence at gmail.com Sat Jul 9 22:47:08 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 9 Jul 2011 19:47:08 -0700 (PDT) Subject: What makes functions special? In-Reply-To: Message-ID: <4e9d97d9-2804-488c-8939-8221bf9a9328@glegroupsg2000goo.googlegroups.com> On Saturday, July 9, 2011 2:28:58 PM UTC-7, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Nope. Compile time and definition time are always distinct. > but it has its own label to mark the contrast with execution time. So > why do functions get this special treatment? They don't really. [snip] > Am I wrong about the optimization expectation? As best as I can tell, you are asking (in a very opaque way) why the Python compiler even bothers to create code objects, rather than just to create a function object outright, because it doesn't (you think) do that for any other kind of object. Two answers (one general, one specific): 1. You're looking for a pattern where it doesn't make any sense for there to be one. The simple truth of the matter is different syntaxes do different things, and there isn't anything more to it. A lambda expression or def statement does one thing; a different syntax, such as an integer constant, does another thing. Neither one is treated "specially"; they're just different. Consider another example: tuple syntax versus list syntax. Python will often build the tuple at compile time, but it never builds a list at compile time. Neither one is "special"; it's just that tuple syntax does one thing, list syntax does a different thing. 2. Now that we've dispensed with the idea that Python is treating functions specially, let's answer your specific question. It's not special, but still, why the code object? The reason, simply, is that code objects are used for more than just functions. Code objects are also used in modules, and in eval and exec statements, and there's one for each statement at the command line. Code objects are also used directly by the interpreter when executing byte code. A function object is only one of several "interfaces" to a code object. A minor reason is that code objects are constant (in fact, any object that is built at compile time must be a constant). However, function objects are mutable. I hope that helps clear things up. Carl Banks From pavlovevidence at gmail.com Sat Jul 9 22:47:08 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 9 Jul 2011 19:47:08 -0700 (PDT) Subject: What makes functions special? In-Reply-To: Message-ID: <4e9d97d9-2804-488c-8939-8221bf9a9328@glegroupsg2000goo.googlegroups.com> On Saturday, July 9, 2011 2:28:58 PM UTC-7, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Nope. Compile time and definition time are always distinct. > but it has its own label to mark the contrast with execution time. So > why do functions get this special treatment? They don't really. [snip] > Am I wrong about the optimization expectation? As best as I can tell, you are asking (in a very opaque way) why the Python compiler even bothers to create code objects, rather than just to create a function object outright, because it doesn't (you think) do that for any other kind of object. Two answers (one general, one specific): 1. You're looking for a pattern where it doesn't make any sense for there to be one. The simple truth of the matter is different syntaxes do different things, and there isn't anything more to it. A lambda expression or def statement does one thing; a different syntax, such as an integer constant, does another thing. Neither one is treated "specially"; they're just different. Consider another example: tuple syntax versus list syntax. Python will often build the tuple at compile time, but it never builds a list at compile time. Neither one is "special"; it's just that tuple syntax does one thing, list syntax does a different thing. 2. Now that we've dispensed with the idea that Python is treating functions specially, let's answer your specific question. It's not special, but still, why the code object? The reason, simply, is that code objects are used for more than just functions. Code objects are also used in modules, and in eval and exec statements, and there's one for each statement at the command line. Code objects are also used directly by the interpreter when executing byte code. A function object is only one of several "interfaces" to a code object. A minor reason is that code objects are constant (in fact, any object that is built at compile time must be a constant). However, function objects are mutable. I hope that helps clear things up. Carl Banks From phlip2005 at gmail.com Sat Jul 9 23:03:13 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 20:03:13 -0700 (PDT) Subject: CI and BDD with Python References: Message-ID: On Jul 9, 7:39?pm, mark curphey wrote: > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) Morelia is "undermaintained" because it's finished. It attaches to any pre-existing TestCase-style test runner, hence there's nothing to maintain! Packages like Lettuce rebuild the entire TestCase back-end just to change the front end. That forces its maintainer to then do the Red Queen thing, and constantly compete with all other test runners just to stay in place. Props for the effort, though..! From bahamutzero8825 at gmail.com Sat Jul 9 23:23:32 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 22:23:32 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E191B34.8090100@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote: > "file" is a built-in (related to "open"). It is? What is it? >>> type(file) Traceback (most recent call last): File "", line 1, in NameError: name 'file' is not defined I don't see it in the docs as a built-in function, constant or type. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGRszAAoJEPiOA0Bgp4/LAG4H/23ZZZWTEVUWDtFb28JtVKnq oIQG3aKGxHTUrvUgZqRge6KbpYhDtZFNXcknPmC6rXjVFTBb6Ag5eOCVbEq1Nu5t Ahonxy9Mr+a5URe+E4oeLvjp0ascLs2NuGxY35QFGm16jRehZ5egCnhvpMOaa1lp q+VbKWIms2xNw4eyYVfGhfGNvBJ0RXDqHfHKjPwA+oDuUNpFeTRGLrBx9T4qazw5 2+P6fmz6Y8oV3Tu9PQe8L7qksV/NrLe4rG8+sxhlpfzqTGisfKbIsYodo1uUgcdc 723hnkxz1Nh3VmUrB+JTYwYz1mD0ndHMJpkNc4JGBEoxp2lSMk1LE+1+tAlA7b4= =Gd/f -----END PGP SIGNATURE----- From benjamin.kaplan at case.edu Sat Jul 9 23:36:58 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 9 Jul 2011 20:36:58 -0700 Subject: How can I make a program automatically run once per day? In-Reply-To: <20110710015859.GA26678@cskk.homeip.net> References: <4E18F9C9.8090006@web.de> <20110710015859.GA26678@cskk.homeip.net> Message-ID: On Sat, Jul 9, 2011 at 6:58 PM, Cameron Simpson wrote: > On 10Jul2011 03:00, Alexander Kapps wrote: > | On 10.07.2011 02:26, John Salerno wrote: > | >I have a script that does some stuff that I want to run every day for > | >maybe a week, or a month. So far I've been good about running it every > | >night, but is there some way (using Python, of course) that I can make > | >it automatically run at a set time each night? > | > | Use your operating system's facilities to run timed jobs. > | > | Unix/Linux: Cron jobs > | Windows: Scheduled Tasks > | Mac: don't know, but probably Cron too > > Yep. Macs are UNIX, BSD derived. > Macs have Cron, but Apple's trying to switch away from it. They wrote their own framework to replace the various process-launching programs called launchd. It uses a pretty simple XML config file to launch programs either at startup (replacing init) or on an schedule (replacing cron). -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Jul 9 23:38:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 13:38:54 +1000 Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: Message-ID: <871uxyhkj5.fsf_-_@benfinney.id.au> Phlip writes: > On Jul 9, 7:39?pm, mark curphey wrote: > > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) > > Morelia is "undermaintained" because it's finished. It attaches to any > pre-existing TestCase-style test runner, hence there's nothing to > maintain! It looks good! But it's not yet in Debian :-( I've filed bug report #633411 to call for an interested Python programmer to package it for Debian. -- \ ?That's the essence of science: Ask an impertinent question, | `\ and you're on the way to the pertinent answer.? ?Jacob | _o__) Boronowski, _The Ascent of Man_, 1976 | Ben Finney From bahamutzero8825 at gmail.com Sun Jul 10 00:04:53 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 23:04:53 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E1924E5.8040500@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote: > "file" is a built-in (related to "open"). Also: > Traceback (most recent call last): File > "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 178, in > save_preset() File > "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 169, in > save_preset logger.info('Binary preset file {barf} successfully > stored.', barf=queue[0].preset_file) File > "C:\Python32\lib\logging\__init__.py", line 1229, in info > self._log(INFO, msg, args, **kwargs) TypeError: _log() got an > unexpected keyword argument 'barf' Is barf built-in as well? - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGSTlAAoJEPiOA0Bgp4/LfbgH/0yo5BegsXcqu3ZTyn3Src+k RJBwnIZNBOpaUS2oogiD8eILF5JonCvztKn6rPuB8uhMWzOKl+jTwf5Y4y2Y+kJ7 37v3d41Bar1vAPQ42vKSqYkQ+p1ZHG5VMjkTFH76g8Q1a82oUMTNucqIXu84an2K 8sZA223ZZqzKa7VTzxr59TNX+4EnUIoBBZGH8LATAp9ILa0cNj/TJm7UOQmRAWzC He2zkhrAERbKm9w0BR/Y9JidJ5BlgdkqY7/yNbaYucAm8aI5xgHYvqt7SrSnSFu8 3X7HBxWz2Kinanvlpb5zZEnBmESrR+PujZqS89Bo/uznipkmgZNdXYPyhO/Rbzk= =QkWp -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 00:53:34 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 23:53:34 -0500 Subject: String concatenation vs. string formatting In-Reply-To: <4E1924E5.8040500@gmail.com> References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1924E5.8040500@gmail.com> Message-ID: <4E19304E.1040607@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 11:04 PM, Andrew Berg wrote: > > Is barf built-in as well? > That came off more hostile than I wanted, so I'll rephrase it: I doubt it has anything to do with built-ins, since it fails on a variable name that obviously does not reference a built-in. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGTBOAAoJEPiOA0Bgp4/LbkcH/2GdaIXnTRbfs4/aZInlf2sJ CK3rxb5OVY2Xz8rWVyHSd5tLRcCV8+R8+Mvv0/Ho6ckZjVi3xi6LHvoVFnhUP5Iv wayXHIJEjrN2oU5DJCSBbKGdtxjAMg48UUe6c2d4UUnV05bFX31SnHfI6Jq13uhs RpLSS3vELl/XDrcNGzMpOP1z8NYt7KpwHWoAWwN2wSZ8SQnyJFcFqbapWxA165Lp btDz1ufJ0nO/td+28y8FELoAkDtwrSBHCPqokbURA6zXy7KmVeGH9nVRO08Lz5ez qRII3lTBzeI9E2X/CUMOwrfLiWYDYYvh6VWBJZifBe5B4PQe/ksVe586A1LHetM= =5Xeo -----END PGP SIGNATURE----- From phlip2005 at gmail.com Sun Jul 10 01:10:46 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 22:10:46 -0700 (PDT) Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: <871uxyhkj5.fsf_-_@benfinney.id.au> Message-ID: <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> On Jul 9, 8:38?pm, Ben Finney wrote: > Phlip writes: > > On Jul 9, 7:39?pm, mark curphey wrote: > > > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) > > > Morelia is "undermaintained" because it's finished. It attaches to any > > pre-existing TestCase-style test runner, hence there's nothing to > > maintain! > > It looks good! But it's not yet in Debian :-( Tx - I never added anything to a distro before! But..! 'sudo pip install morelia' just worked for me, on Ubuntu. I don't think a python-morelia aptitude package would add any value. Such test rigs shall never have any embedded C code or other shenanigans. If I needed to think of a feature to add, it would be P notation in the regular expressions, to then enforce the names of the matching arguments. But this is fluff; real programmers can do without it. If I worked closer to the center of the BDD thought leadership I'd know what else to add... From phlip2005 at gmail.com Sun Jul 10 01:11:26 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 22:11:26 -0700 (PDT) Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: <871uxyhkj5.fsf_-_@benfinney.id.au> Message-ID: <0922c0f1-1c3e-49fa-87d0-92d43b96f7bf@17g2000prr.googlegroups.com> > -- > ?\ ? ? ? ??That's the essence of science: Ask an impertinent question, | > ? `\ ? ? ? ? ? ?and you're on the way to the pertinent answer.? ?Jacob | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ?Boronowski, _The Ascent of Man_, 1976 | > Ben Finney That nose keeps reminding me of the start of one of the Pirates of the Caribbean movies... From ben+python at benfinney.id.au Sun Jul 10 01:21:30 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 15:21:30 +1000 Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> Message-ID: <87wrfqg17p.fsf@benfinney.id.au> Phlip writes: > 'sudo pip install morelia' just worked for me, on Ubuntu. The problem with ?pip? is that it's a parallel package installation that ignores the available package management system on the OS. That's not a fault of ?pip? or Setuptools or PyPI or the rest; but it's a higher maintenance burden for the user than getting a package from the same system that provides all the rest of their packages on the computer. On operating systems with poor package management, Python's distutils and PyPI etc. are better than nothing. But on an OS like Debian with good package management already for free software, it's a step backward to rely on external dependencies from a disjoint package system. > I don't think a python-morelia aptitude package would add any value. I think it would add great value, since without it I'm unlikely to bother using Morelia in any project. The maintenance burden is too high to keep adding dependencies that come from a distinct dependency system outside my OS. -- \ ?Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff.? ?Jack Handey | _o__) | Ben Finney From bahamutzero8825 at gmail.com Sun Jul 10 02:15:52 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 01:15:52 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E191B34.8090100@gmail.com> Message-ID: <4E194398.4040802@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 12:55 AM, Dennis Lee Bieber wrote: > Maybe it's been removed, but from the help file for my installation help(file) returns a NameError in 3.2. It shows up as a built-in function in the 2.7 docs, but not in the py3k docs. It's not mentioned in any of the "what's new" sections of the docs for any version since 2.2, though. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGUOYAAoJEPiOA0Bgp4/LS+oH/iirBETfcYYYtr3kaR/0JPMT iz4eEwCvReiXGdNE/AsIfB7aUCwlNPP+KBr3fq9e8N+a8OvM8pwGcDbYGJd92zxI atujVPZqYFWt8EfJEJBoqEmuofbnNlVdqzDaYFmrxQfXFxv2gl7wyEY1QH/udLt4 oL+zzNLgxMYGWp85Xrf/MLqqWOkp1Yk56m90oyU+DhzGnP15r/1jiQQ7/U6dydkc ZgJ09W7mZ7svOq4+pVG+rOk3UFQKEe3E1XO5nEreRp9KGwWp+qYE9XUCzxv40/Y2 WKUN3G5MJ1GvkdfeeNcf4a08mTNe1wtVJQdtUyBQzZ23eTxN0PqNZXwSkg2OIIg= =9nbT -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 02:45:15 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 01:45:15 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: Message-ID: <4E194A7B.30804@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 How should I go about switching from concatenation to string formatting for this? avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + dn_filter + fpsout_filter + trim_filter + info_filter) I can think of a few ways, but none of them are pretty. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGUp7AAoJEPiOA0Bgp4/L3koIAMntYStREGjww6yKGKE/xI0W ecAg2BHdqBxTFsPT6NMrSRyrNbdfnWRQcRi/0Z+Hhbwqp4qsz5hDFgsoVPkT5gyj 6q0TeJqaSE+Uoj5g2BofqVlWydyQ7fW34KaANbj7V71/UqXXgb+fl8TYvVRJbg0A KlfytOO0HBrDW8f6dzGZuxLxCb3EONt7buIUV3Pa7b9jQZNTTiOKktLtWAteMMiC CHivQhqzB8/cNVddpyk5LaMEDzJ9yz8a83fjuK8F5E/wrYk22t6Fad6PKgDEivaj hAiE5HMeUw+gQ7xFhJGkK31/KyHRqAaFR4mUh16u9GHMTaGPobk8NEj81LwCbvg= =g3kL -----END PGP SIGNATURE----- From stefan_ml at behnel.de Sun Jul 10 02:52:34 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 10 Jul 2011 08:52:34 +0200 Subject: Morelia for BDD in Python In-Reply-To: <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> Message-ID: Phlip, 10.07.2011 07:10: > On Jul 9, 8:38 pm, Ben Finney wrote: >> Phlip writes: >>> On Jul 9, 7:39 pm, mark curphey wrote: >> >>>> Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) >> >>> Morelia is "undermaintained" because it's finished. It attaches to any >>> pre-existing TestCase-style test runner, hence there's nothing to >>> maintain! >> >> It looks good! But it's not yet in Debian :-( > > Tx - I never added anything to a distro before! But..! > > 'sudo pip install morelia' just worked for me, on Ubuntu. I don't > think a python-morelia aptitude package would add any value. There's no "pip uninstall", though. Stefan From tjreedy at udel.edu Sun Jul 10 03:04:20 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jul 2011 00:04:20 -0700 Subject: What makes functions special? In-Reply-To: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7/9/2011 6:34 PM, Steven D'Aprano wrote: > Suppose instead an implementation of Python did not pre-compile the > function. Each time you called spam(n), the implementatio n would have to > locate the source code and interpret it on the spot. Would that be > allowed?" > > If that's your question, then I would call that a Python interpreter using > c.1960 technology (as opposed to a byte-code compiler, which all the main > implementations currently are). > > If that were the *only* difference, then I see no reason why it wouldn't be > allowed as an implementation of Python. A horribly slow implementation, but > still an implementation. while and for loops would also be terribly slow if their bodies were not compiled but were reinterpreted at the source code level for each loop. Having to reinterpred the compiled byte code for each loop does make them slower than compiled to native code C. Same as for functions. From vinay_sajip at yahoo.co.uk Sun Jul 10 03:23:12 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 10 Jul 2011 07:23:12 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > How would I do that with the newer formatting? I've tried: There are examples in the blog post I linked to earlier: http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun Jul 10 03:50:50 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 02:50:50 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E1959DA.80600@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 02:23 AM, Vinay Sajip wrote: > There are examples in the blog post I linked to earlier: It seems that would require logutils. I'm trying to keep dependencies to a minimum in my project, but I'll take a look at logutils and see if there's anything else I could use. Thanks. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGVnZAAoJEPiOA0Bgp4/LvLoH/3DL2mf7UcI/JVrrYfRmh2gb oofQzskbFrIp74U9w+8Qdxu2dmgctIk7q0S+y6jKVbc1tk1SfqQS+wAIP058ckak SDq0AoVrTSYEee+cuAvMiGHZCom2Y49mzdbXEHOOLDYZi8y3KojOJEAm0PWMdpN6 1dIpojozNOZU3V4j91E5UXV4APe8ixXrjlWNwhxqiTITrMenCG6O0LfxVvnHedTl gKvpC2Sfr2ql1+Xo7Nl6Z5jbMjFb0m8DmYaPXpS7QU6KXHOD7L6wt9+iG4H2F146 aYXukjkTXu9nwtn2s6EVn2QUyImlfzxtpd+UrpfAb0mMwItdInTKOrCwAAHSHl0= =/VOv -----END PGP SIGNATURE----- From rafadurancastaneda at gmail.com Sun Jul 10 04:49:44 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 10 Jul 2011 10:49:44 +0200 Subject: How can I make a program automatically run once per day? In-Reply-To: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Message-ID: <4E1967A8.5010006@gmail.com> On 10/07/11 04:01, John Salerno wrote: > Thanks everyone! I probably should have said something like "Python, > if possible and efficient, otherwise any other method" ! :) > > I'll look into the Task Scheduler. Thanks again! You may use Celery http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html From vinay_sajip at yahoo.co.uk Sun Jul 10 05:47:08 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 10 Jul 2011 09:47:08 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1959DA.80600@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > On 2011.07.10 02:23 AM, Vinay Sajip wrote: > > There are examples in the blog post I linked to earlier: > It seems that would require logutils. I'm trying to keep dependencies to > a minimum in my project, but I'll take a look at logutils and see if > there's anything else I could use. Thanks. You don't need logutils, just the BraceMessage class - which is shown in the blog post (around 10 lines). Feel free to use it with copy and paste :-) Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun Jul 10 06:10:02 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 05:10:02 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1959DA.80600@gmail.com> Message-ID: <4E197A7A.9040000@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 04:47 AM, Vinay Sajip wrote: > You don't need logutils, just the BraceMessage class - which is > shown in the blog post (around 10 lines). Feel free to use it with > copy and paste :-) I didn't realize that was the actual class when I first read it. Thanks. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGXp6AAoJEPiOA0Bgp4/LHhgH/2lLFrRPep9rBsmSVSc794YM w2A/e8KMTuChITTSa90WOsjqfIAkS1cvP7JWEJZ1QUqtZJMAWLhlZBaG8QuZRR2b OGBia15fzMEfHcWkNfLZ9fbZvSVZNH71YSA7bEbz5MYy+iBUcbmHI8KmQiJN1kI3 Be4uXH+l09iJBqgQKsfARzNcVxtauKylfla4/0aIWoumX6ioP+l6C+M/2iq+mYG5 w+NX1AWH2f85UT5Wlt3FcyNMP6PZHFZg+hojS4p+NVZChl7KMlJihWPSRxZNWhGp 0qf/qh9y4d1M2Kfo1C3DTDdpdL+tWWanlJ3ghXSF096/ylmytxivZ17utl3U5vA= =RQGa -----END PGP SIGNATURE----- From paul.nospam at rudin.co.uk Sun Jul 10 06:21:40 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 10 Jul 2011 11:21:40 +0100 Subject: How can I make a program automatically run once per day? References: Message-ID: <87r55y4erv.fsf@no-fixed-abode.cable.virginmedia.net> John Salerno writes: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? Well - you can make a long lived python process that puts itself to sleep for 24 hours and then wakes up and does stuff, but the normal approach to this kind of thing is to use cron. On windows there's also some kind of scheduler. From kevin.misc.10 at gmail.com Sun Jul 10 09:20:52 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Sun, 10 Jul 2011 21:20:52 +0800 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: On Fri, Jul 8, 2011 at 8:37 PM, Billy Mays wrote: > > > I recently wrote a program after reading an article ( > http://www.hackerfactor.com/**blog/index.php?/archives/432-** > Looks-Like-It.html) using the DCT method he proposes. It worked surprisingly well even with > just the 64bit hash it produces. > > The link you provided was so great. It mentioned an implementation of the hash algorithm in Python though invalid, so I spent some time writing my own version. It works really fine and kind of solved the problem of finding duplicated pictures to delete I recently came across. Thanks Billy! ps. If anyone's interested, pleas checkout the source code in the attachment and welcome any advise. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pic_seeker.py Type: application/octet-stream Size: 3992 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Sun Jul 10 09:42:48 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2011 23:42:48 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e19ac59$0$29977$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > How should I go about switching from concatenation to string formatting > for this? > > avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + > dn_filter + fpsout_filter + trim_filter + info_filter) > > I can think of a few ways, but none of them are pretty. fields = (demux_filter, field_filter, fpsin_filter, i2pfilter, dn_filter, fpsout_filter, trim_filter, info_filter) avs.write("%s"*len(fields) % fields) works for me. -- Steven From lanyjie at yahoo.com Sun Jul 10 10:21:43 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 10 Jul 2011 07:21:43 -0700 (PDT) Subject: anonymous function with multiple statements Message-ID: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> Hi all, I wonder if Python provides a way to define anonymous functions containing multiple statements? With lambda form, we can only define a function of a single expression. In Javascript, it is possible to define a full-fledged anonymous functions, which suggests it is useful to have it. In Python, it might be like this: #============== def test( fn, K ): return sum(fn(i) for i in range(K))/K test( def (i): #indent from start of this line, not from 'def' from math import sin #the last statement ends with a ',' or ')'. return sin(i)+i*i;, 100) #';' to mark end of statement #another way: test( def (i): #indent from start of this line, not from 'def' from math import sin return sin(i)+i*i , 100) #freely place ',' anywhere #=============== Any thoughts? Yingjie From roy at panix.com Sun Jul 10 10:33:08 2011 From: roy at panix.com (Roy Smith) Date: Sun, 10 Jul 2011 10:33:08 -0400 Subject: String concatenation vs. string formatting References: Message-ID: In article , Andrew Berg wrote: > How should I go about switching from concatenation to string formatting > for this? > > avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + > dn_filter + fpsout_filter + trim_filter + info_filter) > > I can think of a few ways, but none of them are pretty. The canonical way to do that would be something like fields = [demux_filter, field_filter, fpsin_filter, i2pfilter, dn_filter, fpsout_filter, trim_filter, info_filter] avs.write(''.join(fields)) From nobody at nowhere.net.no Sun Jul 10 10:50:11 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 10 Jul 2011 22:50:11 +0800 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? References: Message-ID: smith jack wrote: > have run this program for many times,and the result is always 5050 You might not need to make it in a multiprocess environment Try it in the python (3) shell >>> tot= 0 >>> for k in range(1,100): ... tot += k ... print(tot) ... And watch the risults. -- goto /dev/null From phlip2005 at gmail.com Sun Jul 10 11:00:25 2011 From: phlip2005 at gmail.com (Phlip) Date: Sun, 10 Jul 2011 08:00:25 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: <303c5739-89ae-48ba-9680-c0218b33d66e@p29g2000pre.googlegroups.com> > I think it would add great value, since without it I'm unlikely to > bother using Morelia in any project. The maintenance burden is too high > to keep adding dependencies that come from a distinct dependency system > outside my OS. pip freeze! Specifically, we already added pip freeze and virtualenv support to our project's fab file... > There's no "pip uninstall", though. I can see that would matter to projects you would want to uninstall, but not Morelia... From tjreedy at udel.edu Sun Jul 10 11:20:34 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jul 2011 08:20:34 -0700 Subject: anonymous function with multiple statements In-Reply-To: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> References: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> Message-ID: On 7/10/2011 7:21 AM, Yingjie Lan wrote: > I wonder if Python provides a way to define anonymous functions containing > multiple statements? No, intentionally not. Forget this idea. Multiple functions named '' are inferior for representation purposes, like in error tracebacks, to those with individual names. Just use def statements. Terry J. Reedy From phlip2005 at gmail.com Sun Jul 10 11:29:09 2011 From: phlip2005 at gmail.com (Phlip) Date: Sun, 10 Jul 2011 08:29:09 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> <303c5739-89ae-48ba-9680-c0218b33d66e@p29g2000pre.googlegroups.com> Message-ID: Two of my feature requests for Morelia: - integrate with the test runner (nose etc.) to provide one dot . per passing step - insert a long multi-line abstract string (typically XML) with inside [[CDATA-style escaping tags - the ability to stub a step as - the ability to pass a | delimited | table into a step as an argument containing an array, instead of unrolling the table into multiple calls to one step - a rapid conversion to an HTML report, with folding blocks, as an instant project documentation. Lack of the second option is why we _didn't_ use M for the BDD test runner on our latest project. (The onsite customer is an XML-freak, AND the lead architect until I can manage to retire him upstairs!;) But if I could put those four in, then write a disposable script that converted our XML "project definition" file back into Morelia-Cucumber- Gherkin notation, I'd have Morelia back in our project! From rantingrick at gmail.com Sun Jul 10 13:15:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 10:15:07 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> Message-ID: On Jul 4, 3:43?am, Gregory Ewing wrote: > rantingrick wrote: > > what concerns me is the fact that virtual methods in derived > > classes just blend in to the crowd. > > I think we really need some > > sort of visual cue in the form of forced syntactical notation (just > > like the special method underscores). > > If you're suggesting that it should be impossible to override > a method unless it is specially marked somehow in the base > class, I think that would be a bad idea. Sorry i did explain properly... No NOT marked in the BASE class but marked in the DERIVED class! My concerns are from a readability standpoint. Here's a naive example... class Top(object): def __init__(self): pass def m1(self): """overide""" return True def m2(self): print 'm2' def Derived(Top): def __init__(self): Top.__init__(self) def m1(self): return False My argument is this... """If class "Derived" exists in another module the reader has no idea which methods where clobbered and which were not WITHOUT being intimate with the entire code base.""" I suggest we solve this dilemma by forcing a syntax "tag" when declaring clobbering virtual functions. And if someone forgets to include the tag python would throw an exception. This has the effect of making the code MUCH easier to follow by the human readers. And it put NO constraints on the API. Also it has the added effect of warning unsuspecting programmers of name clashes that would otherwise not produce an error. > One of the principles behind the design of Eiffel is that > classes should *always* be open to modification in any way > by a subclass. The reason is that the author of a class > library can't anticipate all the ways people might want to > use it. Consequently Eiffel has no equivalent of C++'s > "private" declaration -- everything is at most "protected". > It also has no equivalent of Java's "final". Exactly! We should never put limits on what methods CAN be virtual. However, we CAN enforce a syntax that removes ambiguity from the equation. From rosuav at gmail.com Sun Jul 10 13:30:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 03:30:12 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: References: <97dcpqFdndU1@mid.individual.net> Message-ID: On Mon, Jul 11, 2011 at 3:15 AM, rantingrick wrote: > ?I suggest we solve this dilemma by forcing a syntax "tag" when > declaring clobbering virtual functions. Python has other dilemmas, too. I suggest we adopt the same solution. For instance, every statement should begin with a marker, so that we know it isn't a comment; every variable name should be adorned, so that we know it's not a keyword like 'if'; and every decimal integer should begin with "0d" so that we know it isn't hex. Plus, we should get rid of binary operators with their messy precedence tables; everything should become function calls. $assign($x,$add(0d5,0d7)) # assigns 12 (decimal) to x This would make Python far less ambiguous. We should proceed with this right away. ChrisA From tim at johnsons-web.com Sun Jul 10 13:41:21 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 09:41:21 -0800 Subject: Function docstring as a local variable Message-ID: <20110710174121.GB12935@johnsons-web.com> Consider the following: ## code def test(): """This is my docstring""" print(??) ## can I print the docstring above? ## /code It possible for a function to print it's own docstring? thanks (pointers to docs could be sufficient) -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From rantingrick at gmail.com Sun Jul 10 13:44:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 10:44:30 -0700 (PDT) Subject: Function docstring as a local variable References: Message-ID: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> On Jul 10, 12:41?pm, Tim Johnson wrote: > It possible for a function to print it's own docstring? def f(): """docstring""" print "docstring" any questions? From rustompmody at gmail.com Sun Jul 10 13:45:01 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 10 Jul 2011 10:45:01 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: On Jul 10, 10:21?am, Ben Finney wrote: > Phlip writes: > > 'sudo pip install morelia' just worked for me, on Ubuntu. > > The problem with ?pip? is that it's a parallel package installation that > ignores the available package management system on the OS. > > That's not a fault of ?pip? or Setuptools or PyPI or the rest; but it's > a higher maintenance burden for the user than getting a package from the > same system that provides all the rest of their packages on the > computer. > > On operating systems with poor package management, Python's distutils > and PyPI etc. are better than nothing. But on an OS like Debian with > good package management already for free software, it's a step backward > to rely on external dependencies from a disjoint package system. Just curious: Do you manage to stay within debian packages and have all the python packages you want/need at the versions that are most convenient? For myself, until recently my debian testing did not even give python2.7. From bahamutzero8825 at gmail.com Sun Jul 10 13:47:17 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 12:47:17 -0500 Subject: Function docstring as a local variable In-Reply-To: <20110710174121.GB12935@johnsons-web.com> References: <20110710174121.GB12935@johnsons-web.com> Message-ID: <4E19E5A5.5020905@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 12:41 PM, Tim Johnson wrote: > It possible for a function to print it's own docstring? >>> def test(): ... """Hi there.""" ... print(test.__doc__) ... >>> test() Hi there. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGeWlAAoJEPiOA0Bgp4/LT1EIAM32NS/RdZ9y6IlAkpEYkYeP qGf2A/+8eZHrSYtCWYWwpfusa9guYaQsDvq31sFHnI3VPria7mUeB6HoyqP1sO3B 5D0lpBK0/u3rWNL9FHeWeb+Cc6CLXBB7531VAR1pzfUVb1mw3LPww16klNMkr5Gd 9Qob710lKIW+om8rEF+L5o/DOFSTN7oodTsNpdj8zhHVnPVpV/gtL7iQR82C0KPq UuukVkCuhvYyWoJMz1qDZjKU1bI2T064TC8IeOQLdOVMnQLhTJdgsHD4nNVszixN EU9eemscW0cABF2MgUPnuJLytUJHcxtEC4aj3Cue0oLhMyVN57yNIBaf1Pm6M7E= =tCFP -----END PGP SIGNATURE----- From rosuav at gmail.com Sun Jul 10 14:11:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 04:11:14 +1000 Subject: Function docstring as a local variable In-Reply-To: <4E19E5A5.5020905@gmail.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: On Mon, Jul 11, 2011 at 3:47 AM, Andrew Berg wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: RIPEMD160 > > On 2011.07.10 12:41 PM, Tim Johnson wrote: >> It possible for a function to print it's own docstring? >>>> def test(): > ... ? ? """Hi there.""" > ... ? ? print(test.__doc__) That's assuming that it knows its own name, and that that name hasn't been rebound. Is there a way for a function to find its own self? >>> def findself(): """Find myself. Ooh look, there I am!""" import sys try: 1/0 except: traceback=sys.exc_info()[2] # Now I'm not sure what to do with traceback. # traceback.tb_frame.f_code.co_name is the function name ("findself"). # Is there a way to get the function object? I'm kinda half-way there, but I've never worked with traceback objects. Someone will know, I'm sure! ChrisA ChrisA From bruce at whealton.info Sun Jul 10 15:28:40 2011 From: bruce at whealton.info (Bruce Whealton) Date: Sun, 10 Jul 2011 15:28:40 -0400 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <4E19121F.4010203@gmail.com> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> <4E19121F.4010203@gmail.com> Message-ID: <5DF6A565818746A89E82DC7D3375C181@BrucePC> Thanks for the tips. I actually had done some studies with Python, mainly Python 3, back about 6 months ago and over a period of a few months. I didn't write a great deal of programs though, at the time. I got away from it in a while and I didn't want to go back to step one of being like a total beginner. There are so many things I try to keep up with as a Web Developer and coder and trying to expand my skills. Unfortunately, I don't do well with picking a focus. I remember reading through this long reference manual, called "Learning Python," while I was on a flight and over a trip. That was without a computer, so I was just reading, which is not the way to learn programming, obviously. I feel the many concepts will come back to me fast. I have another text, called "Beginning Python: From Novice to Professional" which covers Python 3. This is a bit more practical in orientation. I'm debating whether to jump to the chapters dealing with the web and see what I can do or starting from the beginning. I did look into some online training, tutorials, or the like. The Programming the Semantic Web book uses Python but all the code is included. So, while it won't be a way to learn python, I hope I can get the code to run correctly. In that text, they must be using Python 2.7 because I see print statements and not the print function call. If you know of any good resources for finding python applications on the web, this might be a good way to learn. I don't know if I should look for Python applications, or if I'll have more luck looking for Python Libraries. Thanks, Bruce -----Original Message----- From: Andrew Berg Sent: Saturday, July 09, 2011 10:44 PM To: comp.lang.python Subject: Re: Newbie help - Programming the Semantic Web with Python On 2011.07.09 08:32 PM, Bruce Whealton wrote: > Hello, > So, I got this book on Programming the Semantic Web about > the same time I started learning Python. The code seems to be > developed for python 2.7 and not 3, I believe. If you're going to learn Python 3, I suggest learning from a book that deals with Python 3 (if there's not an updated text for the area you're dealing with, go with something that teaches the basics). Once you have the basics down and you know the common differences, then it will be much easier to learn from a text that's based on Python 2 (you'll stumble a whole lot less when trying to learn from such texts). You'll also find some things in Python 3 that have been added to recent versions of Python 2 that the text may not cover (e.g., the old % string formatting syntax vs. the new format() string method). > If I was using python 3, it would require () around the thing that is > going to be printed, right? That's not really the right way to think of the print() function. The print statement has some very arbitrary syntax that could cause unexpected behavior if simply put in the print() function. The print function has parameters for optional behavior rather than odd syntax. In the simplest cases, print and print() are extremely similar, but print() has a bunch of functionality that is either difficult/annoying to decipher (for humans, not the interpreter) or simply doesn't exist in print. -- http://mail.python.org/mailman/listinfo/python-list From tim at johnsons-web.com Sun Jul 10 16:34:36 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 12:34:36 -0800 Subject: Function docstring as a local variable In-Reply-To: <4E19E5A5.5020905@gmail.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: <20110710203436.GC12935@johnsons-web.com> * Andrew Berg [110710 09:59]: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: RIPEMD160 > > On 2011.07.10 12:41 PM, Tim Johnson wrote: > > It possible for a function to print it's own docstring? > >>> def test(): > ... """Hi there.""" > ... print(test.__doc__) Holy Moly. Of course! thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From tyler at tysdomain.com Sun Jul 10 16:59:29 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 10 Jul 2011 14:59:29 -0600 Subject: parsing packets Message-ID: <4E1A12B1.8060205@tysdomain.com> Hello all: I'm working on a server that will need to parse packets sent from a client, and construct it's own packets. The setup is something like this: the first two bytes is the type of the packet. So, lets say we have a packet set to connect. There are two types of connect packet: a auth packet and a connect packet. The connect packet then has two bytes with the type, another byte that notes that it is a connect packet, and 4 bytes that contains the version of the client. The auth packet has the two bytes that tells what packet it is, one byte denoting that it is an auth packet, then the username, a NULL character, and a password and a NULL character. With all of this said, I'm kind of curious how I would 1) parse out something like this (I am using twisted, so it'll just be passed to my Receive function), and how I get the length of the packet with multiple NULL values. I'm also looking to build a packet and send it back out, is there something that will allow me to designate two bytes, set individual bits, then put it altogether in a packet to be sent out? -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 My programs don't have bugs; they're randomly added features! From chardster at gmail.com Sun Jul 10 17:16:05 2011 From: chardster at gmail.com (Richard Thomas) Date: Sun, 10 Jul 2011 14:16:05 -0700 (PDT) Subject: Function docstring as a local variable References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: > >>> def findself(): > > ? ? ? ? """Find myself. Ooh look, there I am!""" > ? ? ? ? import sys > ? ? ? ? try: > ? ? ? ? ? ? ? ? 1/0 > ? ? ? ? except: > ? ? ? ? ? ? ? ? traceback=sys.exc_info()[2] > ? ? ? ? # Now I'm not sure what to do with traceback. > ? ? ? ? # traceback.tb_frame.f_code.co_name is the function name ("findself"). > ? ? ? ? # Is there a way to get the function object? I'm pretty sure there isn't. I've tried a number of times before to find it but failed. Fundamentally frame objects don't need to know about functions. Functions are just one way of wrapping code objects but sometimes code objects come in modules. You can use sys._getframe() to get the current frame instead of the traceback. Richard From debatem1 at gmail.com Sun Jul 10 17:34:10 2011 From: debatem1 at gmail.com (geremy condra) Date: Sun, 10 Jul 2011 17:34:10 -0400 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > The setup is something like this: the first two bytes is the type of the > packet. > So, lets say we have a packet set to connect. There are two types of connect > packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that notes > that it is a connect packet, and 4 bytes that contains the version of the > client. > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, and > a password and a NULL character. > > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), and how I get the length of the packet with multiple NULL > values. I'm also looking to build a packet and send it back out, is there > something that will allow me to designate two bytes, set individual bits, > then put it altogether in a packet to be sent out? Just use the struct module[0] to do your packing for you. There's not enough info in your description to write it out for you, but it sounds like it should do everything you need. Geremy Condra [0]: http://docs.python.org/library/struct.html From bahamutzero8825 at gmail.com Sun Jul 10 17:45:57 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 16:45:57 -0500 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <5DF6A565818746A89E82DC7D3375C181@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> <4E19121F.4010203@gmail.com> <5DF6A565818746A89E82DC7D3375C181@BrucePC> Message-ID: <4E1A1D95.1040702@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 02:28 PM, Bruce Whealton wrote: > If you know of any good resources for finding python applications on > the web, this might be a good way to learn. I don't know if I > should look for Python applications, or if I'll have more luck > looking for Python Libraries. Tutorials and simple code examples are the best way to learn (walk before you run). If you tried to study the standard libraries (or any but the simplest libraries on PyPI), you'd get lost. Studying the standard libraries would probably be a good way to learn good design once you have a great command of the language. Of course, actually doing a project to solve a real problem is probably the best way to learn once you have the basics down (I'm learning a lot doing my first Python project). - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGh2VAAoJEPiOA0Bgp4/LIjoIAOaAnLWpPwRvwZm2VxhnA5CY dNEJvEU4DyCvqKBOQ5Eh0NKgK7M81+sibgqsIqKLzIdUdK9io7zVQ+mYfS0h40TO WzYOTX54Tx1d9w9K2/UWNAz+csWJ06TSsHDDVmhQ1JdHAhWz9EM4RzSt96RtdHsc 1dh/UtWTpn6Fm+9o2nIJ/471ZwtxAjOENprrC8SGchRT9mxlNvOyWe9+N3xr/g6l qqGHHqSfazQU1wqbEbyvQxB0CsJ5kVVm764c0a1tkiVcGT6o+e93zB1tm0Di4KNe gbDXVHtfo5jQIKCs8utt0a+m4IMzuU182MLz05ngWIQxIbhHW/zBNfw2pMxRxBA= =RFgH -----END PGP SIGNATURE----- From ben+python at benfinney.id.au Sun Jul 10 17:57:21 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 07:57:21 +1000 Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: <87hb6tg5oe.fsf@benfinney.id.au> rusi writes: > Just curious: Do you manage to stay within debian packages and have > all the python packages you want/need at the versions that are most > convenient? When that's not the case, I consider it not a status quo to live with, but a problem to be addressed. -- \ ?I cannot conceive that anybody will require multiplications at | `\ the rate of 40,000 or even 4,000 per hour ?? ?F. H. Wales, 1936 | _o__) | Ben Finney From egriffith92 at gmail.com Sun Jul 10 18:06:37 2011 From: egriffith92 at gmail.com (Eric) Date: Sun, 10 Jul 2011 18:06:37 -0400 Subject: A beginning programmer Message-ID: Greetings everyone; Fresh High School graduate here with a passion for problem solving. My last 2 years of HS I took programming courses (actually fairly good ones; yay for good tech departments) that showed me QuickBasic VisualBasic C++ Java (in that order) A friend of mine often talked about how nice Python was and being an xkcd fan, i saw Python come up alot in the jokes. Python's awesome; I see limitless possibilities in a very easy to understand and use language that as xkcd put it "Programmings fun again!" My problem is this though... I don't know what to do with this new found knowledge of these languages. I'm a linux user so availability of development tools is haaaaaaardly a problem. But I just don't know what to do with it, I don't have any problems that need to be solved and unfortunately I'm not familar enough with the languages (except maybe c++) to help out the big projects like KDE / Gnome. I realize this is the python mailing list and that I brought up some non-python languages but I'm sure my situation is hardly new for those looking to get into programming but having no idea of where to begin. Any feedback is much appreciated! -Eric- From python at bdurham.com Sun Jul 10 18:13:29 2011 From: python at bdurham.com (python at bdurham.com) Date: Sun, 10 Jul 2011 18:13:29 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <20110710174121.GB12935@johnsons-web.com><4E19E5A5.5020905@gmail.com> Message-ID: <1310336009.20776.2150240761@webmail.messagingengine.com> I'm not sure how a function can get a generic handle to itself, but if you're willing to hardcode the function name, then this technique works: def test(): """This is my doc string""" print test.__doc__ test() Outputs: This is my doc string Malcolm From t at jollybox.de Sun Jul 10 18:22:38 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 00:22:38 +0200 Subject: A beginning programmer In-Reply-To: References: Message-ID: <4E1A262E.5040108@jollybox.de> On 07/11/2011 12:06 AM, Eric wrote: > My problem is this though... I don't know what to do with this new > found knowledge of these languages. I'm a linux user so availability > of development tools is haaaaaaardly a problem. But I just don't know > what to do with it, I don't have any problems that need to be solved > and unfortunately I'm not familar enough with the languages (except > maybe c++) to help out the big projects like KDE / Gnome. Open source bug trackers are a great source of problems. Take an open source program you like, ideally one with a sizeable and active user base, written in a programming language you're comfortable with, check out an open bug, and try solving it. This will * Get you reading other people's code. You can learn a lot from this * Provide a challenge * Do good CPython itself is a great project to have a go at. I don't know how familiar you are with C (as opposed to C++), but a large part of the code is written in Python, there's loads of activity on the bug tracker, and, in my experience, the community is very happy to help along new people contributing their first patch. Cheers, Thomas From bahamutzero8825 at gmail.com Sun Jul 10 18:24:46 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 17:24:46 -0500 Subject: A beginning programmer In-Reply-To: References: Message-ID: <4E1A26AE.4090401@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 05:06 PM, Eric wrote: > But I just don't know what to do with it You and I are quite different. I don't enjoy programming much, but Python is a great tool to accomplish a few goals that I have. > I don't have any problems that need to be solved and unfortunately > I'm not familar enough with the languages (except maybe c++) to help > out the big projects like KDE / Gnome. The KDE for Windows project is really struggling. You could help there with your C++ skills. > I realize this is the python mailing list and that I brought up some > non-python languages but I'm sure my situation is hardly new for > those looking to get into programming but having no idea of where to > begin. I could use some help on my project, but two inexperienced coders are going to be slower than one. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGiatAAoJEPiOA0Bgp4/LqxkH/1fbq+m0uyQDAV38mJq861HC a4r3XZAka5BbGqIF753LRMzPdd31RpTiv+AUWtF7/AUVE+b0UsHaBDvyVvSBRcw9 XGwXUOy9WWtpeGS5CaKyJumMJStzzhCGetKeX+86F7RB6XgiBOCAFuaH4NRCpkYb 4y+Kg+0FqzYJk/lW9J/ZsoqyIbloet7zDC1EkrmwsfsodoTqL/NqRW4MY0u9PzU3 HTg2hBshj8EGe1wLG1DHxR7q/T88GuQZq7f6dYjwLmyljzs21cIj+Dn2d7nhbPpi KwszNCpENbn4fssUh+xca71kd4S2zWEkxz0gLkVPdsuVffWKkLgrY8flnqVuXQk= =NFjK -----END PGP SIGNATURE----- From cjw at ncf.ca Sun Jul 10 18:28:15 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 10 Jul 2011 18:28:15 -0400 Subject: Function docstring as a local variable In-Reply-To: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: On 10-Jul-11 13:44 PM, rantingrick wrote: > On Jul 10, 12:41 pm, Tim Johnson wrote: >> It possible for a function to print it's own docstring? > > def f(): > """docstring""" > print "docstring" > > any questions? Try: def f(): ds= """docstring""" print ds > Colin W. From roy at panix.com Sun Jul 10 18:41:51 2011 From: roy at panix.com (Roy Smith) Date: Sun, 10 Jul 2011 18:41:51 -0400 Subject: Function docstring as a local variable References: <20110710174121.GB12935@johnsons-web.com> Message-ID: In article , python at bdurham.com wrote: > I'm not sure how a function can get a generic handle to itself, but if > you're willing to hardcode the function name, then this technique works: > > def test(): > """This is my doc string""" > print test.__doc__ > > test() > > Outputs: > > This is my doc string > > Malcolm I'm sure there has to be a cleaner way that this, but one possible way for a function to find its name is to catch an exception and look at the traceback: --------------------------------------- #!/usr/bin/env python import sys import traceback def foo(): "The Larch" try: raise Exception except Exception, ex: _, _, tb = sys.exc_info() stacks = traceback.extract_tb(tb) file_name, line_number, function_name, text = stacks[0] print "I am %s", function_name print "My docstring is", eval(function_name).__doc__ foo() -------------------------------------- This works, but yuck. From t at jollybox.de Sun Jul 10 18:42:16 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 00:42:16 +0200 Subject: A beginning programmer In-Reply-To: <4E1A262E.5040108@jollybox.de> References: <4E1A262E.5040108@jollybox.de> Message-ID: <4E1A2AC8.2070604@jollybox.de> On 07/11/2011 12:22 AM, Thomas Jollans wrote: > On 07/11/2011 12:06 AM, Eric wrote: >> My problem is this though... I don't know what to do with this new >> found knowledge of these languages. I'm a linux user so availability >> of development tools is haaaaaaardly a problem. But I just don't know >> what to do with it, I don't have any problems that need to be solved >> and unfortunately I'm not familar enough with the languages (except >> maybe c++) to help out the big projects like KDE / Gnome. > > Open source bug trackers are a great source of problems. Take an open > source program you like, ideally one with a sizeable and active user > base, written in a programming language you're comfortable with, check > out an open bug, and try solving it. This will > * Get you reading other people's code. You can learn a lot from this > * Provide a challenge > * Do good Do note: Maybe you won't be able to create quality patches at first. But you'll familiarize yourself with the language (and project) in time, and if you follow a bug on a bug tracker, you can, when somebody else has fixed it, study their patch as well. It's like a puzzle ;-) As Andrew pointed out, KDE is written in C++. So you might want to check that out. > > CPython itself is a great project to have a go at. I don't know how > familiar you are with C (as opposed to C++), but a large part of the > code is written in Python, there's loads of activity on the bug tracker, > and, in my experience, the community is very happy to help along new > people contributing their first patch. > > Cheers, > Thomas From steve+comp.lang.python at pearwood.info Sun Jul 10 18:48:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2011 08:48:29 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e1a2c3e$0$29966$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > The canonical way to do that would be something like > > fields = [demux_filter, > field_filter, > fpsin_filter, > i2pfilter, > dn_filter, > fpsout_filter, > trim_filter, > info_filter] > avs.write(''.join(fields)) I can't believe I didn't think of that. I must be getting sick. (The sore throat, stuffy nose and puffy eyes may also be a sign.) Yes, ''.join() is far to be preferred over my solution using "%s". -- Steven From tim at johnsons-web.com Sun Jul 10 18:50:18 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 14:50:18 -0800 Subject: Function docstring as a local variable In-Reply-To: <1310336009.20776.2150240761@webmail.messagingengine.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> <1310336009.20776.2150240761@webmail.messagingengine.com> Message-ID: <20110710225018.GD12935@johnsons-web.com> * python at bdurham.com [110710 14:17]: > I'm not sure how a function can get a generic handle to itself, but if > you're willing to hardcode the function name, then this technique works: > > def test(): > """This is my doc string""" > print test.__doc__ > > test() Works for me. Works for the application I'm after. thanks Here's a related question: I can get the docstring for an imported module: >>> import tmpl as foo >>> print(foo.__doc__) Python templating features Author - tim at akwebsoft dot com ## Is it possible to get the module docstring ## from the module itself? Thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From ikljaic at gmail.com Sun Jul 10 18:50:31 2011 From: ikljaic at gmail.com (Ivan Kljaic) Date: Sun, 10 Jul 2011 15:50:31 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python Message-ID: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Ok Guys. I know that most of us have been expiriencing the need for a nice Gui builder tool for RAD and most of us have been googling for it a lot of times. But seriously. Why is the not even one single RAD tool for Python. I mean what happened to boa constructor that it stopped developing. I simply do not see any reasons why there isn't anything. Please help me understand it. Any insights? From pavlovevidence at gmail.com Sun Jul 10 18:59:02 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 10 Jul 2011 15:59:02 -0700 (PDT) Subject: Function docstring as a local variable In-Reply-To: Message-ID: On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > Here's a related question: > I can get the docstring for an imported module: > >>> import tmpl as foo > >>> print(foo.__doc__) > Python templating features > > Author - tim at akwebsoft dot com > > ## Is it possible to get the module docstring > ## from the module itself? print __doc__ Carl Banks From kb1pkl at aim.com Sun Jul 10 19:00:11 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:00:11 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <1310338587-sup-7938@dalek> Excerpts from Colin J. Williams's message of Sun Jul 10 18:28:15 -0400 2011: > Try: > > def f(): > ds= """docstring""" > print ds That doesn't actually make a docstring, though. It makes a string object and points the name ds at it. Do you know what a docstring is? def foo(): """I am a docstring""" pass def bar(): ds = "I am not a docstring!" def baz(): "I am a docstring too!" pass def qux(): 'And even me! Quote type don't matter (besides style)' pass -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From kb1pkl at aim.com Sun Jul 10 19:03:47 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:03:47 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310338946-sup-2322@dalek> Excerpts from Ivan Kljaic's message of Sun Jul 10 18:50:31 -0400 2011: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? What is RAD? If you're just looking for a GUI builder there's Glade for gtk, wxGlade for wxWidgets, QtCreator (And something new for their newer system, don't remember the name), etc. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From kb1pkl at aim.com Sun Jul 10 19:06:27 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:06:27 -0400 Subject: Function docstring as a local variable In-Reply-To: References: Message-ID: <1310339164-sup-5162@dalek> Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > print __doc__ > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def foo(): ... "Docstring" ... print __doc__ ... >>> foo() None >>> What does yours do? -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From python.list at tim.thechases.com Sun Jul 10 19:14:53 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 10 Jul 2011 18:14:53 -0500 Subject: Function docstring as a local variable In-Reply-To: <20110710225018.GD12935@johnsons-web.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> <1310336009.20776.2150240761@webmail.messagingengine.com> <20110710225018.GD12935@johnsons-web.com> Message-ID: <4E1A326D.3050107@tim.thechases.com> On 07/10/2011 05:50 PM, Tim Johnson wrote: > * python at bdurham.com [110710 14:17]: >> def test(): >> """This is my doc string""" >> print test.__doc__ >> test() > > Works for me. Works for the application I'm after. thanks > Here's a related question: > ## Is it possible to get the module docstring > ## from the module itself? You're gonna kick yourself :) print __doc__ -tkc From bahamutzero8825 at gmail.com Sun Jul 10 19:24:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 18:24:33 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: Message-ID: <4E1A34B1.5010205@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 09:33 AM, Roy Smith wrote: > The canonical way to do that would be something like > > fields = [demux_filter, field_filter, fpsin_filter, i2pfilter, > dn_filter, fpsout_filter, trim_filter, info_filter] > avs.write(''.join(fields)) That would look really awful (IMO) if the strings weren't intended to be on separate lines (I use embedded newlines instead of joining them with newlines in order to prevent blank lines whenever a certain filter isn't used). In this particular case, they are, so even though it uses a lot of whitespace, it does match the layout of its output. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGjSxAAoJEPiOA0Bgp4/LHzcH+gKeSCkbdEh8jg2UV0vICJdS Fea95/vqCbZkjQxSuW8L73CpoACiv4XQ6hoxyIUq7maf+W89rGMVmLsPWYXtmif9 FV6WM3kSpg4hoC1cbqGW5g1bnpMnSPlznm74mKtdGhF+3zEtlm9+j8m53362YQHc 0Y9D+4KAeee5QUT/NII5QBRvSG2rAuv5+sayMNayix0pCJLEGrRLp/7LJOyhvJLN eDdywE+svfcQAi4iGAylrmvDfgf6pBgysyY/pv2YD9IpdpYL5mkVqLi+ADZdZBOb M4uxBReowgC/RaWxB+qEvfg5AxWmfg4uCtAl48Z/Jv/uYR9d9jeHAlbuV2xPfnk= =wRB5 -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 19:27:53 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 18:27:53 -0500 Subject: Function docstring as a local variable In-Reply-To: <1310339164-sup-5162@dalek> References: <1310339164-sup-5162@dalek> Message-ID: <4E1A3579.2050500@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 06:06 PM, Corey Richardson wrote: > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) [GCC 4.4.5] on > linux2 Type "help", "copyright", "credits" or "license" for more > information. >>>> def foo(): > ... "Docstring" ... print __doc__ ... >>>> foo() > None I get the same result with Python 3.2. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGjV5AAoJEPiOA0Bgp4/LF2YH/jaEjS6sFuwekVG0cKyjnx/z 8j28OHB9mklXg6oEMSsypU5dVPst2a6fmEHm+sXPYgQHZ9tk0oun+xxmdldNyV8h knfFVgMC5ww1Q7gLkPWzY8me3k4YcokYGhsuwXEGBvPby4M4ZC5uyetKTzVWp+uH sO11DPBaaXzGj7E7wu+HbfWsvPxw9h9jfJ7ihjhHNSUiL3MkGEqlxK8Pw2o3cw1e sCY7XWm1x8qClJLrwwxnB7pfuOfNJ6aS3xLd8FFs4hRp1J9W+z4on91XZooa5kT+ UEfkrzppOjw1UNA1etxIGmJQ+/qrKSGg5Nmc4jHXNfwIZCECHuWxEqaL5e0WdHU= =5gdS -----END PGP SIGNATURE----- From mhrivnak at hrivnak.org Sun Jul 10 19:33:38 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Sun, 10 Jul 2011 19:33:38 -0400 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: In order to find the end of the packet, include a field that is the packet length. This is what IP packets do to find the end of their header. http://en.wikipedia.org/wiki/IPv4#Header And the TCP header (see "data offset") does the same: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure Of course in both cases they are specifying the header length, not including a data payload. However, it sounds like you might not have a payload, so your entire packet might consist of header-like data. Michael On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > The setup is something like this: the first two bytes is the type of the > packet. > So, lets say we have a packet set to connect. There are two types of connect > packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that notes > that it is a connect packet, and 4 bytes that contains the version of the > client. > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, and > a password and a NULL character. > > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), and how I get the length of the packet with multiple NULL > values. I'm also looking to build a packet and send it back out, is there > something that will allow me to designate two bytes, set individual bits, > then put it altogether in a packet to be sent out? > > -- > > Take care, > Ty > my website: > http://tds-solutions.net > my blog: > http://tds-solutions.net/blog > skype: st8amnd127 > My programs don't have bugs; they're randomly added features! > > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Sun Jul 10 19:48:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 09:48:46 +1000 Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <87d3hhg0ip.fsf@benfinney.id.au> "Colin J. Williams" writes: > On 10-Jul-11 13:44 PM, rantingrick wrote: > > On Jul 10, 12:41 pm, Tim Johnson wrote: > >> It possible for a function to print it's own docstring? > > > > def f(): > > """docstring""" > > print "docstring" > > Try: > > def f(): > ds= """docstring""" > print ds The OP wants the function to print its own docstring, which your example does not do. You've defined a function with an empty docstring. >>> def foo(): ... ds = "The Larch" ... print ds ... >>> foo.__doc__ >>> -- \ ?Firmness in decision is often merely a form of stupidity. It | `\ indicates an inability to think the same thing out twice.? | _o__) ?Henry L. Mencken | Ben Finney From cmpython at gmail.com Sun Jul 10 19:49:51 2011 From: cmpython at gmail.com (CM) Date: Sun, 10 Jul 2011 16:49:51 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Jul 10, 6:50?pm, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? Just because Boa Constructor stopped (or lengthily paused?) development doesn't mean it doesn't exist. It does, and (at least on Windows), it is, IMO, really good. So why don't you use it? Che From tim at johnsons-web.com Sun Jul 10 20:00:54 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 16:00:54 -0800 Subject: Function docstring as a local variable In-Reply-To: References: Message-ID: <20110711000054.GF12935@johnsons-web.com> * Carl Banks [110710 15:18]: > On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > Here's a related question: > > I can get the docstring for an imported module: > > >>> import tmpl as foo > > >>> print(foo.__doc__) > > Python templating features > > > > Author - tim at akwebsoft dot com > > > > ## Is it possible to get the module docstring > > ## from the module itself? > > > print __doc__ Thanks Carl. Where is general documentation on the subject of variables beginning with 2 underscores? I'm presuming the key phrase is 'builtin variables'. I'm searching too ... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From clp2 at rebertia.com Sun Jul 10 20:09:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 10 Jul 2011 17:09:27 -0700 Subject: Function docstring as a local variable In-Reply-To: <20110711000054.GF12935@johnsons-web.com> References: <20110711000054.GF12935@johnsons-web.com> Message-ID: On Sun, Jul 10, 2011 at 5:00 PM, Tim Johnson wrote: > * Carl Banks [110710 15:18]: >> On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: >> > ?## Is it possible to get the module docstring >> > ?## from the module itself? >> >> print __doc__ > ?Thanks Carl. > > ?Where is general documentation on the subject of variables > ?beginning with 2 underscores? > > ?I'm presuming the key phrase is 'builtin variables'. I'm searching > ?too ... I've never heard that phrase used to describe __doc__ or its friends. Look in the "underscore" section of the documentation index: http://docs.python.org/genindex-_.html Cheers, Chris From clp2 at rebertia.com Sun Jul 10 20:16:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 10 Jul 2011 17:16:23 -0700 Subject: Function docstring as a local variable In-Reply-To: <1310339164-sup-5162@dalek> References: <1310339164-sup-5162@dalek> Message-ID: On Sun, Jul 10, 2011 at 4:06 PM, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: >> print __doc__ >> > > Python 2.7.1 (r271:86832, Jul ?8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def foo(): > ... ? ? "Docstring" > ... ? ? print __doc__ > ... >>>> foo() > None >>>> > > > What does yours do? The question Carl's code was in answer to was, slightly paraphrased: "Is it possible to get a *module*'s docstring from within the module itself?" The question had nothing to do with *function* docstrings. The interactive interpreter environment also isn't quite a true module, so you can't give it a docstring or really test the relevant feature there. Try this instead: $ cat test.py """I am the docstring of the `test` module!""" print("This module's docstring is:", __doc__) $ python test.py This module's docstring is: I am the docstring of the `test` module! $ Cheers, Chris -- http://rebertia.com From tim at johnsons-web.com Sun Jul 10 20:21:59 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 16:21:59 -0800 Subject: Function docstring as a local variable In-Reply-To: References: <20110711000054.GF12935@johnsons-web.com> Message-ID: <20110711002159.GG12935@johnsons-web.com> * Chris Rebert [110710 16:14]: > > > > ?Where is general documentation on the subject of variables > > ?beginning with 2 underscores? > > I've never heard that phrase used to describe __doc__ or its friends. :) That why I wasn't satified with my search results. > Look in the "underscore" section of the documentation index: > http://docs.python.org/genindex-_.html And that is what I was looking for. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From kb1pkl at aim.com Sun Jul 10 20:26:02 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 20:26:02 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <1310339164-sup-5162@dalek> Message-ID: <1310343648-sup-869@dalek> Excerpts from Chris Rebert's message of Sun Jul 10 20:16:23 -0400 2011: > The question Carl's code was in answer to was, slightly paraphrased: > "Is it possible to get a *module*'s docstring from within the module > itself?" > The question had nothing to do with *function* docstrings. > Ah. My bad, thank you for clarifying. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From mhrivnak at hrivnak.org Sun Jul 10 20:31:49 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Sun, 10 Jul 2011 20:31:49 -0400 Subject: Virtual functions are virtually invisible! In-Reply-To: References: <97dcpqFdndU1@mid.individual.net> Message-ID: It sounds to me like you need a better IDE, better documentation, and/or better code to work on and use. I don't understand why it's difficult to look at a derived class as see what methods are overridden. If you are working on the code, it is quite obvious what methods exist in the base class. If you're not willing to get an intimate understanding of how the base class works, you probably shouldn't be working on the subclass. If the base class is difficult to understand, it's probably poorly written and/or poorly documented. Neither of these problems should be solved by adding complexity to the language. Referencing the Zen of Python: "If the implementation is hard to explain, it's a bad idea." If you are just using a library but not developing it, why does it matter what methods are overridden? As long as class "Derived" behaves the way it is documented, who cares how it got that way or what is going on behind the scenes? If you need to read the code to figure out how it works, then it's just poorly documented. Django is a great example, because it is very well documented. Most users have little idea of what base classes are involved and what features are overridden, because it doesn't matter when you are just using the library. When you need to write your own subclass of a django class, then it might matter, and you should see my first paragraph. And in terms of "non-starters", any "Pythonista" who isn't willing to adhere to the style guide and document their code wouldn't work on my team for very long, if at all. There is just no excuse for that. Michael On Sun, Jul 10, 2011 at 1:15 PM, rantingrick wrote: > On Jul 4, 3:43?am, Gregory Ewing wrote: >> rantingrick wrote: >> > what concerns me is the fact that virtual methods in derived >> > classes just blend in to the crowd. >> > I think we really need some >> > sort of visual cue in the form of forced syntactical notation (just >> > like the special method underscores). >> >> If you're suggesting that it should be impossible to override >> a method unless it is specially marked somehow in the base >> class, I think that would be a bad idea. > > Sorry i did explain properly... No NOT marked in the BASE class but > marked in the DERIVED class! My concerns are from a readability > standpoint. Here's a naive example... > > class Top(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def m1(self): > ? ? ? ?"""overide""" > ? ? ? ?return True > ? ?def m2(self): > ? ? ? ?print 'm2' > > > def Derived(Top): > ? ?def __init__(self): > ? ? ? ?Top.__init__(self) > ? ?def m1(self): > ? ? ? ?return False > > My argument is this... > > ? """If class "Derived" exists in another module the reader has no > idea which methods where clobbered and which were not WITHOUT being > intimate with the entire code base.""" > > ?I suggest we solve this dilemma by forcing a syntax "tag" when > declaring clobbering virtual functions. And if someone forgets to > include the tag python would throw an exception. This has the effect > of making the code MUCH easier to follow by the human readers. And it > put NO constraints on the API. Also it has the added effect of warning > unsuspecting programmers of name clashes that would otherwise not > produce an error. > >> One of the principles behind the design of Eiffel is that >> classes should *always* be open to modification in any way >> by a subclass. The reason is that the author of a class >> library can't anticipate all the ways people might want to >> use it. Consequently Eiffel has no equivalent of C++'s >> "private" declaration -- everything is at most "protected". >> It also has no equivalent of Java's "final". > > Exactly! We should never put limits on what methods CAN be virtual. > However, we CAN enforce a syntax that removes ambiguity from the > equation. > -- > http://mail.python.org/mailman/listinfo/python-list > From awilliam at whitemice.org Sun Jul 10 20:42:11 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sun, 10 Jul 2011 20:42:11 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310344932.3072.6.camel@linux-yu4c.site> On Sun, 2011-07-10 at 15:50 -0700, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? I've pondered this myself, for a long time - since I could use RAD to build very nice applications using Borland's OWL on Windows For Workgroups.... it is sad. But Open Source land is simply too fragmented. There are too many database bindings [and RAD requires something like an ORM (think SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list goes on and on]. Nothing can muster the gravity required to bring a quality RAD tool into existence. I also suspect - seeing some of the articles that float across the FLOSS-o-sphere mentioning "RAD" - that many Open Source developers have never had the pleasure [yes, it is a pleasure] of using a professional RAD tool. From benjamin.kaplan at case.edu Sun Jul 10 20:42:16 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 10 Jul 2011 17:42:16 -0700 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 10, 2011 at 3:50 PM, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? > -- > Because RAD tools are for GUI toolkits, not for languages. If you're using GTK, Glade works fine. Same with QT and QTDesigner. If you're using WPF with IronPython, there's plenty of tools out there for you to use. And Boa Constructor isn't the only RAD tool for wx- you can also use wxGlade, which can output code in several languages in addition to XRC files (an XML file you can load into wx from any language) > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Sun Jul 10 20:43:53 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sun, 10 Jul 2011 20:43:53 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310345034.3072.8.camel@linux-yu4c.site> >Because RAD tools are for GUI toolkits, not for languages. If you're >using GTK, Glade works fine. Same with QT and QTDesigner. If you're >using WPF with IronPython, t These [Glade, etc...] are *NOT* RAD tools. They are GUI designers. A RAD tool provides a GUI designer that can be bound to a backend [typically an SQL database]. RAD = GUI + ORM. From papillion at gmail.com Sun Jul 10 20:51:57 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 19:51:57 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: As someone who was a Visual Studio user for many years, I felt much the same way you do when I made the jump to Python on Linux last year. But then I discovered Glade and am quite satisfied. Glades UI design paradigm is a little different than that of VS but it's not so hard that you couldn't learn it in a week. It's very usable, pretty easy to learn, and doesn't cost you a penny. If you've not already, I recommend you check out Glade. I think it's probably what you're looking for. Anthony On 7/10/11, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Anthony Papillion Advanced Data Concepts Get real about your software/web development and IT Services Phone: (918) 919-4624 Does your business need to reduce its phone bill? I can help! Email me and ask me how! From steve+comp.lang.python at pearwood.info Sun Jul 10 21:54:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2011 11:54:32 +1000 Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <4e1a57df$0$29987$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jul 2011 09:00 am Corey Richardson wrote: > Excerpts from Colin J. Williams's message of Sun Jul 10 18:28:15 -0400 > 2011: >> Try: >> >> def f(): >> ds= """docstring""" >> print ds > > That doesn't actually make a docstring, though. It makes a string object > and points the name ds at it. Do you know what a docstring is? Colin might not be aware of why docstrings are useful, and arbitrary local variables ds="""docstring""" are not. def f1(): """This is my documentation string. Imagine this has actual useful information. """ def f2(): dc = """This is my documentation string. Imagine this has actual useful information. """ Now, at the interactive interpreter, call: help(f1) help(f2) -- Steven From drsalists at gmail.com Sun Jul 10 22:02:57 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 10 Jul 2011 19:02:57 -0700 Subject: Backshift mailing list create - opensource, deduplicating, compressing backups in Python Message-ID: I've created a google mailing list for the discussion of the backup program I've been working on, "backshift". You can find it at: backshift at googlegroups.com And I'd be pleased if you were to choose to join, if you're interested in the subject of Python and Backups. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amannijhawan at gmail.com Sun Jul 10 22:08:45 2011 From: amannijhawan at gmail.com (Aman Nijhawan) Date: Sun, 10 Jul 2011 19:08:45 -0700 Subject: parsing packets Message-ID: Are you sending binary data if so you can use the struct module to pack, unpack and interpret binary data http://docs.python.org/library/struct.html , You will have to design the header scheme yourself you can either embed length in the packets or try to use a carefully selected delimiter character . Thanks Aman On Sun, Jul 10, 2011 at 5:31 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: parsing packets (Michael Hrivnak) > 2. Re: Wgy isn't there a good RAD Gui tool fo python (CM) > 3. Re: Function docstring as a local variable (Ben Finney) > 4. Re: Function docstring as a local variable (Tim Johnson) > 5. Re: Function docstring as a local variable (Chris Rebert) > 6. Re: Function docstring as a local variable (Chris Rebert) > 7. Re: Function docstring as a local variable (Tim Johnson) > 8. Re: Function docstring as a local variable (Corey Richardson) > 9. Re: Virtual functions are virtually invisible! (Michael Hrivnak) > > > ---------- Forwarded message ---------- > From: Michael Hrivnak > To: tyler at tysdomain.com > Date: Sun, 10 Jul 2011 19:33:38 -0400 > Subject: Re: parsing packets > In order to find the end of the packet, include a field that is the > packet length. This is what IP packets do to find the end of their > header. > > http://en.wikipedia.org/wiki/IPv4#Header > > And the TCP header (see "data offset") does the same: > > > http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure > > Of course in both cases they are specifying the header length, not > including a data payload. However, it sounds like you might not have > a payload, so your entire packet might consist of header-like data. > > Michael > > > On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler > wrote: > > Hello all: > > I'm working on a server that will need to parse packets sent from a > client, > > and construct it's own packets. > > The setup is something like this: the first two bytes is the type of the > > packet. > > So, lets say we have a packet set to connect. There are two types of > connect > > packet: a auth packet and a connect packet. > > The connect packet then has two bytes with the type, another byte that > notes > > that it is a connect packet, and 4 bytes that contains the version of the > > client. > > The auth packet has the two bytes that tells what packet it is, one byte > > denoting that it is an auth packet, then the username, a NULL character, > and > > a password and a NULL character. > > > > With all of this said, I'm kind of curious how I would 1) parse out > > something like this (I am using twisted, so it'll just be passed to my > > Receive function), and how I get the length of the packet with multiple > NULL > > values. I'm also looking to build a packet and send it back out, is there > > something that will allow me to designate two bytes, set individual bits, > > then put it altogether in a packet to be sent out? > > > > -- > > > > Take care, > > Ty > > my website: > > http://tds-solutions.net > > my blog: > > http://tds-solutions.net/blog > > skype: st8amnd127 > > My programs don't have bugs; they're randomly added features! > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > ---------- Forwarded message ---------- > From: CM > To: python-list at python.org > Date: Sun, 10 Jul 2011 16:49:51 -0700 (PDT) > Subject: Re: Wgy isn't there a good RAD Gui tool fo python > On Jul 10, 6:50 pm, Ivan Kljaic wrote: > > Ok Guys. I know that most of us have been expiriencing the need for a > > nice Gui builder tool for RAD and most of us have been googling for it > > a lot of times. But seriously. Why is the not even one single RAD tool > > for Python. I mean what happened to boa constructor that it stopped > > developing. I simply do not see any reasons why there isn't anything. > > Please help me understand it. Any insights? > > Just because Boa Constructor stopped (or lengthily paused?) > development > doesn't mean it doesn't exist. It does, and (at least on Windows), it > is, IMO, really good. So why don't you use it? > > Che > > > > > ---------- Forwarded message ---------- > From: Ben Finney > To: python-list at python.org > Date: Mon, 11 Jul 2011 09:48:46 +1000 > Subject: Re: Function docstring as a local variable > "Colin J. Williams" writes: > > > On 10-Jul-11 13:44 PM, rantingrick wrote: > > > On Jul 10, 12:41 pm, Tim Johnson wrote: > > >> It possible for a function to print it's own docstring? > > > > > > def f(): > > > """docstring""" > > > print "docstring" > > > > Try: > > > > def f(): > > ds= """docstring""" > > print ds > > The OP wants the function to print its own docstring, which your example > does not do. You've defined a function with an empty docstring. > > >>> def foo(): > ... ds = "The Larch" > ... print ds > ... > >>> foo.__doc__ > >>> > > -- > \ ?Firmness in decision is often merely a form of stupidity. It | > `\ indicates an inability to think the same thing out twice.? | > _o__) ?Henry L. Mencken | > Ben Finney > > > > ---------- Forwarded message ---------- > From: Tim Johnson > To: python-list at python.org > Date: Sun, 10 Jul 2011 16:00:54 -0800 > Subject: Re: Function docstring as a local variable > * Carl Banks [110710 15:18]: > > On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > > Here's a related question: > > > I can get the docstring for an imported module: > > > >>> import tmpl as foo > > > >>> print(foo.__doc__) > > > Python templating features > > > > > > Author - tim at akwebsoft dot com > > > > > > ## Is it possible to get the module docstring > > > ## from the module itself? > > > > > > print __doc__ > Thanks Carl. > > Where is general documentation on the subject of variables > beginning with 2 underscores? > > I'm presuming the key phrase is 'builtin variables'. I'm searching > too ... > > -- > Tim > tim at johnsons-web dot com or akwebsoft dot com > http://www.akwebsoft.com > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Tim Johnson > Date: Sun, 10 Jul 2011 17:09:27 -0700 > Subject: Re: Function docstring as a local variable > On Sun, Jul 10, 2011 at 5:00 PM, Tim Johnson wrote: > > * Carl Banks [110710 15:18]: > >> On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > >> > ## Is it possible to get the module docstring > >> > ## from the module itself? > >> > >> print __doc__ > > Thanks Carl. > > > > Where is general documentation on the subject of variables > > beginning with 2 underscores? > > > > I'm presuming the key phrase is 'builtin variables'. I'm searching > > too ... > > I've never heard that phrase used to describe __doc__ or its friends. > > Look in the "underscore" section of the documentation index: > http://docs.python.org/genindex-_.html > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Corey Richardson > Date: Sun, 10 Jul 2011 17:16:23 -0700 > Subject: Re: Function docstring as a local variable > On Sun, Jul 10, 2011 at 4:06 PM, Corey Richardson wrote: > > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > >> print __doc__ > >> > > > > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) > > [GCC 4.4.5] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> def foo(): > > ... "Docstring" > > ... print __doc__ > > ... > >>>> foo() > > None > >>>> > > > > > > What does yours do? > > The question Carl's code was in answer to was, slightly paraphrased: > "Is it possible to get a *module*'s docstring from within the module > itself?" > The question had nothing to do with *function* docstrings. > > The interactive interpreter environment also isn't quite a true > module, so you can't give it a docstring or really test the relevant > feature there. Try this instead: > $ cat test.py > """I am the docstring of the `test` module!""" > > print("This module's docstring is:", __doc__) > $ python test.py > This module's docstring is: I am the docstring of the `test` module! > $ > > Cheers, > Chris > -- > http://rebertia.com > > > > ---------- Forwarded message ---------- > From: Tim Johnson > To: Python ML > Date: Sun, 10 Jul 2011 16:21:59 -0800 > Subject: Re: Function docstring as a local variable > * Chris Rebert [110710 16:14]: > > > > > > Where is general documentation on the subject of variables > > > beginning with 2 underscores? > > > > I've never heard that phrase used to describe __doc__ or its friends. > :) That why I wasn't satified with my search results. > > Look in the "underscore" section of the documentation index: > > http://docs.python.org/genindex-_.html > And that is what I was looking for. > thanks > -- > Tim > tim at johnsons-web dot com or akwebsoft dot com > http://www.akwebsoft.com > > > > ---------- Forwarded message ---------- > From: Corey Richardson > To: python-list > Date: Sun, 10 Jul 2011 20:26:02 -0400 > Subject: Re: Function docstring as a local variable > Excerpts from Chris Rebert's message of Sun Jul 10 20:16:23 -0400 2011: > > The question Carl's code was in answer to was, slightly paraphrased: > > "Is it possible to get a *module*'s docstring from within the module > > itself?" > > The question had nothing to do with *function* docstrings. > > > > Ah. My bad, thank you for clarifying. > -- > Corey Richardson > "Those who deny freedom to others, deserve it not for themselves" > -- Abraham Lincoln > > > ---------- Forwarded message ---------- > From: Michael Hrivnak > To: rantingrick > Date: Sun, 10 Jul 2011 20:31:49 -0400 > Subject: Re: Virtual functions are virtually invisible! > It sounds to me like you need a better IDE, better documentation, > and/or better code to work on and use. I don't understand why it's > difficult to look at a derived class as see what methods are > overridden. If you are working on the code, it is quite obvious what > methods exist in the base class. If you're not willing to get an > intimate understanding of how the base class works, you probably > shouldn't be working on the subclass. If the base class is difficult > to understand, it's probably poorly written and/or poorly documented. > Neither of these problems should be solved by adding complexity to the > language. Referencing the Zen of Python: "If the implementation is > hard to explain, it's a bad idea." > > If you are just using a library but not developing it, why does it > matter what methods are overridden? As long as class "Derived" > behaves the way it is documented, who cares how it got that way or > what is going on behind the scenes? If you need to read the code to > figure out how it works, then it's just poorly documented. > > Django is a great example, because it is very well documented. Most > users have little idea of what base classes are involved and what > features are overridden, because it doesn't matter when you are just > using the library. When you need to write your own subclass of a > django class, then it might matter, and you should see my first > paragraph. > > And in terms of "non-starters", any "Pythonista" who isn't willing to > adhere to the style guide and document their code wouldn't work on my > team for very long, if at all. There is just no excuse for that. > > Michael > > On Sun, Jul 10, 2011 at 1:15 PM, rantingrick > wrote: > > On Jul 4, 3:43 am, Gregory Ewing wrote: > >> rantingrick wrote: > >> > what concerns me is the fact that virtual methods in derived > >> > classes just blend in to the crowd. > >> > I think we really need some > >> > sort of visual cue in the form of forced syntactical notation (just > >> > like the special method underscores). > >> > >> If you're suggesting that it should be impossible to override > >> a method unless it is specially marked somehow in the base > >> class, I think that would be a bad idea. > > > > Sorry i did explain properly... No NOT marked in the BASE class but > > marked in the DERIVED class! My concerns are from a readability > > standpoint. Here's a naive example... > > > > class Top(object): > > def __init__(self): > > pass > > def m1(self): > > """overide""" > > return True > > def m2(self): > > print 'm2' > > > > > > def Derived(Top): > > def __init__(self): > > Top.__init__(self) > > def m1(self): > > return False > > > > My argument is this... > > > > """If class "Derived" exists in another module the reader has no > > idea which methods where clobbered and which were not WITHOUT being > > intimate with the entire code base.""" > > > > I suggest we solve this dilemma by forcing a syntax "tag" when > > declaring clobbering virtual functions. And if someone forgets to > > include the tag python would throw an exception. This has the effect > > of making the code MUCH easier to follow by the human readers. And it > > put NO constraints on the API. Also it has the added effect of warning > > unsuspecting programmers of name clashes that would otherwise not > > produce an error. > > > >> One of the principles behind the design of Eiffel is that > >> classes should *always* be open to modification in any way > >> by a subclass. The reason is that the author of a class > >> library can't anticipate all the ways people might want to > >> use it. Consequently Eiffel has no equivalent of C++'s > >> "private" declaration -- everything is at most "protected". > >> It also has no equivalent of Java's "final". > > > > Exactly! We should never put limits on what methods CAN be virtual. > > However, we CAN enforce a syntax that removes ambiguity from the > > equation. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Aman Nijhawan -------------- next part -------------- An HTML attachment was scrubbed... URL: From kvaradhan3 at gmail.com Sun Jul 10 22:13:33 2011 From: kvaradhan3 at gmail.com (Kannan Varadhan) Date: Sun, 10 Jul 2011 19:13:33 -0700 (PDT) Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: <2be5417f-6b4c-4296-bcb0-e01961701a79@h38g2000pro.googlegroups.com> Thanks folks, Tried all of these, and went with staticmethod(). Was cleanest solution, > After skimming over Steven's post: use staticmethod. > No idea why I didn't think of that myself. Kannan From papillion at gmail.com Sun Jul 10 22:14:10 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 21:14:10 -0500 Subject: How to get or set the text of a textfield? Message-ID: Hi Everyone, So I've built a UI with Glade and have loaded it using the standard Python code. In my UI, I have a textfield called txtUsername. How do I get and set the text in this field from my Python code? Thanks! Anthony -- Anthony Papillion Advanced Data Concepts Get real about your software/web development and IT Services Phone: (918) 919-4624 Does your business need to reduce its phone bill? I can help! Email me and ask me how! From rantingrick at gmail.com Sun Jul 10 22:35:05 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 19:35:05 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> Message-ID: <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> On Jul 10, 7:31?pm, Michael Hrivnak wrote: > It sounds to me like you need a better IDE, better documentation, > and/or better code to work on and use. Yes the last two points are relevant here. However whilst IDE choice belongs to the user, documentation and code are in the hands of the developer; who's own selfish needs often outweigh that of the user AND community as a whole. >?I don't understand why it's > difficult to look at a derived class as see what methods are > overridden. Well in my simple example it is VERY easy, WHY? Here are a few reasons why the clobbered methods are easy to spot (in both the base and derived classes)... * Both exists within the same view frame. No need to flip back and forth between two windows. * Both have only one method. The complexity increases exponentially by the number of methods AND the length of their respective code blocks! * "Derived.m1" has a syntactical mark. You can clearly see which method has been clobbered WITHOUT even bothering to look at the base class. The only time you SHOULD have to look at the base class is to see what mandates the virtual method may impose. Does it require a Boolean return? An Integer? A Float? A List? Does it modify an object? Etc, etc? > ?If you are working on the code, it is quite obvious what > methods exist in the base class. Let me correct your statement... IF you have an intimate understanding of the base. Heck what if the base is derived also? These things are NOT strictly single level you know. > ?If you're not willing to get an > intimate understanding of how the base class works, you probably > shouldn't be working on the subclass. ? Not true, many times you don't need an intimate understanding of the base to wield a derived class. That's when the syntactical markers come in handy. > If the base class is difficult > to understand, it's probably poorly written and/or poorly documented. > Neither of these problems should be solved by adding complexity to the > language. How is adding syntactical markers to an otherwise obfuscation of virtual method clobbering going to confuse anyone? I would say the opposite is true. Python has used the forced convention "double- leading-and-trailing-underscores" to mark special methods since it's beginning. One reason for this convention is prevent name clashes HOWEVER the most important reason (i would argue) is for readability of source code. When Guido implemented this convention it was one of his greatest gifts to Python and the world (only to be outdone by forced indention!). >?Referencing the Zen of Python: "If the implementation is > hard to explain, it's a bad idea." What if the code is "difficult" to read? Does "readability count" ring a bell? > If you are just using a library but not developing it, why does it > matter what methods are overridden? ?As long as class "Derived" > behaves the way it is documented, who cares how it got that way or > what is going on behind the scenes? ?If you need to read the code to > figure out how it works, then it's just poorly documented. Yes. It is obviously poorly documented. And all the writer would have to do is put a little doc string there saying "clobbered virtual method here". HOWEVER, do you know how many folks bother to ACTUALLY do that? Huh? Do ya? None! Exactly. > Django is a great example, because it is very well documented. ?Most > users have little idea of what base classes are involved and what > features are overridden, because it doesn't matter when you are just > using the library. ?When you need to write your own subclass of a > django class, then it might matter, and you should see my first > paragraph. When a method has been clobbered any reader of such code NEEDS to know about it. WHY, well because usually clobbered methods have "magic" going on being the scenes. Sometimes many layers of "magic". > And in terms of "non-starters", any "Pythonista" who isn't willing to > adhere to the style guide and document their code wouldn't work on my > team for very long, if at all. ?There is just no excuse for that. I agree. However as we are all aware many "great Pythonistas" refuse to follow the style guide (*cough* freg! :). The only way to correct this problem is via a forced syntactical marker placed by the derived class's writer. Just like with "__IDENTIFIER__" READABILITY COUNTS! From jialiuonlineshoe02 at 163.com Sun Jul 10 23:28:41 2011 From: jialiuonlineshoe02 at 163.com (amy) Date: Sun, 10 Jul 2011 20:28:41 -0700 (PDT) Subject: paypal wholesale all brand(UGGBOOTS, SHOES, CLOTHES, HANDBAG, WATCH, JEANS, JERSEY, T-SHIRT, SHIRTS, HOODY, EYEGLASS, CAP, SHAWL, WALLT) and so on. Message-ID: <5cfc664b-557c-47d5-a39c-424df921f867@t38g2000prj.googlegroups.com> paypal payment wholesale all brand shoes(NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,UGG BOOTS,D&G,DIOR )and so on. paypal payment wholesale all brand clothing(T- SHIRT,JEANS,JERSEY,HOODIES,JACKETS,HARDY,SWEATER,SHIRTS )and so on . http://www.24hour-buy.com paypal payment all brand watch(ROLEX,OMEGA,CHANEL,LV,CARTIER,IWC,GUCCI,RADO )and so on. http://www.24hour-buy.com paypal payment all brand handbag(LV,GUCCI,CHANEL,PRADA,POLO,COACH,FENDI,CHLOE,BUBERRY,JUICY) and so on. paypal payment brand CAP,SHAWL,BELT,WALLET,UNDER WEAR)and so on. More detail land,address: http://www.24hour-buy.com From gordon at panix.com Sun Jul 10 23:44:44 2011 From: gordon at panix.com (John Gordon) Date: Mon, 11 Jul 2011 03:44:44 +0000 (UTC) Subject: How to get or set the text of a textfield? References: Message-ID: In Anthony Papillion writes: > So I've built a UI with Glade and have loaded it using the standard > Python code. In my UI, I have a textfield called txtUsername. How do I > get and set the text in this field from my Python code? I don't know anything about Glade, so I can't answer your question definitively. However, as a general rule, you can use the dir() builtin function to see what methods are defined by an object. So, assuming you have access to an interactive shell within your Glade environment, you can do this: dir(txtUsername) and it will print a list of methods that are defined by that object. Hopefully one of them will be called something helpful like set_text() or set_property(). Once you know the method name, you might try a Google search to determine the exact usage and arguments. -- 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 wuwei23 at gmail.com Mon Jul 11 00:05:47 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 10 Jul 2011 21:05:47 -0700 (PDT) Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: On Jul 11, 9:00?am, Corey Richardson wrote: > def qux(): > ? ? 'And even me! Quote type don't matter (besides style)' Well, style and the presence of the string literal notation in the quoted text :) From papillion at gmail.com Mon Jul 11 00:09:27 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 23:09:27 -0500 Subject: How to get or set the text of a textfield? - SOLVED In-Reply-To: References: Message-ID: <4E1A7777.8040101@gmail.com> > I don't know anything about Glade, so I can't answer your question > definitively. However, as a general rule, you can use the dir() builtin > function to see what methods are defined by an object. Hi John, Thanks for the input and it looks like it's pretty simple. Basically, I can access the properties of objects like: self.objectname.property_or_method() So, to solve my question, I'd just use: self.txtUsername.set_text('Whatever I want') or enteredText = self.txtUsername.get_text() Pretty simple and this actually solves ALL of my Glade problems. I'm excited. Thanks for the direction! Anthony From wuwei23 at gmail.com Mon Jul 11 00:14:11 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 10 Jul 2011 21:14:11 -0700 (PDT) Subject: Function docstring as a local variable References: Message-ID: <44de56f6-8ded-488f-a2bb-5b0f19582ef5@e20g2000prf.googlegroups.com> On Jul 11, 9:06?am, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > > > print __doc__ > > Python 2.7.1 (r271:86832, Jul ?8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> def foo(): > > ... ? ? "Docstring" > ... ? ? print __doc__ > ... > > >>> foo() > None > > What does yours do? Is foo() declared in a module with a docstring? Because that's what Carl was talking about. test_module.py: '''module docstring''' def foo(): print __doc__ Works for me. From mhrivnak at hrivnak.org Mon Jul 11 00:45:45 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Mon, 11 Jul 2011 00:45:45 -0400 Subject: Virtual functions are virtually invisible! In-Reply-To: <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> Message-ID: I can't believe you're saying that you will create a sub-class without taking the time to understand the base class. Seriously? That right there is why you are seeing method overrides that aren't documented. How can you document something you don't understand? Furthermore, how can you have any confidence in your subclass if you don't understand what its base class is doing? Do you write unit tests? How do you know what to test if you don't understand the code you are subclassing? Suggesting that no developers document their methods? Incredible. Clobbered methods have "magic"? Multi-layered "magic"? Perhaps when you take the time to 1) document the base class and 2) understand that base class before subclassing it, that "magic" will start to look like reasonable and logical processes. Professional developers document their code. They take the time to understand the code they are working on. If you don't want to do those things, that's your business, and I'm sure you can find other people who also don't do those things. But I really don't think you'll have much success changing the language to accommodate your refusal to follow the most basic best practices. Best of luck, Michael On Sun, Jul 10, 2011 at 10:35 PM, rantingrick wrote: > On Jul 10, 7:31?pm, Michael Hrivnak wrote: >> It sounds to me like you need a better IDE, better documentation, >> and/or better code to work on and use. > > Yes the last two points are relevant here. However whilst IDE choice > belongs to the user, documentation and code are in the hands of the > developer; who's own selfish needs often outweigh that of the user AND > community as a whole. > >>?I don't understand why it's >> difficult to look at a derived class as see what methods are >> overridden. > > Well in my simple example it is VERY easy, WHY? Here are a few reasons > why the clobbered methods are easy to spot (in both the base and > derived classes)... > > ?* Both exists within the same view frame. No need to flip back and > forth between two windows. > ?* Both have only one method. The complexity increases exponentially > by the number of methods AND the length of their respective code > blocks! > ?* "Derived.m1" has a syntactical mark. You can clearly see which > method has been clobbered WITHOUT even bothering to look at the base > class. > > The only time you SHOULD have to look at the base class is to see what > mandates the virtual method may impose. Does it require a Boolean > return? An Integer? A Float? A List? Does it modify an object? Etc, > etc? > >> ?If you are working on the code, it is quite obvious what >> methods exist in the base class. > > Let me correct your statement... IF you have an intimate understanding > of the base. Heck what if the base is derived also? These things are > NOT strictly single level you know. > >> ?If you're not willing to get an >> intimate understanding of how the base class works, you probably >> shouldn't be working on the subclass. > > Not true, many times you don't need an intimate understanding of the > base to wield a derived class. That's when the syntactical markers > come in handy. > >> If the base class is difficult >> to understand, it's probably poorly written and/or poorly documented. >> Neither of these problems should be solved by adding complexity to the >> language. > > How is adding syntactical markers to an otherwise obfuscation of > virtual method clobbering going to confuse anyone? I would say the > opposite is true. Python has used the forced convention "double- > leading-and-trailing-underscores" to mark special methods since it's > beginning. One reason for this convention is prevent name clashes > HOWEVER the most important reason (i would argue) is for readability > of source code. When Guido implemented this convention it was one of > his greatest gifts to Python and the world (only to be outdone by > forced indention!). > >>?Referencing the Zen of Python: "If the implementation is >> hard to explain, it's a bad idea." > > What if the code is "difficult" to read? Does "readability count" ring > a bell? > >> If you are just using a library but not developing it, why does it >> matter what methods are overridden? ?As long as class "Derived" >> behaves the way it is documented, who cares how it got that way or >> what is going on behind the scenes? ?If you need to read the code to >> figure out how it works, then it's just poorly documented. > > Yes. It is obviously poorly documented. And all the writer would have > to do is put a little doc string there saying "clobbered virtual > method here". HOWEVER, do you know how many folks bother to ACTUALLY > do that? Huh? Do ya? None! Exactly. > >> Django is a great example, because it is very well documented. ?Most >> users have little idea of what base classes are involved and what >> features are overridden, because it doesn't matter when you are just >> using the library. ?When you need to write your own subclass of a >> django class, then it might matter, and you should see my first >> paragraph. > > When a method has been clobbered any reader of such code NEEDS to know > about it. WHY, well because usually clobbered methods have "magic" > going on being the scenes. Sometimes many layers of "magic". > >> And in terms of "non-starters", any "Pythonista" who isn't willing to >> adhere to the style guide and document their code wouldn't work on my >> team for very long, if at all. ?There is just no excuse for that. > > I agree. However as we are all aware many "great Pythonistas" refuse > to follow the style guide (*cough* freg! :). The only way to correct > this problem is via a forced syntactical marker placed by the derived > class's writer. Just like with "__IDENTIFIER__" > > READABILITY COUNTS! > -- > http://mail.python.org/mailman/listinfo/python-list > From wm at localhost.localdomain Mon Jul 11 01:03:10 2011 From: wm at localhost.localdomain (Waldek M.) Date: Mon, 11 Jul 2011 07:03:10 +0200 Subject: How to get or set the text of a textfield? References: Message-ID: Dnia Sun, 10 Jul 2011 21:14:10 -0500, Anthony Papillion napisa?(a): > > So I've built a UI with Glade and have loaded it using the standard > Python code. In my UI, I have a textfield called txtUsername. How do I > get and set the text in this field from my Python code? http://developer.gnome.org/pygtk/stable/ http://www.learningpython.com/2006/05/07/creating-a-gui-using-pygtk-and-glade/ Br. Waldek From timr at probo.com Mon Jul 11 01:12:31 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 10 Jul 2011 22:12:31 -0700 Subject: ctypes: point to buffer in structure References: Message-ID: Jesse R wrote: > >Hey I've been trying to convert this to run through ctypes and i'm >having a hard time > >typedef struct _SYSTEM_PROCESS_ID_INFORMATION >{ > HANDLE ProcessId; > UNICODE_STRING ImageName; >} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, >*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; > >to > >class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): > _fields_ = [('pid', ctypes.c_ulong), > ('imageName', ctypes.c_wchar_p)] >... >does anyone know how to get this working? UNICODE_STRING is not just a pointer to wide characters. It is itself a structure: typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; So, I think you want fields of ctypes.c_ulong, ctypes.c_ushort, ctypes.c_ushort, and ctypes.c_wchar_p. MaximumLength gives the allocated size of the buffer. Length gives the length of the string currently held in the buffer. It can be less than the maximum length, and the buffer does NOT necessarily contain a zero-terminator. UNICODE_STRING and ANSI_STRING are used in kernel programming to avoid the potential ambiguities of counted strings. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From shilparani9030 at gmail.com Mon Jul 11 01:13:46 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Sun, 10 Jul 2011 22:13:46 -0700 (PDT) Subject: south actress hot photos and videos Message-ID: <4fa16485-0b74-4209-887e-462954f92941@y13g2000prb.googlegroups.com> v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From georg at python.org Mon Jul 11 01:23:32 2011 From: georg at python.org (Georg Brandl) Date: Mon, 11 Jul 2011 07:23:32 +0200 Subject: [RELEASED] Python 3.2.1 Message-ID: <4E1A88D4.5070704@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the final release of Python 3.2.1. Python 3.2.1 is the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a final release: Please report any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEARECAAYFAk4aiNMACgkQN9GcIYhpnLDofwCglfgDQ1/B/TxxwfqtDxK13ksz micAn0CVWmNNaYE2a6z0N7+Dz+hCZSj1 =7Mia -----END PGP SIGNATURE----- From kracethekingmaker at gmail.com Mon Jul 11 01:23:54 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Sun, 10 Jul 2011 22:23:54 -0700 (PDT) Subject: python xauth Message-ID: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> I am looking to use xauth in python?It is for my command line process,I would like to have few examples and resources. From papillion at gmail.com Mon Jul 11 02:42:30 2011 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 11 Jul 2011 01:42:30 -0500 Subject: OK, I lied, I do have another question... Message-ID: <4E1A9B56.6080608@gmail.com> Hi Everyone, So I've used Glade to build a simple UI and I'm loading it with gtkBuilder. The UI loads fine but, for some reason, none of my signals are being connected. For example, in Glade, I said when the button called btnExit was clicked, execute the btnExit_clicked method. Then, in my App() class definition, I defined btnExit_clicked(self, widget) and simply added the gtk.main_quit() statement (to exit). But when I start my app, I am told that the btnExit_clicked() method isn't defined. This happens for every single signal I define. I'm assuming I'm simply putting something in the wrong place so can anyone have a look at this and tell me what that might be? It looks almost identical to examples I've seen on the net. Thanks! CODE: class App: def __init__(self): builder = gtk.Builder() builder.add_from_file('bcbackup.ui') builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : btnExit_clicked}) self.window = builder.get_object("winMain") self.window.show() def btnSaveInformation_clicked(self, widget): pass def btnExit_clicked(self, widget): gtk.main_quit() if __name__ == "__main__": myApp = App() gtk.main() END CODE From cousinstanley at gmail.com Mon Jul 11 02:48:26 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 11 Jul 2011 06:48:26 +0000 (UTC) Subject: python xauth References: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> Message-ID: kracekumar ramaraju wrote: > I am looking to use xauth in python ? > > It is for my command line process, > I would like to have few examples > and resources. A simple example .... >>> import subprocess as SP >>> >>> proc = [ 'xauth' , 'list' , ':0' ] >>> >>> pipe = SP.Popen( proc , stdout = SP.PIPE ) >>> >>> data = pipe.stdout.readline() >>> >>> print '\n' , data em1dsq/unix:0 MIT-MAGIC-COOKIE-1 10a533afab15a57c8704a16d1dc5bb12 -- Stanley C. Kitching Human Being Phoenix, Arizona From ian.g.kelly at gmail.com Mon Jul 11 02:57:01 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 00:57:01 -0600 Subject: python xauth In-Reply-To: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> References: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, Jul 10, 2011 at 11:23 PM, kracekumar ramaraju wrote: > I am looking to use xauth in python?It is for my command line process,I would like to have few examples and resources. First, by "xauth" do you mean the X11 authorization scheme, or the "extended authentication" (xauth.org) scheme? The name is unfortunately overloaded. Second, have you tried googling for "python xauth"? Cheers, Ian From rosuav at gmail.com Mon Jul 11 04:09:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 18:09:52 +1000 Subject: A beginning programmer In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 8:06 AM, Eric wrote: > But I just don't know what > to do with it, I don't have any problems that need to be solved... There are always more problems to be solved than people willing to solve them! It's just a matter of finding ones you're interested in. Several people have recommended looking at bugtrackers and such. Another good source of programming tasks is automation - look for any task that you or someone else does repeatedly, and write a script that does it. That can range from a half-dozen lines of shell script up to full-on commercial-grade packages (if you think about it, an accounting system is nothing more than reports automation). Learn as many languages as you can. Develop the skill of picking up a new language and mastering it; obscure languages have just as interesting problems as do mainstream ones, and being able to learn Pike might suddenly come in handy when you find yourself invited to code on somebody's MUD some day! Chris Angelico Currently striving to be the Mr Melas of programming languages From awilliam at whitemice.org Mon Jul 11 06:24:53 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 11 Jul 2011 06:24:53 -0400 Subject: How to get or set the text of a textfield? In-Reply-To: References: Message-ID: <1310379894.3072.17.camel@linux-yu4c.site> On Mon, 2011-07-11 at 03:44 +0000, John Gordon wrote: > In Anthony Papillion writes: > > So I've built a UI with Glade and have loaded it using the standard > > Python code. In my UI, I have a textfield called txtUsername. How do I > > get and set the text in this field from my Python code? field.get_text() field.set_text(value) > and it will print a list of methods that are defined by that object. > Hopefully one of them will be called something helpful like set_text() > or set_property(). Once you know the method name, you might try a Google > search to determine the exact usage and arguments. -1 -1 -1 Do not "google" [search the Internet] for solutions to pyGtk problems. That is just a confusing waste of time. Use the *excellent* and well-linked documentation: The FAQ is extensive and really does cover a lot of the common questions. Also there is a list specifically for pygtk questions: Google, or Bing, or even DuckDuckGo, are *not* your friends. They are enormous and inefficient time-sinks. They are a *BAD* way to solve problems. Use the documentation. From sturlamolden at yahoo.no Mon Jul 11 06:34:03 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 03:34:03 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <9b368b53-6de3-4bbd-8dca-1fc3bb4af5bb@gh5g2000vbb.googlegroups.com> On 11 Jul, 00:50, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? If you by "RAD tool" mean "GUI builder", I'd recommend wxFormBuilder for wxPython, QtCreator for PyQt or PySide, and GLADE for PyGTK. Personally I prefer wxFormBuilder and wxPython, but it's a matter of taste. Sturla From sturlamolden at yahoo.no Mon Jul 11 06:47:02 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 03:47:02 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On 11 Jul, 02:43, Adam Tauno Williams wrote: > >Because RAD tools are for GUI toolkits, not for languages. If you're > >using GTK, Glade works fine. Same with QT and QTDesigner. If you're > >using WPF with IronPython, t > > These [Glade, etc...] are *NOT* RAD tools. ?They are GUI designers. ?A > RAD tool provides a GUI designer that can be bound to a backend > [typically an SQL database]. ?RAD = GUI + ORM. The type speciemens for "RAD tools" were Borland Delphi and Microsoft Visual Basic. They were not a combination of GUI designer and SQL/ORM backend. They were a combination of GUI designer, code editor, compiler, and debugger. Sturla From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jul 11 08:05:17 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Jul 2011 14:05:17 +0200 Subject: parsing packets In-Reply-To: References: Message-ID: Am 10.07.2011 22:59 schrieb Littlefield, Tyler: > Hello all: > I'm working on a server that will need to parse packets sent from a > client, and construct it's own packets. Are these packets sent as separate UDP packets or embedded in a TCP stream? In the first case, you already have packets and only have to parse them. In a stream, you first have to split them up. In the following, I will talk about UDP datagrams. For TCP, further work is needed. > The setup is something like this: the first two bytes is the type of the > packet. Then you have type = struct.unpack(">H", packet), payload1 = packet[2:] > So, lets say we have a packet set to connect. There are two types of > connect packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that > notes that it is a connect packet, and 4 bytes that contains the version > of the client. if type == CONNECT: subtype = struct.unpack("B", payload1) payload2 = payload1[1:] if subtype == CONNECT: upx = payload2.split("\0") assert len(upx) == 3 and upx[-1] == '' username, password = upx[:2] else: assert len(payload2) == 4 version = struct.unpack(">L", payload2) > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, > and a password and a NULL character. > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), I. e., you already have your packets distinct? That's fine. > and how I get the length of the packet with multiple NULL values. With len(), how else? > I'm also looking to build a packet and send it back out, is > there something that will allow me to designate two bytes, set > individual bits, then put it altogether in a packet to be sent out? The same: with struct.pack(). Thomas From bruno.desthuilliers at gmail.com Mon Jul 11 08:09:07 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Mon, 11 Jul 2011 05:09:07 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> On Jul 11, 2:42?am, Adam Tauno Williams wrote: > > But Open Source land is simply too fragmented. ?There are too many > database bindings [and RAD requires something like an ORM (think > SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list > goes on and on]. > > Nothing can muster the gravity required to bring a quality RAD tool into > existence. Why "too many" ? Natural selection is a GoodThing. Python is known as "the language with more web frameworks than keywords", and this doesn't prevent some of these frameworks to be 1/ pretty good and 2/ becoming de facto standards. > I also suspect - seeing some of the articles that float across the > FLOSS-o-sphere mentioning "RAD" - that many Open Source developers have > never had the pleasure [yes, it is a pleasure] of using a professional > RAD tool. This is slightly arrogant. Did you occur to you that quite a few OSS developers may have at least as much experience as you do with these kind of tools and just happen to actually prefer the unix way of doing things ? From fluxius at gmail.com Mon Jul 11 08:24:47 2011 From: fluxius at gmail.com (Sebastien Dudek) Date: Mon, 11 Jul 2011 05:24:47 -0700 (PDT) Subject: Freeze statically Message-ID: <41e815ee-e00b-41ef-9b95-f84018d86dab@q15g2000yqk.googlegroups.com> Hi everyone! Let me explain you my big adventure. So I trying to make a static python executable using the native Python freeze. I've modified the file Modules/Setup.dist using this perl cli : perl -pi -e 's!(^# \*shared\*)!*static*\n$1!' Modules/Setup.dist Then ./configure, make && make install If I'm using my python interpreter to build with freeze a simple project that we can call "hello world". It works perfectly but it is still : "dynamically linked (uses shared libs)". So modifying the Makefile using '-static' for linking, I hopped I could make it static. But... it fail : +------------------------------------------------------------------------------------------------------------------------------------------ + ... /home/fluxius/Python-2.7.2/./Modules/pwdmodule.c:156: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /home/fluxius/Python-2.7.2/./Modules/pwdmodule.c:168: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/ 4.5.2/../../../libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie collect2: ld returned 1 exit status make: *** [hello] Erreur 1 +------------------------------------------------------------------------------------------------------------------------------------------ + Help me please!! =) From ben+python at benfinney.id.au Mon Jul 11 08:39:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 22:39:46 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> Message-ID: <871uxxf0tp.fsf@benfinney.id.au> "bruno.desthuilliers at gmail.com" writes: > On Jul 11, 2:42?am, Adam Tauno Williams > wrote: > > > > But Open Source land is simply too fragmented. ?There are too many > > database bindings [and RAD requires something like an ORM (think > > SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list > > goes on and on]. > > Why "too many" ? Natural selection is a GoodThing. Natural selection is not a good thing. It is blind and unthinking and cruel and wasteful and haphazard and purposeless. Those aren't traits to recommend it, IMO. (It's also not a bad thing. Natural selection just is.) Natural selection is not what's happening here. Rather, *artifical* selection, with people as the agents of selection, have purposes and wants that guide their selections. It would be better to say: Competition can be (not an unalloyed ?is?) a Good Thing. > Python is known as "the language with more web frameworks than > keywords", and this doesn't prevent some of these frameworks to be 1/ > pretty good and 2/ becoming de facto standards. Right. People are selecting web frameworks for their fitness to purposes, but their purposes are many and change over time. So there can be many such frameworks, of varying popularity, and that's a good thing. > > I also suspect - seeing some of the articles that float across the > > FLOSS-o-sphere mentioning "RAD" - that many Open Source developers > > have never had the pleasure [yes, it is a pleasure] of using a > > professional RAD tool. > > This is slightly arrogant. Did you occur to you that quite a few OSS > developers may have at least as much experience as you do with these > kind of tools and just happen to actually prefer the unix way of doing > things ? Yes. As someone who has used some of those all-in-one one-size-fits-most tools, I can testify that their usefulness is severely limited when compared with the Unix model. The Unix model is: a collection of general-purpose, customisable tools, with clear standard interfaces that work together well, and are easily replaceable without losing the benefit of all the others. -- \ ?Are you pondering what I'm pondering?? ?Umm, I think so, | `\ Brain, but what if the chicken won't wear the nylons?? ?_Pinky | _o__) and The Brain_ | Ben Finney From rantingrick at gmail.com Mon Jul 11 09:42:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 06:42:50 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> Message-ID: <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> On Jul 10, 11:45?pm, Michael Hrivnak wrote: > I can't believe you're saying that you will create a sub-class without > taking the time to understand the base class. I'm NOT saying that so stop putting words in my mouth! > Seriously? ?That right > there is why you are seeing method overrides that aren't documented. You being a bit bombastic now with this *rolls-eyes* > How can you document something you don't understand? ?Furthermore, how > can you have any confidence in your subclass if you don't understand > what its base class is doing? ?Do you write unit tests? ?How do you > know what to test if you don't understand the code you are > subclassing? You took my simple statement of... " It is not ALWAYS necessary to have an intimate knowledge of the base class when creating derived classes"... and extrapolated THAT nonsense? Okay let me show you a simple example of not needing to know the base class intimatly. I'll use the tkSimpleDialog... class MyDialog(tkSimpleDialog.Dialog): def body(self, master): #imagine i created widgets here. NOW. Would it really be nessesary at this point to have an intimate knowledge of the base class? Hmm? > Suggesting that no developers document their methods? ?Incredible. Very, very few document clobbered virtual methods. yes. > Clobbered methods have "magic"? ?Multi-layered "magic"? Of course! That is, in the perverted case of Clarke's third law[1]... "Any sufficiently advanced technology is indistinguishable from magic"... And since class inheritance can be multi-layered, um, you get the idea. > ?Perhaps when > you take the time to 1) document the base class and 2) understand that > base class before subclassing it, that "magic" will start to look like > reasonable and logical processes. You're preaching to the choir reverend! > Professional developers document their code. ?They take the time to > understand the code they are working on. ?If you don't want to do > those things, that's your business, and I'm sure you can find other > people who also don't do those things. ?But I really don't think > you'll have much success changing the language to accommodate your > refusal to follow the most basic best practices. It's not me that needs to change kind sir, it is the community in general. I document my code. I follow the python style guide. I always create unit tests. Unfortunately no matter how well i write code i cannot force others to do so. Heck i have posted many fixes for the abomination called tkSimpleDialog and not only do they refuse to upgrade the code, they refuse to even post comments! This mandate must be handed down from the gods who reside on "Mount REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" [1] http://en.wikipedia.org/wiki/Clarke's_three_laws From sturlamolden at yahoo.no Mon Jul 11 09:44:22 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 06:44:22 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> Message-ID: <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> On 11 Jul, 14:39, Ben Finney wrote: > The Unix model is: a collection of general-purpose, customisable tools, > with clear standard interfaces that work together well, and are easily > replaceable without losing the benefit of all the others. This is opposed to the "Windows model" of a one-click installer for a monolithic application. Many Windows users get extremely frustrated when they have to use more than one tool. There is also a deep anxiety of using the keyboard. This means that command line tools are out of the question (everything needs a GUI). In the Windows world, even programming should be drag-and-drop with the mouse. Windows programmers will go to extreme measures to avoid typing code on their own, as tke keyboard is so scary. The most extreme case is not Visual Basic but LabView, where even business logic is drag-and-drop. A side-effect is that many Windows developers are too dumb to write code on their own, and rely on pre-coded "components" that can be dropped on a "form". A common fail-case is multiuser applications, where the developers do not understand anything about what is going on, and scalability is non-existent. Sturla From anthony.hw.kong at gmail.com Mon Jul 11 09:51:30 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Mon, 11 Jul 2011 23:51:30 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? Message-ID: Hi, all, Lately I am giving some presentations to my colleagues about the python language. A new internal project is coming up which will require the use of python. One of my colleague asked an interesting: *If Python use indentation to denote scope, why it still needs semi-colon at the end of function declaration and for/while/if loop?* My immediate response is: it allows us to fit statements into one line. e.g. if a == 1: print a However I do not find it to be a particularly strong argument. I think PEP8 does not recommend this kind of coding style anyway, so one-liner should not be used in the first place! Is there any other reasons for use of semi-colon in python? Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Mon Jul 11 09:58:10 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Jul 2011 09:58:10 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <769cc$4e1b01fb$4275d90a$18434@FUSE.NET> On 7/10/11 6:50 PM, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? http://pyobjc.sourceforge.net/ -- Kevin Walzer Code by Kevin http://www.codebykevin.com From thorsten at thorstenkampe.de Mon Jul 11 10:10:28 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 11 Jul 2011 16:10:28 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: * sturlamolden (Mon, 11 Jul 2011 06:44:22 -0700 (PDT)) > On 11 Jul, 14:39, Ben Finney wrote: > > The Unix model is: a collection of general-purpose, customisable > > tools, with clear standard interfaces that work together well, and > > are easily replaceable without losing the benefit of all the others. > > This is opposed to the "Windows model" of a one-click installer for a > monolithic application. Many Windows users get extremely frustrated > when they have to use more than one tool. *sigh* There is no Windows nor Unix "model". There is only you-get-what- you-pay-for. On Windows, you're a customer and the developer wants to make using his application as convenient as possible for you, the customer. On Unix you don't pay and the developer couldn't care less if his application works together with application b or how much it takes you to actually get this damn thing running. And as soon as developers start developing for Unix customers (say Komodo, for instance), they start following the "Windows model" - as you call it. Thorsten From t at jollybox.de Mon Jul 11 10:16:17 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 16:16:17 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: <4E1B05B1.1050201@jollybox.de> On 07/11/2011 03:51 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use > of python. > > One of my colleague asked an interesting: > > /If Python use indentation to denote scope, why it still needs > semi-colon at the end of function declaration and for/while/if loop?/ > > My immediate response is: it allows us to fit statements into one line. > e.g. if a == 1: print a > > However I do not find it to be a particularly strong argument. I think > PEP8 does not recommend this kind of coding style anyway, so one-liner > should not be used in the first place! Basically, it looks better, and is more readable. A colon, in English like in Python, means that something follows that is related to what was before the colon. So the colon makes it abundantly clear to the human reader that a block follows, and that that block is to be considered in relation to what was just said, before the colon. Coincidentally, Guido wrote this blog post just last week, without which I'd be just as much at a loss as you: http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html From sturlamolden at yahoo.no Mon Jul 11 10:21:37 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 07:21:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> On 11 Jul, 16:10, Thorsten Kampe wrote: > And as soon as developers start developing for Unix customers (say > Komodo, for instance), they start following the "Windows model" - as you > call it. You are probably aware that Unix and Unix customers have been around since the 1970s. I would expect the paradigm to be changed by now. S.M. From call_me_not_now at yahoo.it Mon Jul 11 10:21:37 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:21:37 +0800 Subject: Saving emails Message-ID: Hello, my curiosity these day lay around the problem given by Kmail2. I'd like to keep my old emails and a backup would satisfy my needs. The only conditions should be that the mails will come back in a quick way. I found this page http://www.ducea.com/2006/11/25/cleanup-maildir-folders-archive-delete-old- mails/ Which gives me some point, but the program is too old and I'd like to use Python 3. Another chance it would be to implement an IMAP server which move old emails in and out of an archive. Then it will be simple to recall old emails. Some docs about email deciphering. Kmail uses a maildir and several subfolders. I'd like to export the emails in mbox file and perhaps to separate by a period of time, say July2010, September2010 end so forth. Thanks in advance From anthony.hw.kong at gmail.com Mon Jul 11 10:23:43 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 00:23:43 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B05B1.1050201@jollybox.de> References: <4E1B05B1.1050201@jollybox.de> Message-ID: Awesome! Thanks for blog post link Cheers On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans wrote: > On 07/11/2011 03:51 PM, Anthony Kong wrote: > > Hi, all, > > > > Lately I am giving some presentations to my colleagues about the python > > language. A new internal project is coming up which will require the use > > of python. > > > > One of my colleague asked an interesting: > > > > /If Python use indentation to denote scope, why it still needs > > semi-colon at the end of function declaration and for/while/if loop?/ > > > > My immediate response is: it allows us to fit statements into one line. > > e.g. if a == 1: print a > > > > However I do not find it to be a particularly strong argument. I think > > PEP8 does not recommend this kind of coding style anyway, so one-liner > > should not be used in the first place! > > Basically, it looks better, and is more readable. A colon, in English > like in Python, means that something follows that is related to what was > before the colon. So the colon makes it abundantly clear to the human > reader that a block follows, and that that block is to be considered in > relation to what was just said, before the colon. > > Coincidentally, Guido wrote this blog post just last week, without which > I'd be just as much at a loss as you: > > > http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html > > -- > http://mail.python.org/mailman/listinfo/python-list > -- /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Jul 11 10:24:57 2011 From: gordon at panix.com (John Gordon) Date: Mon, 11 Jul 2011 14:24:57 +0000 (UTC) Subject: How to get or set the text of a textfield? References: Message-ID: In Adam Tauno Williams writes: > Google, or Bing, or even DuckDuckGo, are *not* your friends. They are > enormous and inefficient time-sinks. They are a *BAD* way to solve > problems. Use the documentation. One would hope that a Google search might lead to the documentation. -- 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 davea at ieee.org Mon Jul 11 10:36:48 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 11 Jul 2011 10:36:48 -0400 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: <4E1B0A80.3060305@ieee.org> On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use of > python. > > One of my colleague asked an interesting: > > *If Python use indentation to denote scope, why it still needs semi-colon at > the end of function declaration and for/while/if loop?* > > My immediate response is: it allows us to fit statements into one line. e.g. > if a == 1: print a > > However I do not find it to be a particularly strong argument. I think PEP8 > does not recommend this kind of coding style anyway, so one-liner should not > be used in the first place! > > Is there any other reasons for use of semi-colon in python? > > > Cheers > You're confusing the colon with the semi-colon. If you want two statements on the same line, you use a semi-colon. The character you're asking about is the colon. It goes at the end of an if, else, for, with, while statement. I doubt it's absolutely essential, but it helps readability, since a conditional expression might span multiple lines. if someexpression == someotherexpression: body_of_the_conditional DaveA From thorsten at thorstenkampe.de Mon Jul 11 10:38:05 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 11 Jul 2011 16:38:05 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: * sturlamolden (Mon, 11 Jul 2011 07:21:37 -0700 (PDT)) > On 11 Jul, 16:10, Thorsten Kampe wrote: > > And as soon as developers start developing for Unix customers (say > > Komodo, for instance), they start following the "Windows model" - as > > you call it. > > You are probably aware that Unix and Unix customers have been around > since the 1970s. I would expect the paradigm to be changed by now. For the /customers/ on Unix it never was a paradigm. They would have laughed in their vendor's face if they had gotten the "here are the tools, just make them work together as you like" attitude[1]. Thorsten [1] at least starting from the beginning of the nineties when commercial alternatives to Unix began to emerge From rosuav at gmail.com Mon Jul 11 10:39:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 00:39:17 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 12:21 AM, sturlamolden wrote: > You are probably aware that Unix and Unix customers have been around > since the 1970s. I would expect the paradigm to be changed by now. > The paradigm of small tools that do exactly what they're supposed to, and can be combined? Nope. There's still a philosophy of services that fit together like a jigsaw puzzle, rather than expecting each application to do everything you want it to. A standard Unix command line might consist of three or more tools, piping from one into another - grep the Apache log for lines containing the name of a PHP script, pipe that into awk to pick up just the user name, IP address, and date (without time), then pipe into uniq (deliberately without first going through sort) to show who's been using the script lately. And then piped it through sed to clean up the format a bit. Yep, that's something I did recently. Point to note: This is the Unix *philosophy* versus the Windows *philosophy*, not Unix *programs* versus Windows *programs*. There are Windows programs that follow the Unix philosophy. ChrisA From rosuav at gmail.com Mon Jul 11 10:41:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 00:41:59 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 11:42 PM, rantingrick wrote: > This mandate must be handed down from the gods who reside on "Mount > REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" > I assume you're trying to reference Mount Olympus where the Greek gods live, but I'm left thinking more of Mount Vesuvius... possibly not the best reference for what you're saying. But once again, Ranting Rick posts something saying that he is perfect and everyone else needs to change. I can see why you keep landing in killfiles [1]. ChrisA [1] http://bofh.ch/bofh/bsmh2.html From call_me_not_now at yahoo.it Mon Jul 11 10:42:19 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:42:19 +0800 Subject: Finding duplicated photo References: Message-ID: Thomas Jollans wrote: > If Gwenview simply moves/renames the images, is it not enough to compare > the actual files, byte by byte? For the work at the spot I found Geeqie, doing right. In the other hand learning some PIL function is one of my interest. From invalid at invalid.invalid Mon Jul 11 10:43:53 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Jul 2011 14:43:53 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-11, Thomas Jollans wrote: > On 07/11/2011 03:51 PM, Anthony Kong wrote: >> Hi, all, >> >> Lately I am giving some presentations to my colleagues about the python >> language. A new internal project is coming up which will require the use >> of python. >> >> One of my colleague asked an interesting: >> >> /If Python use indentation to denote scope, why it still needs >> semi-colon at the end of function declaration and for/while/if loop?/ >> >> My immediate response is: it allows us to fit statements into one line. >> e.g. if a == 1: print a >> >> However I do not find it to be a particularly strong argument. I think >> PEP8 does not recommend this kind of coding style anyway, so one-liner >> should not be used in the first place! > > Basically, it looks better, and is more readable. And it makes adding a "python mode" to a programming editor almost trivial. -- Grant Edwards grant.b.edwards Yow! I am a jelly donut. at I am a jelly donut. gmail.com From call_me_not_now at yahoo.it Mon Jul 11 10:50:00 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:50 +0800 Subject: Finding duplicated photo References: Message-ID: Kevin Zhang wrote: > If anyone's interested, pleas checkout the source code in the attachment > and welcome any advise. I found that isn't python 3 code :( Then the code should go into some other program to allow actions on those pictures which are matching each other. Am I right? From sebastien.volle at gmail.com Mon Jul 11 10:50:20 2011 From: sebastien.volle at gmail.com (=?ISO-8859-1?Q?S=E9bastien_Volle?=) Date: Mon, 11 Jul 2011 16:50:20 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: Could it have been made optional, like the trailing comma in list declaration? -- Seb 2011/7/11 Anthony Kong > Awesome! Thanks for blog post link > > Cheers > > > On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans wrote: > >> On 07/11/2011 03:51 PM, Anthony Kong wrote: >> > Hi, all, >> > >> > Lately I am giving some presentations to my colleagues about the python >> > language. A new internal project is coming up which will require the use >> > of python. >> > >> > One of my colleague asked an interesting: >> > >> > /If Python use indentation to denote scope, why it still needs >> > semi-colon at the end of function declaration and for/while/if loop?/ >> > >> > My immediate response is: it allows us to fit statements into one line. >> > e.g. if a == 1: print a >> > >> > However I do not find it to be a particularly strong argument. I think >> > PEP8 does not recommend this kind of coding style anyway, so one-liner >> > should not be used in the first place! >> >> Basically, it looks better, and is more readable. A colon, in English >> like in Python, means that something follows that is related to what was >> before the colon. So the colon makes it abundantly clear to the human >> reader that a block follows, and that that block is to be considered in >> relation to what was just said, before the colon. >> >> Coincidentally, Guido wrote this blog post just last week, without which >> I'd be just as much at a loss as you: >> >> >> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > /*--*/ > Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence _much_ too much credit. > > - Linus Torvalds > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From call_me_not_now at yahoo.it Mon Jul 11 10:54:44 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:54:44 +0800 Subject: Finding duplicated photo References: Message-ID: Dave Angel wrote: > If your real problem is identifying a renamed file amongst thousands of > others, why not just compare the metadata? it'll be much faster. > This was the primer situation, then to get into the dirt I tought something more sophisticated. There was a program some year's back which was brilliant an fast to find similar pictures on several thousand of them. Now I can't recall what was the program name and very interesting to do some of mine experiments. From t at jollybox.de Mon Jul 11 11:01:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 17:01:58 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B0A80.3060305@ieee.org> References: <4E1B0A80.3060305@ieee.org> Message-ID: <4E1B1066.5070107@jollybox.de> On 07/11/2011 04:36 PM, Dave Angel wrote: > The character you're asking about is the colon. It goes at the end of > an if, else, for, with, while statement. I doubt it's absolutely > essential, but it helps readability, since a conditional expression > might span multiple lines. > if someexpression == > someotherexpression: > body_of_the_conditional That, of course, is not legal Python. Your point stands when you add brackets or a backslash to hold the condition together. From anthony.hw.kong at gmail.com Mon Jul 11 11:07:17 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:07:17 +1000 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? Message-ID: Hi, all, Lately I am giving some presentations to my colleagues about the python language. A new internal project is coming up which will require the use of python. One of the goals of the presentations, as told by the 'sponsor' of the presentation, is to help the existing Java/Excel VBA programming team to become productive in python asap. I have a feeling that they are asking it based on their Java/Eclipse experience. By productive they are actually looking for some GUI tools that are as helpful as Eclipse. Having done Java programming before, I am thinking of answering the question this way: 1) For many of us, vi/emacs are sufficient for python development. (I used vim + ctags as my primary IDE for a very long time) 2) For a feature-rich GUI environment, we can consider pyCharm. (I was totally 'wowed' by it, and has convinced my last employer to purchased a few enterprise licenses) 3) The Python language itself is actually small and concise. The need for a full-blown IDE is less. The language itself could be counted as a part of the productive tool. 4) The functional aspect of the language (e.g. map, reduce, partial) helps to make program shorter and easier to understand 5) The 'battery included' standard library helps to avoid the need of complicated build tool. 6) The interactive shell helps to test out solutions in smaller units. It is probably not the team is expecting. Do you have more to add? What do you think about this 'answer'? Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.hw.kong at gmail.com Mon Jul 11 11:10:44 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:10:44 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B0A80.3060305@ieee.org> References: <4E1B0A80.3060305@ieee.org> Message-ID: Sorry, typo in my original question. I do mean 'colon'. It should have read *If Python use indentation to denote scope, why it still needs colon at the end of function declaration and for/while/if loop?* Thanks On Tue, Jul 12, 2011 at 12:36 AM, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > >> Hi, all, >> >> Lately I am giving some presentations to my colleagues about the python >> language. A new internal project is coming up which will require the use >> of >> python. >> >> One of my colleague asked an interesting: >> >> *If Python use indentation to denote scope, why it still needs semi-colon >> at >> the end of function declaration and for/while/if loop?* >> >> My immediate response is: it allows us to fit statements into one line. >> e.g. >> if a == 1: print a >> >> However I do not find it to be a particularly strong argument. I think >> PEP8 >> does not recommend this kind of coding style anyway, so one-liner should >> not >> be used in the first place! >> >> Is there any other reasons for use of semi-colon in python? >> >> >> Cheers >> >> You're confusing the colon with the semi-colon. If you want two > statements on the same line, you use a semi-colon. > > The character you're asking about is the colon. It goes at the end of an > if, else, for, with, while statement. I doubt it's absolutely essential, > but it helps readability, since a conditional expression might span multiple > lines. > if someexpression == > someotherexpression: > body_of_the_conditional > > DaveA > > -- /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 11 11:28:11 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 09:28:11 -0600 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle wrote: > Could it have been made optional, like the trailing comma in list > declaration? Cobra makes the colons optional, so probably yes. From chris.hulan at gmail.com Mon Jul 11 11:33:45 2011 From: chris.hulan at gmail.com (Chris Hulan) Date: Mon, 11 Jul 2011 08:33:45 -0700 (PDT) Subject: OK, I lied, I do have another question... In-Reply-To: Message-ID: The callback is a method so you need to specify the owner builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : self.btnExit_clicked}) Got this info from http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm cheers From chris.hulan at gmail.com Mon Jul 11 11:33:45 2011 From: chris.hulan at gmail.com (Chris Hulan) Date: Mon, 11 Jul 2011 08:33:45 -0700 (PDT) Subject: OK, I lied, I do have another question... In-Reply-To: Message-ID: The callback is a method so you need to specify the owner builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : self.btnExit_clicked}) Got this info from http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm cheers From anthony.hw.kong at gmail.com Mon Jul 11 11:54:18 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:54:18 +1000 Subject: Property setter and lambda question Message-ID: Hi, all, This question is in the same context of my two earlier questions. This question was raised by some python beginners, and I would like to check with the list to ensure I provide a correct answer. Here is a code snippet I used to demonstrate the keyword *property*: class A(object): def __init__(self): self.__not_here = 1 def __get_not_here(self): return self.__not_here def __set_not_here(self, v): print "I am called" self.__not_here = v not_here = property(lambda self: self.__get_not_here(), lambda self, v: self.__set_not_here(v)) # not_here = property(lambda self: self.__not_here, lambda self, v: self.__not_here = v) So the question: is it possible to use lambda expression at all for the setter? (As in the last, commented-out line) Python interpreter will throw an exception right there if I use the last line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a setter method anyway. What is your preferred solution? -- Tony Kong *blog:* www.ahwkong.com /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Jul 11 12:00:55 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:00:55 +0200 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: References: Message-ID: <4E1B1E37.4050900@jollybox.de> On 07/11/2011 05:07 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use > of python. > > One of the goals of the presentations, as told by the 'sponsor' of the > presentation, is to help the existing Java/Excel VBA programming team to > become productive in python asap. > > I have a feeling that they are asking it based on their Java/Eclipse > experience. By productive they are actually looking for some GUI tools > that are as helpful as Eclipse. > > Having done Java programming before, I am thinking of answering the > question this way: > > 1) For many of us, vi/emacs are sufficient for python development. (I > used vim + ctags as my primary IDE for a very long time) > > 2) For a feature-rich GUI environment, we can consider pyCharm. (I was > totally 'wowed' by it, and has convinced my last employer to purchased a > few enterprise licenses) > > 3) The Python language itself is actually small and concise. The need > for a full-blown IDE is less. The language itself could be counted as a > part of the productive tool. If your colleagues are used to Eclipse, it's almost certainly best to continue using Eclipse, with PyDev. Don't make a big deal of the tools, just say that many Pythonista don't use a heavy IDE, mention PyDev, and, if you want to, recommend pyCharm. > 4) The functional aspect of the language (e.g. map, reduce, partial) > helps to make program shorter and easier to understand Don't overemphasize this. Those functions can be very useful, and using them can lead to very concise and simple code, but (big BUT) more often than not, they're overly cryptic when compared to list comprehension and generator expressions. Do make a huge case for generator expressions/list comprehension, and generators. > 5) The 'battery included' standard library helps to avoid the need of > complicated build tool. > > 6) The interactive shell helps to test out solutions in smaller units. Speaking of testing: introduce them to the doctest module. > It is probably not the team is expecting. Do you have more to add? What > do you think about this 'answer'? If using Jython is an option, present it! Jython will allow Java programmers to use their existing knowledge of the Java standard library. Explain, and make the case for, duck typing. While actual functional programming is, as I said, a bit "out there" from a Java/VBA standpoint, do show off function objects. If you know what they're going to do with Python, you should point them to relevant libraries/modules. From wanderer at dialup4less.com Mon Jul 11 12:04:10 2011 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 11 Jul 2011 09:04:10 -0700 (PDT) Subject: ctypes: point to buffer in structure References: Message-ID: <2ffb0be9-923b-4122-b68d-9a5813a579a9@a31g2000vbt.googlegroups.com> On Jul 11, 1:12?am, Tim Roberts wrote: > Jesse R wrote: > > >Hey I've been trying to convert this to run through ctypes and i'm > >having a hard time > > >typedef struct _SYSTEM_PROCESS_ID_INFORMATION > >{ > > ? ?HANDLE ProcessId; > > ? ?UNICODE_STRING ImageName; > >} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, > >*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; > > >to > > >class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): > > ? ?_fields_ = [('pid', ctypes.c_ulong), > > ? ? ? ? ? ? ? ? ? ?('imageName', ctypes.c_wchar_p)] > >... > >does anyone know how to get this working? > > UNICODE_STRING is not just a pointer to wide characters. ?It is itself a > structure: > > typedef struct _UNICODE_STRING { > ? ? USHORT Length; > ? ? USHORT MaximumLength; > ? ? PWSTR ?Buffer; > > } UNICODE_STRING; > > So, I think you want fields of ctypes.c_ulong, ctypes.c_ushort, > ctypes.c_ushort, and ctypes.c_wchar_p. ?MaximumLength gives the allocated > size of the buffer. ?Length gives the length of the string currently held > in the buffer. ?It can be less than the maximum length, and the buffer does > NOT necessarily contain a zero-terminator. > > UNICODE_STRING and ANSI_STRING are used in kernel programming to avoid the > potential ambiguities of counted strings. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. if UNICODE_STRING is a structure you will want a structure for it class UNICODE_STRING(ctypes.Structure): _fields_ = [("Length", ctypes.c_ushort), ("MaximumLength" ,ctypes.c_ushort), ("Buffer", ctypes.c_wchar_p)] class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): _fields_ = [("pid", ctypes.c_ulong), ("imageName", UNICODE_STRING)] From t at jollybox.de Mon Jul 11 12:23:39 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:23:39 +0200 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: <4E1B238B.7050607@jollybox.de> On 07/11/2011 05:54 PM, Anthony Kong wrote: > Hi, all, > > This question is in the same context of my two earlier questions. This > question was raised by some python beginners, and I would like to check > with the list to ensure I provide a correct answer. > > Here is a code snippet I used to demonstrate the keyword *property*: > > > class A(object): > > def __init__(self): > self.__not_here = 1 > > def __get_not_here(self): > return self.__not_here > > def __set_not_here(self, v): > print "I am called" > self.__not_here = v > > not_here = property(lambda self: self.__get_not_here(), lambda self, > v: self.__set_not_here(v)) > # not_here = property(lambda self: self.__not_here, lambda self, v: > self.__not_here = v) > > So the question: is it possible to use lambda expression at all for the > setter? (As in the last, commented-out line) > > Python interpreter will throw an exception right there if I use the last > line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a > setter method anyway. > > What is your preferred solution? No, a lambda can only contain an expression, not a statement. This is not C, assignments are not expressions. As to what I would do: There's really no need to use lambdas at all here: class A(object): def __init__(self): self.not_here = 1 def __get_not_here(self): return self.__not_here def __set_not_here(self, val): self.__not_here = val not_here = property(__get_not_here, __set_not_here) My favourite way to create properties is of course with decorators: class A(object): def __init__(self): self.not_here = 1 @property def not_here(self): return self.__not_here @not_here.setter def not_here(self, val): self.__not_here = val From rustompmody at gmail.com Mon Jul 11 12:33:35 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 11 Jul 2011 09:33:35 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: On Jul 11, 7:39?pm, Chris Angelico wrote: > On Tue, Jul 12, 2011 at 12:21 AM, sturlamolden wrote: > > You are probably aware that Unix and Unix customers have been around > > since the 1970s. I would expect the paradigm to be changed by now. > > The paradigm of small tools that do exactly what they're supposed to, > and can be combined? Nope. There's still a philosophy of services that > fit together like a jigsaw puzzle, rather than expecting each > application to do everything you want it to. A standard Unix command > line might consist of three or more tools, piping from one into > another - grep the Apache log for lines containing the name of a PHP > script, pipe that into awk to pick up just the user name, IP address, > and date (without time), then pipe into uniq (deliberately without > first going through sort) to show who's been using the script lately. > And then piped it through sed to clean up the format a bit. Yep, > that's something I did recently. > > Point to note: This is the Unix *philosophy* versus the Windows > *philosophy*, not Unix *programs* versus Windows *programs*. There are > Windows programs that follow the Unix philosophy. > > ChrisA The intention of programming is to close the semantic gap. ------------- It is a fundamental task of software engineering to close the gap between application specific knowledge and technically doable formalization. For this purpose domain specific (high-level) knowledge must be transferred into an algorithm and its parameters (low-level). (from http://en.wikipedia.org/wiki/Semantic_gap ------------- A gui-builder reduces the semantic gap by showing a widget when the programmer things 'widget.' Banging out hundreds of lines in vi/emacs for the same purpose does a measurably poorer job. Note it can reduce but not close. By choosing fidelity to the gui we have corresponding less fidelity to the algos and data-structures [And one may assume that someone even using a gui toolkit wants to do something with the gui and not just paint the screen] Still it seems a bit naive to suggest that building a gui by a few point&clicks is 'windows-model' and banging out hundreds of lines in vi/emacs is 'unix-model.' It does disservice to python and to unix. If a student of mine came and said: Is Python better or Unix? he would receive a dressing down. And yet more than one person here seems to think such type-wrong comparisons are ok. I find this disturbing... From julio at techfuel.net Mon Jul 11 12:38:22 2011 From: julio at techfuel.net (Speedbird) Date: Mon, 11 Jul 2011 09:38:22 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <6609283c-27ec-4e9d-99b3-758c2cdc80ac@17g2000prr.googlegroups.com> > On Windows, you're a customer and the developer wants to make using his > application as convenient as possible for you, the customer. > So the well-behavioured, good-intentioned windows devs are making sure the customer feels pampered and cozy, how nice and dandy. > On Unix you don't pay and the developer couldn't care less if his > application works together with application b or how much it takes you > to actually get this damn thing running. > Now, on the other hand, the bad, bearded, grumpy and ugly unix devs want to make the customer's life miserable, bad boys.. What a load of bull, I am a unix developer and do _care_ for my customers, being them sysadmins, end users or even windows heads, and I am sure I am not the only one thinking this way. The windows "way of doing things" ("user friendly experience", "point and click", "plug and play") etc is not a bad one at all, it consists of tools to allow developers who have lesser understanding about computers to create applications that will be used by users with also little understanding about computers in general, on the other hand, unix/linus/posix devs develop applications that can potentially be used more efficiently by people with great understanding about computers in general. Both have their user base, and this is IMO the primary reason why windows is the dominant OS currently, those with little understanding about computers and technology in general far outnumber those who do. From anthony.hw.kong at gmail.com Mon Jul 11 12:42:56 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:42:56 +1000 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: <4E1B1E37.4050900@jollybox.de> References: <4E1B1E37.4050900@jollybox.de> Message-ID: Thomas, Thanks for the excellent suggestions. Generator is certainly an interesting subject. >From what i understand, the advantage of generator is mainly about saving memory, right? (i.e. no need to create a list in memory before iterate thru it) Duck typing... Although it can be easily demonstrated, I find it hard to explain its advantages to Java developers who are so used to Interfaces. (Is it about the certainty of type info... I am not sure about their concern actually) Jython is not a possibility, but I will show them an example anyway. We can use it to write some support script, I suppose. (Off topic) Monkey patching - It is a term used by Ruby developer a lot. If it means to change a function's implementation in run-time, i think python can achieve the same, right? Is it equivalent to Mixin? Cheers On Tue, Jul 12, 2011 at 2:00 AM, Thomas Jollans wrote: > On 07/11/2011 05:07 PM, Anthony Kong wrote: > > Hi, all, > > > > Lately I am giving some presentations to my colleagues about the python > > language. A new internal project is coming up which will require the use > > of python. > > > > One of the goals of the presentations, as told by the 'sponsor' of the > > presentation, is to help the existing Java/Excel VBA programming team to > > become productive in python asap. > > > > I have a feeling that they are asking it based on their Java/Eclipse > > experience. By productive they are actually looking for some GUI tools > > that are as helpful as Eclipse. > > > > Having done Java programming before, I am thinking of answering the > > question this way: > > > > 1) For many of us, vi/emacs are sufficient for python development. (I > > used vim + ctags as my primary IDE for a very long time) > > > > 2) For a feature-rich GUI environment, we can consider pyCharm. (I was > > totally 'wowed' by it, and has convinced my last employer to purchased a > > few enterprise licenses) > > > > 3) The Python language itself is actually small and concise. The need > > for a full-blown IDE is less. The language itself could be counted as a > > part of the productive tool. > > If your colleagues are used to Eclipse, it's almost certainly best to > continue using Eclipse, with PyDev. Don't make a big deal of the tools, > just say that many Pythonista don't use a heavy IDE, mention PyDev, and, > if you want to, recommend pyCharm. > > > 4) The functional aspect of the language (e.g. map, reduce, partial) > > helps to make program shorter and easier to understand > > Don't overemphasize this. Those functions can be very useful, and using > them can lead to very concise and simple code, but (big BUT) more often > than not, they're overly cryptic when compared to list comprehension and > generator expressions. > > Do make a huge case for generator expressions/list comprehension, and > generators. > > > 5) The 'battery included' standard library helps to avoid the need of > > complicated build tool. > > > > 6) The interactive shell helps to test out solutions in smaller units. > > Speaking of testing: introduce them to the doctest module. > > > It is probably not the team is expecting. Do you have more to add? What > > do you think about this 'answer'? > > If using Jython is an option, present it! Jython will allow Java > programmers to use their existing knowledge of the Java standard library. > > Explain, and make the case for, duck typing. > > While actual functional programming is, as I said, a bit "out there" > from a Java/VBA standpoint, do show off function objects. > > If you know what they're going to do with Python, you should point them > to relevant libraries/modules. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 11 12:43:56 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 10:43:56 -0600 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 9:54 AM, Anthony Kong wrote: > Hi, all, > This question is in the same context of my two earlier questions. This > question was raised by some python beginners, and I would like to check with > the list to ensure I provide a correct answer. > Here is a code?snippet?I used to demonstrate the keyword property: What Thomas said. But also, please note that "property" is a builtin, not a keyword. Cheers, Ian From anthony.hw.kong at gmail.com Mon Jul 11 12:53:29 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:53:29 +1000 Subject: Property setter and lambda question In-Reply-To: <4E1B238B.7050607@jollybox.de> References: <4E1B238B.7050607@jollybox.de> Message-ID: Thanks again for your input, Thomas. I normally prefer not_here = property(lambda self: self.__get_not_here(), lambda self, v: self.__set_not_here(v)) than not_here = property(__get_not_here, __set_not_here) Because it allows me to have a pair getter/setter (when there is a need for it). Use of lambda there is ensure derived class of A can provide their custom version of getter/setter. But decorator! Of course! Thanks for reminding me this. In your example, where does '@not_here' come from? (Sorry, this syntax is new to me) Cheers On Tue, Jul 12, 2011 at 2:23 AM, Thomas Jollans wrote: > On 07/11/2011 05:54 PM, Anthony Kong wrote: > > Hi, all, > > > > This question is in the same context of my two earlier questions. This > > question was raised by some python beginners, and I would like to check > > with the list to ensure I provide a correct answer. > > > > Here is a code snippet I used to demonstrate the keyword *property*: > > > > > > class A(object): > > > > def __init__(self): > > self.__not_here = 1 > > > > def __get_not_here(self): > > return self.__not_here > > > > def __set_not_here(self, v): > > print "I am called" > > self.__not_here = v > > > > not_here = property(lambda self: self.__get_not_here(), lambda self, > > v: self.__set_not_here(v)) > > # not_here = property(lambda self: self.__not_here, lambda self, v: > > self.__not_here = v) > > > > So the question: is it possible to use lambda expression at all for the > > setter? (As in the last, commented-out line) > > > > Python interpreter will throw an exception right there if I use the last > > line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a > > setter method anyway. > > > > What is your preferred solution? > > No, a lambda can only contain an expression, not a statement. This is > not C, assignments are not expressions. > > As to what I would do: > There's really no need to use lambdas at all here: > > class A(object): > def __init__(self): > self.not_here = 1 > def __get_not_here(self): > return self.__not_here > def __set_not_here(self, val): > self.__not_here = val > not_here = property(__get_not_here, __set_not_here) > > My favourite way to create properties is of course with decorators: > > class A(object): > def __init__(self): > self.not_here = 1 > > @property > def not_here(self): > return self.__not_here > > @not_here.setter > def not_here(self, val): > self.__not_here = val > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.hw.kong at gmail.com Mon Jul 11 12:54:17 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:54:17 +1000 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: Good point! Need to get my terminology right. Thanks On Tue, Jul 12, 2011 at 2:43 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 9:54 AM, Anthony Kong > wrote: > > Hi, all, > > This question is in the same context of my two earlier questions. This > > question was raised by some python beginners, and I would like to check > with > > the list to ensure I provide a correct answer. > > Here is a code snippet I used to demonstrate the keyword property: > > What Thomas said. But also, please note that "property" is a builtin, > not a keyword. > > > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Mon Jul 11 12:56:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 09:56:09 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> On Jul 11, 11:33?am, rusi wrote: > A gui-builder reduces the semantic gap by showing a widget when the > programmer things 'widget.' > Banging out hundreds of lines in vi/emacs for the same purpose does a > measurably poorer job. It is very rare to need to "bang out" hundreds of lines of code to replace a mouse click interface. If properly designed a good API can compete with a GUI. In far less time than it takes me to scroll down a list of widgets, pick the appropriate one, drag it across the screen, tinker with it's absolute position, and set some attributes, i could have typed Widget(parent, **kw).geometry(blah, blah) and been done. > Note it can reduce but not close. ?By choosing fidelity to the gui we > have corresponding less fidelity to the algos and data-structures [And > one may assume that someone even using a gui toolkit wants to do > something with the gui and not just paint the screen] Exactly. For this very reason i have always refused to used any "point- and-click" GUI builders. I prefer to get up-close and personal with my code bases. Of course i use high levels of API abstraction for most of the work, however i already know what is happening in the lower levels if i need to dive down one tier. From t at jollybox.de Mon Jul 11 12:58:06 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:58:06 +0200 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: References: <4E1B1E37.4050900@jollybox.de> Message-ID: <4E1B2B9E.9080700@jollybox.de> On 07/11/2011 06:42 PM, Anthony Kong wrote: > Thomas, > > Thanks for the excellent suggestions. > > Generator is certainly an interesting subject. > > From what i understand, the advantage of generator is mainly about > saving memory, right? (i.e. no need to create a list in memory before > iterate thru it) When it comes to generator expression vs. list comprehension, yes. It also has the benefit that, if you're reading, say, from the network, you can do things with the content elegantly as it arrives: you can process the first bit when the last bit doesn't yet exist. "Classic" Python-2.3 (?) generators themselves are brilliant invention that makes it easy to create custom iterators. Java has iterators too, but nothing akin to this: def foo(): # do stuff: yield x > Duck typing... Although it can be easily demonstrated, I find it hard to > explain its advantages to Java developers who are so used to Interfaces. > (Is it about the certainty of type info... I am not sure about their > concern actually) They're used to interfaces, yes. Duck typing is little more than implicit interfaces. Python does support Java-style interfaces via ABC, but all the metaclasses and isinstance calls are needless complexity. > Jython is not a possibility, but I will show them an example anyway. We > can use it to write some support script, I suppose. > > (Off topic) Monkey patching - It is a term used by Ruby developer a lot. > If it means to change a function's implementation in run-time, i think > python can achieve the same, right? Is it equivalent to Mixin? Python doesn't have Ruby mixins as such. It's possible to replace functions and methods on any object, but it is almost always better (as in easier to understand and maintain) to modify the class/module you're using, or to subclass it. The only case when it's useful IMHO is when there's a bug or shortcoming in an external library you use, cannot modify, and if subclassing can't achieve the desired results. Don't show your Java programmers this. Being used to static typing, they'll be terrified, and rightly so. Cheers, Thomas From t at jollybox.de Mon Jul 11 13:06:05 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 19:06:05 +0200 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> Message-ID: <4E1B2D7D.4030000@jollybox.de> # On 07/11/2011 06:53 PM, Anthony Kong wrote: # But decorator! Of course! Thanks for reminding me this. # # In your example, where does '@not_here' come from? (Sorry, this syntax # is new to me) class A(object): def __init__(self): self.not_here = 1 @property def not_here(self): return self.__not_here @not_here.setter def not_here(self, val): self.__not_here = val """ Let's translate that to non-decorator Python: """ class A(object): def __init__(self): self.not_here = 1 def _(self): return self.__not_here not_here = property(_) del _ def _(self, val): self.__not_here = val not_here = not_here.setter(_) del _ """ @not_here.setter exists because not_here.setter exists. not_here exists since we set it (when the getter/property was set). Cheers Thomas PS: are you sure the lambda self: self.__foo() trick works, with subclasses or otherwise? I haven't tested it, and I'm not saying it doesn't, but I have a feeling double-underscore name mangling might be a problem somewhere down the line? """ From stefan_ml at behnel.de Mon Jul 11 13:11:56 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 11 Jul 2011 19:11:56 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: Ivan Kljaic, 11.07.2011 00:50: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. Just a quick suggestion regarding the way you posed your question. It's usually better to ask if anyone knows a good tool to do a specific job (which you would describe in your post), instead of complaining about there being none. Even if you googled for it, you may have missed something because it's known under a different name or because it works differently than you expected. Also, as the answers show, your usage of the term "RAD" is ambiguous - not everyone seems to know what you mean with it. Stefan From anthony.hw.kong at gmail.com Mon Jul 11 13:21:14 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 03:21:14 +1000 Subject: Property setter and lambda question In-Reply-To: <4E1B2D7D.4030000@jollybox.de> References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: > > PS: are you sure the lambda self: self.__foo() trick works, with > subclasses or otherwise? I haven't tested it, and I'm not saying it > doesn't, but I have a feeling double-underscore name mangling might be a > problem somewhere down the line? > > Awesome, Thomas. The trick only works if there is only *one* leading underscore in the *method* names. The following example works as I expected for the derived class B. class A(object): def __init__(self): self.__not_here = 1 def _get_not_here(self): return self.__not_here def _set_not_here(self, v): print "I am called" self.__not_here = v not_here = property(lambda self: self._get_not_here(), lambda self, v: self._set_not_here(v)) class B(A): def _set_not_here(self, v): print "version B" self.__not_here = v a = A() # print a.__not_here print a.not_here # a.set_not_here(10) a.not_here = 10 print a.not_here b = B() print b.not_here b.not_here = 70 # print version B print b.not_here -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at codicesoftware.com Mon Jul 11 13:26:27 2011 From: jjposner at codicesoftware.com (John Posner) Date: Mon, 11 Jul 2011 13:26:27 -0400 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: <4E1B3243.4060304@codicesoftware.com> On 2:59 PM, Anthony Kong wrote: > So the question: is it possible to use lambda expression at all for > the setter? (As in the last, commented-out line) > > Python interpreter will throw an exception right there if I use the > last line ('SyntaxError: lambda cannot contain assignment'). I'd use > pass a setter method anyway. > > What is your preferred solution? Anthony, you might take a look at this alternative writeup for "property", which I placed on the Python Wiki: http://wiki.python.org/moin/AlternativeDescriptionOfProperty HTH, John From ian.g.kelly at gmail.com Mon Jul 11 13:35:05 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 11:35:05 -0600 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 10:53 AM, Anthony Kong wrote: > Thanks again for your input, Thomas. > I normally prefer > not_here = property(lambda self: self.__get_not_here(), lambda self,?v: > self.__set_not_here(v)) > than > not_here = property(__get_not_here, __set_not_here) > Because it allows me to have a pair getter/setter (when there is a need for > it). Use of lambda there is ensure derived class of A can provide their > custom version of getter/setter. The .setter convenience method also makes it a bit easier for derived classes to modify getters and setters: class Base(object): def get_my_property(self): return self._my_property def set_my_property(self, value): self._my_property = value my_property = property(get_my_property, set_my_property) class Derived(Base): def set_my_property(self, value): super(Derived, self).set_my_property(convert(value)) my_property = Base.my_property.setter(set_my_property) From ian.g.kelly at gmail.com Mon Jul 11 13:41:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 11:41:41 -0600 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong wrote: > Awesome, Thomas. The trick only works if there is only?one?leading > underscore in the?method?names. > The following example works as I expected for the derived class B. > class A(object): > ? ? def __init__(self): > ? ? ? ? self.__not_here = 1 > ? ? def _get_not_here(self): > ? ? ? ? return self.__not_here > ? ? def _set_not_here(self, v): > ? ? ? ? print "I am called" > ? ? ? ? self.__not_here = v > ? ? not_here = property(lambda self: self._get_not_here(), lambda self, v: > self._set_not_here(v)) > class B(A): > ? ? def _set_not_here(self, v): > ? ? ? ? print "version B" > ? ? ? ? self.__not_here = v It shouldn't. You've still got the name __not_here used in both A and B, so that the B version is setting a different attribute than the A version (_B__not_here vs. _A__not_here). From anthony.hw.kong at gmail.com Mon Jul 11 13:56:19 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 03:56:19 +1000 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: So subclass B has no access to __not_here in A after all... OK, in one of legacy Python I supported there are a lot of code floating around like this. It works OK (in term of business logic and unit test). That's probably due to luck :-) It also uses a lot of __slot__ = ['attr_a', 'attr_b'...] in class definitions to prevent accidental creation of new variables (due to typo for example). Needless to say it was first written up by programmers of static lang background who want to enforce the java/.net behavior... (private variables, variable declaration) Cheers On Tue, Jul 12, 2011 at 3:41 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong > wrote: > > Awesome, Thomas. The trick only works if there is only one leading > > underscore in the method names. > > The following example works as I expected for the derived class B. > > class A(object): > > def __init__(self): > > self.__not_here = 1 > > def _get_not_here(self): > > return self.__not_here > > def _set_not_here(self, v): > > print "I am called" > > self.__not_here = v > > not_here = property(lambda self: self._get_not_here(), lambda self, > v: > > self._set_not_here(v)) > > class B(A): > > def _set_not_here(self, v): > > print "version B" > > self.__not_here = v > > It shouldn't. You've still got the name __not_here used in both A and > B, so that the B version is setting a different attribute than the A > version (_B__not_here vs. _A__not_here). > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jul 11 14:03:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 04:03:21 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 2:56 AM, rantingrick wrote: > It is very rare to need to "bang out" hundreds of lines of code to > replace a mouse click interface. If properly designed a good API can > compete with a GUI. In far less time than it takes me to scroll down a > list of widgets, pick the appropriate one, drag it across the screen, > tinker with it's absolute position, and set some attributes, ?i could > have typed Widget(parent, **kw).geometry(blah, blah) and been done. > Point to ponder: Human beings tend to memorize names better than images from long lists. Most widgets have names as well as appearances (although it's arguable that the appearance is more what the widget _is_, and the name is somewhat arbitrary), although in some cases there's odd pairings - some toolkits merge Radio Button and Check Box/Button into a single object, others call them two different things. To find the widget you need, you must either scroll a long list and pick the one you want, or key in - possibly with autocompletion assistance - the name. Which is easier to memorize? Which is easier to explain? I'd always rather work with the name. And even with the most point-and-clicky of interface designers, it's normal to be able to see the names of the objects you're working with. The one time where point and click is majorly superior to scripted design is with pixel positioning of widgets. You can drag things around until you're artistically happy with them, rather than have to fiddle with the numbers in code. That's how I learned to code GUIs, but when I started doing cross-platform work and discovered rule-based layouts (where you put objects in boxes and lay out the boxes in order, etc), suddenly life got a LOT easier. ChrisA From ikljaic at gmail.com Mon Jul 11 14:28:40 2011 From: ikljaic at gmail.com (Ivan Kljaic) Date: Mon, 11 Jul 2011 11:28:40 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Ok. I asked about this questio because I am working with python for the last 5 years and I am always in touch about signifigact things in Python. I am pissed of that I make my living by developing applications at work in Java an C#. My comPany would switch to python but they complained that there is not even one single gui builder or framework that can allow it to make a living from it. If you are going to say that there are also other libraries with every single one there is a significant problem that make the development painfull. About the natural selection... I'll say it with the words of penn&teller:bullshit For how many years are this vui library wars going on. How many. Look. I am a open source supporter but Windows will always kick the ass of open source because the open source comunity can not make a decision. Just imagine what we would have today if the effort of development would have been used to develop one really good library. We would have kicked the ass of MS and steve balmer. The average user wants something simple and not something to program to do something. It looks that the firs linux os to realize that is successfull. I am talking about android. And the python development team is doing nothing to improve the situatio to solve this dispute that lasts for the last years by including the worthless Tk library and now upgrading it with Tix. To summarize it. It would be very helpfull for python to spread if there qould be one single good rad gui builder similar to vs or netbeAns but for python. So right now if i need to make a gui app i need to work with an applicatio that is dicontinued for the last 5 years is pretty buggy but is ok. If it would only be maintained and the libraby updated it would be great. When it comes to other application, sorry but they are just bad. Their userfriendlyness is simmilar to most of Ms products, they are "user friendly" but the problem is that they very wisely chose their friends. The ony worthly ones mentioning as an gui builder are boa constructor fo wx, qtDesigner with the famous licence problems why companies do not want to work with it, sharpdevelop for ironpython and netbeans for jython. Did you notice that 2 of these 4 are not for python? One is out of dTe and one has a fucked up licence. Sorry guys but there is not even one single rad gui tool for python as long as there is no serious guibuilder. From igor.begic at gmail.com Mon Jul 11 14:31:18 2011 From: igor.begic at gmail.com (=?UTF-8?Q?Igor_Begi=C4=87?=) Date: Mon, 11 Jul 2011 20:31:18 +0200 Subject: perceptron feed forward neural networks in python Message-ID: Hi, I,m new to Python and i want to study and write programs about perceptron feed forward neural networks in python. Does anyone have a good book or link for this? Thx, Bye -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwatford+python at gmail.com Mon Jul 11 14:47:16 2011 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 11 Jul 2011 14:47:16 -0400 Subject: perceptron feed forward neural networks in python In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > Hi, > I,m new to Python and i want to study and write programs about?perceptron > feed forward neural networks in python. Does anyone have a good book or link > for this? Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". All example code is done in Python, and there's a chapter on multilayer perceptrons. The code for the book is available online here: http://www-ist.massey.ac.nz/smarsland/MLbook.html From rantingrick at gmail.com Mon Jul 11 14:52:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 11:52:14 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Jul 11, 1:03?pm, Chris Angelico wrote: > > The one time where point and click is majorly superior to scripted > design is with pixel positioning of widgets. You can drag things > around until you're artistically happy with them, rather than have to > fiddle with the numbers in code. This is true mostly for the new user of a GUI library or anyone unlucky enough to use a poorly designed API(which leads into my next response) > That's how I learned to code GUIs, > but when I started doing cross-platform work and discovered rule-based > layouts (where you put objects in boxes and lay out the boxes in > order, etc), suddenly life got a LOT easier. A bit tangential however still relevant... i had always considered Tkinter's three geometry managers (pack, place, and grid) to be perfect. However lately i have been musing on the idea of rewriting the pack API into something more intuitive like a "linear-box-style" which then manifests itself in two forms; horizontal and vertical. Of course you can create horizontal and vertical layouts ALREADY by passing the side=LEFT or side=RIGHT to the pack geometry manager of Tkinter widgets (TOP being the default BTW) but that fact isn't always apparent to the new user as the full set of options are side={TOP| BOTTOM|LEFT|RIGHT}. And besides, the current API allows you to pack in all sorts of ridiculous manners; BOTTOM, then TOP, then LEFT, then TOP, then RIGHT, then TOP, then LEFT, then RIGHT, THEN GHEE WHIZ! Are you trying to win the obfuscation award of the year here lad? As we all know you only need three types of geometry management: * Linear (horizontal&vertical) * Grid * Absolute Anything else is just multiplicity run a muck, again! And by propagating such API's we also induce ignorance into our ranks. Before we EVER consider a Python4000 we really need to clean up this atrocious stdlib! It's like i tell people: when you keep screwing your customers over then very soon you'll be out of buisness. Sure you can make a decent living for a short time but the whole house of cards comes crumbling down without the core base of repeat customers. PS: I noticed that Python.org has a suggestion box now for which modules we should be concentrating our community efforts. Well like they say... "imitation is the greatest form of flattery". And i am quite flattered. From egriffith92 at gmail.com Mon Jul 11 14:58:10 2011 From: egriffith92 at gmail.com (Eric Griffith) Date: Mon, 11 Jul 2011 14:58:10 -0400 Subject: A beginning programmer In-Reply-To: References: Message-ID: Shell scripts are ones that I do all the time, sometimes in BASH sometimes in python + system calls. A lot of the mainly for post-install setups of Ubuntu / Fedora / Arch trying to take some of the load off of my hands in a way that I actually know what is going on behind the scenes. But I'll definitely go and check out bugtrackers, I posted this same email to the kde mailing list and one of the developers told me to check out their Junior Jobs, which are things such as comment clean up, spelling errors and things like that so its an introduction to the code itself and I can ease my way in. Thanks or the quick responses guys! From efotinis at yahoo.com Mon Jul 11 14:59:32 2011 From: efotinis at yahoo.com (Elias Fotinis) Date: Mon, 11 Jul 2011 21:59:32 +0300 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel wrote: > Just a quick suggestion regarding the way you posed your question. It's > usually better to ask if anyone knows a good tool to do a specific job > (which you would describe in your post), instead of complaining about there > being none. Opinion is divided on this? From rantingrick at gmail.com Mon Jul 11 15:03:37 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 12:03:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On Jul 11, 1:28?pm, Ivan Kljaic wrote: > To summarize it. It would be very helpfull for python to spread if > there qould be one single good rad gui builder similar to vs or > netbeAns but for python. Well don't hold your breath friend because i have been ranting for years about the sad state of GUI libraries (not just in Python but everywhere). However if somehow "we" (the Python community) could grow a collective brain and build the three tiered system (that i proposed on THIS very list!) then we would have something that no one has! Yes, we would have a future! * Layer1: A 3rd party low level GUI library (owned by the python community) that will be the base from which to build the cake. A Gui library that carries the torch of true 21st century GUI's look and feel, and widgets! (aka: lots of C code here). * Layer2: An abstraction of Layer1 (written in 100% python) for the python std library. (think "PythonGUI") * Layer3: A Graphical GUI builder front end for this expansive and beautiful library (so the kids can play along too). Yes, i DID mention a Graphical Builder. Even though i'd never use one, i DO realize the importance of such tools to this community. From rosuav at gmail.com Mon Jul 11 15:16:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 05:16:30 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 4:28 AM, Ivan Kljaic wrote: > For how many years are this vui library wars going on. How many. Look. > I am a open source supporter but Windows will always kick the ass of > open source because the open source comunity can not make a decision. You think Microsoft makes decisions and sticks with them? Look at Office's last few versions. They can't decide on a file format, an interface, a featureset... everything keeps changing. The difference is that in the open-source world, everything survives and can be seen as a set of alternatives, whereas in the closed-source world, it's either different versions of one program (like MS Office), or competing products (which usually means one of them dies for lack of money - or is bought out by the other). What we have is not indecision, it is options. Imagine if you went to a hardware shop and were offered only one tool: a magnet. Would you laud them for making a decision and sticking with it? No, you'd wonder what they have against hammers and screwdrivers. I like to have tools available to my use, not someone else making my decisions for me. There's competition in the open source world, too; primarily competition for developer time, a quite scarce resource. If a toolkit is not of value to people, it won't get as many dev hours, so you can often gauge popularity and usefulness by the VCS checkins. ChrisA From noway at nohow.com Mon Jul 11 15:21:40 2011 From: noway at nohow.com (Billy Mays) Date: Mon, 11 Jul 2011 15:21:40 -0400 Subject: Why isn't there a good RAD Gui tool for python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On 07/11/2011 02:59 PM, Elias Fotinis wrote: > On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel > wrote: > >> Just a quick suggestion regarding the way you posed your question. It's >> usually better to ask if anyone knows a good tool to do a specific job >> (which you would describe in your post), instead of complaining about >> there >> being none. > > Opinion is divided on this? > There is another way: http://bash.org/?684045 From rosuav at gmail.com Mon Jul 11 15:27:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 05:27:35 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 4:52 AM, rantingrick wrote: > As we all know you only need three types of geometry management: > ?* Linear (horizontal&vertical) > ?* Grid > ?* Absolute > I contend that Absolute is unnecessary and potentially dangerous. Grid and Box (linear) are the most flexible, but there are others that come in handy too. GTK has quite a few [1] including a scrollable, a notebook, hor/vert panes (where the user can adjust the size between the two panes), and so on. Once again, Ranting Rick is asking for all tools to be destroyed except his preferred minimal set. I think this strongly suggests that Rick is, in point of fact, either brain something'd (keeping this G-rated) or an orangutan, because the ultimate end of his logic is coding in either Brain-*[2] or Ook [3]. ChrisA [1] http://developer.gnome.org/gtk3/stable/LayoutContainers.html [2] http://www.muppetlabs.com/~breadbox/bf/ [3] http://www.dangermouse.net/esoteric/ook.html From sturlamolden at yahoo.no Mon Jul 11 15:37:32 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 12:37:32 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 11 Jul, 20:28, Ivan Kljaic wrote: > The ony worthly ones mentioning as an gui builder are boa constructor > fo wx, qtDesigner with the famous licence problems why companies do > not want to work with it, sharpdevelop for ironpython and netbeans for > jython. There is wxFormBuilder for wxPython, I suppose you've missed it. Of three GUI builders for wxPython (wxFormBuilder, wxGLADE, Boa Constructor), you managed to pick the lesser. The license for Qt is LGPL, the same as for wxWidgets. Both have LGPL Python bindings (PySide and wxPython), so why is Qt's license more scary than wxWidgets? I have an idea why you think QtCreator cannot be used with Python. If you had actually used it, you would have noticed that the XML output file can be compiled by PyQt and PySide. SharpDevelop for IronPython means you've missed Microsoft Visual Studio. Bummer. And I am not going to mention IBM's alternative to NetBeans, as I am sure you can Google it. And did you forget abpout GLADE, or do you disregard GTK (PyGTK) as a toolkit completely? Regards, Sturla From bahamutzero8825 at gmail.com Mon Jul 11 15:48:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 11 Jul 2011 14:48:33 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <4E1B5391.1070807@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.11 02:16 PM, Chris Angelico wrote: > You think Microsoft makes decisions and sticks with them? Look at > Office's last few versions. They can't decide on a file format, an > interface, a featureset... everything keeps changing. Of course they do. They've decided to change things in each major version to give people a reason to pay for the new version when there's nothing wrong with the old one (at least nothing that's been fixed in the new version :P ). Of course, MS is not the only software company that employs such a strategy... - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOG1ORAAoJEPiOA0Bgp4/LF7oH/Al6RTGIQ2hAKztEiob/oXnz +eV8HZ0K+OBpd/FtRBkiMTJaQm5LU1jKPdwsf/RhF7UU69FfCQNfhzW5LsdMMQYE +lh4YwbJ8cXVEkCgdkf2zh7BElJ9/95nYedd64Ev4sG+QECvLFYoeql5mjcO45S9 V+iElE9y4FsPr1E0tC2BhFPQuiRMRIIOjQQ7UKP28dnIOKf6u9QM4UdN4WYKOy+n jgXRaFtstA3YtbzqmKfVoj9Go8SstF71XnGjSzAQeq4j96IfbvW/PTaPhkvyfB7y tHG861oW19orvZ1ESJue/lvd/KQ7rRDRn7IjH+fKvKuYlgjM3+Q7hR7hcXi97Wg= =a5A/ -----END PGP SIGNATURE----- From sturlamolden at yahoo.no Mon Jul 11 15:58:26 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 12:58:26 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> On 11 Jul, 20:28, Ivan Kljaic wrote: > To summarize it. It would be very helpfull for python to spread if > there qould be one single good rad gui builder similar to vs or > netbeAns but for python. So right now if i need to make a gui app i > need to work with an applicatio that is dicontinued for the last 5 > years is pretty buggy but is ok. http://wxformbuilder.org/ Shut up. > The ony worthly ones mentioning as an gui builder are boa constructor > fo wx, qtDesigner with the famous licence problems why companies do > not want to work with it, sharpdevelop for ironpython and netbeans for > jython. > Did you notice that 2 of these 4 are not for python? One is out of dTe > and one has a fucked up licence. Qt and PySide have LGPL license. QtCreator can be used with Python (there is a Python uic). SharpDevelop has an IronPython GUI builder. Boa Constructor is abandonware, yes. Is it just me, or did I count to three? And yes, you forgot: Visual Studio for IronPython wxGLADE for wxPython GLADE for PyGTK BlackAdder for Python and Qt SpecTcl for Tkinter That's eight. From sturlamolden at yahoo.no Mon Jul 11 16:02:44 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:02:44 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> Message-ID: <111958c7-5b36-4940-9c44-511e17ae37ed@u30g2000vby.googlegroups.com> On 11 Jul, 21:58, sturlamolden wrote: > That's eight. Sorry, nine ;) From caleb.hattingh at gmail.com Mon Jul 11 16:13:11 2011 From: caleb.hattingh at gmail.com (cjrh) Date: Mon, 11 Jul 2011 13:13:11 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <0092c388-20f0-4dd1-a74a-9bf96af45c34@glegroupsg2000goo.googlegroups.com> On Monday, 11 July 2011 00:50:31 UTC+2, Ivan Kljaic wrote: > But seriously. Why is the not even one single RAD tool > for Python. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? The set of reasons that nobody else has made one is *exactly* the same set of reasons that you're not going to make one. Note that if you prove me wrong, and make one, I still win ;) I am in the somewhat interesting position of having worked continuously with both Python and Delphi (yes, formerly by Borland) for the last decade. I like to think I use both languages/tools idiomatically. I used to lament not having a GUI builder like the Delphi IDE for Python, but I don't any more. Use the right tool for the job, and all that old-timer stuff is starting to make sense. From sturlamolden at yahoo.no Mon Jul 11 16:19:45 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:19:45 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> Message-ID: <9ecbc879-9719-4276-8517-e6bdb29f3b12@v12g2000vby.googlegroups.com> On 11 Jul, 21:58, sturlamolden wrote: > http://wxformbuilder.org/ This Demo is using C++, it works the same with Python (wxPython code is generated similarly). http://zamestnanci.fai.utb.cz/~bliznak/screencast/wxfbtut1/wxFBTut1_controller.swf Sturla From kw at codebykevin.com Mon Jul 11 16:35:27 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Jul 2011 16:35:27 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 7/11/11 2:28 PM, Ivan Kljaic wrote: > Did you notice that 2 of these 4 are not for python? One is out of dTe > and one has a fucked up licence. Sorry guys but there is not even one > single rad gui tool for python as long as there is no serious > guibuilder. One reason there hasn't been much demand for a GUI builder is that, in many cases, it's just as simpler or simpler to code a GUI by hand. Certainly with the Tkinter library this is trivial. The only GUI builder I've ever used that was arguably superior to hand-coding is Interface Builder, on Mac OS X, and it's truly needed there. (The Cocoa frameworks don't really lend themselves to hand-coding.) Otherwise I find GUI builders inflexible, and more trouble than they are worth. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From sturlamolden at yahoo.no Mon Jul 11 16:52:48 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:52:48 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 11 Jul, 22:35, Kevin Walzer wrote: > One reason there hasn't been much demand for a GUI builder is that, in > many cases, it's just as simpler or simpler to code a GUI by hand. Often a GUI builder is used as a bad replacement for sketch-pad and pencil. With layout managers (cf. wxWidgets, Qt, Swing, SWT, Tkinter) it is easier to "sketch and code" than with common MS Windows toolkits (eg. MFC, .NET Forms, Visual Basic, Delphi) which use absolute positioning and anchors. Using a GUI builder with layout managers might actually feel awkward. But with absolute positioning and anchors, there is no way to avoid a GUI builder. That said, we have good GUI builders for all the common Python GUI toolkits. Sometimes a mock-up GUI designer like DesignerVista might help. Yes, and actually hiring a graphical designer helps too. Sturla From sturlamolden at yahoo.no Mon Jul 11 17:07:36 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 14:07:36 -0700 (PDT) Subject: perceptron feed forward neural networks in python References: Message-ID: <9bbb3188-9f96-4dd4-833a-3ce60fd7421e@h14g2000yqd.googlegroups.com> On 11 Jul, 20:47, Ken Watford wrote: > On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > > Hi, > > I,m new to Python and i want to study and write programs about?perceptron > > feed forward neural networks in python. Does anyone have a good book or link > > for this? > > Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". > All example code is done in Python, and there's a chapter on > multilayer perceptrons. > > The code for the book is available online here:http://www-ist.massey.ac.nz/smarsland/MLbook.html This is quite simple with tools like NumPy and SciPy. E.g. use numpy.dot (level-3 BLAS matrix multiply) for the forward pass, and scipy.optimize.leastsq (MINPACK Levenberg-Marquardt) for the training. Sturla From rantingrick at gmail.com Mon Jul 11 17:46:51 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 14:46:51 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> On Jul 11, 9:41?am, Chris Angelico wrote: > On Mon, Jul 11, 2011 at 11:42 PM, rantingrick wrote: > > This mandate must be handed down from the gods who reside on "Mount > > REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" > > I assume you're trying to reference Mount Olympus where the Greek gods > live, but I'm left thinking more of Mount Vesuvius... possibly not the > best reference for what you're saying. Actually no i was purposely implying Mt. Vesuvius. You know, the VOLCANO that erupted and left poor Pompeii in ruins? Here is some text from the wiki verbatim: """Mount Vesuvius is best known for its eruption in AD 79 that led to the burying and destruction of the Roman cities of Pompeii and Herculaneum. They were never rebuilt, although surviving townspeople and probably looters did undertake extensive salvage work after the destructions.""" I modified the text "slightly" to reflect our current conundrum: """Guido and Pydev are best known for their absence around 2000, which led to the burying and destruction of comp.lang.Python (and the community as a whole) in ash clowns. They were never rebuilt, although a few surviving "good" townspeople did undertake extensive attacks from trolls after the destruction.""" From bruce at whealton.info Mon Jul 11 18:04:18 2011 From: bruce at whealton.info (Bruce Whealton) Date: Mon, 11 Jul 2011 18:04:18 -0400 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: This didn't seem to work either. I was getting errors the number of arguments expected being two, when I changed to def add (self, args): I seem to remember that if I removed the parentheses around sub, pred, obj, it worked. I thought that was how it worked. What is strange is that this is not reported as an error on the books page. So, it should have worked as is with either Python 2.7, which I have installed or Python 3.0 which I also have installed. So, it seems like it would have worked as is for one of the versions of Python, but it doesn't seem to work that way. I'll paste a link to where the code exists. Could someone help me figure it out please. The code is here on the site: http://semprog.com/content/the-book/ I wonder if I can also try it out from the IDLE interactive session. Thanks, Bruce On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton wrote: problem with is this line: > def add(self, (sub, pred, obj)): > I think the problem is with the parentheses before the sub. I removed > those and that seemed to fix that error or make it go away. I don?t > remember how I figured that out, It should be on the Errata page for > sure. > Then it has a problem with this line: > print list(g.triples((None, None, None))) > If I was using python 3, it would require () around the thing that is > going to be printed, right? Maybe python 2.7 doesn?t like this line for > the same reason. > The issue there is with tuple unpacking. To match the older syntax, don't touch the call, but change the definition thus: def add(self, args): (sub, pred, obj)=args Or, of course, simply list the arguments directly, rather than in a tuple; but that requires changing every call (if it's a small program that may not be a problem). You're right about needing parentheses around the print() call; in Python 2 it's a statement, but in Python 3, print is a function like any other. Regarding the module search path, this may help: http://docs.python.org/dev/tutorial/modules.html#the-module-search-path Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list From pavlovevidence at gmail.com Mon Jul 11 18:11:17 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 11 Jul 2011 15:11:17 -0700 (PDT) Subject: Function docstring as a local variable In-Reply-To: Message-ID: <667f794a-33f6-4b71-a4f5-fe44b96b8d70@glegroupsg2000goo.googlegroups.com> On Sunday, July 10, 2011 4:06:27 PM UTC-7, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > > print __doc__ > > > > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def foo(): > ... "Docstring" > ... print __doc__ > ... > >>> foo() > None > >>> > > What does yours do? It prints the module docstring, same as your example does. You did realize that was the question I was answering, right? Carl Banks From nad at acm.org Mon Jul 11 18:22:09 2011 From: nad at acm.org (Ned Deily) Date: Mon, 11 Jul 2011 15:22:09 -0700 Subject: How to compile on OS X PPC? was: Re: [RELEASED] Python 3.2 References: <4d640175$0$81482$e4fe514c@news.xs4all.nl> Message-ID: In article , Ned Deily wrote: > In article <4d640175$0$81482$e4fe514c at news.xs4all.nl>, > Irmen de Jong wrote: > > However, I'm having trouble compiling a framework build from source on > > Mac OS 10.5.8 on PowerPC. No matter what I try (gcc 4.0, gcc 4.2, > > different compiler options), the compilation aborts with the following > > error: > > > > Undefined symbols: > > "___fixdfdi", referenced from: > > _rlock_acquire in libpython3.2m.a(_threadmodule.o) > > _lock_PyThread_acquire_lock in libpython3.2m.a(_threadmodule.o) > > "___moddi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > "___divdi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > ld: symbol(s) not found > > /usr/bin/libtool: internal link edit command failed > > Unfortunately, this is a variation of an old issue that hasn't yet been > fixed (http://bugs.python.org/issue1099). UPDATE: this problem has been fixed in the newly-release Python 3.2.1. On a 10.4 or 10.5 PPC machine, you should now be able to successfully build a PPC-only 3.2 framework with just: ./configure --enable-framework ; make On 10.5, you may want to use: ./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.5 ; make -- Ned Deily, nad at acm.org From RJones at iso.com Mon Jul 11 18:30:34 2011 From: RJones at iso.com (Jones, Rebecca) Date: Mon, 11 Jul 2011 18:30:34 -0400 Subject: Read SAS files with Python? Message-ID: <3F4E4D643FA05D499A93FB483D68C3020BC757A5@ISOEMAILP6.iso.com> Apologies in advance if this is already a time-worn question! We are essentially a "SAS shop" and use Base SAS, Enterprise Guide and E-Miner for statistical and predictive modeling purposes, often working on big datasets (30M rows of 100+ columns). There are some applications for which we have had to craft Python solutions, such as interfacing with ArcView to automate the generation of map overelays from shapefiles, but the vast majority of our work is well-handled by our SAS suite. However, in the interest of expanding our skillset (and hedging our bets), we are investigating whether anyone has yet developed a Python module that can read SAS datasets directly? Thank you! RJones -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Mon Jul 11 18:33:27 2011 From: nad at acm.org (Ned Deily) Date: Mon, 11 Jul 2011 15:33:27 -0700 Subject: Problem compiling Python 3.2 in 32bit on Snow Leopard References: <8t5vunFcasU1@mid.individual.net> Message-ID: In article , Ned Deily wrote: > In article <8t5vunFcasU1 at mid.individual.net>, > Gregory Ewing wrote: > > Attempting to compile Python 3.2 in 32-bit mode > > on MacOSX 10.6.4 I get: > > > > Undefined symbols: > > "___moddi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > "___divdi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > ld: symbol(s) not found > > /usr/bin/libtool: internal link edit command failed > > > > Any suggestions? > > http://article.gmane.org/gmane.comp.python.general/685151 UPDATE: this problem has been fixed in the newly-released Python 3.2.1. On OX X 10.6, you should be able to build a 10.6 32-bit-only framework with: ./configure --enable-framework CFLAGS="-arch i386" \ LDFLAGS="-arch i386" MACOSX_DEPLOYMENT_TARGET=10.6 -- Ned Deily, nad at acm.org From igor.begic at gmail.com Mon Jul 11 19:04:14 2011 From: igor.begic at gmail.com (=?UTF-8?Q?Igor_Begi=C4=87?=) Date: Tue, 12 Jul 2011 01:04:14 +0200 Subject: perceptron feed forward neural networks in python In-Reply-To: References: Message-ID: thx, bye On Mon, Jul 11, 2011 at 8:47 PM, Ken Watford wrote: > On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > > Hi, > > I,m new to Python and i want to study and write programs about perceptron > > feed forward neural networks in python. Does anyone have a good book or > link > > for this? > > Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". > All example code is done in Python, and there's a chapter on > multilayer perceptrons. > > The code for the book is available online here: > http://www-ist.massey.ac.nz/smarsland/MLbook.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Jul 11 19:11:26 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:11:26 -0700 Subject: parsing packets In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 5:05 AM, Thomas Rachel < nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de> wrote: > Am 10.07.2011 22:59 schrieb Littlefield, Tyler: > > Hello all: >> I'm working on a server that will need to parse packets sent from a >> client, and construct it's own packets. >> > > Are these packets sent as separate UDP packets or embedded in a TCP stream? > In the first case, you already have packets and only have to parse them. In > a stream, you first have to split them up. > Aren't UDP packets subject to fragmentation and aggregation? -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Jul 11 19:16:32 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:16:32 -0700 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: On Sun, Jul 10, 2011 at 1:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > I like to use this module (I wrote while in the employ of UCI, so it's under a UCI - BSDesque - license, but they've given redistribution permission so long as the module is under their license) to extract pieces from a data source with varied field lengths: http://stromberg.dnsalias.org/~dstromberg/bufsock.html I use it often with TCP. For UDP, I'd probably catentate the blocks recieved and then pull data back out of the aggregate using bufsock - to deal with the possibility of fragmentation or aggregation in transit. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davecook at nowhere.net Mon Jul 11 19:33:46 2011 From: davecook at nowhere.net (Dave Cook) Date: 11 Jul 2011 23:33:46 GMT Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> On 2011-07-10, Ivan Kljaic wrote: > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. I prefer spec-generators (almost all generate XML these days) like QtDesigner to code-generators like Boa. I've only seen one good argument for code generation, and that's to generate code for a layout to "see how it's done". But code could always be generated automatically from a spec. I already have an editor I like, I don't see the need to tie GUI layout to a code editor. If you want something with more sophisticated Python specific features, there's PyDev. Dave Cook From drsalists at gmail.com Mon Jul 11 19:35:53 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:35:53 -0700 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 8:28 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle > wrote: > > Could it have been made optional, like the trailing comma in list > > declaration? > > Cobra makes the colons optional, so probably yes. > -- > http://mail.python.org/mailman/listinfo/python-list > A little redundancy in a computer language facilitates error checking - much like the bits of redundancy in one's English make written and voice communication less error prone. But strictly speaking, the colon could've been left out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon Jul 11 20:40:33 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jul 2011 12:40:33 +1200 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: <981jg1F6e9U1@mid.individual.net> Chris Angelico wrote: > either brain something'd (keeping this > G-rated) or an orangutan, There's a certain librarian who might take issue with your lumping orangutans in with the brain-something'd... -- Greg From nambo4jb at gmail.com Mon Jul 11 20:42:10 2011 From: nambo4jb at gmail.com (Cathy James) Date: Mon, 11 Jul 2011 19:42:10 -0500 Subject: Please Help with vertical histogram Message-ID: Please kindly help- i have a project where I need to plot dict results as a histogram. I just can't get the y- axis to print right. May someone please help? I have pulled my hair for the past two weeks, I am a few steps ahead, but stuck for now. def histo(his_dict = {1:16, 2:267, 3:267, 4:169, 5:140, 6:112, 7:99, 8:68, 9:61, 10:56, 11:35, 12:13, 13:9, 14: 7, 15:2}): x_max = 17 #get maximum value of x y_max = 400 #get minimum value of y # print each line print ('^') for j in range(y_max, 0, -100):# draw s = '|' for i in range(1, x_max): if i in his_dict.keys() and his_dict[i] >= j: s += '***' else: s += ' ' print (s) print (j) # print x axis s = '+' for i in range(1, x_max): s += '-+-' s += '>' print (s) # print indexes s = ' ' for i in range(1, x_max): s += ' %d ' % i print (s) histo() # I need it to look like this: 400 -| | | | | 300 -| | | ****** | ****** | ****** 200 -| ****** | ****** | ********* | ************ | ************ 100 -| *************** | ****************** | ************************ | *************************** |********************************* 0 -+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 From drsalists at gmail.com Mon Jul 11 21:06:20 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 18:06:20 -0700 Subject: Please Help with vertical histogram In-Reply-To: References: Message-ID: I have a histogram script in Python at http://stromberg.dnsalias.org/svn/histogram/trunk/ It's under a UCI (BSD-like) license. Feel free to use it or borrow ideas from it. On Mon, Jul 11, 2011 at 5:42 PM, Cathy James wrote: > Please kindly help- i have a project where I need to plot dict results > as a histogram. I just can't get the y- axis to print right. May > someone please help? I have pulled my hair for the past two weeks, I > am a few steps ahead, but stuck for now. > > > def histo(his_dict = {1:16, 2:267, 3:267, 4:169, 5:140, 6:112, 7:99, > 8:68, 9:61, 10:56, 11:35, 12:13, 13:9, 14: 7, 15:2}): > > x_max = 17 #get maximum value of x > y_max = 400 #get minimum value of y > # print each line > print ('^') > for j in range(y_max, 0, -100):# draw > > s = '|' > for i in range(1, x_max): > if i in his_dict.keys() and his_dict[i] >= j: > s += '***' > else: > s += ' ' > print (s) > print (j) > # print x axis > s = '+' > for i in range(1, x_max): > s += '-+-' > s += '>' > print (s) > > # print indexes > s = ' ' > for i in range(1, x_max): > s += ' %d ' % i > print (s) > > histo() > > # I need it to look like this: > 400 -| > | > | > | > | > 300 -| > | > | ****** > | ****** > | ****** > 200 -| ****** > | ****** > | ********* > | ************ > | ************ > 100 -| *************** > | ****************** > | ************************ > | *************************** > |********************************* > 0 -+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Jul 11 21:10:26 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2011 11:10:26 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <87wrfoe22l.fsf@benfinney.id.au> Ivan Kljaic writes: > My comPany would switch to python but they complained that there is > not even one single gui builder or framework that can allow it to make > a living from it. That response from your company is a non sequitur. What does ?one single gui builder or framework? have to do with ?allow it to make a living from it?? Evidently many organisations are making a living with Python, so that statement is just false. > For how many years are this vui library wars going on. How many. Why see it as a war that must have one clear winner? You have options. > I am a open source supporter but Windows will always kick the ass of > open source because the open source comunity can not make a decision. Different people make different decisions. If you want a monolithic organisation that makes a single decision for everyone, you don't want software freedom. > To summarize it. It would be very helpfull for python to spread Please find a different language to ?fix?; Python is spreading quite successfully. -- \ ?I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means ?put down?.? ?Bob Newhart | Ben Finney From kevin.misc.10 at gmail.com Mon Jul 11 21:30:28 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Tue, 12 Jul 2011 09:30:28 +0800 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 10:50 PM, Fulvio wrote: > > > I found that isn't python 3 code :( > > It's written in python 2.6. > Then the code should go into some other program to allow actions on those > pictures which are matching each other. Am I right? > > The leverages PIL to get the job done. The performance from PIL's quite poor, though not precisely measured, most of the time was spent on resizing pictures with PIL. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Mon Jul 11 21:38:21 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 18:38:21 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <469cd063-7dd8-41f2-af16-55269f67fa29@g16g2000yqg.googlegroups.com> On 12 Jul, 01:33, Dave Cook wrote: > I prefer spec-generators (almost all generate XML these days) like > QtDesigner to code-generators like Boa. I've only seen one good > argument for code generation, and that's to generate code for a layout > to "see how it's done". ?But code could always be generated > automatically from a spec. wxFormBuilder will produce C++, Python and XML. Pick the one you like! The advantage of using XML in tools like GLADE, QtCreator, and more recently Visual C#, is separation of layout and program logic. The problem with code generators like Visual C++ or Delphi was the mixing of generated and hand-written code. However, there is no real advantage over using XML instead of C++ or Python: C++ and Python code are also structured text. One structured text is as good as another: "There once was a man who had a problem. He said: 'I know, I will use XML.' Now he had two problems." When using wxFormBuilder, the generated .cpp, .h, .py or .xrc files are not to be edited. To write event handlers, we inherit from the generated classes. Thus, program view (generated code) and program control (hand-written code) are kept in separate source files. Because C++ and Python have multiple inheritance, we can even separate the program control into multiple classes. What we instantate is a class that inherit the designed dialog class (generated) and event handler classes (hand-written). Therefore, XML has no advantage over Python in the case of wxFormBuilder. XML just adds a second layer of complexity we don't need: I.e. not only must we write the same program logic, we must also write code to manage the XML resources. Hence, we are left with two problems instead of one. This is not special for wxFormBuilder: In many cases when working with Python (and to somewhat lesser extent C++), one is left to conclude that XML serves no real purpose. Sturla From sturlamolden at yahoo.no Mon Jul 11 21:42:09 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 18:42:09 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <46ca0ce1-2817-499b-bc7b-ca41d97a97a0@b21g2000yqc.googlegroups.com> On 12 Jul, 01:33, Dave Cook wrote: > I prefer spec-generators (almost all generate XML these days) like > QtDesigner to code-generators like Boa. I've only seen one good > argument for code generation, and that's to generate code for a layout > to "see how it's done". But code could always be generated > automatically from a spec. wxFormBuilder will produce C++, Python and XML. Pick the one you like! The advantage of using XML in tools like GLADE, QtCreator, and more recently Visual C#, is separation of layout and program logic. The problem with code generators like Visual C++ or Delphi was the mixing of generated and hand-written code. However, there is no real advantage over using XML instead of C++ or Python: C++ and Python code are also structured text. One structured text is as good as another: "There once was a man who had a problem. He said: 'I know, I will use XML.' Now he had two problems." When using wxFormBuilder, the generated .cpp, .h, .py or .xrc files are not to be edited. To write event handlers, we inherit from the generated classes. Thus, program view (generated code) and program control (hand-written code) are kept in separate source files. Because C++ and Python have multiple inheritance, we can even separate the program control into multiple classes. What we instantate is a class that inherit the designed dialog class (generated) and event handler classes (hand-written). Therefore, XML has no advantage over Python in the case of wxFormBuilder. XML just adds a second layer of complexity we don't need: I.e. not only must we write the same program logic, we must also write code to manage the XML resources. Hence, we are left with two problems instead of one. This is not special for wxFormBuilder: In many cases when working with Python (and to somewhat lesser extent C++), one is left to conclude that XML serves no real purpose. Sturla From xahlee at gmail.com Mon Jul 11 23:37:30 2011 From: xahlee at gmail.com (Xah Lee) Date: Mon, 11 Jul 2011 20:37:30 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> Message-ID: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> 2011-07-11 On Jul 11, 6:51?am, jvt wrote: > I might as well toss my two cents in here. ?Xah, I don't believe that > the functional programming idiom demands that we construct our entire > program out of compositions and other combinators without ever naming > anything. ?That is much more the province of so-called "function- > level" programming languages like APL/J and to a more limited extent > concatenative languages where data (but not code) is mostly left > without names. > > Functional programming, in my mind, is about identifying reproducibly > useful abstractions, _naming them_, and constructing other > abstractions from them. ?Your piece of code above probably needs to be > factored out into named pieces so that the composition is more > sensible. ?If a piece of code isn't comprehensible, it might be > because it isn't using the right abstractions in the right way, not > because the notion of functional programming is itself problematic. > > One might instead provide a nightmare nest of procedural code and > claim that procedural programming has problems. Of course, this > particular kind of problem might be less common in procedural code, > since it depends heavily on naming and side effecting values, but it > isn't hard to find procedural code with a long list of operations and > namings wherein the chose names are random or otherwise unrelated to > the problem domain. ?My adviser in grad school used to name variables > after pieces of furniture in dutch, but that didn't cause me to > impeach the _notion_ of procedural code. hi jvt, of course, you are right. But i wasn't criticising functional programing in anyway. was just putting out my tale as a caution, to those of us ? e.g. academic scheme lispers and haskell types ? who are perpetually mangling their code for the ultimate elegant constructs. but speaking on this now... as you guys may know, i was a naive master of Mathematica while being absolute illiterate in computer science or any other lang. (see ?Xah Lee's Computing Experience (Impression Of Lisp from Mathematica)? @ http://xahlee.org/PageTwo_dir/Personal_dir/xah_comp_exp.html ) When i didn't know anything about lisp, i thought lisp would be similar, or even better, as a highlevel lang in comparison to Mathematica. In retrospect now, i was totally wrong. lisp, or scheme lisp, is a magnitude more highlevel in comparison to C or C derivatives such as C++, Java. However, in comparison to Mathematica, it's one magnitude low level. (it pains me to see lisp experts here talking about cons and macros all day, even bigshot names such as one Paul Graham and in lisp books praising lisp macros. Quite ridiculous.) over the years, i had curiosity whether perhaps ML/OCaml, Haskell, would be equivalent high-level as Mathematica as i thought. Unfortunately, my study of them didn't went far. (best result is my incomplete ?OCaml Tutorial? @ http://xahlee.org/ocaml/ocaml.html ) Am not qualified to comment on this, but i think that even Haskell, OCaml, are still quite low in comparison to Mathematica. it's funny, in all these supposedly modern high-level langs, they don't provide even simple list manipulation functions such as union, intersection, and the like. Not in perl, not in python, not in lisps. (sure, lib exists, but it's a ride in the wild) It's really exceedingly curious to me. And it seems that lang authors or its users, have all sorts of execuse or debate about whether those should be builtin if you force them to answer. (i.e. they don't get it) While, we see here regularly questions about implementing union etc with follow up of wild answers and re-invention the thousandth time. Of course, Mathematica has Union, Intersection, and a host of others some 20 years ago, and today it has a complete set of combinatorics functions as *builtin* functions (as opposed to add-on libs of second- rate quality). (this is not a question. No need to suggest some possible reasons why lang might not want to have a whole set of list manipulation builtin. You (the lisper/python/perl regulars and other lang fans) are a complete idiot, that's what i'm saying. COMPLETE IDIOT. (actually, this is not surprising, since genius and true thinkers are rare and few. (such as myself. As they say, beyond the times))) i also wondered, if Mathematica is truely a magnitude higher level than lisp, why we don't see any computer scientists talk about it? (of course there are, but almost non-existant in comparison to, say, academic publications on Scheme, Haskell, even Java) I think the reason is social, again. Proprietary langs isn't a revue of academicians, together with the fact that Stephen Wolfram goes about as if the entire science of computer science comprises of himself. Want Mathematica? Pay $2k+. recently i spent several days studying and watching a talk by Douglas Crockford. it is incredible. He went thru history, and explained, how it is the very people in computing community who laughed and stifled all the great innovations in computing (e.g. innovations in computer languages). Many of these innovations we enjoy today (e.g web) took few decades to finally be accepted (usually in a inferior form (and he showed, how the web came to be thru Tim, and Mosaic etc folks, and cookies and javascript of Netscape by utterly ignoring the tech geeker's loud cries of pain about how things ?should? be. e.g. Tim ignored SGML folk's cries. Mosaic added the image tag, ignoring Tim's cries. ?)). These people, i call tech geekers. (e.g. as we witness here recently, where lisper idiots siging the tunes of cons ? a concept based on hardware that's obsolete for like 30 years.) Douglas Crockford gave many examples thru-out his lectures. i had similar impressions about how new tech is always sneered upon first by the very people of that field (e.g. cookies, js, web email, blogs, instant messaging, and in recent years youtube, twitter, facebook), and old habit really are impossible to die. Progress on comp lang is exceedingly slow, usually in the form of tiny improvements (think of the C C++ Java C# C-go spanning 40 years of minor tweaks, or think of acceptance of functional programing langs). (Douglas says it take a generation to swap people out) For example, lisp cons business, computer language formatting, 80 char line truncation business, unix line truncation business, netquette issues, RFC idiocies and RFC idolization, unix philosphy shit, emacs meta key and UI gospels ?. (you can read bout my take here: ?Computing ? its People? http://xahlee.org/Periodic_dosage_dir/skami_prosa.html ) watch the first episode of Douglas Crockford's talk here: http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 it's a hour and 42 minutes, worth every minute. There are 5 more. Xah From zjuwufan at gmail.com Mon Jul 11 23:59:29 2011 From: zjuwufan at gmail.com (Fan) Date: Mon, 11 Jul 2011 20:59:29 -0700 (PDT) Subject: Questions about os.waitpid(pid, options) on windows Message-ID: <05e436fe-ad07-4e28-a65b-11ea2ad07d3e@eb1g2000vbb.googlegroups.com> It seems that waitpid take process handle instead of process id as the first parameter on Windows. On Unices platform, the first parameter is process id. This interface is a little bit confusing. What's the purpose for such a design? Thanks a lot, Fan From hansmeetschool at gmail.com Tue Jul 12 00:05:45 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Mon, 11 Jul 2011 20:05:45 -0800 Subject: Why isn't there a good RAD Gui tool for python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: lol isnt billy mays dead On 7/11/11, Billy Mays wrote: > On 07/11/2011 02:59 PM, Elias Fotinis wrote: >> On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel >> wrote: >> >>> Just a quick suggestion regarding the way you posed your question. It's >>> usually better to ask if anyone knows a good tool to do a specific job >>> (which you would describe in your post), instead of complaining about >>> there >>> being none. >> >> Opinion is divided on this? >> > > There is another way: http://bash.org/?684045 > -- > http://mail.python.org/mailman/listinfo/python-list > From davidbtdt at gmail.com Tue Jul 12 01:39:55 2011 From: davidbtdt at gmail.com (David) Date: Mon, 11 Jul 2011 22:39:55 -0700 (PDT) Subject: Python bug? Indexing to matrices Message-ID: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Should the following line work for defining a matrix with zeros? c= [[0]*col]*row where "col" is the number of columns in the matrix and "row" is of course the number of rows. If this a valid way of initializing a matrix in Python 3.2.1, then it appears to me that a bug surfaces in Python when performing this line: c[i][j] = c[i][j] + a[i][k] * b[k][j] It writes to the jth column rather than just the i,j cell. I'm new at Python and am not sure if I'm just doing something wrong if there is really a bug in Python. The script works fine if I initialize the matrix with numpy instead: c = np.zeros((row,col)) So, I know my matrix multiply algorithm is correct (I know I could use numpy for matrix multiplication, this was just to learn Python). I've attached my source code below. TIA, David ----- #!python # dot.py - Matrix multiply in matricies: [c] = [a] * [b] import numpy as np a = [[3, 7], [-2, 1], [2, 4]] b = [[2, 1, -3, 1], [4, 3, -2, 3]] print("a = {0}, b = {1}".format(a,b)) row = len(a) col = len(b[0]) #c = np.zeros((row,col)) # <----- Correct results when using this line c= [[0]*col]*row # <----- Incorrect results when using this line print(c) for i in range(row): # Index into rows of [a] for j in range(col): # Index into columns of [b] c[i][j] = 0 for k in range(len(b)): # Index into columns of [a] and rows of [b] print("c[{0}][{1}] + a[{2}][{3}] * b[{4}][{5}] = {6} + {7} * {8}".format(i,j,i,k,k,j,c[i][j],a[i][k],b[k][j])) c[i][j] = c[i][j] + a[i][k] * b[k][j] print(c) From clp2 at rebertia.com Tue Jul 12 01:44:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 11 Jul 2011 22:44:05 -0700 Subject: Python bug? Indexing to matrices In-Reply-To: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 10:39 PM, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row > > where "col" is the number of columns in the matrix and "row" is of > course the number of rows. Nope. See the FAQ: http://docs.python.org/faq/programming.html#how-do-i-create-a-multidimensional-list Cheers, Chris From thorsten at thorstenkampe.de Tue Jul 12 01:50:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 12 Jul 2011 07:50:50 +0200 Subject: Please Help with vertical histogram References: Message-ID: * Cathy James (Mon, 11 Jul 2011 19:42:10 -0500) > Please kindly help- i have a project where I need to plot dict results > as a histogram. I just can't get the y- axis to print right. May > someone please help? I have pulled my hair for the past two weeks, I > am a few steps ahead, but stuck for now. This sounds like homework. There's the Python Tutor mailing list where you will receive help. Thorsten From ben+python at benfinney.id.au Tue Jul 12 01:59:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2011 15:59:59 +1000 Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: <87sjqcdoo0.fsf@benfinney.id.au> David writes: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. Python lists are not matrixes and are not arrays. If you want good implementations of arrays and matrices, use NumPy . -- \ ?Properly read, the Bible is the most potent force for atheism | `\ ever conceived.? ?Isaac Asimov | _o__) | Ben Finney From rosuav at gmail.com Tue Jul 12 04:40:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 18:40:56 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 7:46 AM, rantingrick wrote: > Actually no i was purposely implying Mt. Vesuvius. You know, the > VOLCANO that erupted and left poor Pompeii in ruins? Here is some text > from the wiki verbatim: > Yes, I do know that mountain. But it doesn't have very many gods sitting on it... maybe a magma elemental, but that's all. Anyhow, this is quite off-topic for Python I think. (Though not off-topic for rantingrick.) ChrisA From steve+comp.lang.python at pearwood.info Tue Jul 12 06:24:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2011 20:24:02 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Thorsten Kampe wrote: > * sturlamolden (Mon, 11 Jul 2011 06:44:22 -0700 (PDT)) >> On 11 Jul, 14:39, Ben Finney wrote: >> > The Unix model is: a collection of general-purpose, customisable >> > tools, with clear standard interfaces that work together well, and >> > are easily replaceable without losing the benefit of all the others. >> >> This is opposed to the "Windows model" of a one-click installer for a >> monolithic application. Many Windows users get extremely frustrated >> when they have to use more than one tool. > > *sigh* There is no Windows nor Unix "model". There is only you-get-what- > you-pay-for. > > On Windows, you're a customer and the developer wants to make using his > application as convenient as possible for you, the customer. That's an astonishing statement. Today, I started to update a commercial, proprietary Windows application, Quickbooks. I didn't actually get around to running the installer application yet, on account of the installer having trouble if your data is on a network share. (Apparently the developers of Quickbooks never considered that when you have multiple users connected to the same database at once, at least one of them must be accessing it over the network.) But in preparation for the process, I took note of the information needed to make QB run. I don't have the list in front of me, but there were something like 6 or 8 keys needed to make the software work: Customer account number Licence key Upgrade key Validation code etc. (I don't remember the full list. I try not to bring that part of my work home :) Or consider the Windows licence key, product activation code, etc. If "as convenient as possible" was their aim (as opposed to "making a profit from licencing"), then you wouldn't need all that. Why on earth should I have to install a "Amazon MP3 Downloader" app to purchase mp3s? Or the iTunes app? The internet and web browsers excel at making it easy to download files. Rather than taking advantage of that convenience, commercial vendors put barriers in the way and try to carve out little walled gardens. Did they not learn anything from AOL? Where is the Windows equivalent of yum or apt-get? Why isn't there a central repository of independent and third party Windows software? It seems clear to me that it is the major open source communities that aim for convenience, at the cost of the opportunity to sell licences. In fairness though, open source developers' idea of "convenient" is not always the same as mine. > On Unix you don't pay and the developer couldn't care less if his > application works together with application b or how much it takes you > to actually get this damn thing running. That might have been true, oh, 20 years ago, but today, that's far less of a rule. Linux distros make interoperability far simpler. Some level of savvy is needed, but it is remarkable how much Linux software Just Works. In my experience, two categories of Linux software are generally hard to deal with: one-man projects (usually stuck on version 0.2b for the last seven years), and big, popular projects that have been taken over by developers from the Windows world (I'm looking at you, Firefox). YMMV. > And as soon as developers start developing for Unix customers (say > Komodo, for instance), they start following the "Windows model" - as you > call it. Surely that's because Komodo started off as a Windows application before being ported to Unix? -- Steven From bahamutzero8825 at gmail.com Tue Jul 12 07:20:36 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 12 Jul 2011 06:20:36 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E1C2E04.9020704@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.12 05:24 AM, Steven D'Aprano wrote: > Rather than taking advantage of that convenience, commercial vendors > put barriers in the way and try to carve out little walled gardens. > Did they not learn anything from AOL? DRM and activation schemes will /always/ make things harder, but that is the cost of doing business, at least in the minds of commercial software vendors. There are actually a lot of good freeware (proprietary, but zero cost) apps out there. Some even better than open-source alternatives. I avoid commercial apps, though, since they tend to be far inferior to the alternatives (inconvenience aside). > Where is the Windows equivalent of yum or apt-get? Why isn't there a > central repository of independent and third party Windows software? If Microsoft made such a repository, how much of the repository would be high-quality open-source software, and how much would be commercial shovelware? Attempts at independent repos have been made, but they all fail because there's no effort among developers (especially developers of proprietary software), to package their software this way. These attempts also fail because they fail to gain support from users (a catch-22 where users don't bother because there's not much in the repo and there's not much in the repo because users don't bother). > It seems clear to me that it is the major open source communities > that aim for convenience, at the cost of the opportunity to sell > licences. The developers of open-source projects often aim to please the user rather than make money. You'd think pleasing the user and making money would go hand-in-hand, but history has shown that the latter can be achieved with little thought of the former. > That might have been true, oh, 20 years ago, but today, that's far > less of a rule. Linux distros make interoperability far simpler. Some > level of savvy is needed, but it is remarkable how much Linux > software Just Works. At first, Linux had to learn how to crawl and then walk. Now it's doing gymnastics. :) > In my experience, two categories of Linux software are generally hard > to deal with: one-man projects (usually stuck on version 0.2b for the > last seven years), and big, popular projects that have been taken > over by developers from the Windows world (I'm looking at you, > Firefox). YMMV. Firefox (and Thunderbird with it) are falling into the same trap that many fall into when they become popular. This is more prevalent among commercial apps, but it's not too surprising considering Firefox's popularity. The trap is making things shiny. That is, using UI designs (and to a lesser extent adding neat, but generally useless features) that appeal to the computer-illiterate masses who cling to something that looks neat, regardless of how useful it ultimately is. AFAICT, Mozilla's problem isn't that incompetent Windows-centric devs took over, but rather that Google and MS were stepping up their game with their respective browsers and is desperately trying not to lose market share. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHC4EAAoJEPiOA0Bgp4/Lgm0IAOT+/LQNalPHm5pvt4ilF1yt RM9fPBSgAF5k9U8jWBuQy/V6QJ/a1Sfkzu8ulZ8TyAYS64quucIqTwMJugdTUmct KsGbDsyXg0FObMxNiKKFuZblVYOtnULkYtYZOxeE33qy+85X6NMuFUv7ARHaLi/3 1Bdmnsj43hRrzJ1Rwb8x+xbOmiq+fJ7199loPQ+unSu7s37NJoL1e1vFNnsmGz8A Jg58Q0MbGiwettPdM9ZySYWgTJhiawtEX4SF6YiQqf22e04OyPWyxUfejixnZNoQ 7vbksr9k8PQzuTlG2y3G1pJx6XGrxgOQuEoVjInMGbZW0tx43paJLEWCOcd38FI= =3FGv -----END PGP SIGNATURE----- From xahlee at gmail.com Tue Jul 12 07:54:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 12 Jul 2011 04:54:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? Message-ID: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> maybe this will be of interest. ?What Programing Language Are the Largest Website Written In?? http://xahlee.org/comp/website_lang_popularity.html --------------------------------- i don't remember how, but today i suddenly got reminded that Facebook is written in PHP. So, on the spur of the moment, i twitted: ?Remember folks, the world's largest sites {Facebook, Wikipedia, ?Yahoo!?, etc} are written in Pretty Home Page!? and followed with: ?To Chinese friends, what's Baido, QQ, Taobao, Sina written in?? Then, this question piqued me, even i tried to not waste my time. But it overpowered me before i resisted, becuase i quickly spend 15 min to write this list (with help of Google): 1 Google ? Java 2 Facebook ? PHP 3 YouTube ? Python 4 Yahoo! ? PHP 5 blogger.com ? Java 6 baidu.com ? C/C++. perl/python/ruby 7 Wikipedia ? PHP 8 Windows Live live.com 9 Twitter.com ? Scala and Ruby? 10 QQ.com ? ? 11 MSN.com ? ? 13 LinkedIn ? PHP? 15 TaoBao.com ? ? 16 sina.com.cn ? ? 17 Amazon.com ? ? 18 WordPress.com ? PHP 22 eBay.com ? ? 23 yandex.ru (Russian) ? ? 24 Bing ? ? 27 Microsoft.com ? ? 28 ?? 163.com ? ? 29 PayPal.com ? Java? 31 ???? weibo.com ? ? 32 Flickr.com ? ? 34 mail.ru ? ? 35 Craiglist.org ? perl 36 FC2.com ? ? 38 Apple.com ? Objective J? 39 imdb.com ? ? 41 VKontakte.ru ? ? 43 ??? sohu.com ? ? 44 Ask.com ? ? 45 BBC.co.uk ? ? 46 tumblr.com ? PHP 47 LiveJasmin.com (porn) ? ? 48 xvideos.com (porn) ? ? ? 56 ??? Todou.com ? ? 81 YouPorn.com ? ? StumbleUpon.com ? PHP, Perl, C++ ? the numbers is site ranking, from alexa.com. (missing ones are mostly duplicates, such as google japan, google india, etc.) i think notable interest is that twitter stands out, with Scala and Ruby. Those with perl are probably going back to the first dot com era (aka Web 1.0, ~1995 to ~2002). At that time, perl was basically the only game in town (secondarily: Java). (i don't recall what amazon and ebay were in... was it perl or php? how about imdb.com?) most php follows starting in early 2000s, that's when PHP quietly surpassed perl in all battle fronts. it'd be interesting to know what some of the chinese sites uses, and porn sites (e.g. livejasmin, xvideos, youporn) as for Microsoft sites... are they in C/C++ and or dotnet? Xah From xahlee at gmail.com Tue Jul 12 07:54:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 12 Jul 2011 04:54:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? Message-ID: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> maybe this will be of interest. ?What Programing Language Are the Largest Website Written In?? http://xahlee.org/comp/website_lang_popularity.html --------------------------------- i don't remember how, but today i suddenly got reminded that Facebook is written in PHP. So, on the spur of the moment, i twitted: ?Remember folks, the world's largest sites {Facebook, Wikipedia, ?Yahoo!?, etc} are written in Pretty Home Page!? and followed with: ?To Chinese friends, what's Baido, QQ, Taobao, Sina written in?? Then, this question piqued me, even i tried to not waste my time. But it overpowered me before i resisted, becuase i quickly spend 15 min to write this list (with help of Google): 1 Google ? Java 2 Facebook ? PHP 3 YouTube ? Python 4 Yahoo! ? PHP 5 blogger.com ? Java 6 baidu.com ? C/C++. perl/python/ruby 7 Wikipedia ? PHP 8 Windows Live live.com 9 Twitter.com ? Scala and Ruby? 10 QQ.com ? ? 11 MSN.com ? ? 13 LinkedIn ? PHP? 15 TaoBao.com ? ? 16 sina.com.cn ? ? 17 Amazon.com ? ? 18 WordPress.com ? PHP 22 eBay.com ? ? 23 yandex.ru (Russian) ? ? 24 Bing ? ? 27 Microsoft.com ? ? 28 ?? 163.com ? ? 29 PayPal.com ? Java? 31 ???? weibo.com ? ? 32 Flickr.com ? ? 34 mail.ru ? ? 35 Craiglist.org ? perl 36 FC2.com ? ? 38 Apple.com ? Objective J? 39 imdb.com ? ? 41 VKontakte.ru ? ? 43 ??? sohu.com ? ? 44 Ask.com ? ? 45 BBC.co.uk ? ? 46 tumblr.com ? PHP 47 LiveJasmin.com (porn) ? ? 48 xvideos.com (porn) ? ? ? 56 ??? Todou.com ? ? 81 YouPorn.com ? ? StumbleUpon.com ? PHP, Perl, C++ ? the numbers is site ranking, from alexa.com. (missing ones are mostly duplicates, such as google japan, google india, etc.) i think notable interest is that twitter stands out, with Scala and Ruby. Those with perl are probably going back to the first dot com era (aka Web 1.0, ~1995 to ~2002). At that time, perl was basically the only game in town (secondarily: Java). (i don't recall what amazon and ebay were in... was it perl or php? how about imdb.com?) most php follows starting in early 2000s, that's when PHP quietly surpassed perl in all battle fronts. it'd be interesting to know what some of the chinese sites uses, and porn sites (e.g. livejasmin, xvideos, youporn) as for Microsoft sites... are they in C/C++ and or dotnet? Xah From rosuav at gmail.com Tue Jul 12 08:27:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 22:27:18 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 12, 2011 at 8:24 PM, Steven D'Aprano wrote: > Where is the Windows equivalent of yum or apt-get? Why isn't there a central > repository of independent and third party Windows software? It seems clear > to me that it is the major open source communities that aim for > convenience, at the cost of the opportunity to sell licences. > The nearest commercial equivalent is probably Apple's iTunes store. It manages to be the "one place to go" for iphone apps, many of which cost money. Upside: Developers know where to host their stuff if they want it to sell. Downside: Developers have to host it there if they want it to sell - and Apple snag 30% on the way through. I've not seen a Windows equivalent, but Microsoft could make one if they wanted to. All they need is for the next version of Windows to recommend that all software be signed, and make it somewhat awkward to install unsigned software, and that would be that. It would probably be the knell of Windows, but it could be done. ChrisA From sturlamolden at yahoo.no Tue Jul 12 08:59:12 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 05:59:12 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> On 12 Jul, 07:39, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. The rows will be aliased. This will work: c = [[0]*col for i in range(row)] Note that Python lists are not ment to be used as matrices. We have NumPy or the array module for that. > If this a valid way of initializing a matrix in Python 3.2.1, then it > appears to me that a bug surfaces in Python when performing this line: > > c[i][j] = c[i][j] + a[i][k] * b[k][j] > > It writes to the jth column rather than just the i,j cell. That is due to aliasing. > I'm new at Python and am not sure if I'm just doing something wrong if > there is really a bug in Python. ?The script works fine if I > initialize the matrix with numpy instead: > > c = np.zeros((row,col)) > > So, I know my matrix multiply algorithm is correct (I know I could use > numpy for matrix multiplication, this was just to learn Python). Like so: np.dot(a,b) or ma = np.matrix(a) mb = np.matrix(b) a*b or call BLAS directly: scipy.linalg.fblas.dgemm Sturla From sturlamolden at yahoo.no Tue Jul 12 09:03:25 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 06:03:25 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> Message-ID: <0e81b1d3-da91-45ca-8f2f-be2c4790300e@t5g2000yqj.googlegroups.com> On 12 Jul, 14:59, sturlamolden wrote: > ? ?ma = np.matrix(a) > ? ?mb = np.matrix(b) > ? ?a*b ma*mb Sorry for the typo. From davidbtdt at gmail.com Tue Jul 12 09:23:25 2011 From: davidbtdt at gmail.com (David) Date: Tue, 12 Jul 2011 06:23:25 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> Message-ID: Thank all for the very helpful replies. The goal of the matrix multiply exercise was just to help my son and I learn Python better. I now understand *why* my initialization of [c] was wrong and I am continuing to check out numpy and scipy. Regards, David From gnarlodious at gmail.com Tue Jul 12 09:32:32 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 06:32:32 -0700 (PDT) Subject: Set run vars with each call Message-ID: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Question. Is there a special method or easy way to set default values with each call to an instance? Any ideas to make it easier? What I want to do is have a constantly updating set of values which can be overridden. Just thought there was an easy way to set that up. -- Gnarlie From vincent.toups at gmail.com Tue Jul 12 10:30:59 2011 From: vincent.toups at gmail.com (jvt) Date: Tue, 12 Jul 2011 07:30:59 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: I might argue that it isn't quite right (or politic) to call those who resist technological changes "idiots" so much as to observe they often have goals which cannot wait for the ideal expressive system. People love python not because Python is the platonic programming language, but because it does what they need it to do right now. Ditto (often) for Lisp. It is easy to point out an example of forward thinking languages like Mathematica, and who knows, perhaps it will be the template upon which languages are built in the next 100 years. But if it is, there will be tons of other technologies which _didn't_ make it but which might have seemed equally advanced. Early adoption is always a risk, and few people want to deal with it when technology exists now that solves their problem now, however sub-optimally. That is hardly idiotic, Xah. From alister.ware at ntlworld.com Tue Jul 12 10:46:01 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Tue, 12 Jul 2011 14:46:01 GMT Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: On Tue, 12 Jul 2011 06:32:32 -0700, Gnarlodious wrote: > Question. Is there a special method or easy way to set default values > with each call to an instance? Any ideas to make it easier? What I want > to do is have a constantly updating set of values which can be > overridden. Just thought there was an easy way to set that up. > > -- Gnarlie I thought that was the role of the __init__ function class Something: def __init__(self): self.value="some value" -- No matter how subtle the wizard, a knife in the shoulder blades will seriously cramp his style. From noway at nohow.com Tue Jul 12 10:46:38 2011 From: noway at nohow.com (Billy Mays) Date: Tue, 12 Jul 2011 10:46:38 -0400 Subject: How to write a file generator Message-ID: I want to make a generator that will return lines from the tail of /var/log/syslog if there are any, but my function is reopening the file each call: def getLines(): with open('/var/log/syslog', 'rb') as f: while True: line = f.readline() if line: yield line else: raise StopIteration I know the problem lies with the StopIteration, but I'm not sure how to tell the caller that there are no more lines for now. -- Bill From tjreedy at udel.edu Tue Jul 12 11:03:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 15:03:08 -0000 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On 7/11/2011 11:37 PM, Xah Lee wrote: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, Union and intersection are set operations, not list operations. Python has had a set type with a full set of set operations for several years. It has list concatenation, which is the list equivalent of union. It has lots of other useful list operations. > Mathematica has Union, Intersection, and a host of others > some 20 years ago, and today it has a complete set of combinatorics > functions as *builtin* functions Python has the basic combinatoric function in the itertools module, though they are not used much. If Mathematica has Catalan sequences builtin, I wonder how much they are used. Since Python is free, in both meanings, it does not have paid people sitting around writing things to pad numbers to justify a $2k price tag. On the other hand, lots of people have added and made available lots of good add-ons. Mathematica should probably be most fairly compared with Python+numpy+scipy and maybe a few other things. -- Terry Jan Reedy From w_a_x_man at yahoo.com Tue Jul 12 11:27:27 2011 From: w_a_x_man at yahoo.com (WJ) Date: 12 Jul 2011 15:27:27 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: Xah Lee wrote: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. Ruby has them. Intersection: [2,3,5,8] & [0,2,4,6,8] ==>[2, 8] Union: [2,3,5,8] | [0,2,4,6,8] ==>[2, 3, 5, 8, 0, 4, 6] From bruno.desthuilliers at gmail.com Tue Jul 12 11:34:36 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 12 Jul 2011 08:34:36 -0700 (PDT) Subject: How to write a file generator References: Message-ID: On Jul 12, 4:46?pm, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any Err... I must have missed something, but python files are their own iterators. Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. pythonrc start pythonrc done >>> f = open("/var/log/syslog") >>> for line in f: ... print line ... (snip unintersting syslog stuff)) >, but my function is reopening the file > each call: How do you know, and how do you call your function ? > def getLines(): > ? ? ?with open('/var/log/syslog', 'rb') as f: > ? ? ? ? ?while True: > ? ? ? ? ? ? ?line = f.readline() > ? ? ? ? ? ? ?if line: > ? ? ? ? ? ? ? ? ?yield line > ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ?raise StopIteration > > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. If you want the generator to wait until new content is available, just remove the raise part - but you'll have a blocking call... Else, I don't see what behaviour you are expecting exactly. From ckaynor at zindagigames.com Tue Jul 12 11:47:47 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 12 Jul 2011 08:47:47 -0700 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 8:37 PM, Xah Lee wrote: > > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. > (sure, lib exists, but it's a ride in the wild) Python has them, but, as they are set functions, not list functions, they exist for the set type: Intersection: >>> set((1, 2, 3)) & set((2,3,4)) set([2, 3]) Union: >>> set((1, 2, 3)) | set((2,3,4)) set([1, 2, 3, 4]) Symmetric Difference: >>> set((1, 2, 3)) ^ set((2,3,4)) set([1, 4]) You can also get a non-symmetric difference by calling the difference method of the set: >>> set((1, 2, 3)).difference(set((2,3,4))) set([1]) >>> set((2, 3, 4)).difference(set((1,2,3))) set([4]) >>> In Python 3 (2.7?) there is even more syntactical sugar for them: {1, 2, 3} ^ {2, 3, 4} produces {1, 4}. -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Tue Jul 12 11:52:50 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 17:52:50 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C6DD2.5050707@jollybox.de> On 07/12/2011 04:46 PM, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call: > > def getLines(): > with open('/var/log/syslog', 'rb') as f: > while True: > line = f.readline() > if line: > yield line > else: > raise StopIteration > > > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. > > -- > Bill http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep From daniel.eliason at excite.com Tue Jul 12 12:16:33 2011 From: daniel.eliason at excite.com (fortunatus) Date: Tue, 12 Jul 2011 09:16:33 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <39f3f8c3-67e6-4c14-9e20-286dcef106ea@o4g2000vbv.googlegroups.com> I think the problem with so-called "forward looking" or "highest level" languages is that they tend to become domain specific. What Lispers are always saying is construct your own high level language out of your favorite Lisp. Of course no one else will use it then, or even discuss it, unless you have some good buddies. What happens is that high level languages don't end up addressing needs across a large community. The lower down languages can be common denominators across wide swaths of programmers. So we live in this world of roll-your-own on top of the common denominator language. One exception to this is in data base development, where there were some "4th generation" languages that had some success, where the needs of mapping business data models onto data base oriented implementation has had a large community. I guess Mathematica, or MatLab in my environment, also address a community of needs for modelling mathematical algorithms, or for doing analysis of data sets. However both the data base field and the math/arithmetic tool field are examples of domains that are narrower than programming in general. Hence those higher level languages could be seen as domain specific, but for domains with lots of users. From maththespian87 at gmail.com Tue Jul 12 12:40:23 2011 From: maththespian87 at gmail.com (John Keisling) Date: Tue, 12 Jul 2011 09:40:23 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who Message-ID: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> After too much time coding Python scripts and reading Mark Lutz's Python books, I was inspired to write the following lyrics. For those too young to remember, the tune is that of "Pinball Wizard," by The Who. May it bring you as much joy as it brought me! I cut my teeth on BASIC At scripting I'm no pawn >From C++ to Java My code goes on and on But I ain't seen nothing like this In any place I've gone That modeling and sim guy Sure codes some mean Python! He knows his dictionaries His exceptions never pass His polymorphic methods Extend each superclass He uses indentation Its lines are clearly drawn That modeling and sim guy Sure codes some mean Python! He's a Python wizard His code just never wrecks A Python wizard He knows simple beats complex How do you think he does it? (I don't know) What makes him so good? He codes with TkInter He can render treble clefs He uses lamdba functions With *args in their defs Defines his module search path Of tuples he's the don That modeling and sim guy Sure codes some mean Python! I thought I was The scripting language king But I just handed My Python crown to him He links in to libraries All optimized in C He always uses docstrings For readability He knows file iterators He bids all bugs begone That modeling and sim guy Sure codes some mean Python! From noway at nohow.com Tue Jul 12 12:42:34 2011 From: noway at nohow.com (Billy Mays) Date: Tue, 12 Jul 2011 12:42:34 -0400 Subject: How to write a file generator References: Message-ID: On 07/12/2011 11:52 AM, Thomas Jollans wrote: > On 07/12/2011 04:46 PM, Billy Mays wrote: >> I want to make a generator that will return lines from the tail of >> /var/log/syslog if there are any, but my function is reopening the file >> each call: >> >> def getLines(): >> with open('/var/log/syslog', 'rb') as f: >> while True: >> line = f.readline() >> if line: >> yield line >> else: >> raise StopIteration >> >> >> I know the problem lies with the StopIteration, but I'm not sure how to >> tell the caller that there are no more lines for now. >> >> -- >> Bill > > http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep That was actually the behavior I was trying to avoid. If there is no data to be read, the call will hang. That function is actually called by a webserver (from wsgiref) so it cannot hang indefinitely. -- Bill From msarro at gmail.com Tue Jul 12 12:48:37 2011 From: msarro at gmail.com (Matty Sarro) Date: Tue, 12 Jul 2011 12:48:37 -0400 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: I don't know whether to LOL or mourn the part of me that just died inside :-P j/k j/k clever song, and it made me laugh :) On Tue, Jul 12, 2011 at 12:40 PM, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > > > I cut my teeth on BASIC > At scripting I'm no pawn > >From C++ to Java > My code goes on and on > But I ain't seen nothing like this > In any place I've gone > That modeling and sim guy > Sure codes some mean Python! > > He knows his dictionaries > His exceptions never pass > His polymorphic methods > Extend each superclass > He uses indentation > Its lines are clearly drawn > That modeling and sim guy > Sure codes some mean Python! > > He's a Python wizard > His code just never wrecks > A Python wizard > He knows simple beats complex > > How do you think he does it? > (I don't know) > What makes him so good? > > He codes with TkInter > He can render treble clefs > He uses lamdba functions > With *args in their defs > Defines his module search path > Of tuples he's the don > That modeling and sim guy > Sure codes some mean Python! > > I thought I was > The scripting language king > But I just handed > My Python crown to him > > He links in to libraries > All optimized in C > He always uses docstrings > For readability > He knows file iterators > He bids all bugs begone > That modeling and sim guy > Sure codes some mean Python! > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Tue Jul 12 12:49:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 16:49:40 -0000 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On 7/11/2011 11:37 PM, Xah Lee wrote: > watch the first episode of Douglas Crockford's talk here: > http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 The link includes a transcript of the talk, which I read I suspect Lee likes Crockford because they both think they are smarter than everyone else. Writing about Smalltalk, for instance, Crockford says: "I don't know why it is, but a lot of programmers just couldn't get used to this syntax. [everything is done by sending a message with arguments to some object] ...So this may be a superior notation, but it was profoundly rejected. By who? By us, by the programmers, because we couldn't understand it." Actually, I and others see Smalltalk as deeply flawed because its message passing syntax arbitrarily breaks symmetries in operations. For instance, in the expression 'a+b', both operands have equivalent roles in the operation for all normal interpretations of '+'.# On the other hand, in the expression 'a.extend(b)', where a is a list and b any iterable and the result is to mutate a but not b, a and b have very different roles in both the operation and the expression that invokes it. # Under the covers, Python implements 'a+b' as first 'a.__add__(b)', but it also tries 'b.__radd__(a)' if the first does not work. This introduces a slight asymmetry in that a gets first say at defining the meaning of 'a+b', but it does not get the only say. And, as far as I can presently remember, this asymmetry is never visible with builtins. In fact, this implementation makes it possible for 'a+b' and 'b+a' to both give the same answer when a is a builtin and b is a user-class instance. Crockford is right that he does not 'know why it is' that not everyone loves Smalltalk. He should have stopped there instead of projecting his ignorance on everyone else. As a side note, the same principle of expressions matching operations in symmetry suggest that majority of up are quite sensible and not dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a function call, the function has a different role than the arguments, so it is appropriate that it have a different role in the expression. -- Terry Jan Reedy From sturlamolden at yahoo.no Tue Jul 12 12:53:23 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 09:53:23 -0700 (PDT) Subject: How to write a file generator References: Message-ID: <2ed7d9e9-3b58-404d-a1dd-8f2688fb4012@e7g2000vbw.googlegroups.com> On 12 Jul, 16:46, Billy Mays wrote: > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. Try 'yield None' instead of 'raise StopIteration'. Sturla From tundra at tundraware.com Tue Jul 12 13:08:53 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 12 Jul 2011 12:08:53 -0500 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <5mbue8-v3i.ln1@ozzie.tundraware.com> On 7/12/2011 11:40 AM, John Keisling said this: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > You realize that you must now reprise this with, "I'm your wicked Uncle Guido" ... right? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From shilparani9030 at gmail.com Tue Jul 12 13:22:39 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Tue, 12 Jul 2011 10:22:39 -0700 (PDT) Subject: SOUTH ACTRESS Message-ID: <625dcdf3-5dd7-49c3-a601-1d96482cd6cb@h7g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gnarlodious at gmail.com Tue Jul 12 13:32:12 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 10:32:12 -0700 (PDT) Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> On Jul 12, 8:46?am, Alister Ware wrote: > I thought that was the role of the __init__ function > > class Something: > ? ? ? ? def __init__(self): > ? ? ? ? ? ? ? ? self.value="some value" OK, that sets a value at init time. But is there a similar built-in to run whenever the class instance is called? -- Gnarlie From tundra at tundraware.com Tue Jul 12 13:34:17 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 12 Jul 2011 12:34:17 -0500 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <5mbue8-v3i.ln1@ozzie.tundraware.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <5mbue8-v3i.ln1@ozzie.tundraware.com> Message-ID: On 7/12/2011 12:08 PM, Tim Daneliuk said this: > On 7/12/2011 11:40 AM, John Keisling said this: >> After too much time coding Python scripts and reading Mark Lutz's >> Python books, I was inspired to write the following lyrics. For those >> too young to remember, the tune is that of "Pinball Wizard," by The >> Who. May it bring you as much joy as it brought me! >> > > > > You realize that you must now reprise this with, > "I'm your wicked Uncle Guido" ... right? > > While were on the subject: "T-t-t-alking 'bout my generator ...." -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From bahamutzero8825 at gmail.com Tue Jul 12 13:50:59 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 12 Jul 2011 12:50:59 -0500 Subject: Set run vars with each call In-Reply-To: <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> Message-ID: <4E1C8983.4070008@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.12 12:32 PM, Gnarlodious wrote: > OK, that sets a value at init time. But is there a similar built-in > to run whenever the class instance is called? What do you mean by call an instance? Do you want to run certain code whenever any method is called? Do you want to want certain code to run whenever an attribute is accessed? Calling an instance doesn't make any sense, especially if you're not referring to the __init__() method. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHImDAAoJEPiOA0Bgp4/LEzYH/1R+cXobysF02GiB45LcXjHm oQsSkrbXtlvutgOlVHOI8MRVRzMndgK+0jWsujYD4nZYf45GO3b0hw/zb9jy3bUI 7BafZMRAz+wI1BJFlDD3P+IjPDoW4WvpMP0q09H4f664DYwQNuXfeveNOwAQnPXl SpqpcvnTm0fqocC0o2G9jUuV50QXFFPntz/VVwl+3UpJLS95pCuAq+URs4OVhLM2 QB1ulmZ35PyfArdz5pYvoXvtfeURldfZhhAm1/mkVThzffUxAcCTANg6AeYd2JNb QO0jSCedhrzWfsK5J63Ax+nrmjvms8+gZ3TxNkdMaz0zICtDuq5lLSIml1JuUfk= =EMT2 -----END PGP SIGNATURE----- From rodneygomes at gmail.com Tue Jul 12 13:59:28 2011 From: rodneygomes at gmail.com (Rodney Gomes) Date: Tue, 12 Jul 2011 10:59:28 -0700 (PDT) Subject: new python contracts library Message-ID: Hey I recently created a contracts library for python and was wondering if anyone finds it useful or wants to have additional features added ? Feel free to open new issues on the github project. https://github.com/rlgomes/contracts This is just a v0.1 and I welcome any and all suggestions to make it into something really useful. I've found it useful for when I start putting together a few other project ideas I have and want to make sure that the certain functions are being used correctly and that bad arguments or return values don't end up blowing up the application in a completely unrelated function call sometime later than the original point where the bug actually occurred. If this is not the correct forum for this posting let me know and i'll move it elsewhere. From phlip2005 at gmail.com Tue Jul 12 14:01:59 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 12 Jul 2011 11:01:59 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <9c6b4082-4b62-4dfc-ab9a-96bf697abb60@k19g2000prn.googlegroups.com> > That modeling and sim guy > Sure codes some mean Python! C-; And he changes key on the fly, too! From tjreedy at udel.edu Tue Jul 12 14:02:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 18:02:15 -0000 Subject: How to write a file generator In-Reply-To: References: Message-ID: On 7/12/2011 10:46 AM, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call: > > def getLines(): > with open('/var/log/syslog', 'rb') as f: > while True: > line = f.readline() > if line: > yield line > else: > raise StopIteration Please use spaces rather than (disappearing) tabs in posted code. > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. The same way you currently decide when to raise StopIteration def tail(filename): with open(filename, 'rb') as f: while True: yield f.readline() When the caller gets '', it should go and do something else for awhile. -- Terry Jan Reedy From gheskett at wdtv.com Tue Jul 12 14:23:39 2011 From: gheskett at wdtv.com (gene heskett) Date: Tue, 12 Jul 2011 14:23:39 -0400 Subject: Lisp refactoring puzzle In-Reply-To: References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <201107121423.39951.gheskett@wdtv.com> On Tuesday, July 12, 2011 02:08:02 PM Terry Reedy did opine: > On 7/11/2011 11:37 PM, Xah Lee wrote: > > watch the first episode of Douglas Crockford's talk here: > > http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 > > The link includes a transcript of the talk, which I read > > I suspect Lee likes Crockford because they both think they are smarter > than everyone else. Writing about Smalltalk, for instance, Crockford > says: > > "I don't know why it is, but a lot of programmers just couldn't get used > to this syntax. [everything is done by sending a message with arguments > to some object] ...So this may be a superior notation, but it was > profoundly rejected. By who? By us, by the programmers, because we > couldn't understand it." > > Actually, I and others see Smalltalk as deeply flawed because its > message passing syntax arbitrarily breaks symmetries in operations. For > instance, in the expression 'a+b', both operands have equivalent roles > in the operation for all normal interpretations of '+'.# On the other > hand, in the expression 'a.extend(b)', where a is a list and b any > iterable and the result is to mutate a but not b, a and b have very > different roles in both the operation and the expression that invokes > it. > > # Under the covers, Python implements 'a+b' as first 'a.__add__(b)', but > it also tries 'b.__radd__(a)' if the first does not work. This > introduces a slight asymmetry in that a gets first say at defining the > meaning of 'a+b', but it does not get the only say. And, as far as I can > presently remember, this asymmetry is never visible with builtins. In > fact, this implementation makes it possible for 'a+b' and 'b+a' to both > give the same answer when a is a builtin and b is a user-class instance. > > Crockford is right that he does not 'know why it is' that not everyone > loves Smalltalk. He should have stopped there instead of projecting his > ignorance on everyone else. > I have my own reasons to hate smalltalk but won't elaborate. > As a side note, the same principle of expressions matching operations in > symmetry suggest that majority of up are quite sensible and not dumb > idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a function call, > the function has a different role than the arguments, so it is > appropriate that it have a different role in the expression. Which should be well documented if one expects the programmers to use it properly. So far, I have only found two languages that are adequately defined and implemented. K&R C, and the now essentially defunct Amiga ARexx. But I should preface that by saying that I have not yet adequately studied python, one of the reasons I joined this list. Specifically, I am trying to install the altera quartus software so I can program one of their DE1 boards, but because the majority of the linux distro's have not kept their repo's zlib packages up to date, one of the quartus imports, gzdirect is on the missing list and I am dead in the water until I install zlib version 1.2.5. I hope this list serves me as a tutorial to fill in the gaps of my python knowledge which at the moment seem too wide to jump over. I hope I can ask intelligent, if newbie, questions occasionally. Now, I hate to mention it Terry, but your clock seems to be about 126 months behind the rest of the world. Does your system not run ntpd by default? The date in the header from your machine is "Mon Jan 1 14:11:11 2001". Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) What makes us so bitter against people who outwit us is that they think themselves cleverer than we are. From cmpython at gmail.com Tue Jul 12 14:43:53 2011 From: cmpython at gmail.com (CM) Date: Tue, 12 Jul 2011 11:43:53 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> > > One reason there hasn't been much demand for a GUI builder is that, in > > many cases, it's just as simpler or simpler to code a GUI by hand. I use a GUI builder because I'd rather click less than type more. I just tried that in Boa Constructor; with ~10 mouse clicks I produced 964 characters of Python code. Now, sure, depending on how I wrote the code I could do better than that, but for me, I just find it more intuitive and easier to use a GUI to make a GUI. > Often a GUI builder is used as a bad replacement for sketch-pad and > pencil. I would use a sketch-pad and pencil and *then* use the GUI builder. What's nice about a builder is one can move things around quickly and see the results in the real application, which one can never really see well on a paper sketch. You could use a mock-up program of course, but I feel you might as well do it in the builder because when you're satisfied with it you have a real runnable application instead of just a picture. > Using a GUI builder with layout managers might actually > feel awkward. It takes some getting used to in Boa, in my experience, but then it feels intuitive and I really like using sizers with Boa. It helps if you give your sizers descriptive names. Che From maththespian87 at gmail.com Tue Jul 12 14:47:13 2011 From: maththespian87 at gmail.com (John Keisling) Date: Tue, 12 Jul 2011 11:47:13 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <5mbue8-v3i.ln1@ozzie.tundraware.com> Message-ID: <8b876209-2146-418c-97d4-8ac63b2d33aa@g3g2000prf.googlegroups.com> On Jul 12, 11:34?am, Tim Daneliuk wrote: > On 7/12/2011 12:08 PM, Tim Daneliuk said this: > > > On 7/12/2011 11:40 AM, John Keisling said this: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. For those > >> too young to remember, the tune is that of "Pinball Wizard," by The > >> Who. May it bring you as much joy as it brought me! > > > > > > You realize that you must now reprise this with, > > "I'm your wicked Uncle Guido" ... right? > > While were on the subject: > > ? "T-t-t-alking 'bout my generator ...." > > -- > ------------------------------------------------------------------------ > Tim Daneliuk > tun... at tundraware.com Brilliant! LOL! From pavlovevidence at gmail.com Tue Jul 12 14:58:26 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 12 Jul 2011 11:58:26 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Tuesday, July 12, 2011 9:40:23 AM UTC-7, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > > > I cut my teeth on BASIC > At scripting I'm no pawn > From C++ to Java > My code goes on and on > But I ain't seen nothing like this > In any place I've gone > That modeling and sim guy > Sure codes some mean Python! That's pretty funny. I knew what it would be even when I saw the cut-off subject line, and I am too young to remember it. Carl Banks From ian.g.kelly at gmail.com Tue Jul 12 14:59:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jul 2011 12:59:18 -0600 Subject: Set run vars with each call In-Reply-To: <4E1C8983.4070008@gmail.com> References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> <4E1C8983.4070008@gmail.com> Message-ID: On Tue, Jul 12, 2011 at 11:50 AM, Andrew Berg wrote: > On 2011.07.12 12:32 PM, Gnarlodious wrote: >> OK, that sets a value at init time. But is there a similar built-in >> to run whenever the class instance is called? > What do you mean by call an instance? Do you want to run certain code > whenever any method is called? Do you want to want certain code to run > whenever an attribute is accessed? Calling an instance doesn't make any > sense, especially if you're not referring to the __init__() method. If I'm understanding correctly, I think the OP wants to do something like this: class Gadget: def do_something(self, some_argument=some_default_value): # do stuff where the exact default value of some_argument depends on the current state of the Gadget instance. The canonical approach here would be: class Gadget: def do_something(self, some_argument=None): if some_argument is None: some_argument = self._some_argument_default # do stuff And then the other instance methods of Gadget can update the default by setting the value of the _some_argument_default attribute. From newsmailcomp6 at gustad.com Tue Jul 12 15:02:51 2011 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: Tue, 12 Jul 2011 21:02:51 +0200 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <87y603nwys.fsf@pangea.home.gustad.com> Xah Lee writes: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. In Common Lisp you have: CL-USER> (union '(a b c) '(b c d)) (A B C D) CL-USER> (intersection '(a b c) '(b c d)) (C B) //Petter -- .sig removed by request. From t at jollybox.de Tue Jul 12 15:04:37 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 21:04:37 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C9AC5.4010204@jollybox.de> On 07/12/2011 06:42 PM, Billy Mays wrote: > On 07/12/2011 11:52 AM, Thomas Jollans wrote: >> On 07/12/2011 04:46 PM, Billy Mays wrote: >>> I want to make a generator that will return lines from the tail of >>> /var/log/syslog if there are any, but my function is reopening the file >>> each call: >>> >>> def getLines(): >>> with open('/var/log/syslog', 'rb') as f: >>> while True: >>> line = f.readline() >>> if line: >>> yield line >>> else: >>> raise StopIteration >>> >>> >>> I know the problem lies with the StopIteration, but I'm not sure how to >>> tell the caller that there are no more lines for now. >>> >>> -- >>> Bill >> >> http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep >> > > > That was actually the behavior I was trying to avoid. If there is no > data to be read, the call will hang. That function is actually called > by a webserver (from wsgiref) so it cannot hang indefinitely. In that case, what Bruno said. From t at jollybox.de Tue Jul 12 15:05:52 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 21:05:52 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C9B10.3020409@jollybox.de> On 07/12/2011 06:42 PM, Billy Mays wrote: > On 07/12/2011 11:52 AM, Thomas Jollans wrote: >> On 07/12/2011 04:46 PM, Billy Mays wrote: >>> I want to make a generator that will return lines from the tail of >>> /var/log/syslog if there are any, but my function is reopening the file >>> each call: >>> >>> def getLines(): >>> with open('/var/log/syslog', 'rb') as f: >>> while True: >>> line = f.readline() >>> if line: >>> yield line >>> else: >>> raise StopIteration >>> >>> >>> I know the problem lies with the StopIteration, but I'm not sure how to >>> tell the caller that there are no more lines for now. >>> >>> -- >>> Bill >> >> http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep >> > > > That was actually the behavior I was trying to avoid. If there is no > data to be read, the call will hang. That function is actually called > by a webserver (from wsgiref) so it cannot hang indefinitely. What Terry said, then. (Not Bruno, I confused that. Sorry for sending a mail both short and wrong.) From ameliagrace143 at gmail.com Tue Jul 12 15:07:50 2011 From: ameliagrace143 at gmail.com (Amelia Grace) Date: Tue, 12 Jul 2011 12:07:50 -0700 (PDT) Subject: Complete Google Advertising Solutions Message-ID: <40a1c4de-5774-4c8d-a4ea-1a8c728c72e8@fv14g2000vbb.googlegroups.com> TheItValley is a capable web development application, software combination, search engine optimization, E-commerce, E-banking and complete Google advertising solution Organization based in UK main branches office in Sweden, Norway and Pakistan. The Internet is the most efficient and greatest growing sales channel for many organizations. Through internet every organization can enhance the sale and purchase volume which is very effective and significant way. Therefore TheitValley is offering complete Google advertising solutions to evaluate the E commerce and E business solutions using the Internet to increase customers and generate more sales. Choosing the right E commerce supplier is a key decision: choosing one with a proven track record, experience and deep familiarity with all aspects of the online marketing, TIV is aimed at providing elevated quality and cost-induced web application/software solutions from small to medium organizations worldwide by combining the onsite analysis phase with offshore development & testing phase, followed by onsite implementation. With the help of TIV?s Global Delivery Model, software project costs of its clients worldwide can be reduced by about 50% without having to compromise on absolute quality and delivery schedules. The projects are executed on Fixed-Price or Time & Material basis, depending upon the nature of each project. Internet marketing is the origin link building for any quality Internet marketing operation. We Build Pages views links as ?votes? for your website, justification from the Internet society that your website and associated services and resources are valuable. The additional links, the more popular the website, and the higher it will rank in the search engines; but there is a catch, not all votes are the same. The more authoritative the site that links to another site, the more ?votes? its worth. We Build Pages targets the most authoritative sites to ensure that your link building efforts get the most bang for your buck. We all want more traffic, and more importantly, we want that traffic to turn into customers. With this common goal in mind, We Build Pages is dedicated to providing our clients with the tools and feedback to make your website and services successful. Search engine optimization is the permanent performance of civilizing search engine position of a website. We Build Pages Internet Marketing Services believes that by growing traffic to a website using link building services, proactive Internet marketing, and original SEO content creation to improve search engine positioning. With the latest organic link building services, We Build Pages provides the most significant and modified SEO services accessible. Web design and web application development is a complex process that requires a extensive range of creative, business and technical skills. Good design must impressively communicate key marketing messages and well as providing simple intuitive navigation. In web development felid, we have successfully established ourselves in providing high quality web design and web development from our wide range and verity to our client all around the world. The design also lays down a sequence of ?calls to action? designed to engage and facilitate the business process. TheitValley is the biggest and largest providing complete Google advertising solution after Google. The first and foremost priority of the TIV is to attain the customer objective without any compromise. The work procedure of the TIV is planning and analysis, user interface design, project management, documentation, onsite testing, implementation, post implementation, warranty support achieving the goal with effectively and efficiently work. http://www.theitvalley.com/seo.html From neilc at norwich.edu Tue Jul 12 15:44:33 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Jul 2011 19:44:33 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> Message-ID: <983mh1Fs7cU1@mid.individual.net> On 2011-07-12, Petter Gustad wrote: > Xah Lee writes: > >> it's funny, in all these supposedly modern high-level langs, they >> don't provide even simple list manipulation functions such as union, >> intersection, and the like. Not in perl, not in python, not in lisps. > > In Common Lisp you have: > > CL-USER> (union '(a b c) '(b c d)) > (A B C D) > CL-USER> (intersection '(a b c) '(b c d)) > (C B) What's the rationale for providing them? Are the definitions obvious for collections that a not sets? -- Neil Cerutti From w_a_x_man at yahoo.com Tue Jul 12 15:52:32 2011 From: w_a_x_man at yahoo.com (WJ) Date: 12 Jul 2011 19:52:32 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> Message-ID: Petter Gustad wrote: > Xah Lee writes: > > > it's funny, in all these supposedly modern high-level langs, they > > don't provide even simple list manipulation functions such as union, > > intersection, and the like. Not in perl, not in python, not in lisps. > > In Common Lisp you have: > > CL-USER> (union '(a b c) '(b c d)) > (A B C D) > CL-USER> (intersection '(a b c) '(b c d)) > (C B) The order was changed. COBOL Lisp is always mindless. * (union '(2 2 3 4) '(7 7 8 9)) (4 3 2 2 7 7 8 9) The right way (MatzLisp): [2,2,3,4] | [7,7,8,9] ==>[2, 3, 4, 7, 8, 9] From phlip2005 at gmail.com Tue Jul 12 16:31:00 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 12 Jul 2011 13:31:00 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: Message-ID: > That's pretty funny. ?I knew what it would be even when I saw the cut-off subject line, and I am too young to remember it. > > Carl Banks TTTO "[She put the lime in the] Coconut": Brother wrote a database, he finish it on time His sister add requirements, refactor every line She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in that database, she called the doctor, woke him up, Sayin' "Doctor, now I got to pay my dues, I say, Doctor, to debug away my blues, I say, Doctor, such a big change has to break, I say, Doctor! I must'a made a bug mistake!" "Now let me get this straight, You change the design in the database, mix things all up You change the design in the database, mix it all up, You change the design in the database, mix it all up..." http://c2.com/cgi/wiki?SheChangeDesignInTheDatabase From rbanffy at gmail.com Tue Jul 12 16:35:38 2011 From: rbanffy at gmail.com (=?ISO-8859-1?Q?Ricardo_B=E1nffy?=) Date: Tue, 12 Jul 2011 17:35:38 -0300 Subject: Building Python 2.5.6 on Ubuntu Natty Message-ID: Hi folks. Has anyone succeeded in building Python 2.5.6 from sources in Ubuntu Natty? I installed all the build dependencies and keep getting running build_ext /usr/include/sqlite3.h: version 3.7.4 Traceback (most recent call last): File "./setup.py", line 1545, in main() File "./setup.py", line 1540, in main 'Lib/smtpd.py'] File "/tmp/Python-2.5.6/Lib/distutils/core.py", line 151, in setup File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 974, in run_commands File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 994, in run_command File "/tmp/Python-2.5.6/Lib/distutils/command/build.py", line 112, in run File "/root/Python-2.5.6/Lib/cmd.py", line 333, in run_command del help[cmd] File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 994, in run_command File "/tmp/Python-2.5.6/Lib/distutils/command/build_ext.py", line 290, in run File "./setup.py", line 97, in build_extensions self.detect_modules() File "./setup.py", line 810, in detect_modules sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] File "/root/Python-2.5.6/Lib/posixpath.py", line 119, in dirname return split(p)[0] File "/root/Python-2.5.6/Lib/posixpath.py", line 77, in split i = p.rfind('/') + 1 AttributeError: 'NoneType' object has no attribute 'rfind' make: *** [sharedmods] Error 1 when I do "make test" and Compiling /opt/python2.5/lib/python2.5/zipfile.py ... make: *** [libinstall] Error 1 when I do "make install" Any ideas? -- Ricardo B?nffy http://www.dieblinkenlights.com http://twitter.com/rbanffy -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 12 17:18:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:18:13 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> Message-ID: <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> On Jul 12, 1:43?pm, CM wrote: > > > One reason there hasn't been much demand for a GUI builder is that, in > > > many cases, it's just as simpler or simpler to code a GUI by hand. > > I use a GUI builder because I'd rather click less than > type more. I just tried that in Boa Constructor; with ~10 > mouse clicks I produced 964 characters of Python code. Remember, it's NOT the length of the code that matters, no, it's the motion of the "sources" ocean. Did it produce rough seas full of spaghetti monsters? Or tranquil fjords worth pining over (sadly to death apparently?)? 1. Never judge the quality of code simply by it's length. Because if you do, some folks might suffer from "source envy"! Also, you MAY have created 964 chars of code with your ten or so clicks HOWEVER that is just template code. You'll need to set many attributes for the widgets before they are ready for prime time. Your "supposed" ten or so click estimate is very naive. It takes MUCH more to create even a simple GUI, because, we have NOT even discussed logic yet! > Now, sure, depending on how I wrote the code I could do > better than that, but for me, I just find it more > intuitive and easier to use a GUI to make a GUI. Personal opinions should always be respected, and as such i respect yours but later i would outline my GUI design workflow so pay close attention. > > Often a GUI builder is used as a bad replacement for > > sketch-pad and pencil. > > I would use a sketch-pad and pencil and *then* use the GUI builder. But do you really? Your following statements lead me to believe that you don't. > What's nice about a builder is one can move things around > quickly and see the results in the real application, which > one can never really see well on a paper sketch.? I prefer to skip any pencil and paper completely myself. I just use my imagination. UNLESS the GUI is EXTREMELY complicated. For me the design of a GUI starts in my brain. No pencil, no paper, no three hours using Auto Cad GUI designer. Next i start creating widgets and laying them out using geometry managers (in CODE). Finally i run a few tests, make a few changes, and design phase is over. Time for logic. --------------------------------------------- My argument against GUI builders is two fold. --------------------------------------------- 1. GUI builders remove us from the initial "mental design phase" and temp us to let our inner "click-ity-click" and "drag-ity-drag" child loose. This inner child likes to play but he hates to plan. Very soon he has the play room floor (source code) overflowing with toys (code) arranged in a completely haphazard way. Unlike the child however, there is no code mommy to spank this bad little boy when he is a programmer. So he just keeps messing up play room after play room making a complete fool of himself along the way. 2. GUI builders remove us from the source code. When you are playing "clicky-click" with yourself you could be in the trenches fighting the spaghetti code monster. Instead you are losing mental focus. Remember, playing with yourself makes you lazy! ---------------------------------------------- What happens is... you get lost "playing" and fail to keep your mental focus. A programmers metal focus is his most valuable weapon in the fight against the spaghetti code monster. I am a programmer. I love my source code more than i love most people in this world. I do not want to be away from my source. I am jealous of my source! And so too should you be. Kevin made the argument earlier that Tkinter (and others) are so easy to use that they render needing a GUI builder useless -- and he is correct! But did you know that there are GUI libraries EVEN more highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and using my imagination is so difficult" *crap* is really making me laugh. That is my argument people. Opinions may vary. Keep watch for the spaghetti code monster! Cheers folks. PS: if you don't like to type, programming IS NOT the best career (or hobby) choice for you. From ethan at stoneleaf.us Tue Jul 12 17:19:17 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jul 2011 14:19:17 -0700 Subject: Enhanced dir() function In-Reply-To: <4E0E1491.8070007@stoneleaf.us> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> <4E0E01F9.80803@tim.thechases.com> <4E0E1491.8070007@stoneleaf.us> Message-ID: <4E1CBA55.1090206@stoneleaf.us> Ethan Furman wrote: > Tim Chase wrote: >> If it came in as an effortless (i.e. O(1) where I do it once and never >> again; not an O(n) where n=the number of times I invoke Python) >> default replacement for dir(), I'd reach for it a lot more readily. I >> seem to recall there's some environment-var or magic file-name that >> gets sourced on every startup. > > interact.py > 8<----------------------------------------------- > import os, sys > sys.ps1 = '--> ' > > from cookbook.utils import dir # or whereever you keep your copy > sys.modules['__builtin__'].dir = dir > 8<----------------------------------------------- Imagine my amusement when I went to change an environment variable today and found: PYTHONSTARTUP=c:\python25\interact.py ~Ethan~ From ben+python at benfinney.id.au Tue Jul 12 17:36:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jul 2011 07:36:49 +1000 Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> Message-ID: <87bowzdvv2.fsf@benfinney.id.au> Gnarlodious writes: > OK, [the ?__init__? method] sets a value at init time. But is there a > similar built-in to run whenever the class instance is called? You can write a ?__call__? method which will be called when the instance is called. But I suspect that's still not what you're asking. Maybe it will be quicker to ask: What is it you want to achieve? -- \ ?Compulsory unification of opinion achieves only the unanimity | `\ of the graveyard.? ?Justice Roberts in 319 U.S. 624 (1943) | _o__) | Ben Finney From rantingrick at gmail.com Tue Jul 12 17:38:11 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:38:11 -0700 (PDT) Subject: Enhanced dir() function References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56fefd0b-afee-4b94-bb3a-5a04aa42d1ae@x10g2000vbl.googlegroups.com> On Jun 30, 11:29?pm, Steven D'Aprano wrote: > The dir() function is designed for interactive use, inspecting objects for > the names of attributes and methods. > > Here is an enhanced version that allows you to pass a glob to filter the > names you see: meh, I have always believed in keeping my namespace squeaky clean so i never have this problem. Modules like Tkinter (where you yourself have supported the global import!) i always import as "tk". I think this IS more a housekeeping issue than a "nail on patch" issue. PS: However pay attention because i have some interesting ideas about "dir culling" in my next post to this thread. From rantingrick at gmail.com Tue Jul 12 17:46:44 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:46:44 -0700 (PDT) Subject: Enhanced dir() function References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> On Jul 1, 12:20?pm, Tim Chase wrote: > If it came in as an effortless (i.e. O(1) where I do it once and > never again; not an O(n) where n=the number of times I invoke > Python) default replacement for dir(), I'd reach for it a lot > more readily. ?I seem to recall there's some environment-var or > magic file-name that gets sourced on every startup. > > I use the list-comp version on a regular basis: I strongly agree with this statement because i prefer the LC myself. HOWEVER i've always lamented the verbosity of dir(). --------------------------- Case in Point --------------------------- >>> dir([]) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] --------------------------- Do we really need to see all the built in methods EVERY time? I don't, i've had them memorized for years. HOWEVER i do understand the fact that n00bs need to see them every time. So why should old hats need to type this every time... >>> [x for x in dir([]) if not x.startswith('_')] ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] Because we have plenty of room for args in this function... >>> dir(verbose=False) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] Ahhh, i love it when a plan comes together! From kylotan at gmail.com Tue Jul 12 17:47:57 2011 From: kylotan at gmail.com (Ben Sizer) Date: Tue, 12 Jul 2011 14:47:57 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? Message-ID: <9c887bcb-e25f-4974-9fbe-c39a5f042a26@l18g2000yql.googlegroups.com> I'd like to evaluate the recent build of PyPy on the project I'm currently working on, but am not sure how best to go about it. So my question is simply - how would I go about installing PyPy alongside Python 2.7 on Windows? In particular, unzipping PyPy and adding it to the PATH is easy enough, but what about getting setuptools and easy_setup working to install various packages for it? Is there a virtualenv-based method I can use here? (And is pip a decent replacement for setuptools on Windows yet?) -- Ben Sizer From ethan at stoneleaf.us Tue Jul 12 18:19:06 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jul 2011 15:19:06 -0700 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <4E1CC85A.4030302@stoneleaf.us> John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! Absolutely hilarious! Thanks! ~Ethan~ From pjb at informatimago.com Tue Jul 12 18:51:51 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 13 Jul 2011 00:51:51 +0200 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> <983mh1Fs7cU1@mid.individual.net> Message-ID: <87aacji03c.fsf@kuiper.lan.informatimago.com> Neil Cerutti writes: > What's the rationale for providing them? Are the definitions > obvious for collections that a not sets? The rational is to prove that Xah is dumb. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jul 12 19:26:01 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 13 Jul 2011 01:26:01 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: Am 12.07.2011 16:46 schrieb Billy Mays: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call ... I have another solution: an object which is not an iterator, but an iterable. class Follower(object): def __init__(self, file): self.file = file def __iter__(self): while True: l = self.file.readline() if not l: return yield l if __name__ == '__main__': f = Follower(open("/var/log/messages")) while True: for i in f: print i, print "foo" import time time.sleep(4) Here, you iterate over the object until it is exhausted, but you can iterate again to get the next entries. Thomas From cmpython at gmail.com Tue Jul 12 20:22:07 2011 From: cmpython at gmail.com (CM) Date: Tue, 12 Jul 2011 17:22:07 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> Message-ID: <79a7dab4-16ce-436e-ac54-62e314360fae@j25g2000vbr.googlegroups.com> On Jul 12, 5:18?pm, rantingrick wrote: > On Jul 12, 1:43?pm, CM wrote: > > > > > One reason there hasn't been much demand for a GUI builder is that, in > > > > many cases, it's just as simpler or simpler to code a GUI by hand. > > > I use a GUI builder because I'd rather click less than > > type more. I just tried that in Boa Constructor; with ~10 > > mouse clicks I produced 964 characters of Python code. > > Remember, it's NOT the length of the code that matters, no, it's the > motion of the "sources" ocean. Did it produce rough seas full of > spaghetti monsters? Or tranquil fjords worth pining over (sadly to > death apparently?)? In my experience, the GUI builder I use creates reasonable code that deals with the GUI in a separate portion of the code. It does not strike me as spaghetti-ish (though it's not perfect). > Also, you MAY have created 964 chars of code with your ten or so > clicks HOWEVER that is just template code. You'll need to set many > attributes for the widgets before they are ready for prime time. Your > "supposed" ten or so click estimate is very naive. It takes MUCH more > to create even a simple GUI, because, we have NOT even discussed logic > yet! Sure. But my point was just that to even get as far as I did (which was just a frame and two unspecified widgets) takes 964+ keystrokes, but only ~10 clicks. So the pacing of keystrokes:clicks is favorable. If I built a small functioning GUI application, it might take 100 clicks and 9,640 keystrokes (very roughly). But it is the same point. > > I would use a sketch-pad and pencil and *then* use the GUI builder. > > But do you really? Your following statements lead me to believe that > you don't. > > > What's nice about a builder is one can move things around > > quickly and see the results in the real application, which > > one can never really see well on a paper sketch.? I just meant that though I might start on paper, once it is on the screen I sometimes will shift things around a bit at that point to see how it looks. This is easily done with sizers and a sizer collection manager and an up/down arrow, so it is worth an extra minute to just see how it looks. > ?1. GUI builders remove us from the initial "mental design phase" and > temp us to let our inner "click-ity-click" and "drag-ity-drag" child > loose. This inner child likes to play but he hates to plan. Very soon > he has the play room floor (source code) overflowing with toys (code) > arranged in a completely haphazard way. Unlike the child however, > there is no code mommy to spank this bad little boy when he is a > programmer. So he just keeps messing up play room after play room > making a complete fool of himself along the way. > > ?2. GUI builders remove us from the source code. When you are playing > "clicky-click" with yourself you could be in the trenches fighting the > spaghetti code monster. Instead you are losing mental focus. Remember, > playing with yourself makes you lazy! I've certainly heard of others who feel that working with only code is "cleaner" for them, mentally speaking. I can understand that. I think it just depends on what one is used to. I don't find the GUI builder disrupts my ability to plan or keep things orderly. In fact, most of my disorder and spaghetti problems have been in the logic side of the applications, the part which the GUI builder doesn't have anything to do with. (That's my own issue to keep working on). > Kevin made the argument earlier that Tkinter (and others) are so easy > to use that they render needing a GUI builder useless -- and he is > correct! But did you know that there are GUI libraries EVEN more > highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and > using my imagination is so difficult" *crap* is really making me > laugh. My attitude is, if I could speak in English to an AI to tell it what I'd like the program to do, I'd do it. Yes, since I can't do that, I inevitably do sometimes enjoy puzzling things out, but only because I have to. > PS: if you don't like to type, programming IS NOT the best career (or > hobby) choice for you. I guess it is not so much that I dislike typing, as I dislike having to switch from visual mode to code mode, remember the keywords and such for the widgets, rather than quickly clicking around. The keystroke count is really just a proxy for that sort of effort. CM From steve+comp.lang.python at pearwood.info Tue Jul 12 20:44:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 10:44:54 +1000 Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: <4e1cea87$0$29974$c3e8da3$5496439d@news.astraweb.com> Gnarlodious wrote: > Question. Is there a special method or easy way to set default values > with each call to an instance? Any ideas to make it easier? What I > want to do is have a constantly updating set of values which can be > overridden. Just thought there was an easy way to set that up. All the words are in English, but the sentences make no sense :) Seriously, I don't understand what you mean. "Call to an instance"? Do mean treating instances as a callable (like a function), or do you mean calling an arbitrary method? To make an instance itself callable, define a __call__ method. What do you mean, "constantly updating set of values that can be overridden"? Perhaps a simple example might help. The closest thing I can think of, might be: you want to store a data attribute in an instance, and use that if the caller doesn't specify differently. Something like: class Parrot: name = "Polly" def speak(self, name=None): if name is None: name = self.name print("%s wants a cracker!" % name) And in use: >>> p = Parrot() >>> p.speak() Polly wants a cracker! >>> p.speak("Peter") Peter wants a cracker! >>> p.name = "Penelope" >>> p.speak() Penelope wants a cracker! If None is a legitimate value, then you can define your own sentinel to use instead: MISSING = object() # Unique object guaranteed not to be used by the caller. # (Guarantee void on planet Earth.) then replace None by MISSING in the code above. Is this the sort of scenario you are talking about? If not, I'm completely lost. -- Steven From jimmy at retzlaff.com Tue Jul 12 20:51:23 2011 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 12 Jul 2011 17:51:23 -0700 Subject: mrjob v0.2.7 released Message-ID: What is mrjob? ----------------- mrjob is a Python package that helps you write and run Hadoop Streaming jobs. mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which allows you to buy time on a Hadoop cluster on an hourly basis. It also works with your own Hadoop cluster. Some important features: * Run jobs on EMR, your own Hadoop cluster, or locally (for testing). * Write multi-step jobs (one map-reduce step feeds into the next) * Duplicate your production environment inside Hadoop * Upload your source tree and put it in your job's $PYTHONPATH * Run make and other setup scripts * Set environment variables (e.g. $TZ) * Easily install python packages from tarballs (EMR only) * Setup handled transparently by mrjob.conf config file * Automatically interpret error logs from EMR * SSH tunnel to hadoop job tracker on EMR * Minimal setup * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY * To run on your Hadoop cluster, install simplejson and make sure $HADOOP_HOME is set. More info: * Install mrjob: python setup.py install * Documentation: http://packages.python.org/mrjob/ * PyPI: http://pypi.python.org/pypi/mrjob * Development is hosted at github: http://github.com/Yelp/mrjob What's new? ------------- Big thank you to Yelp intern Steve Johnson, who wrote the majority of the code for this release. Wahbeh Qardaji, another Yelp intern, contributed as well, and has been working hard on features for v0.3.0. v0.2.7, 2011-07-12 -- Hooray for interns! * All runner options can be set from the command line (Issue #121) * Including for mrjob.tools.emr.create_job_flow (Issue #142) * New EMR options: * availability_zone (Issue #72) * bootstrap_actions (Issue #69) * enable_emr_debugging (Issue #133) * Read counters from EMR log files (Issue #134) * Clean old files out of S3 with mrjob.tools.emr.s3_tmpwatch (Issue #9) * EMR parses and reports job failure due to steps timing out (Issue #15) * EMR boostrap files are no longer made public on S3 (Issue #70) * mrjob.tools.emr.terminate_idle_job_flows handles custom hadoop streaming jars correctly (Issue #116) * LocalMRJobRunner separates out counters by step (Issue #28) * bootstrap_python_packages works regardless of tarball name (Issue #49) * mrjob always creates temp buckets in the correct AWS region (Issue #64) * Catch abuse of __main__ in jobs (Issue #78) * Added mr_travelling_salesman example -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Jul 12 21:02:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 11:02:12 +1000 Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! [...] I wouldn't know a good song parody if it kicked me in the head, but my wife is a (retired) professional musician with a history of writing parodies. She's not impressed by the work of most "filk singers" and supposed parodies, most of which are seventeen kinds of crap... but she gives you full marks. And trust me on this, she does not give compliments lightly. She says you got the rhyming scheme and number of syllables spot on. Technically, "That modeling and sim guy" needs to be slurred to make it fit, "That mod'ling and sim guy", but that's acceptable. (Most parodies get the syllable count wrong -- if a lyric goes dum-de-dum-de-dum, the parody ends up like dum-dum-de-dum-de-dum or dum-de-dum-de.) Have a +1 from me and the missus. -- Steven From greg.ewing at canterbury.ac.nz Tue Jul 12 21:47:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jul 2011 13:47:34 +1200 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <4E1CF936.4050902@canterbury.ac.nz> Xah Lee wrote: > they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. Since 2.5 or so, Python has a built-in set type that provides these (which is arguably a better place for them than lists). -- Greg From roy at panix.com Tue Jul 12 21:58:45 2011 From: roy at panix.com (Roy Smith) Date: Tue, 12 Jul 2011 21:58:45 -0400 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <4E1CF936.4050902@canterbury.ac.nz> Message-ID: In article <4E1CF936.4050902 at canterbury.ac.nz>, Gregory Ewing wrote: > Xah Lee wrote: > > they > > don't provide even simple list manipulation functions such as union, > > intersection, and the like. Not in perl, not in python, not in lisps. > > Since 2.5 or so, Python has a built-in set type that > provides these (which is arguably a better place for them > than lists). Set is the best addition to Python since string methods. From gnarlodious at gmail.com Tue Jul 12 22:01:50 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 19:01:50 -0700 (PDT) Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <4e1cea87$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3ab3cab1-fdab-414d-95e4-d5e55b2fcab0@v7g2000vbk.googlegroups.com> On Jul 12, 6:44?pm, Steven D'Aprano wrote: > All the words are in English, but the sentences make no sense :) LOL, impressive powers of mind-reading! Exactly what I needed: import time class Event: epoch=time.time() def doSomething(self, epoch=None): if epoch is None: epoch = self.epoch print(epoch) e = Event() e.doSomething() e.doSomething(123456789) e.epoch = 1310522110.404471 e.doSomething() Thanks for the help! -- Gnarlie http://Gnarlodious.com From ccassie58 at gmail.com Tue Jul 12 22:59:01 2011 From: ccassie58 at gmail.com (goodseller) Date: Tue, 12 Jul 2011 19:59:01 -0700 (PDT) Subject: A pair of comfortable basketball shoes can not only provide you great Message-ID: <518f60c6-51f5-474c-8dca-0fa852503b80@p10g2000prf.googlegroups.com> As we all know, the basketball game needs all the players pay much attention to the protection. The players, not only the profession players but also the basketball amour, needs to take lots measure to protect themselves. Basketball game is a fierce game on the playing court. Playing basketball,http:// www.cheap- nbabasketballshoes.com/ you need to run quickly, jump and stop suddenly. Not only the wrist cuff, but also the leg cuff is also necessary on the playing court. Protection is your first step to play basketball game. Well, the second should be your suitable basketball shoes. A pair of comfortable basketball shoes can not only provide you great support on the playing court, but also can protect your feet. The basketball shoes are divided into three http://www.cheap-nbabasketballshoes.com/tops ? low top, mid top and high top. The different top can be used for different place on the playing court. For example, the low top is used for the guard, who need to run much. The high top may avoid you running quickly, but they play an important role in protecting your ankle. You shouldn?t ignore the shoes on the playing court. From rosuav at gmail.com Wed Jul 13 00:20:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 14:20:42 +1000 Subject: Enhanced dir() function In-Reply-To: <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 7:46 AM, rantingrick wrote: >>>> [x for x in dir([]) if not x.startswith('_')] > ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', > 'reverse', 'sort'] > > Because we have plenty of room for args in this function... > >>>> dir(verbose=False) > ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', > 'reverse', 'sort'] > #define my_dir(o,verbose) verbose?dir(o):[x for x in dir(o) if not x.startswith('_')] And there you are, out of your difficulty at once. Granted, you now have to run your code through cpp, but is that so big a problem? ChrisA (For the sarcasm-impaired: I am NOT advocating this.) From tjreedy at udel.edu Wed Jul 13 00:39:10 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 00:39:10 -0400 Subject: Lisp refactoring puzzle In-Reply-To: <201107121423.39951.gheskett@wdtv.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: On 7/12/2011 2:23 PM, gene heskett wrote: > Now, I hate to mention it Terry, but your clock seems to be about 126 > months behind the rest of the world. Please do not hate to be helpful. It was a bad malfunction perhaps due to a run-down battery on a machine turned off for two weeks. I will keep watch to see if it happens again overnight. > Does your system not run ntpd by default? Is that *nix or Windows? My XP system only checks the net time automatically once a week and refused to update at first on request because the dates did not match. Typically windows stupidity. If I click 'Update from internet', it should believe that I really mean it. -- Terry Jan Reedy From rustompmody at gmail.com Wed Jul 13 01:10:14 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 12 Jul 2011 22:10:14 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: <7f92caef-9a98-4eb5-bae9-6568178bf4de@m6g2000prh.googlegroups.com> On Jul 13, 9:39?am, Terry Reedy wrote: > On 7/12/2011 2:23 PM, gene heskett wrote: > > > Now, I hate to mention it Terry, but your clock seems to be about 126 > > months behind the rest of the world. > > Please do not hate to be helpful. Ha Ha. Cute one. Thanks From wuwei23 at gmail.com Wed Jul 13 01:48:34 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 12 Jul 2011 22:48:34 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: <95ddb38a-ef54-41aa-a3bf-f7220d9a2be8@t8g2000prm.googlegroups.com> rantingrick wrote: > i cannot force others If only you really understood that. From wuwei23 at gmail.com Wed Jul 13 02:26:30 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 12 Jul 2011 23:26:30 -0700 (PDT) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> Thomas Jollans wrote: > Coincidentally, Guido wrote this blog post just last week, without which > I'd be just as much at a loss as you: > > http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an... It's also part of the Python FAQ: http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements From caleb.hattingh at gmail.com Wed Jul 13 02:29:09 2011 From: caleb.hattingh at gmail.com (cjrh) Date: Tue, 12 Jul 2011 23:29:09 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? In-Reply-To: <9c887bcb-e25f-4974-9fbe-c39a5f042a26@l18g2000yql.googlegroups.com> Message-ID: You can just extract the windows pypy 1.5 distribution to any folder and run "pypy.exe" from there as if it was called "python.exe". This is how I have been using it. In fact, pypy has been the default python for my portable eclipse for a good while now. From bahamutzero8825 at gmail.com Wed Jul 13 02:54:54 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 01:54:54 -0500 Subject: Code hosting services Message-ID: <4E1D413E.7080002@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 I know this isn't specific to Python, but it is somewhat on topic. Way back when I had a simple project, SourceForge was by far the most prominent place to host (and it still is, though to a lesser extent now). SourceForge is still an option for me, but I know there are many other hosts out there. The problem is I don't which one what the pros and cons of each are. Wikipedia has some information, but it's generally objective. This is useful, but it's not enough to narrow my choices down to one or two. What can you guys recommend? BTW, I'll likely be sticking with Mercurial for revision control. TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse working well. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHUE+AAoJEPiOA0Bgp4/LvRUIAOX4XcC2+am9uFzBH9BpYh4l epHZptB3qrNd0QV+TWXuOG6V6tOESsoQaECZYplykzD5/fxsuSgisv62mAEY+afw gqJbsVka1XuWJQTUYBVFcA5ytL3v07SYcQ1m9EsAkgBejRD7nuXuWBB2bNUcPhMY s3IfyVFZ82utxEnbWxGo6mK4NPXnhMXdJgLbDPzg3Xg2KjI29eJLHQsKv1GjnWJC 5tYxNpVqPaeYNzGxjWtwCuDxzGuGnpWWYhSx8dUhgQbZKlR9SGhfcs9onsIroM2j z9B8cuaQe8GxbU0vneMtiLGJt8+hsCpuFTAIrMTn6AGeK7He06LXYU49skg6Bxw= =5uDV -----END PGP SIGNATURE----- From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Jul 13 03:09:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 13 Jul 2011 09:09:57 +0200 Subject: Code hosting services In-Reply-To: References: Message-ID: Am 13.07.2011 08:54 schrieb Andrew Berg: > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. In this case, I would recommend bitbucket. Thomas From thorsten at thorstenkampe.de Wed Jul 13 03:36:39 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 09:36:39 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400) > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > > My immediate response is: it allows us to fit statements into one > > line. e.g. > > if a == 1: print a > > > You're confusing the colon with the semi-colon. If you want two > statements on the same line, you use a semi-colon. He's not confusing anything at all. His example made it pretty clear that he didn't mean "two statements" but "multiline statemements". Thorsten From benjokal at gmail.com Wed Jul 13 04:01:43 2011 From: benjokal at gmail.com (Benji Benjokal) Date: Wed, 13 Jul 2011 04:01:43 -0400 Subject: How do you get the value you entered using the Entry widget in Tkinter? Message-ID: What is the simplist way to get the value you entered from the Entry widget in Tkinter? Thanks Benji -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Wed Jul 13 04:08:53 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 10:08:53 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) > Basically, it looks better, and is more readable. People tend to overlook the colon for the same reason they tend to forget to set the colon in the first place: a) it's a very weak marker in comparison to indentation and b) it looks like doubling the markup to them (colon plus indentation) What makes the if syntax for me even more weird, is the fact that you can have an else clause with an else without a then clause with a then. if x > 5: print whatever else: print whatever in comparison to: if x > 5 then print whatever else print whatever > A colon, in English like in Python, means that something follows that > is related to what was before the colon. So the colon makes it > abundantly clear to the human reader that a block follows, The block that follows makes it abundantly clear to the human reader that a block follows. > and that that block is to be considered in relation to what was just > said, before the colon. The indentation makes it abundantly clear to the human reader that that indented block is to be considered in relation to what was just said, before the indentation. Thorsten From tlikonen at iki.fi Wed Jul 13 04:29:58 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 13 Jul 2011 11:29:58 +0300 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <87mxgilh15.fsf@mithlond.arda> * 2001-01-01T14:11:11-05:00 * Terry Reedy wrote: > As a side note, the same principle of expressions matching operations > in symmetry suggest that majority of up are quite sensible and not > dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a > function call, the function has a different role than the arguments, > so it is appropriate that it have a different role in the expression. Please don't forget that the whole point of Lisps' (f x) syntax is that code is also Lisp data. It's not just a function call with arguments. First, it's literal data (two linked cons cells and symbols) and then the Lisp evaluating model makes it a function call in certain situations. Lisp is CL-USER> (let ((lisp (cons 'programmable nil))) (setf (rest lisp) lisp)) #1=(PROGRAMMABLE . #1#) programming language and it's totally irrelevant and pointless to say "which syntax someone prefers" because this feature (code being data) is very fundamental principle of the language. You know, it's easy to write programs that write programs. If we remove this feature (i.e., don't talk about Lisp at all) then it's perhaps relevant to discuss about such choices in syntax. You wouldn't want Python arrays have a read and print format "a[b, c]", that is, the first item of the array printed outside []'s. It would be silly. From gheskett at wdtv.com Wed Jul 13 05:46:32 2011 From: gheskett at wdtv.com (gene heskett) Date: Wed, 13 Jul 2011 05:46:32 -0400 Subject: Lisp refactoring puzzle In-Reply-To: References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: <201107130546.32114.gheskett@wdtv.com> On Wednesday, July 13, 2011 05:34:23 AM Terry Reedy did opine: > On 7/12/2011 2:23 PM, gene heskett wrote: > > Now, I hate to mention it Terry, but your clock seems to be about 126 > > months behind the rest of the world. > > Please do not hate to be helpful. It was a bad malfunction perhaps due > to a run-down battery on a machine turned off for two weeks. I will keep > watch to see if it happens again overnight. > > > Does your system not run ntpd by default? > > Is that *nix or Windows? That's a *nix name. I have no clue what winderz might call it as I've only ever had one winderz machine here. My laptop had a copy of XP on it when I bought it years ago, shrunk it to 10Gb and let it live for about 6 months, but its had several fedora's, 2 different MDV installs, and now PCLos on it after discovering the windows bcm4318 driver was a bigger POS than the current linux driver. Everything else here is either 25 years old & running nitros9, or some flavor of *buntu LTS. IOW, all my windows are glass. ;-) > My XP system only checks the net time > automatically once a week and refused to update at first on request > because the dates did not match. Typically windows stupidity. If I click > 'Update from internet', it should believe that I really mean it. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Swap read error. You lose your mind. From cs at zip.com.au Wed Jul 13 05:59:17 2011 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 13 Jul 2011 19:59:17 +1000 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <20110713095917.GA8232@cskk.homeip.net> On 13Jul2011 01:54, Andrew Berg wrote: | I know this isn't specific to Python, but it is somewhat on topic. Way | back when I had a simple project, SourceForge was by far the most | prominent place to host (and it still is, though to a lesser extent | now). SourceForge is still an option for me, but I know there are many | other hosts out there. The problem is I don't which one what the pros | and cons of each are. Wikipedia has some information, but it's generally | objective. This is useful, but it's not enough to narrow my choices down | to one or two. What can you guys recommend? | | BTW, I'll likely be sticking with Mercurial for revision control. | TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse | working well. I'm using bitbucket and liking it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If not for the one-percent inspiration, that would have just been a lot of sweat. - overhead by WIRED at the Intelligent Printing conference Oct2006 From t at jollybox.de Wed Jul 13 06:05:14 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:05:14 +0200 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <4E1D6DDA.5040808@jollybox.de> On 07/13/2011 08:54 AM, Andrew Berg wrote: > I know this isn't specific to Python, but it is somewhat on topic. Way > back when I had a simple project, SourceForge was by far the most > prominent place to host (and it still is, though to a lesser extent > now). SourceForge is still an option for me, but I know there are many > other hosts out there. The problem is I don't which one what the pros > and cons of each are. Wikipedia has some information, but it's generally > objective. This is useful, but it's not enough to narrow my choices down > to one or two. What can you guys recommend? > > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. GitHub is massively popular, and a great service. It's based on git (not mercurial), and is centred around the source repository, and has bug tracking, wiki, downloads, everything you'll need. What makes GitHub special (and popular) is the social aspect, allowing you to follow people, with great management of forks ? real distributed (git is a distributed VCS after all) collaboration. One of GitHub's great features is, in a way, the huge community ? kind of a self-fulfilling prophecy. Bitbucket, which Mr Rachel mentioned, is essentially a not-quite-as-good clone of GitHub, just using Mercurial. Don't get me wrong, it's a good product, and may be exactly what you want, but it is a clone, and it doesn't have the community GitHub has. Google Code is more SourceForge-style in that it focuses more on having the landing page linking downloads, not focusing so much on the code repository. It supports Mercurial repositories, as far as I know. I don't have much experience with it. All the standard features. There are a load of older sites, SourceForge, Savannah, Gna!, etc etc etc, but they don't support VCS other than CVS/Svn for the most part. From bahamutzero8825 at gmail.com Wed Jul 13 06:23:20 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 05:23:20 -0500 Subject: Code hosting services In-Reply-To: <4E1D6DDA.5040808@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> Message-ID: <4E1D7218.9010108@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.13 05:05 AM, Thomas Jollans wrote: > There are a load of older sites, SourceForge, Savannah, Gna!, etc > etc etc, but they don't support VCS other than CVS/Svn for the most > part. Many do support Mercurial. In fact, I have a Mercurial repo for one of my projects on SourceForge (Bazaar and Mercurial are available as extra features that have to be explicitly enabled). Google Code and Savannah support Mercurial (at least according to Wikipedia; I haven't set up a project on either). - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHXIYAAoJEPiOA0Bgp4/L+yYIAKaHlDF1Sx2yoxo6wENy5kVf QEvtf4cbHaFP+ORBDDhCdWxiQO6jzlrryphrv5BhZ1B2CqXmkFaMzhj7HIErG4i+ NI27+RPtQno3iOTtnOBxsAdGkQzoNG8PDb4qSxxUlzM8iApIGSotEuLrKJGzZrP0 /IFPw83X2sAwaRZGOxPIzMuN7MrUnvCpcNfq5tTqgBgBF5rvNaV8vb/zmFxw2gkh r0Df5Cik2MsaHAj0mHY4Ypusprwi9ClIpL21xuNbefdtJJyPbrnRGxW03yvExJjg OHmUtrFxxBvj8IYWAOjQr/Q76uPaHTX/oV2xEkigMjvhxaiWMjjO4HqJFE+ghR8= =AtfH -----END PGP SIGNATURE----- From awilliam at whitemice.org Wed Jul 13 06:23:32 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 13 Jul 2011 06:23:32 -0400 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <1310552613.7271.1.camel@linux-yu4c.site> On Wed, 2011-07-13 at 01:54 -0500, Andrew Berg wrote: > I know this isn't specific to Python, but it is somewhat on topic. Way > back when I had a simple project, SourceForge was by far the most > prominent place to host (and it still is, though to a lesser extent > now). SourceForge is still an option for me, but I know there are many > other hosts out there. The problem is I don't which one what the pros > and cons of each are. Wikipedia has some information, but it's generally > objective. This is useful, but it's not enough to narrow my choices down > to one or two. What can you guys recommend? SourceForge; it is a comprehensive platform [in addition to being an Open Source platform: Allura]. It is a much improved platform over several years ago. > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. I use Hg on SF, it works very well. From shankaraman.r at gmail.com Wed Jul 13 06:31:07 2011 From: shankaraman.r at gmail.com (Shankar Raman) Date: Wed, 13 Jul 2011 16:01:07 +0530 Subject: Python Contribution Message-ID: Hello everyone, My name is Shankarraman and I have been working with Python for past 5 months.I find it really interesting and cool and would like to know different ways I can contribute to it. Though I went through the bug lists, I was wondering if I could contribute to Python in other ways. -- Namashivaya, R.Shankarraman, Computer Science and Engineering, Amrita School of Engineering. -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Jul 13 06:34:28 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:34:28 +0200 Subject: Code hosting services In-Reply-To: <4E1D7218.9010108@gmail.com> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> Message-ID: <4E1D74B4.9030803@jollybox.de> On 07/13/2011 12:23 PM, Andrew Berg wrote: > On 2011.07.13 05:05 AM, Thomas Jollans wrote: >> There are a load of older sites, SourceForge, Savannah, Gna!, etc >> etc etc, but they don't support VCS other than CVS/Svn for the most >> part. > Many do support Mercurial. In fact, I have a Mercurial repo for one of > my projects on SourceForge (Bazaar and Mercurial are available as extra > features that have to be explicitly enabled). Google Code and Savannah > support Mercurial (at least according to Wikipedia; I haven't set up a > project on either). > Okay, fair enough. Question is, does it integrate with the bug tracker? It does for Google Plus. In the olden days when Mercurial was young, Savannah, IIRC, bolted on Mercurial hosting that didn't do any of the usual integration. Half the point of getting VCS hosting and bug tracking from the same service is being able to do "closes #4" in a commit. From anthony.hw.kong at gmail.com Wed Jul 13 06:40:40 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 20:40:40 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: Thanks, mate! I was writing that up really late at night. Somehow I changed term to semi-colon half way through, Cheers On Wed, Jul 13, 2011 at 5:36 PM, Thorsten Kampe wrote: > * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400) > > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > > > My immediate response is: it allows us to fit statements into one > > > line. e.g. > > > if a == 1: print a > > > > > You're confusing the colon with the semi-colon. If you want two > > statements on the same line, you use a semi-colon. > > He's not confusing anything at all. His example made it pretty clear > that he didn't mean "two statements" but "multiline statemements". > > Thorsten > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Jul 13 06:40:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:40:58 +0200 Subject: Code hosting services In-Reply-To: <4E1D74B4.9030803@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> <4E1D74B4.9030803@jollybox.de> Message-ID: <4E1D763A.9050103@jollybox.de> On 07/13/2011 12:34 PM, Thomas Jollans wrote: > It does for Google Plus. Code. Code, not plus. Not concentrating. Argh. From anthony.hw.kong at gmail.com Wed Jul 13 06:59:09 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 20:59:09 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? Message-ID: Hi, all, If you have read my previous posts to the group, you probably have some idea why I asked this question. I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. I think I will go through the following items: - itertools module - functools module - concept of currying ('partial') I would therefore want to ask your input e.g. - Is there any good example to illustrate the concept? - What is the most important features you think I should cover? - What will happen if you overdo it? Cheers -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed Jul 13 06:59:56 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 05:59:56 -0500 Subject: Code hosting services In-Reply-To: <4E1D74B4.9030803@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> <4E1D74B4.9030803@jollybox.de> Message-ID: <4E1D7AAC.2070302@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.13 05:34 AM, Thomas Jollans wrote: > Okay, fair enough. Question is, does it integrate with the bug > tracker? It does for Google Plus. In the olden days when Mercurial > was young, Savannah, IIRC, bolted on Mercurial hosting that didn't do > any of the usual integration. I don't know about SF. There's nothing special that happens during a commit, but I suppose it's possible that SF will recognize a word like "issue" or "bug" and automatically provide a link to the issue number referenced on its native bug tracker (or maybe even to an issue on Trac). I'm pretty new to this whole thing; my simple project from ages ago didn't use a bug tracker or a VCS. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHXqsAAoJEPiOA0Bgp4/LlpoH+wXxAPB57UOWa+ewDTw3MTUQ q1IiUJvWyyX8+NcYZ7oTMrnHjpPG0povnAq32HckzlCcyz+5YSRCKCgdvebcSSaQ BuGTrNQmwN+eiZFN5CJN9P2m8t2M2bdpEBeQoD01iezMrs5nDMTtgrlkDflV8B5J oynrN1uRzKVsy5Gb4carRGMza3vV+K8Tq8LVFDf+CPC7Sh20BwWxUXWikWCK8dOp fsEzBppkaHU9Po2N/nDTeszvDd+ZHqchNIG4lEo5ekY5yyKRjyN47LJHDTPRDNVy dG92kGjaumMLhHIyItlj5w7GpM7GbpQokbDKSEyK0kohEqPNyOKh49pLiQf8t9o= =LBnZ -----END PGP SIGNATURE----- From steve+comp.lang.python at pearwood.info Wed Jul 13 07:07:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 21:07:17 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Thorsten Kampe wrote: > * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) >> Basically, it looks better, and is more readable. > > People tend to overlook the colon for the same reason they tend to > forget to set the colon in the first place: > a) it's a very weak marker in comparison to indentation and > b) it looks like doubling the markup to them (colon plus indentation) I can't speak for others, but speaking for myself, I wonder whether this is a difference between English speakers and non-English speakers? To me, as a native English speaker, leaving the colon out of a header line, as follows below, just looks wrong. Nobody expects the Spanish Inquisition! Our three weapons are * fear * surprise * and ruthless efficiency * and an almost fanatical devotion to the Pope! Although the bullet list is indented, the header line "Our three weapons are" looks like something is missing, as if I had started to write something and forgotten to finish. It needs a colon to be complete: Nobody expects the Spanish Inquisition! Amongst our weapons are: * fear * surprise * ruthless efficiency * an almost fanatical devotion to the Pope * and nice red uniforms The colon indicates that the sentence has more to follow: I think of it as a pointer. It doesn't finish the thought, like a full stop, nor is it a mere pause, like a comma or semi-colon. An indented block on its own is surprising. It just hangs there, with no connection to what was going on before. Why is it indented? Is it connected to the previous sentence? On the other hand, a colon gives the reader that connection: It gives the reader a clue to expect additional information, that the indented block that follows is not an independent block, floating in space for its own reasons, but is intimately linked to the previous line. I know that Python is not English, and not all English conventions apply. For example, Python uses newlines to end "sentences" (lines of code) instead of a full stop. Nevertheless, as an English reader, it would look wrong and awkward to drop the colon. >> A colon, in English like in Python, means that something follows that >> is related to what was before the colon. So the colon makes it >> abundantly clear to the human reader that a block follows, > > The block that follows makes it abundantly clear to the human reader > that a block follows. But it's too late by then. You have to mentally backtrack. blah blah blah blah indented block blah blah blah blah colon indented block -- Steven From thorsten at thorstenkampe.de Wed Jul 13 07:26:21 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 13:26:21 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (Wed, 13 Jul 2011 21:07:17 +1000) > Thorsten Kampe wrote: > > * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) > >> Basically, it looks better, and is more readable. > > > > People tend to overlook the colon for the same reason they tend to > > forget to set the colon in the first place: > > a) it's a very weak marker in comparison to indentation and > > b) it looks like doubling the markup to them (colon plus indentation) > > I can't speak for others, but speaking for myself, I wonder whether this is > a difference between English speakers and non-English speakers? It's not a difference between English and non-English speakers but the difference between a branch (if-then-else) and an enumeration (your example). > To me, as a native English speaker, leaving the colon out of a header > line, as follows below, just looks wrong. > [enumeration] > > Although the bullet list is indented, the header line "Our three weapons > are" looks like something is missing, as if I had started to write > something and forgotten to finish. It needs a colon to be complete: Sure, because it's an enumeration - and not a branch or loop. > An indented block on its own is surprising. It just hangs there, > with no connection to what was going on before. Why is it indented? > Is it connected to the previous sentence? In normal text: sure. You cannot "just indent" in Python as you like. Indentation always shows the connection. > >> A colon, in English like in Python, means that something follows > >> that is related to what was before the colon. So the colon makes it > >> abundantly clear to the human reader that a block follows, > > > > The block that follows makes it abundantly clear to the human reader > > that a block follows. > > But it's too late by then. You have to mentally backtrack. > > blah blah blah blah > indented block > > blah blah blah blah colon > indented block Source code is (unlike normal text) not read line by line. So you (at least I) don't have to backtrack from line 2 to line 1 because you see them both at the same time. Thorsten From rosuav at gmail.com Wed Jul 13 07:58:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 21:58:19 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 13, 2011 at 9:07 PM, Steven D'Aprano wrote: > The colon indicates that the sentence has more to follow: I think of it as a > pointer. It doesn't finish the thought, like a full stop, nor is it a mere > pause, like a comma or semi-colon. > > ? ?An indented block on its own is surprising. It just hangs there, > ? ?with no connection to what was going on before. Why is it indented? > ? ?Is it connected to the previous sentence? It's not necessarily surprising, depending on context; the brain automatically assumes that the indented block was originally said by someone else. The
tag defines a long quotation. A browser inserts white space before and after a blockquote element. It also insert margins for the blockquote element. http://www.w3schools.com/tags/tag_blockquote.asp (I didn't need to quote that, I just wanted to go meta and block quote something about blockquote.) Having the colon makes it clear that the content is part of the same general thought (paragraph or sentence). Chris Angelico From python.list at tim.thechases.com Wed Jul 13 08:16:07 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Jul 2011 07:16:07 -0500 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E1D8C87.4080301@tim.thechases.com> On 07/13/2011 06:26 AM, Thorsten Kampe wrote: > Source code is (unlike normal text) not read line by line. So > you (at least I) don't have to backtrack from line 2 to line 1 > because you see them both at the same time. $a You mean there are people who don't use "ed" to write their code? ;-) -tkc . w q From anthony.hw.kong at gmail.com Wed Jul 13 08:39:16 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 05:39:16 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? Message-ID: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) Hi, all, If you have read my previous posts to the group, you probably have some idea why I asked this question. I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. I think I will go through the following items: itertools module functools module concept of currying ('partial') I would therefore want to ask your input e.g. Is there any good example to illustrate the concept? What is the most important features you think I should cover? What will happen if you overdo it? Cheers From bruno.desthuilliers at gmail.com Wed Jul 13 08:46:14 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 13 Jul 2011 05:46:14 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Jul 12, 6:40?pm, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. Brillant. This deserves to become a cpython easter egg along with import this or from __future__ import braces. From rosuav at gmail.com Wed Jul 13 08:53:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 22:53:55 +1000 Subject: "Python Wizard," with apologies to The Who In-Reply-To: References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilliers at gmail.com wrote: > On Jul 12, 6:40?pm, John Keisling wrote: >> After too much time coding Python scripts and reading Mark Lutz's >> Python books, I was inspired to write the following lyrics. > > Brillant. This deserves to become a cpython easter egg along with > import this or from __future__ import braces. Propose: from eastereggs import wizard ChrisA From invalid at invalid.invalid Wed Jul 13 09:03:22 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jul 2011 13:03:22 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-13, Thorsten Kampe wrote: >> and that that block is to be considered in relation to what was just >> said, before the colon. > > The indentation makes it abundantly clear to the human reader that > that indented block is to be considered in relation to what was just > said, before the indentation. You would think so, but human readers like redundancy. Most natural human languages have plenty of redundancy. For example in English when speaking of multiple subjects one not only uses a plural noun or pronoun (e.g. "they" rather than "him"), but one also uses a plural verb ("run" rather than "runs") even though the plural noun alone should make it abundantly clear to the human reader than we're talking about more than one person. The same holds true for objective and subjective case: the position of the noun in the sentence makes it abundantly clear whether the noun is an object or a subject, yet we still often have two cases (it's "I run" rather than "Me run"). -- Grant Edwards grant.b.edwards Yow! I'm having an at EMOTIONAL OUTBURST!! But, gmail.com uh, WHY is there a WAFFLE in my PAJAMA POCKET?? From rosuav at gmail.com Wed Jul 13 09:11:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 23:11:41 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 11:03 PM, Grant Edwards wrote: > You would think so, but human readers like redundancy. > One of the benefits of redundancy is error-trapping. If you see a list of numbers like this: 40 14 24 56 48 12 60 16 ===== 269 then you know the result can't be right, because they're all even numbers and the total isn't. The redundancy of having both the string of numbers and the total adds only a small amount to the transmission requirement, but it adds a lot to the reliability of transfer. ChrisA From invalid at invalid.invalid Wed Jul 13 09:18:30 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jul 2011 13:18:30 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-07-13, Steven D'Aprano wrote: > Thorsten Kampe wrote: > >> * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) >>> Basically, it looks better, and is more readable. >> >> People tend to overlook the colon for the same reason they tend to >> forget to set the colon in the first place: >> a) it's a very weak marker in comparison to indentation and >> b) it looks like doubling the markup to them (colon plus indentation) > > I can't speak for others, but speaking for myself, I wonder whether this is > a difference between English speakers and non-English speakers? To me, as a > native English speaker, leaving the colon out of a header line, as follows > below, just looks wrong. > > Nobody expects the Spanish Inquisition! > Our three weapons are > * fear > * surprise > * and ruthless efficiency > * and an almost fanatical devotion to the Pope! Except that's wrong English[1]. At least that's not correct usage according to what I learned in school. A colon follows an independent clause: something that could in essence be a complete sentence and expresses a complete thought. The colon separates that independent clause from examples or an explanation or clarification of that independent clause. The phrase "Our three weapons are" isn't an independent clause. It has the transitive verb "are" but no predicate nominative. You've placed the colon in the middle of an independent clause between the verb "are" and the predicate nominative phrase "fear, surprise, and ruthless efficiency, and an almost fanatical devotion to the Pope". Your example should be something like this [accurace of the quotation aside]: The Spanish Inquisition has three main weapons: fear, surprise, ruthless efficiency, and an almost fanatical devotion to the Pope! > Although the bullet list is indented, the header line "Our three weapons > are" looks like something is missing, Something is missing. It's not a complete independent clause. > as if I had started to write something and forgotten to finish. Except a colon doesn't "complete" an independent clause that's otherwise incomplete. > It needs a colon to be complete: > > Nobody expects the Spanish Inquisition! Now, that usage is correct. > The colon indicates that the sentence has more to follow: I think of > it as a pointer. That is correct also. > On the other hand, a colon gives the reader that connection: > > It gives the reader a clue to expect additional information, > that the indented block that follows is not an independent > block, floating in space for its own reasons, but is intimately > linked to the previous line. Yup. [1] Since all posts criticising grammar or spelling will have an above average number of grammar and spelling errors, I thought I'd get a head start on it. -- Grant Edwards grant.b.edwards Yow! I'm ZIPPY the PINHEAD at and I'm totally committed gmail.com to the festive mode. From ramapraba2653 at gmail.com Wed Jul 13 09:24:44 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Wed, 13 Jul 2011 06:24:44 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <67e6e85c-70dc-4830-8f62-56aa4374a003@q34g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gheskett at wdtv.com Wed Jul 13 09:41:14 2011 From: gheskett at wdtv.com (gene heskett) Date: Wed, 13 Jul 2011 09:41:14 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <201107130941.14827.gheskett@wdtv.com> On Wednesday, July 13, 2011 09:38:26 AM Anthony Kong did opine: > (My post did not appear in the mailing list, so this is my second try. > Apology if it ends up posted twice) > Actually, it did, but gmail, in its infinite wisdom, thinks an echo of your post to a mailing list is a duplicate, and deletes it. For this exact reason, I only use gmail for two or 3 of the nearly 40 lists I'm on. [...] Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) He is considered a most graceful speaker who can say nothing in the most words. From vdidenko at Getcollc.com Wed Jul 13 09:42:34 2011 From: vdidenko at Getcollc.com (Vlad Didenko) Date: Wed, 13 Jul 2011 08:42:34 -0500 Subject: sys.tracebacklimit Message-ID: Colleagues, Per documentation at http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit : When [sys.tracebacklimit] set to 0 or less, all traceback information is suppressed and only the exception type and value are printed So, I expect to be able to have a program like: import sys sys.tracebacklimit=0 print(1/0) And see it's result as: ZeroDivisionError: division by zero However, the actual result is: Traceback (most recent call last): File "tbt.py", line 3, in print(1/0) ZeroDivisionError: division by zero Do I misunderstand the docs? Thank you! Vlad ________________________________ This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Wed Jul 13 09:50:42 2011 From: james at agentultra.com (J Kenneth King) Date: Wed, 13 Jul 2011 09:50:42 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <87aaci8f2l.fsf@agentultra.com> Anthony Kong writes: > (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) > > Hi, all, > > If you have read my previous posts to the group, you probably have some idea why I asked this question. > > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? > > > Cheers You might also want to cover gotchas like Python's references. If you have the time I'd introduce weakref too. From anthony.hw.kong at gmail.com Wed Jul 13 10:06:02 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 00:06:02 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <87aaci8f2l.fsf@agentultra.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <87aaci8f2l.fsf@agentultra.com> Message-ID: Hi, James, > > You might also want to cover gotchas like Python's references. > Not sure what it means in the context of functional programming. If you can give some code to demonstrate, it will be great. Cheers -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From justmailnaveen at gmail.com Wed Jul 13 10:06:37 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:06:37 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? Message-ID: Hey guys,i am a python newbie, i just read a qustion on quora where it said that quora quys used pypy (and pylon) to develop quora. So, i want to know what are the core diff btw PyPy and Python ? And they also talked about the lack of type check in python. So, how does it help (strongly typed) in debugging? Thanks From remi.druilhe at orange-ftgroup.com Wed Jul 13 10:19:31 2011 From: remi.druilhe at orange-ftgroup.com (remi.druilhe at orange-ftgroup.com) Date: Wed, 13 Jul 2011 16:19:31 +0200 Subject: Odd caracteres Message-ID: <1310566771.2520.18.camel@g-e6400-55> Hello everyone, I am using a Python script to get data from a BlueTooth device but it seems there is some problem when reading from the interface on Linux. I have a three devices (PowerSpy) that measure energy from an outlet (I plug a computer on a PowerSpy that I plug on an outlet). This device communicates using BlueTooth. So I connect my laptop via BT to get those data (using : sudo rfcomm bind /dev/rfcomm0 powerspy_mac_address). Then, I execute my Python script. This script reads data from /dev/rfcomm0 (with root priviledge). The first data is successfully read. The second and the third too. But the fourth time that I access /dev/rfcomm0, I get some odd caracteres: A I tried to access to this interface using minicom, no problem, I can read easily these data. I changed the computer that was under test, no change. I changed every physical devices by other, no change. That's why, I think I have a problem with my script. Here is the error: Traceback (most recent call last): 4107A6A File "./PowerSpy.py", line 64, in powerspy = PowerSpy("/dev/rfcomm0") File "./PowerSpy.py", line 33, in __init__ u = (struct.unpack('> ards, -- R?mi Druilhe RD-MAPS-GRE OLNC/MAPS/SHINE/MADE Phone: +33 (0)4 76 76 24 27 E-mail : remi.druilhe at orange-ftgroup.com Orange Labs Grenoble - 28 chemin du Vieux Ch?ne - BP98 38243 Meylan Cedex - France -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: orange_logo.gif Type: image/gif Size: 765 bytes Desc: orange_logo.gif URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PowerSpy.py Type: text/x-python Size: 2011 bytes Desc: PowerSpy.py URL: From anthony.hw.kong at gmail.com Wed Jul 13 10:19:35 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 00:19:35 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: One of the main difference is that pypy supports only R-Python, which stands for 'Restricted Python". It is a subset of C-python language. See here for more info: http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#rpython-definition-not Cheers On Thu, Jul 14, 2011 at 12:06 AM, ArrC wrote: > Hey guys,i am a python newbie, > i just read a qustion on quora where it said that quora quys used pypy (and > pylon) to develop quora. > > So, i want to know what are the core diff btw PyPy and Python ? > > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jul 13 10:21:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 00:21:14 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 12:06 AM, ArrC wrote: > So, i want to know what are the core diff btw PyPy and Python ? Python is a language; PyPy is one implementation of that language. The "classic" implementation of Python is CPython, not to be confused with Cython; there are a few others as well. If you talk of "installing Python", it probably means CPython. > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? Sloppy but brief explanation: Python's variables are typeless; its objects are strongly typed. Longer explanation: Every piece of data in Python is an object. Objects can be referenced by names; one object can have more than one name pointing to it. Any name can point to any value, which is somewhat the opposite of "strongly-typed variables" in other languages. For instance: a = "Hello" # a points to or "holds" a string a = 234 # a now points to an integer a = 1.0 # a now points to a float a = [1,2,3] # a now has a list (array) In debugging, all you generally care about is "what does this object point to". I guess whether or not this makes things easier or harder depends a lot on what sort of bugs you're tracking down. Hope that helps! Chris Angelico From tjreedy at udel.edu Wed Jul 13 10:34:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 10:34:41 -0400 Subject: Lisp refactoring puzzle In-Reply-To: <87mxgilh15.fsf@mithlond.arda> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: On 7/13/2011 4:29 AM, Teemu Likonen wrote: > * 2001-01-01T14:11:11-05:00 * Terry Reedy wrote: > >> As a side note, the same principle of expressions matching operations >> in symmetry suggest that majority of up are quite sensible and not >> dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a >> function call, the function has a different role than the arguments, >> so it is appropriate that it have a different role in the expression. > > Please don't forget that the whole point of Lisps' (f x) syntax is that > code is also Lisp data. Thank you for clarifying that. Some Lispers appear to promote the 'simple, uniform syntax' as a end in itself (making code=data a side effect) rather than as a means to accomplish a deeper end. > It's not just a function call with arguments. > First, it's literal data (two linked cons cells and symbols) and then > the Lisp evaluating model makes it a function call in certain > situations. > > Lisp is > > CL-USER> (let ((lisp (cons 'programmable nil))) > (setf (rest lisp) lisp)) This much looks like Lisp > #1=(PROGRAMMABLE . #1#) This must be some of the new-fangled Common LIsp stuff I never learned ;=). > programming language and it's totally irrelevant and pointless to say > "which syntax someone prefers" because this feature (code being data) is > very fundamental principle of the language. You know, it's easy to write > programs that write programs. If we remove this feature (i.e., don't > talk about Lisp at all) then it's perhaps relevant to discuss about such > choices in syntax. > > You wouldn't want Python arrays have a read and print format "a[b, c]", > that is, the first item of the array printed outside []'s. It would be > silly. -- Terry Jan Reedy From justmailnaveen at gmail.com Wed Jul 13 10:49:25 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:49:25 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: Message-ID: <301a47a4-cc74-46ba-920d-9104e2a59417@glegroupsg2000goo.googlegroups.com> Thanks Chris, That was a nice brief explanation,but i got the point. From justmailnaveen at gmail.com Wed Jul 13 10:49:25 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:49:25 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: Message-ID: <301a47a4-cc74-46ba-920d-9104e2a59417@glegroupsg2000goo.googlegroups.com> Thanks Chris, That was a nice brief explanation,but i got the point. From rustompmody at gmail.com Wed Jul 13 10:59:37 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Jul 2011 07:59:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> <79a7dab4-16ce-436e-ac54-62e314360fae@j25g2000vbr.googlegroups.com> Message-ID: On Jul 13, 5:22?am, CM wrote: > On Jul 12, 5:18?pm, rantingrick wrote: > > Kevin made the argument earlier that Tkinter (and others) are so easy > > to use that they render needing a GUI builder useless -- and he is > > correct! But did you know that there are GUI libraries EVEN more > > highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and > > using my imagination is so difficult" *crap* is really making me > > laugh. > > My attitude is, if I could speak in English to an AI to tell it what I'd like the > program to do, I'd do it. Yes, since I can't do that, I inevitably > do sometimes enjoy puzzling things out, but only because I have to. > > > PS: if you don't like to type, programming IS NOT the best career (or > > hobby) choice for you. > > I guess it is not so much that I dislike typing, as I dislike having > to > switch from visual mode to code mode, remember the keywords and > such for the widgets, rather than quickly clicking around. ?The > keystroke count is really just a proxy for that sort of effort. Yes. This is what is called the semantic gap. Say you were a programmer who had to write software for numerical analysis. Would you write it in assembly even if, say, you knew assembly very well? I contend that most sane programmers would choose an algebraic language because they understand (formally or intuitively it does not matter) that minimizing semantic gaps are best for programming. Writing text that indirectly describes a gui rather than directly drawing it is analogous to writing assembly that implies an algebraic operation instead of writing the algebra directly. As for Kevin's point: > One reason there hasn't been much demand for a GUI builder is that, in > many cases, it's just as simpler or simpler to code a GUI by hand. I am not sure how to interpret that. If you are saying that most of today's gui builders are too close to suxware to be worth the time, I guess its true (and eminently practical) If on the other hand the claim is that the very idea of gui-builders is a flawed one I think the jury is still out on that. And the history of computer science repeatedly shows that very high level ideas take decades to enter the mainstream. Think of garbage collection in 1960 in the esoteric lisp finally getting mainlined in Java in 1995. From sturlamolden at yahoo.no Wed Jul 13 11:03:19 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 13 Jul 2011 08:03:19 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? References: Message-ID: <4a7a95d5-e2b6-4c4c-8093-fd33203b7990@a11g2000yqm.googlegroups.com> On 13 Jul, 16:06, ArrC wrote: > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? Python is strongly typed. There are no static type checks in Python. Type checks are done at runtime. Dynamic typing does not mean that Python is a weakly typed language. The question of debugging is often raised, particularly by Java heads: In Python, the "doctest" and "unittest" modules can be used to verify that code works according to specification (e.g. trap type errors), and are common alternatives to static type checks. http://docs.python.org/release/3.2/library/doctest.html http://docs.python.org/release/3.2/library/unittest.html It is a good practice to always write tests for your code. Python 3.x also has function argument and return value type annotations, which is a further guard against type errors: http://www.python.org/dev/peps/pep-3107/ Sturla From rustompmody at gmail.com Wed Jul 13 11:14:36 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Jul 2011 08:14:36 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> On Jul 13, 5:53?pm, Chris Angelico wrote: > On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilli... at gmail.com > > wrote: > > On Jul 12, 6:40?pm, John Keisling wrote: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. > > > Brillant. This deserves to become a cpython easter egg along with > > import this or from __future__ import braces. Well written, funny, educative. Thanks But whats 'the modeling and sym guy' reference? From ian.g.kelly at gmail.com Wed Jul 13 11:18:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2011 09:18:59 -0600 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong wrote: > One of the main difference is that pypy supports only R-Python, which stands > for 'Restricted Python". > It is a subset of C-python language. This is wrong. The PyPy *interpreter* is written in RPython. At the application level, PyPy supports the full syntax and semantics of Python (with a few minor differences of the same sort that you find in Jython or IronPython). From tlikonen at iki.fi Wed Jul 13 11:25:00 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 13 Jul 2011 18:25:00 +0300 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: <87oc0ydwz7.fsf@mithlond.arda> * 2011-07-13T10:34:41-04:00 * Terry Reedy wrote: > On 7/13/2011 4:29 AM, Teemu Likonen wrote: >> Please don't forget that the whole point of Lisps' (f x) syntax is >> that code is also Lisp data. > > Thank you for clarifying that. Some Lispers appear to promote the > simple, uniform syntax' as a end in itself (making code=data a side > effect) rather than as a means to accomplish a deeper end. Perhaps, yes. We can't really speak of Lisp's syntax in the same sense as syntax in other languages. >> CL-USER> (let ((lisp (cons 'programmable nil))) >> (setf (rest lisp) lisp)) > > This much looks like Lisp > >> #1=(PROGRAMMABLE . #1#) > > This must be some of the new-fangled Common LIsp stuff I never learned > ;=). It's a way for the Lisp printer to show circular structures. In this case it shows a cons cell. Its first part is the symbol PROGRAMMABLE and the second part is a pointer back to the cons cell itself. So, it's a kind of infinite linked list with the same item PROGRAMMABLE all the time. With Lisp printer settings (setf *print-circle* nil *print-length* 5) the same thing would be printed this way: (PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE ...) From anthony.hw.kong at gmail.com Wed Jul 13 11:54:05 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 01:54:05 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: I stand corrected. Thanks Ian Cheers On Thu, Jul 14, 2011 at 1:18 AM, Ian Kelly wrote: > On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong > wrote: > > One of the main difference is that pypy supports only R-Python, which > stands > > for 'Restricted Python". > > It is a subset of C-python language. > > This is wrong. The PyPy *interpreter* is written in RPython. At the > application level, PyPy supports the full syntax and semantics of > Python (with a few minor differences of the same sort that you find in > Jython or IronPython). > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Wed Jul 13 11:55:36 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 13 Jul 2011 09:55:36 -0600 Subject: Python Contribution In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 4:31 AM, Shankar Raman wrote: > ?Hello everyone, > ? ?? My name is Shankarraman and I have been working with Python for past 5 > months.I find it really interesting and cool and would like to know > different ways I can contribute to it. Though I went through the bug lists, > I was wondering if I could contribute to Python in other ways. > You're in luck, Shankar. You can you hop into the dev guide (http://docs.python.org/devguide/) which will at least get you [very] started. Not only that, but there is also a mailing list specifically for mentoring people that want to get started at contributing to Python: core-mentorship at python.org. This a wonderful community and I hope you find the opportunity to jump right in! -eric > -- > Namashivaya, > R.Shankarraman, > Computer Science and Engineering, > Amrita School of Engineering. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From ericsnowcurrently at gmail.com Wed Jul 13 12:04:56 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 13 Jul 2011 10:04:56 -0600 Subject: Code hosting services In-Reply-To: <1310552613.7271.1.camel@linux-yu4c.site> References: <4E1D413E.7080002@gmail.com> <1310552613.7271.1.camel@linux-yu4c.site> Message-ID: On Wed, Jul 13, 2011 at 4:23 AM, Adam Tauno Williams wrote: > On Wed, 2011-07-13 at 01:54 -0500, Andrew Berg wrote: >> What can you guys recommend? > > SourceForge; ?it is a comprehensive platform [in addition to being an > Open Source platform: Allura]. ?It is a much improved platform over > several years ago. > Incidently, Mark Ramm of TurboGears fame went to work at SF and they have relatively recently moved a large chunk of their stuff to Python[1]. -eric [1] http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-scaling-python-past-100-4899197 From godson.g at gmail.com Wed Jul 13 12:07:15 2011 From: godson.g at gmail.com (Godson Gera) Date: Wed, 13 Jul 2011 21:37:15 +0530 Subject: How do you get the value you entered using the Entry widget in Tkinter? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 1:31 PM, Benji Benjokal wrote: > What is the simplist way to get the value you entered from the Entry widget > in Tkinter? > Have you tried the get method of Entry widget ? Here is a crude example from Tkinter import* r = Tk() e = Entry(r) e.pack() def printData(): print e.get() b = Button(r,text='getdata',command=printData) b.pack() r.mainloop() -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Wed Jul 13 12:17:58 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 13 Jul 2011 18:17:58 +0200 Subject: How do you get the value you entered using the Entry widget in Tkinter? In-Reply-To: References: Message-ID: 2011/7/13 Benji Benjokal : > What is the simplist way to get the value you entered from the Entry widget > in ?Tkinter? > Thanks Benji > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, you can use the get() method of that widget; see e.g. http://effbot.org/tkinterbook/entry.htm for a sample code. hth, vbr From tjreedy at udel.edu Wed Jul 13 12:18:18 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:18:18 -0400 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> References: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> Message-ID: On 7/13/2011 2:26 AM, alex23 wrote: > Thomas Jollans wrote: >> Coincidentally, Guido wrote this blog post just last week, without which >> I'd be just as much at a loss as you: >> >> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an... > > It's also part of the Python FAQ: > > http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements An added note: the header lines of compound statements do not necessarily occupy just one physical line. The : signals the end of the logical line. Editors can use to to indent intelligently. Consider def myfunc(a, b, c): return a+b+c All indentation was done automatically by IDLE's editor. -- Terry Jan Reedy From drsalists at gmail.com Wed Jul 13 12:22:39 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 13 Jul 2011 09:22:39 -0700 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 8:18 AM, Ian Kelly wrote: > On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong > wrote: > > One of the main difference is that pypy supports only R-Python, which > stands > > for 'Restricted Python". > > It is a subset of C-python language. > > This is wrong. The PyPy *interpreter* is written in RPython. At the > application level, PyPy supports the full syntax and semantics of > Python (with a few minor differences of the same sort that you find in > Jython or IronPython). > PyPy (2.7) and Jython (2.5) are pretty close to each other, though PyPy is quite a bit faster than Jython or CPython. Both PyPy and Jython are good implementations of the Python language, at least if you don't need a lot of C extension modules. IronPython doesn't appear to have a standard library. :( Or rather, it can use a CPython install's standard library, but a significant fraction of it doesn't work on IronPython - it doesn't appear to have been tested or adapted. There's something called FePy that includes IronPython and a better standard library, but AFAIK, it only works on windows. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 13 12:29:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:29:50 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: On 7/13/2011 8:39 AM, Anthony Kong wrote: > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module The iteration protocol and the notion of iteraables as the common data exchange format, with associated notions of iterators, generator functions, and generators, are important features of Python. Not really functional style, I guess. > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? Functions are first-class objects, like everything else. Use of closures to create functions to be returned. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jul 13 12:31:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:31:59 -0400 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On 7/13/2011 10:19 AM, Anthony Kong wrote: > One of the main difference is that pypy supports only R-Python, which > stands for 'Restricted Python". Not true. PyPy is *written* in rpython. It runs standard Python. -- Terry Jan Reedy From k.sahithi2862 at gmail.com Wed Jul 13 12:35:26 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 13 Jul 2011 09:35:26 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <17fd9e70-8091-4c80-a785-410b694b275b@z7g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From ian.g.kelly at gmail.com Wed Jul 13 13:09:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2011 11:09:16 -0600 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 10:29 AM, Terry Reedy wrote: > The iteration protocol and the notion of iteraables as the common data > exchange format, with associated notions of iterators, generator functions, > and generators, are important features of Python. Not really functional > style, I guess. Xah Lee's assertion to the contrary notwithstanding, it seems to me that list comprehensions are basically functional in style. They are, after all, equivalent to "map(f, filter(g, x))". Iterators, on the other hand, by definition have the property that each call to iter.next() has the side effect of changing the iterator's state. Therefore, although they can effectively be used as a functional building block (e.g. by masking their use with a comprehension), the iterators themselves are not actually functional. From clp2 at rebertia.com Wed Jul 13 13:10:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 13 Jul 2011 10:10:45 -0700 Subject: sys.tracebacklimit In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 6:42 AM, Vlad Didenko wrote: > Colleagues, > Per documentation > at?http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit?: > ?? ? When [sys.tracebacklimit]?set to 0 or less, all traceback information > is suppressed and only the exception type and value are printed > So, I expect to be able to have a program like: > ?? ?import sys > ?? ?sys.tracebacklimit=0 > ?? ?print(1/0) > And see it's result as: > ?? ??ZeroDivisionError: division by zero > However, the actual result is: > ?? ??Traceback (most recent call last): > ?? ????File "tbt.py", line 3, in > ?? ???? ?print(1/0) > ?? ??ZeroDivisionError: division by zero > Do I misunderstand the docs? Nope. It's a known bug: http://bugs.python.org/issue12276 Cheers, Chris From stratfordtenants at gmail.com Wed Jul 13 13:11:51 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 10:11:51 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in Message-ID: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Hello I am using the zxJDBC package with jython (similar to python), and I am having "python error PLS-00306: wrong number or types of arguments" error when using the "callproc()" method to execute a stored procedure. The Oracle stored procedure takes a single OUT varchar2 parameter. My code is as follows: p = [None] c.callproc('pkg1_returns', p); ... What I am doing corresponds to the examples..but I can seem to know why it is not working. Help. "Adeoluwa" From thorsten at thorstenkampe.de Wed Jul 13 13:27:02 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 19:27:02 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) > On 2011-07-13, Thorsten Kampe wrote: > > >> and that that block is to be considered in relation to what was just > >> said, before the colon. > > > > The indentation makes it abundantly clear to the human reader that > > that indented block is to be considered in relation to what was just > > said, before the indentation. > You would think so, but human readers like redundancy. I also like redundancy (and consistency). That's why I'd much more prefer a "then" than a colon which is easily overlooked while reading /and/ while writing. Thorsten From shilparani9030 at gmail.com Wed Jul 13 13:28:29 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Wed, 13 Jul 2011 10:28:29 -0700 (PDT) Subject: EXCLUSIVE HOT PHOTOS Message-ID: <5bc4a35f-2128-4bf2-9edf-9fdeddd7d3ab@j9g2000prj.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gordon at panix.com Wed Jul 13 13:40:35 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 17:40:35 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Message-ID: In <01efb6ac-deaa-4bdb-8b2d-b603bdddec57 at n5g2000yqh.googlegroups.com> Adeoluwa Odein writes: > Hello > I am using the zxJDBC package with jython (similar to python), and I > am having "python error PLS-00306: wrong number or types of arguments" > error when using the "callproc()" method to execute a stored > procedure. > The Oracle stored procedure takes a single OUT varchar2 parameter. My > code is as follows: > p = [None] > c.callproc('pkg1_returns', p); If the procedure takes a varchar2 parameter, why are you passing [None]? It might help if you posted the method signature of the Oracle stored procedure you're trying to call. -- 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 stratfordtenants at gmail.com Wed Jul 13 13:58:06 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 10:58:06 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Message-ID: <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Thanks, your assistance will be greatly appreciated on the right way forward. See the Stored Procedure Below -very simple: create or replace package c2_pkg as procedure openc; procedure closec; procedure RS22(v out varchar); end; / create or replace package body c2_pkg as v_first_time boolean := TRUE; v_cursor number; cursor srvr_cur is select distinct b.mid from SVR a,VAR b where a.mid = b.mid; procedure openc as begin if not srvr_cur%ISOPEN then open srvr_cur; end if; end openc; procedure closec as begin close srvr_cur; end closec; procedure RS22(v out varchar2) as -- Server varchar2(64); begin Server := NULL; fetch srvr_cur into Server; v := Server; end RS22; end; / On Jul 13, 1:40?pm, John Gordon wrote: > In <01efb6ac-deaa-4bdb-8b2d-b603bddde... at n5g2000yqh.googlegroups.com> Adeoluwa Odein writes: > > > Hello > > I am using the zxJDBC package with jython (similar to python), and I > > am having "python error PLS-00306: wrong number or types of arguments" > > error when using the "callproc()" method to execute a stored > > procedure. > > The Oracle stored procedure takes a single OUT varchar2 parameter. ?My > > code is as follows: > > p = [None] > > c.callproc('pkg1_returns', p); > > If the procedure takes a varchar2 parameter, why are you passing [None]? > > It might help if you posted the method signature of the Oracle stored > procedure you're trying to call. > > -- > 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" From gordon at panix.com Wed Jul 13 14:10:06 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 18:10:06 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: In <9e937261-d05d-477a-90d2-a690e85e124d at h17g2000yqn.googlegroups.com> Adeoluwa Odein writes: > Thanks, your assistance will be greatly appreciated on the right way > forward. See the Stored Procedure Below -very simple: I don't see a procedure named "pkg1_returns", which is the prodecure called by your code. Where is this procedure? -- 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 stratfordtenants at gmail.com Wed Jul 13 14:18:30 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:18:30 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: The actual jython/python call is: p = [None] c.callproc('c2_pkg.RS22', p); I used a placeholder initially; now that you have the SQL code, there it is. It essentially invokes the stored procedure, and it should return the OUT variable p, with some value. It doesn't have to be a cursor fetch; even a minor text assignment. On Jul 13, 2:10?pm, John Gordon wrote: > In <9e937261-d05d-477a-90d2-a690e85e1... at h17g2000yqn.googlegroups.com> Adeoluwa Odein writes: > > > Thanks, your assistance will be greatly appreciated on the right way > > forward. ?See the Stored Procedure Below -very simple: > > I don't see a procedure named "pkg1_returns", which is the prodecure > called by your code. ?Where is this procedure? > > -- > 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" From gordon at panix.com Wed Jul 13 14:26:40 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 18:26:40 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: In Adeoluwa Odein writes: > The actual jython/python call is: > p =3D [None] > c.callproc('c2_pkg.RS22', p); > I used a placeholder initially; now that you have the SQL code, there > it is. It essentially invokes the stored procedure, and it should > return the OUT variable p, with some value. It doesn't have to be a > cursor fetch; even a minor text assignment. That procedure is defined as taking one parameter, but you're passing an empty parameter list. Why? -- 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 stratfordtenants at gmail.com Wed Jul 13 14:32:18 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:32:18 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: On Jul 13, 2:26?pm, John Gordon wrote: > In Adeoluwa Odein writes: > > > The actual jython/python call is: It's taking an OUT parameter.. I'm just following the examples as documented by zxJDBC. How can I fix it? > > p =3D [None] > > c.callproc('c2_pkg.RS22', p); > > I used a placeholder initially; now that you have the SQL code, there > > it is. ?It essentially invokes the stored procedure, and it should > > return the OUT variable p, with some value. ?It doesn't have to be a > > cursor fetch; even a minor text assignment. > > That procedure is defined as taking one parameter, but you're passing > an empty parameter list. ?Why? > > -- > 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" From rantingrick at gmail.com Wed Jul 13 14:32:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 13 Jul 2011 11:32:50 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> Message-ID: <000e90cf-4dc8-4499-88d7-43c294499d70@z12g2000yqj.googlegroups.com> On Jul 13, 10:14?am, rusi wrote: > Well written, funny, educative. Thanks > But whats 'the modeling and sym guy' reference? I believe it's "esoteric". From stratfordtenants at gmail.com Wed Jul 13 14:33:28 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:33:28 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: <5f0ba12a-4de1-4032-941e-59f3b6878c4b@y13g2000yqy.googlegroups.com> On Jul 13, 2:26?pm, John Gordon wrote: > In Adeoluwa Odein writes: > > > The actual jython/python call is: > > p =3D [None] > > c.callproc('c2_pkg.RS22', p); > > I used a placeholder initially; now that you have the SQL code, there > > it is. ?It essentially invokes the stored procedure, and it should > > return the OUT variable p, with some value. ?It doesn't have to be a > > cursor fetch; even a minor text assignment. > > That procedure is defined as taking one parameter, but you're passing > an empty parameter list. ?Why? > > -- > 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" I'm new to jython... From kylotan at gmail.com Wed Jul 13 15:21:16 2011 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 13 Jul 2011 12:21:16 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? References: Message-ID: On Jul 13, 7:29?am, cjrh wrote: > You can just extract the windows pypy 1.5 distribution to any folder and run "pypy.exe" from there as if it was called "python.exe". ?This is how I have been using it. ?In fact, pypy has been the default python for my portable eclipse for a good while now. That doesn't give access to existing site-packages, or allow me to install binary packages that it can access. Hence me asking about that specifically. From maththespian87 at gmail.com Wed Jul 13 15:31:30 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:31:30 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> On Jul 12, 7:02?pm, Steven D'Aprano wrote: > John Keisling wrote: > > After too much time coding Python scripts and reading Mark Lutz's > > Python books, I was inspired to write the following lyrics. For those > > too young to remember, the tune is that of "Pinball Wizard," by The > > Who. May it bring you as much joy as it brought me! > > [...] > > I wouldn't know a good song parody if it kicked me in the head, but my wife > is a (retired) professional musician with a history of writing parodies. > She's not impressed by the work of most "filk singers" and supposed > parodies, most of which are seventeen kinds of crap... but she gives you > full marks. And trust me on this, she does not give compliments lightly. > > She says you got the rhyming scheme and number of syllables spot on. > Technically, "That modeling and sim guy" needs to be slurred to make it > fit, "That mod'ling and sim guy", but that's acceptable. > > (Most parodies get the syllable count wrong -- if a lyric goes > dum-de-dum-de-dum, the parody ends up like dum-dum-de-dum-de-dum or > dum-de-dum-de.) > > Have a +1 from me and the missus. > > -- > Steven I very much appreciate that, coming from someone who clearly values well-written poetry and lyrics as much as I do! I double majored in math and English, and I always liked structured poetry. It's very important to match not only the syllable count, but the meter too. I also pride myself on never using the same rhyme twice in a song, which even the original does not manage to do (they used "fall" twice). Very glad you and the missus enjoyed it! From maththespian87 at gmail.com Wed Jul 13 15:32:54 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:32:54 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <60e495ba-8a03-42d5-bf0a-995948d2ab26@p29g2000pre.googlegroups.com> On Jul 13, 6:53?am, Chris Angelico wrote: > On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilli... at gmail.com > > wrote: > > On Jul 12, 6:40?pm, John Keisling wrote: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. > > > Brillant. This deserves to become a cpython easter egg along with > > import this or from __future__ import braces. > > Propose: from eastereggs import wizard > > ChrisA I would be honored beyond words to have this become a Python Easter egg! Does anyone know how to make that happen? From maththespian87 at gmail.com Wed Jul 13 15:35:27 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:35:27 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> <000e90cf-4dc8-4499-88d7-43c294499d70@z12g2000yqj.googlegroups.com> Message-ID: <4d025ec6-d603-4206-b78f-5dac6aba1e19@k23g2000pri.googlegroups.com> On Jul 13, 12:32?pm, rantingrick wrote: > On Jul 13, 10:14?am, rusi wrote: > > > Well written, funny, educative. Thanks > > But whats 'the modeling and sym guy' reference? > > I believe it's "esoteric". I actually had myself in mind, with tongue in cheek, of course! I work in modeling and simulation and write Python scripts to automate data visualization and analysis. Of course, that line could also refer to a few of my co-workers. Glad you all enjoyed the song! From cartercc at gmail.com Wed Jul 13 16:04:47 2011 From: cartercc at gmail.com (ccc31807) Date: Wed, 13 Jul 2011 13:04:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: On Jul 12, 7:54 am, Xah Lee wrote: > maybe this will be of interest. > > ?What Programing Language Are the Largest Website Written In??http://xahlee.org/comp/website_lang_popularity.html About five years ago, I did some pretty extensive research, and concluded that the biggest sites were written serverside with JSP. Obviously, this wouldn't include The Biggest site, but if you were a big, multinational corporation, or listed on the NYSE, you used JSP for your web programming. I doubt very seriously PHP is used for the biggest sites -- I'd still guess JSP, or maybe a MS technology (not VB), but it's only a guess. CC. From gordon at panix.com Wed Jul 13 16:09:12 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 20:09:12 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: > It's taking an OUT parameter.. I'm just following the examples as > documented by zxJDBC. How can I fix it? I suspect the example you're looking at was for a procedure which has no arguments, so in that case it would make sense to pass an empty parameter list. I haven't worked with OUT parameters so I don't know if this will work, but try it and see what happens: my_string = "" p = [my_string] c.callproc('c2_pkg.RS22', p); print p -- 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 nberg at atmos.ucla.edu Wed Jul 13 16:22:34 2011 From: nberg at atmos.ucla.edu (Neil Berg) Date: Wed, 13 Jul 2011 13:22:34 -0700 Subject: losing-end-of-row values when manipulating CSV input Message-ID: Hello all, I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. Do you have any suggestions on how to fix this issue? Many thanks in advance, Neil Berg -------------- next part -------------- A non-text attachment was scrubbed... Name: csv_test.py Type: text/x-python-script Size: 1136 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: csv_sample.csv Type: text/csv Size: 416 bytes Desc: not available URL: From stratfordtenants at gmail.com Wed Jul 13 16:33:22 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 13:33:22 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> On Jul 13, 4:09?pm, John Gordon wrote: > > It's taking an OUT parameter.. I'm just following the examples as > > documented by zxJDBC. ?How can I fix it? > > I suspect the example you're looking at was for a procedure which has no > arguments, so in that case it would make sense to pass an empty parameter > list. > > I haven't worked with OUT parameters so I don't know if this will work, > but try it and see what happens: > > ? my_string = "" > ? p = [my_string] > ? c.callproc('c2_pkg.RS22', p); > ? print p > > -- > 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 same error. The sample were found on the following site --I copied exactly what is written there: 1. http://www.jython.org/archive/21/docs/zxjdbc.html From nawijn at gmail.com Wed Jul 13 16:42:10 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Wed, 13 Jul 2011 13:42:10 -0700 (PDT) Subject: losing-end-of-row values when manipulating CSV input References: Message-ID: On Jul 13, 10:22?pm, Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. ?I have attached both a sample of the CSV data and my script. ? > > The attached CSV file contains two rows and 27 columns of data. ?The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". ? > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. ? > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. ?My script, however, is returning 23. ?I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. ?I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > ?csv_test.py > 1KViewDownload > > ?csv_sample.csv > < 1KViewDownload Hello Neil, I just had a quick look at your script. To remove the trailing "\" you can use val = val.rstrip('\\') in your script. Note the double backslash. The script now returns 24 items in the hour_list. Good luck! Marco From nawijn at gmail.com Wed Jul 13 16:44:45 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Wed, 13 Jul 2011 13:44:45 -0700 (PDT) Subject: losing-end-of-row values when manipulating CSV input References: Message-ID: On Jul 13, 10:22?pm, Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. ?I have attached both a sample of the CSV data and my script. ? > > The attached CSV file contains two rows and 27 columns of data. ?The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". ? > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. ? > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. ?My script, however, is returning 23. ?I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. ?I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > ?csv_test.py > 1KViewDownload > > ?csv_sample.csv > < 1KViewDownload Dear Neil, Don't know if this is a double post (previous post seems to be gone), but val = val.rstrip('\\') should fix your problem. Note the double backslash. Kind regards, Marco From gordon at panix.com Wed Jul 13 17:02:37 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 21:02:37 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: In <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592 at f35g2000vbr.googlegroups.com> Adeoluwa Odein writes: > The same error. The sample were found on the following site --I copied > exactly what is written there: > 1. http://www.jython.org/archive/21/docs/zxjdbc.html Ah, I see. You're supposed to call c.fetchall() afterwards to retrieve the OUT parameter. Also, the example page defines the called object as a function, not a procedure. Maybe that's the problem? Try defining RS22 as a function and see if that helps. You might also try defining it outside of a package, as that is how the example code does it. -- 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 stratfordtenants at gmail.com Wed Jul 13 17:06:03 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:06:03 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> On Jul 13, 5:02?pm, John Gordon wrote: > In <86b9e6f2-e18e-41b9-92a2-86ea8d7b4... at f35g2000vbr.googlegroups.com> Adeoluwa Odein writes: > > > The same error. The sample were found on the following site --I copied > > exactly what is written there: > > 1.http://www.jython.org/archive/21/docs/zxjdbc.html > if you define the function in the execute() method, it works (as seen on the page). But this is a stored procedure already residing on the DB. A function/procedure outside of a package, actually works, but then you lose access to private data; which is while I used a package. > Ah, I see. ?You're supposed to call c.fetchall() afterwards to retrieve > the OUT parameter. > > Also, the example page defines the called object as a function, not a > procedure. ?Maybe that's the problem? ?Try defining RS22 as a function > and see if that helps. > > You might also try defining it outside of a package, as that is how the > example code does it. > > -- > 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" From vlastimil.brom at gmail.com Wed Jul 13 17:13:16 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 13 Jul 2011 23:13:16 +0200 Subject: difflib-like library supporting moved blocks detection? Message-ID: Hi all, I'd like to ask about the availability of a text diff library, like difflib, which would support the detection of moved text blocks. Currently I am almost happy with the results of difflib.SequenceMatcher in my app (comparing different versions of natural language texts), however the only drawback seems to be the missing detection of moves of the text parts. I was thinking of simply recomparing the deleted and inserted blocks using difflib again, but this obviously won't be a general solution. I found several algorithm discussions, but unfortunately no suitable python implementation. (E.g. Medite - http://www-poleia.lip6.fr/~ganascia/Medite_Project - seems to be implemented in Python but it targets some rather special and probably much more complex textological issues, than my current needs.) Does maybe someone know such python library (or possibly a way of enhancing difflib) for this task (i.e character-wise comparing of texts - detecting insertion, deletion, substitution and move of text blocks)? Thanks in advance, Vlastimil Brom From EEllerbee at BBandT.com Wed Jul 13 17:13:23 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Wed, 13 Jul 2011 17:13:23 -0400 Subject: I don't know list, I not good at list. Message-ID: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> I've been beating my head against the desk trying to figure out a method to accomplish this: Take a list (this example is 5 items, It could be 150 or more - i.e. it's variable length depending on the city/local calling zones) The first 6 digits of phone numbers(NPA/NXX) in a local calling area. I want to concatenate the last digit for insertion into a call routing pattern. I tried this and failed miserably: list1=['252205','252246','252206','252247','252248'] for item in list1: try: item1=list1[0] item2=list1[1] if item1[0:5] == item2[0:5]: print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' list1.pop(0) else: print item1 list1.pop(0) except: try: print item1 list1.pop(0) except: pass #----------------------------------------------------------------- My intent is to have the end data come out (from the example list above) in the format of 25220[56] 25224[678] I tried putting together a variable inserted into a regular expression, and it doesn't seem to like: Item1=list1[0] Itemreg = re.compile(Item1[0:5]) For stuff in itemreg.list1: #do something Can somebody throw me a bone, code example or module to read on python.org? I'm a n00b, so I'm still trying to understand functions and classes. I thought the experts on this list might take pity on my pathetic code skillz! Thanks so much :) Ed Ellerbee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Jul 13 17:17:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Jul 2011 14:17:41 -0700 Subject: losing-end-of-row values when manipulating CSV input In-Reply-To: References: Message-ID: <4E1E0B75.3000304@stoneleaf.us> Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. > > The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > Your 'csv' file isn't -- it looks like rich text. An actual csv file looks more like this (which is probably what you're seeing in notepad, but is not what is stored on disk): 8<------------------------------------------------------------------------------------ BLS,4,19981101,37,m,36,34,36,35,34,34,35,36,38,39,43,42,42,42,38,36,34,32,33,33,35,34 BLS,4,19981102,34,32,33,32,34,32,33,32,34,38,40,41,44,47,43,42,39,36,35,35,36,36,35,33 8<------------------------------------------------------------------------------------ Try saving in text-only format. ~Ethan~ From tjreedy at udel.edu Wed Jul 13 17:18:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 17:18:12 -0400 Subject: python error PLS-00306: wrong number or types of arguments in In-Reply-To: <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: On 7/13/2011 4:33 PM, Adeoluwa Odein wrote: > The same error. The sample were found on the following site --I copied > exactly what is written there: > 1. http://www.jython.org/archive/21/docs/zxjdbc.html The jython-users mailing list might be a better place to ask your question. Most people here are CPython users. http://sourceforge.net/mail/?group_id=12867 -- Terry Jan Reedy From gordon at panix.com Wed Jul 13 17:19:02 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 21:19:02 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: In <0730c5fb-3b65-45ce-9cc5-69d639f48281 at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > if you define the function in the execute() method, it works (as seen > on the page). But this is a stored procedure already residing on the > DB. A function/procedure outside of a package, actually works, but > then you lose access to private data; which is while I used a package. Did you try changing RS22 from a procedure to a function inside the package? -- 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 nberg at atmos.ucla.edu Wed Jul 13 17:19:21 2011 From: nberg at atmos.ucla.edu (Neil Berg) Date: Wed, 13 Jul 2011 14:19:21 -0700 Subject: losing-end-of-row values when manipulating CSV input In-Reply-To: <4E1E0B75.3000304@stoneleaf.us> References: <4E1E0B75.3000304@stoneleaf.us> Message-ID: Ethan, Thank you for this tip- you are correct that I saved the data as rich text. I remade the files in VI instead of TextEdit, which allowed me to write a true csv file and the script works as expected now. Thanks again, Neil On Jul 13, 2011, at 2:17 PM, Ethan Furman wrote: > Neil Berg wrote: >> Hello all, >> >> I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. >> >> The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. >> >> In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". >> >> Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. >> >> But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. >> >> Do you have any suggestions on how to fix this issue? >> >> Many thanks in advance, >> >> Neil Berg >> >> > Your 'csv' file isn't -- it looks like rich text. An actual csv file > looks more like this (which is probably what you're seeing in notepad, > but is not what is stored on disk): > > 8<------------------------------------------------------------------------------------ > BLS,4,19981101,37,m,36,34,36,35,34,34,35,36,38,39,43,42,42,42,38,36,34,32,33,33,35,34 > BLS,4,19981102,34,32,33,32,34,32,33,32,34,38,40,41,44,47,43,42,39,36,35,35,36,36,35,33 > 8<------------------------------------------------------------------------------------ > > Try saving in text-only format. > > ~Ethan~ From stratfordtenants at gmail.com Wed Jul 13 17:28:10 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:28:10 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: <65ea5860-caf7-4fc5-ab46-829ce29948d9@y13g2000yqy.googlegroups.com> On Jul 13, 5:19?pm, John Gordon wrote: > In <0730c5fb-3b65-45ce-9cc5-69d639f48... at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > > > if you define the function in the execute() method, it works (as seen > > on the page). ?But this is a stored procedure already residing on the > > DB. ?A function/procedure outside of a package, actually works, but > > then you lose access to private data; which is while I used a package. > > Did you try changing RS22 from a procedure to a function inside the > package? > > -- > 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" Correction, the previous actually works, and still gives me access to private data. So I will most likely use it. Basically, just call a function, outside a package. It resolves this entire dilemma. Implementing similar program in Perl DBI, works without any problem. Python/Jython seem quite difficult to work with Store Procedures, in my opinion. Thanks a lot. From stratfordtenants at gmail.com Wed Jul 13 17:28:38 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:28:38 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: On Jul 13, 5:19?pm, John Gordon wrote: > In <0730c5fb-3b65-45ce-9cc5-69d639f48... at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > > > if you define the function in the execute() method, it works (as seen > > on the page). ?But this is a stored procedure already residing on the > > DB. ?A function/procedure outside of a package, actually works, but > > then you lose access to private data; which is while I used a package. > > Did you try changing RS22 from a procedure to a function inside the > package? > > -- > 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 same problem, if done inside a package. I just left it outside a package, and it works. From rosuav at gmail.com Wed Jul 13 17:40:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 07:40:19 +1000 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> Message-ID: On Thu, Jul 14, 2011 at 5:31 AM, John Keisling wrote: > I very much appreciate that, coming from someone who clearly values > well-written poetry and lyrics as much as I do! I double majored in > math and English, and I always liked structured poetry. It's very > important to match not only the syllable count, but the meter too. I > also pride myself on never using the same rhyme twice in a song, which > even the original does not manage to do (they used "fall" twice). Having not known the original, I can't properly appreciate the parody, but I wholeheartedly concur with the above. Especially when you transmit your alternate words by email (as opposed to singing it yourself and posting on Youtube, for instance), you need them to scan perfectly so the reader isn't thrown off by anything. The other big pitfall is polysyllabic rhymes, quite common in Gilbert & Sullivan but probably not an issue here. (For instance, if the original rhymes "modern gunnery" with "in a nunnery", then you have to replace that with three-syllable words whose last two syllables are identical and whose first syllables rhyme. Not an easy task!) This appears to be an excellent parody, but others are better positioned to proclaim its quality than I. Chris Angelico From avfonarev at gmail.com Wed Jul 13 17:50:19 2011 From: avfonarev at gmail.com (Anton Fonarev) Date: Thu, 14 Jul 2011 01:50:19 +0400 Subject: What Programing Language are the Largest Website Written In? In-Reply-To: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: 2011/7/12 Xah Lee : > 23 yandex.ru (Russian) ? ? > As far as I know, the site is written in Perl. However, they are using lots of python in their products and for internal use. Anton. From emile at fenx.com Wed Jul 13 17:51:38 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 13 Jul 2011 14:51:38 -0700 Subject: I don't know list, I not good at list. In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> Message-ID: On 7/13/2011 2:13 PM Ellerbee, Edward said... > I've been beating my head against the desk trying to figure out a method > to accomplish this: > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list above) > in the format of > 25220[56] > 25224[678] this should get you started... >>> list1=['252205','252246','252206','252247','252248'] >>> D = {} >>> for ii in list1: D.setdefault(ii[:5],[]).append(ii[5]) ... >>> print D {'25224': ['6', '7', '8'], '25220': ['5', '6']} >>> Emile From python at mrabarnett.plus.com Wed Jul 13 17:58:50 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 13 Jul 2011 22:58:50 +0100 Subject: I don't know list, I not good at list. In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> Message-ID: <4E1E151A.4070006@mrabarnett.plus.com> > I've been beating my head against the desk trying to figure out a > method to accomplish this: > > Take a list (this example is 5 items, It could be 150 or more - i.e. > it's variable length depending on the city/local calling zones) > > The first 6 digits of phone numbers(NPA/NXX) in a local calling area. > I want to concatenate the last digit for insertion into a call > routing pattern. > > I tried this and failed miserably: > > list1=['252205','252246','252206','252247','252248'] > for item in list1: > try: > item1=list1[0] > item2=list1[1] > if item1[0:5] == item2[0:5]: > print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' > list1.pop(0) > else: > print item1 > list1.pop(0) > except: > try: > print item1 > list1.pop(0) > except: > pass > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list > above) in the format of > 25220[56] > 25224[678] > > I tried putting together a variable inserted into a regular > expression, and it doesn't seem to like: > Item1=list1[0] > Itemreg = re.compile(Item1[0:5]) > For stuff in itemreg.list1: > #do something > > Can somebody throw me a bone, code example or module to read on > python.org? I'm a n00b, so I'm still trying to understand functions > and classes. > > I thought the experts on this list might take pity on my pathetic > code skillz! > defaultdict comes in handy: >>> list1 = ['252205','252246','252206','252247','252248'] >>> from collections import defaultdict >>> d = defaultdict(set) >>> for item in list1: d[item[ : 5]].add(item[5 : ]) >>> d defaultdict(, {'25224': {'8', '7', '6'}, '25220': {'5', '6'}}) >>> for k, v in d.items(): print(k + "[" + "".join(v) + "]") 25224[876] 25220[56] From ryan at rfk.id.au Wed Jul 13 19:24:57 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 14 Jul 2011 09:24:57 +1000 Subject: PyCon Australia 2011: Schedule Announced Message-ID: <1310599497.11156.14.camel@rambutan> Hi Everyone, The official schedule for PyCon Australia 2011 has been announced! This year's conference will feature 3 fantastic keynotes, 7 introductory classroom sessions, and 26 presentations on topics as diverse as web programming, benchmarking, social issues and API design. PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Conference Schedule Announced 2. More Sponsors Announced Please pass this message on to those you feel may be interested. Conference Schedule Announced ============================= The detailed conference schedule has been completed and can now be viewed at the following URL: http://pycon-au.org/2011/conference/schedule/ There's even an iCal version for you to plug the schedule straight into your calendar of choice: http://pycon-au.org/2011/conference/schedule/ical/ Thanks again to all our presenters for some outstanding talk proposals this year. Standard Talks: A Python on the Couch (Mark Rees) Behaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in Python (Duncan Gray) Fun with App Engine 1.5.0 (Greg Darke) Hosting Python Web Applications (Graham Dumpleton) How Python Evolves (and How You Can Help Make It Happen) (Nick Coghlan) Infinite 8-bit Platformer (Chris McCormick) Networking Libraries in Python. (Senthil Kumaran) Pants - Network Programming Made Easy (Evan Davis) Say What You Mean: Meta-Programming a Declarative API (Ryan Kelly) State of CPython and Python Ecosystem (Senthil Kumaran) Sysadmins vs Developers, a take from the other side of the fence (Benjamin Smith) Teaching Python to the young and impressionable (Katie Bell) The NCSS Challenge: teaching programming via automated testing (Tim Dawborn) Weather field warping using Python. (Nathan Faggian) Zookeepr: Home-grown conference management software (Brianna Laugher) In-Depth Talks: Ah! I see you have the machine that goes "BING"! (Graeme Cross) Easy site migration using Diazo and Funnelweb (Adam Terrey) How to maintain big app stacks without losing your mind (Dylan Jay) Introduction to the Geospatial Web with GeoDjango (Javier Candeira) Pyramid: Lighter, faster, better web apps (Dylan Jay) Web micro-framework battle (Richard Jones) Discussion Panels: Panel: Python 3 (Nick Coghlan, Raymond Hettinger, Richard Jones) Panel: Python in the webs (Malcolm Tredinnick, Russell Keith-Magee, Dylan Jay, Richard Jones) Classroom Track: Python 101+ (Peter Lovett) Python's dark corners - the bad bits in Python and how to avoid them (Peter Lovett) Confessions of Joe Developer (Danny Greenfeld) Meta-matters: using decorators for better Python programming (Graeme Cross) Python for Science and Engineering, Part 1 (Edward Schofield) Python for Science and Engineering, Part 2 (Edward Schofield) The Zen of Python (Richard Jones) More Sponsors Announced ======================= We are delighted to announce that Bitbucket by Atlassian has joined us as a Silver Sponsor. Thanks once again to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Silver: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Arclight Silver: Bitbucket by Atlassian Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 From rantingrick at gmail.com Wed Jul 13 19:43:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 13 Jul 2011 16:43:13 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> Message-ID: On Jul 13, 4:40?pm, Chris Angelico wrote: > Having not known the original, I can't properly appreciate the parody, It's only a click away Chris... here let me youtube that for you... http://www.youtube.com/watch?v=4AKbUm8GrbM http://www.youtube.com/watch?v=SHhrZgojY1Q http://www.youtube.com/watch?v=IXWNSb4nUDY Here's one for my would be nemisis(es) http://www.youtube.com/watch?v=fi_rGnw_B9A From thinke365 at gmail.com Wed Jul 13 20:18:07 2011 From: thinke365 at gmail.com (think) Date: Thu, 14 Jul 2011 08:18:07 +0800 Subject: should i install python image library by myself? Message-ID: <201107140818034940258@gmail.com> when i type import image in the python interactive command, i am surprised to find that it does not work. the details are as follows: >>> import image Traceback (most recent call last): File "", line 1, in ? ImportError: No module named image i wonder the image library should be a buildin module, then why i cannot import it? what's wrong? or some version of python does not include image library as a buildin module? so can anybody recommend a version of python which include image libary, thank you ; ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From wobh at yahoo.com Wed Jul 13 20:53:49 2011 From: wobh at yahoo.com (William Clifford) Date: Wed, 13 Jul 2011 17:53:49 -0700 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> <983mh1Fs7cU1@mid.individual.net> Message-ID: <86oc0xn0ma.fsf@gsosw-lego-spare1.domain.actdsltmp> Neil Cerutti writes: > On 2011-07-12, Petter Gustad wrote: >> Xah Lee writes: >> >>> it's funny, in all these supposedly modern high-level langs, they >>> don't provide even simple list manipulation functions such as union, >>> intersection, and the like. Not in perl, not in python, not in lisps. >> >> In Common Lisp you have: >> >> CL-USER> (union '(a b c) '(b c d)) >> (A B C D) >> CL-USER> (intersection '(a b c) '(b c d)) >> (C B) > > What's the rationale for providing them? Are the definitions > obvious for collections that a not sets? This seems like a good general question to me, although, I feel like the answer to this question specifically is "yes, obvious enough." A general purpose programming language ought to be general enough to allow expansion, but have enough "obvious" features, that one doesn't have to reinvent the wheel. I recently read somewhere that human languages "differ less in what they allow, and more in what they require" (paraphrase). I have little-to-no computer science expertise, but I sense that in computer languages with Turing equivalency this is exactly true. -- William Clifford From python at mrabarnett.plus.com Wed Jul 13 20:59:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 01:59:51 +0100 Subject: PyCon Australia 2011: Schedule Announced In-Reply-To: <1310599497.11156.14.camel@rambutan> References: <1310599497.11156.14.camel@rambutan> Message-ID: <4E1E3F87.5010101@mrabarnett.plus.com> On 14/07/2011 00:24, Ryan Kelly wrote: [snip] > > Ah! I see you have the machine that goes "BING"! (Graeme Cross) Surely it goes "PING"! From clp2 at rebertia.com Wed Jul 13 21:04:47 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 13 Jul 2011 18:04:47 -0700 Subject: should i install python image library by myself? In-Reply-To: <201107140818034940258@gmail.com> References: <201107140818034940258@gmail.com> Message-ID: On Wed, Jul 13, 2011 at 5:18 PM, think wrote: > when i?type import image in the python interactive command, i am surprised > to find that it does not work. the details are as follows: What led you to expect that exact command would work in the first place?? >>>>?import?image > Traceback?(most?recent?call?last): > ??File?"",?line?1,?in?? > ImportError:?No?module?named?image > > i wonder the image library should be a buildin module, then why i cannot > import it? > what's wrong? or some version of python does not include image library as a > buildin module? There is no standard library module by that name; no first-party versions of Python include such a module. Thus, it's no surprise that your import throws an exception. > so can anybody recommend a version of python which include image libary, I can only guess that your "image" library refers to either the "Image" (capitalization matters!) *submodule* of PIL (http://www.pythonware.com/products/pil/ ), or the "Image" class of Tkinter (http://docs.python.org/library/tkinter.html#images ). The former requires installation of PIL, and would then be correctly imported via: from PIL import Image The latter is typically built as part of a default Python installation and would be correctly imported via: from Tkinter import Image # Python 2.x or: from tkinter import Image # Python 3.x Cheers, Chris -- http://rebertia.com From python at mrabarnett.plus.com Wed Jul 13 21:04:54 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 02:04:54 +0100 Subject: should i install python image library by myself? In-Reply-To: <201107140818034940258@gmail.com> References: <201107140818034940258@gmail.com> Message-ID: <4E1E40B6.803@mrabarnett.plus.com> On 14/07/2011 01:18, think wrote: > when i type import image in the python interactive command, i am > surprised to find that it does not work. the details are as follows: > >>> import image > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named image > i wonder the image library should be a buildin module, then why i cannot > import it? > what's wrong? or some version of python does not include image library > as a buildin module? > so can anybody recommend a version of python which include image libary, > thank you ; ) > The usual image library used in Python is the Python Imaging Library ("PIL"). It isn't one of the standard modules. Have a look here: http://www.pythonware.com/products/pil/ From ian at excess.org Wed Jul 13 22:02:15 2011 From: ian at excess.org (Ian Ward) Date: Wed, 13 Jul 2011 22:02:15 -0400 Subject: ANN: Urwid 0.9.9.2 - Console UI Library Message-ID: <4E1E4E27.9090501@excess.org> Announcing Urwid 0.9.9.2 ------------------------ Urwid home page: http://excess.org/urwid/ Screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.2.tar.gz About this release: =================== This release is *not* the big, exciting, wow-look-at-all-those-new-features release that just might be coming out very soon. It does, however fix a number of bugs in the previous release. New in this release: ==================== * Fix for an Overlay get_cursor_coords(), and Text top-widget bug * Fix for a Padding rows() bug when used with width=PACK * Fix for a bug with large flow widgets used in an Overlay * Fix for a gpm_mev bug * Fix for Pile and GraphVScale when rendered with no contents * Fix for a Python 2.3 incompatibility (0.9.9 is the last release to claim support Python 2.3) About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, Unicode support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From greg.ewing at canterbury.ac.nz Wed Jul 13 23:12:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jul 2011 15:12:41 +1200 Subject: Lisp refactoring puzzle In-Reply-To: <87mxgilh15.fsf@mithlond.arda> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: <98755cFolU1@mid.individual.net> Teemu Likonen wrote: > Please don't forget that the whole point of Lisps' (f x) syntax is that > code is also Lisp data. It's possible to design other syntaxes that have a similar property. Prolog, for example -- a Prolog program is expressed in terms of Prolog data structures, yet it manages to have things that look like fairly normal function calls and infix expressions. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 13 23:32:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jul 2011 15:32:40 +1200 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <9876asF7v0U1@mid.individual.net> Anthony Kong wrote: > So I have picked this topic for one of my presentation. It is because > functional programming technique is one of my favorite in my bag of python trick. I'm not sure it's a good idea to emphasise functional programming too much. Python doesn't really lend itself to a heavily functional style. While you *can* write Python code that way, it's not idiomatic, and you're likely to give beginners a distorted idea of how Python is normally written. -- Greg From steve+comp.lang.python at pearwood.info Thu Jul 14 00:05:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jul 2011 14:05:24 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <9876asF7v0U1@mid.individual.net> Message-ID: <4e1e6b05$0$29973$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jul 2011 01:32 pm Gregory Ewing wrote: > Anthony Kong wrote: > >> So I have picked this topic for one of my presentation. It is because >> functional programming technique is one of my favorite in my bag of >> python trick. > > I'm not sure it's a good idea to emphasise functional > programming too much. Python doesn't really lend itself > to a heavily functional style. While you *can* write > Python code that way, it's not idiomatic, and you're > likely to give beginners a distorted idea of how Python > is normally written. I think that's true for *purely* functional code, but functional idioms are very Pythonic. Iterators and generators, list comprehensions and generator expressions, itertools, using functions as first-class objects (including decorators) are all in a functional style. Python borrowed list comps from Haskell, just as it borrowed map from Lisp. If you want to claim that map is "not Pythonic", I won't get into a fight over it, but list comps certainly are! I guess it really depends on how you wish to define "functional". To my mind, even something as simple as "don't use global state, instead pass arguments to functions as needed" is a Good Trick learned from functional programming. -- Steven From nospam at torek.net Thu Jul 14 00:47:06 2011 From: nospam at torek.net (Chris Torek) Date: 14 Jul 2011 04:47:06 GMT Subject: difflib-like library supporting moved blocks detection? References: Message-ID: In article Vlastimil Brom wrote: >I'd like to ask about the availability of a text diff library, like >difflib, which would support the detection of moved text blocks. If you allow arbitrary moves, the "minimal edit distance" problem (string-to-string edit) becomes substantially harder. If you only allow insert, delete, or in-place-substitute, you have what is called the "Levenshtein distance" case. If you allow transpositions you get "Damerau-Levenshtein". These are both solveable with a dynamic programming algorithm. Once you allow move operations, though, the problem becomes NP-complete. See http://pages.cs.brandeis.edu/~shapird/publications/JDAmoves.pdf for instance. (They give an algorithm that produces "usually acceptable" results in polynomial time.) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From marco at minasithil.org Thu Jul 14 03:07:12 2011 From: marco at minasithil.org (marco) Date: Thu, 14 Jul 2011 09:07:12 +0200 Subject: [TWISTED] Howto Deferred Message-ID: Hello gals and guys, I'm an experienced Python user and I'd like to begin playing with Twisted. I started RTFM the tutorial advised on the official site and I found it really useful and well done. Now I'd like to practice a bit by coding a little program that reads strings from a serial device and redirects them remotely via TCP. For that sake I'm trying to use deferred. In the tutorial, a deferred class is instantiated at factory level, then used and destroyed. And here things get harder for me. Now, in my test program I need to manage data which comes in a "random" manner, and I thought about doing it in a few possible ways: 1. create a deferred at factory level and every time I read something from the serial port add some callbacks: class SerToTcpProtocol(Protocol): def dataReceived(self, data): # deferred is already instantiated and launched # self.factory.sendToTcp sends data to the TCP client self.factory.deferred.addCallback(self.factory.sendToTcp, data) 2. or, either, create a deferred at protocol level every time I receive something, then let the deferred do what I need and destroy it: class SerToTcpProtocol(Protocol): def dataReceived(self, data): d = defer.Deferred() d.addCallback(self.factory.sendToTcp, data) d.callback(data) 3. or again, use a deferred list: class SerToTcpProtocol(Protocol): def dataReceived(self, data): d = defer.Deferred() d.addCallback(self.factory.sendToTcp, data) self.factory.listDeferred.addCallback(lambda d) d.callback(data) Or I don't know.. hints are welcome. Thank you in advance and sorry for my english. From rosuav at gmail.com Thu Jul 14 03:57:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 17:57:41 +1000 Subject: [TWISTED] Howto Deferred In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 5:07 PM, marco wrote: > Now I'd like to practice a bit by coding a little program that reads > strings from a serial device and redirects them remotely via TCP. For > that sake I'm trying to use deferred. The obvious solution (to my mind) is two threads, one for each direction. On receipt of data, the thread immediately sends it on to the other end. I'm not familiar with deferred; it might work easily, or might need some fancy footwork to make it go. ChrisA From pavlovevidence at gmail.com Thu Jul 14 05:04:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 14 Jul 2011 02:04:01 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <427da0e8-55df-4013-a2e1-cf0bd47d5de7@glegroupsg2000goo.googlegroups.com> On Wednesday, July 13, 2011 5:39:16 AM UTC-7, Anthony Kong wrote: [snip] > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? Java is easily worst language I know of for support of functional programming (unless they added delegates or some other tacked-on type like that), so my advice would be to keep it light, for two reasons: 1. It won't take a lot to impress them 2. Too much will make them roll their eyes Thinking about it, one of the problems with demonstrating functional features is that it's not obvious how those features can simplify things. To get the benefit, you have to take a step back and redo the approach somewhat. Therefore, I'd recommend introducing these features as part of a demo on how a task in Python can be solved much more concisely than in Java. It's kind of an art to find good examples, though. Off the top of my head, I can think of using functools module to help with logging or to apply patches, whereas in Java they'd have to resort to a code weaver or lots of boilerplate. Carl Banks From tartley at tartley.com Thu Jul 14 06:31:55 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 14 Jul 2011 03:31:55 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <92cbf295-ece7-4bd1-8d65-a7ddcfbd8571@gc3g2000vbb.googlegroups.com> On Jul 13, 1:39?pm, Anthony Kong wrote: > (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) > > Hi, all, > > If you have read my previous posts to the group, you probably have some idea why I asked this question. > > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag ?of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? > > Cheers I'd think you'd want to at least mention the relatively new 'lru_cache' decorator, for memoizing the return value expensive functions, providing they are deterministic / pure, etc. From tartley at tartley.com Thu Jul 14 06:33:55 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 14 Jul 2011 03:33:55 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <9876asF7v0U1@mid.individual.net> Message-ID: On Jul 14, 4:32?am, Gregory Ewing wrote: > Anthony Kong wrote: > > So I have picked this topic for one of my presentation. It is because > > functional programming technique is one of my favorite in my bag ?of python trick. > > I'm not sure it's a good idea to emphasise functional > programming too much. Python doesn't really lend itself > to a heavily functional style. While you *can* write > Python code that way, it's not idiomatic, and you're > likely to give beginners a distorted idea of how Python > is normally written. > > -- > Greg Maybe the talk would work well if not aimed at complete all-round beginners, but instead aimed at Pythonistas who are interested in functional programming, or functionistas who are py-curious (I think the same talk would work well for both groups) From calderone.jeanpaul at gmail.com Thu Jul 14 08:21:00 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 14 Jul 2011 05:21:00 -0700 (PDT) Subject: Howto Deferred References: Message-ID: <67bb6752-2df3-4b92-9441-f5d6f0a9ab87@u28g2000yqf.googlegroups.com> On Jul 14, 3:07?am, marco wrote: > Hello gals and guys, > > I'm an experienced Python user and I'd like to begin playing with > Twisted. > I started RTFM the tutorial advised on the official site and I found it > really useful and well done. > > Now I'd like to practice a bit by coding a little program that reads > strings from a serial device and redirects them remotely via TCP. For > that sake I'm trying to use deferred. > Deferreds probably aren't a good solution for this problem. They're useful for one-time events, but you have an event that repeats over and over again with different data. > In the tutorial, a deferred class is instantiated at factory level, then > used and destroyed. > > And here things get harder for me. > Now, in my test program I need to manage data which comes in a "random" > manner, and I thought about doing it in a few possible ways: > > 1. create a deferred at factory level and every time I read something > from the serial port add some callbacks: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? # deferred is already instantiated and launched > ? ? # self.factory.sendToTcp sends data to the TCP client > ? ? self.factory.deferred.addCallback(self.factory.sendToTcp, data) > Or you could do self.factory.sendToTcp(data) > 2. or, either, create a deferred at protocol level every time I receive > something, then let the deferred do what I need and destroy it: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? d = defer.Deferred() > ? ? d.addCallback(self.factory.sendToTcp, data) > ? ? d.callback(data) > Same here. :) > 3. or again, use a deferred list: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? d = defer.Deferred() > ? ? d.addCallback(self.factory.sendToTcp, data) > ? ? self.factory.listDeferred.addCallback(lambda d) > ? ? d.callback(data) > I'm not sure what the listDeferred is there for. Deferreds are a good abstraction for "do one thing and then tell me what the result was". You have a different sort of thing here, where there isn't much of a result (sending to tcp probably always works until you lose your connection). A method call works well for that. Jean-Paul From EEllerbee at BBandT.com Thu Jul 14 09:05:05 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 09:05:05 -0400 Subject: I don't know list, I not good at list. In-Reply-To: <4E1E151A.4070006@mrabarnett.plus.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> <4E1E151A.4070006@mrabarnett.plus.com> Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859A67@clt-exmb02.bbtnet.com> Thank you all for the advice, let me spin this in a different way. I've built a program that goes to the NANPA website, scrapes area code/exchange (npa/nxx) digits for a specified area - be it carolina, alabama, texas, etc - drops it into a file, then massages the data and prints out the correct format to insert into a voice router. The code is ugly, but it works great. The thing I haven't been able to get my script to do is to reduce the amount of dial-peers. Hence the need to reduce the numbers to the least common denominator, and put it in the xxxxx[xx] format.If we had a set number of digits, we could build a dictionary(unless it's possible to do that dynamically). So, a couple assertions: 1. the data will always be 6 digit numbers (in a string format) 2. the data is in a txt file after being put there from my script 3. the data will never be the same (I'm going to use this for site conversions/new site builds e.g. today I might be dealing with 252-, 919- and 704- area codes, tomorrow might be 304- and 754- 4. I wanted a script to reduce the time taking to build the dial-peers manually. I'd previously spent 3-4 hours on gathering and processing data. The script I have so far pulls data and massages in about 6 seconds 5. I'm using python 2.7 - it seems like it had more module availability than 3 And a couple question: 1. Would lists be the best way to handle this data? Would it be better to process this data from a file? 2. Is there a way to determine the common (first-5 digits) denominator among a list (or file) of data? 3. and... Could those common numbers be inserted in a dict for processing? Sorry for the book! thanks Edward Ellerbee -----Original Message----- From: python-list-bounces+eellerbee=bbandt.com at python.org [mailto:python-list-bounces+eellerbee=bbandt.com at python.org] On Behalf Of MRAB Sent: Wednesday, July 13, 2011 5:59 PM To: python-list at python.org Subject: Re: I don't know list, I not good at list. > I've been beating my head against the desk trying to figure out a > method to accomplish this: > > Take a list (this example is 5 items, It could be 150 or more - i.e. > it's variable length depending on the city/local calling zones) > > The first 6 digits of phone numbers(NPA/NXX) in a local calling area. > I want to concatenate the last digit for insertion into a call > routing pattern. > > I tried this and failed miserably: > > list1=['252205','252246','252206','252247','252248'] > for item in list1: > try: > item1=list1[0] > item2=list1[1] > if item1[0:5] == item2[0:5]: > print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' > list1.pop(0) > else: > print item1 > list1.pop(0) > except: > try: > print item1 > list1.pop(0) > except: > pass > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list > above) in the format of > 25220[56] > 25224[678] > > I tried putting together a variable inserted into a regular > expression, and it doesn't seem to like: > Item1=list1[0] > Itemreg = re.compile(Item1[0:5]) > For stuff in itemreg.list1: > #do something > > Can somebody throw me a bone, code example or module to read on > python.org? I'm a n00b, so I'm still trying to understand functions > and classes. > > I thought the experts on this list might take pity on my pathetic > code skillz! > defaultdict comes in handy: >>> list1 = ['252205','252246','252206','252247','252248'] >>> from collections import defaultdict >>> d = defaultdict(set) >>> for item in list1: d[item[ : 5]].add(item[5 : ]) >>> d defaultdict(, {'25224': {'8', '7', '6'}, '25220': {'5', '6'}}) >>> for k, v in d.items(): print(k + "[" + "".join(v) + "]") 25224[876] 25220[56] -- http://mail.python.org/mailman/listinfo/python-list From fzadrozny at appcelerator.com Thu Jul 14 10:30:10 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Thu, 14 Jul 2011 11:30:10 -0300 Subject: PyDev 2.2.1 Released Message-ID: Hi All, PyDev 2.2.1 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Quick-outline * Parent methods may be shown with a 2nd Ctrl+O. * The initial node is selected with the current location in the file. Extract local refactoring * Option to replace duplicates. * Fixed issue where wrong grammar could be used. Others * Improved handling of Ctrl+Shift+T so that no keybinding conflict takes place (now it'll be only active on the PyDev views/editor). * PyLint markers always removed on a project clean. * If the standard library source files are not found, more options are presented. * If the completion popup is focused and shift is pressed on a context insensitive completion, a local import is done. * Fixed issue where a local import wasn't being added to the correct location. * Fixed error message in debugger when there was no caught/uncaught exception set in an empty workspace. * Performance improvements on hierarchy view. * Django commands may be deleted on dialog with backspace. What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From invalid at invalid.invalid Thu Jul 14 10:34:39 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 14 Jul 2011 14:34:39 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-13, Thorsten Kampe wrote: > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) >> On 2011-07-13, Thorsten Kampe wrote: >> >> >> and that that block is to be considered in relation to what was just >> >> said, before the colon. >> > >> > The indentation makes it abundantly clear to the human reader that >> > that indented block is to be considered in relation to what was just >> > said, before the indentation. > >> You would think so, but human readers like redundancy. > > I also like redundancy (and consistency). That's why I'd much more > prefer a "then" than a colon which is easily overlooked while reading > /and/ while writing. How is the "then" going to be consistent with other things that also introduce blocks (def, try, with, etc.). -- Grant Edwards grant.b.edwards Yow! ! I'm in a very at clever and adorable INSANE gmail.com ASYLUM!! From rosuav at gmail.com Thu Jul 14 10:38:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 00:38:32 +1000 Subject: Suppressing newline writing to file after variable In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> Message-ID: On Fri, Jul 15, 2011 at 12:04 AM, Ellerbee, Edward wrote: > Hey Chris, > > I was reading over this again, trying to understand the logic (I'm a > n00b) > > Could you explain this a bit? I'd like to build this emit function, but > I still don't have a firm grasp on functions. All of my code is line by > line. I'll convert it as a learn more. I'm responding on-list as I believe others will wish to weigh in (if only to point out some improvements to my code - it's hastily put together). Caution, post is long. Defining functions in Python is, broadly speaking, just a matter of collecting up a bunch of statements and giving it a name. Compare: if x>5: do_this() do_that() etc() with: def abcde(): do_this() do_that() etc() The first one does the three statements, in order, if and only if the condition is true. The second one gives a name to those three statements, so you can use it as a new statement: abcde() It'll do the same three things, every time you call it. It's effectively the same as putting the function's body in where you call it (that's an extremely sloppy explanation, but near enough). > So, I'd want this to go after the sort step, and before the format step. > I can figure that piece out, just trying to get this little block of > code to work. Yes, that would be the place to put it. Here's a reworked version that you can test in IDLE: def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result It incorporates some of the enhancements I mentioned in the original post. >>> combine(['252205','252206','252208'],5) ['25220[568]'] >>> combine(['252205','252215','252225'],4) ['2522[012]5'] Notice that the 'emit' function is now 'result.append()' - it builds up a list to return. You can now chain the calls; start with a list of numbers and then call combine() in a loop. # List of numbers from your previous post numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] numbers = combine(numbers,5) numbers = combine(numbers,4) numbers = combine(numbers,3) numbers = combine(numbers,2) numbers = combine(numbers,1) numbers = combine(numbers,0) If you do these statements one at a time in IDLE and inspect the 'numbers' list each time, you'll see the combinations sorting themselves out. (With this starting list, only the first two will have any effect.) The last set of calls can be turned into a for loop: for pos in range(5,-1,-1): numbers = combine(numbers,pos) In fact, you could actually take it out of being a function, if you wanted to: list_of_numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] for position in range(5,-1,-1): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) list_of_numbers = result That's what the function definition does - it takes a block of code and gives it a new name. (There's a lot more to it than that, thank you pedants I know, but in this simple example that's what it's doing.) Hope that's of use! Chris Angelico From EEllerbee at BBandT.com Thu Jul 14 10:53:23 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 10:53:23 -0400 Subject: Suppressing newline writing to file after variable In-Reply-To: References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com><77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com><77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> Holy cow, that's perfect! Thanks so much :) Would it be alright if I post my code on the list for critiquing? I'm learning python to supplement my voice engineering position - time consuming tasks that can be automated will take less time. Edward Ellerbee -----Original Message----- From: python-list-bounces+eellerbee=bbandt.com at python.org [mailto:python-list-bounces+eellerbee=bbandt.com at python.org] On Behalf Of Chris Angelico Sent: Thursday, July 14, 2011 10:39 AM To: python-list at python.org Subject: Re: Suppressing newline writing to file after variable On Fri, Jul 15, 2011 at 12:04 AM, Ellerbee, Edward wrote: > Hey Chris, > > I was reading over this again, trying to understand the logic (I'm a > n00b) > > Could you explain this a bit? I'd like to build this emit function, > but I still don't have a firm grasp on functions. All of my code is > line by line. I'll convert it as a learn more. I'm responding on-list as I believe others will wish to weigh in (if only to point out some improvements to my code - it's hastily put together). Caution, post is long. Defining functions in Python is, broadly speaking, just a matter of collecting up a bunch of statements and giving it a name. Compare: if x>5: do_this() do_that() etc() with: def abcde(): do_this() do_that() etc() The first one does the three statements, in order, if and only if the condition is true. The second one gives a name to those three statements, so you can use it as a new statement: abcde() It'll do the same three things, every time you call it. It's effectively the same as putting the function's body in where you call it (that's an extremely sloppy explanation, but near enough). > So, I'd want this to go after the sort step, and before the format step. > I can figure that piece out, just trying to get this little block of > code to work. Yes, that would be the place to put it. Here's a reworked version that you can test in IDLE: def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result It incorporates some of the enhancements I mentioned in the original post. >>> combine(['252205','252206','252208'],5) ['25220[568]'] >>> combine(['252205','252215','252225'],4) ['2522[012]5'] Notice that the 'emit' function is now 'result.append()' - it builds up a list to return. You can now chain the calls; start with a list of numbers and then call combine() in a loop. # List of numbers from your previous post numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] numbers = combine(numbers,5) numbers = combine(numbers,4) numbers = combine(numbers,3) numbers = combine(numbers,2) numbers = combine(numbers,1) numbers = combine(numbers,0) If you do these statements one at a time in IDLE and inspect the 'numbers' list each time, you'll see the combinations sorting themselves out. (With this starting list, only the first two will have any effect.) The last set of calls can be turned into a for loop: for pos in range(5,-1,-1): numbers = combine(numbers,pos) In fact, you could actually take it out of being a function, if you wanted to: list_of_numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] for position in range(5,-1,-1): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) list_of_numbers = result That's what the function definition does - it takes a block of code and gives it a new name. (There's a lot more to it than that, thank you pedants I know, but in this simple example that's what it's doing.) Hope that's of use! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list From ozric at web.de Thu Jul 14 11:00:14 2011 From: ozric at web.de (Christian) Date: Thu, 14 Jul 2011 08:00:14 -0700 (PDT) Subject: String formatting - mysql insert Message-ID: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Hi, I get some problem when i like to set the table name dynamic. I'm appreciate for any help. Christian ### works #### newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s); """ , (rs[1],rs[2])) ### works not newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES (%s, %s); """ , (table_name,rs[1],rs[2])) ### works but is not really perfect: None from rs list result in "None" instead of NULL. newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES ('%s','%s'); """ % (table_name,rs[1],rs[2])) From rosuav at gmail.com Thu Jul 14 11:03:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 01:03:14 +1000 Subject: Suppressing newline writing to file after variable In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> Message-ID: On Fri, Jul 15, 2011 at 12:53 AM, Ellerbee, Edward wrote: > Holy cow, that's perfect! > > Thanks so much :) > > Would it be alright if I post my code on the list for critiquing? I'm > learning python to supplement my voice engineering position - time > consuming tasks that can be automated will take less time. If it's not too long, sure! If it's more than can conveniently be read, post it on one of those code-sharing places like http://pastebin.com/ and post a link; then those who want to read it can do so, and those who would rather avoid it have that option too. ChrisA From wanderer at dialup4less.com Thu Jul 14 11:14:01 2011 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 14 Jul 2011 08:14:01 -0700 (PDT) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <147a626f-21e0-42f6-a939-50d0ee1e0303@g16g2000yqg.googlegroups.com> On Jul 14, 10:34?am, Grant Edwards wrote: > On 2011-07-13, Thorsten Kampe wrote: > > > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) > >> On 2011-07-13, Thorsten Kampe wrote: > > >> >> and that that block is to be considered in relation to what was just > >> >> said, before the colon. > > >> > The indentation makes it abundantly clear to the human reader that > >> > that indented block is to be considered in relation to what was just > >> > said, before the indentation. > > >> You would think so, but human readers like redundancy. > > > I also like redundancy (and consistency). That's why I'd much more > > prefer a "then" than a colon which is easily overlooked while reading > > /and/ while writing. > > How is the "then" going to be consistent with other things that also > introduce blocks (def, try, with, etc.). > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! ! ?I'm in a very > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? clever and adorable INSANE > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?ASYLUM!! But if you have the colon, why do you need the brackets or backslashes in an if statement. Why not if condition1 or condition2 or condition3: do_something() The statement ain't over til there's a colon. From rosuav at gmail.com Thu Jul 14 11:21:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 01:21:32 +1000 Subject: String formatting - mysql insert In-Reply-To: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: On Fri, Jul 15, 2011 at 1:00 AM, Christian wrote: > Hi, > > I get some problem ?when i like to set the table name dynamic. > I'm appreciate for any help. > > ### works but is not really perfect: None from rs list result in > "None" instead of NULL. > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES > ('%s','%s'); """ ?% ?(table_name,rs[1],rs[2])) I'll start with the easy one. This one is wrong for several reasons; firstly, it converts everything to strings (which is why a None comes out as 'None'), but secondly and more seriously, it cannot handle apostrophes or backslashes in your strings. SQL engines such as MySQL need strings to be properly escaped, and the execute() function will do that for you - but the % interpolation won't. > ### works not > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES ?(%s, > %s); """ , (table_name,rs[1],rs[2])) What's happening here is that the table name is being sent in apostrophes. Just as it puts quotes around your data, it also puts quotes around the table name - which you don't want. You're getting something like INSERT INTO 'foobar'_events, which MySQL doesn't like. I recommend a hybrid: newcur.execute ( ?""" INSERT INTO {0}_events (id1,id2) ? VALUES (%s,%s); """.format(table_name), (,rs[1],rs[2])) Note that I'm using the format() method rather than the % operator, specifically because it uses a different notation - {0} - and will leave the %s markers alone. This assumes that your table name is clean. If it comes from your own code, that's probably safe; but if it comes from user-supplied data, you WILL need to sanitize it (I recommend whitelisting valid characters eg letters and numbers, and keeping only those - and then imposing a length limit too) before giving it to .execute(). As far as I know, MySQL doesn't have facilities for dynamic table names, so your best bet is to make the SQL statement itself dynamic, as per this example. Hope that helps! Chris Angelico From noway at nohow.com Thu Jul 14 11:31:36 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 11:31:36 -0400 Subject: String formatting - mysql insert References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: On 07/14/2011 11:00 AM, Christian wrote: > Hi, > > I get some problem when i like to set the table name dynamic. > I'm appreciate for any help. > > Christian > > ### works #### > newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s); > """ , (rs[1],rs[2])) > > ### works not > newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES (%s, > %s); """ , (table_name,rs[1],rs[2])) > > ### works but is not really perfect: None from rs list result in > "None" instead of NULL. > newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES > ('%s','%s'); """ % (table_name,rs[1],rs[2])) You shouldn't use The bottom form at all since that is how injection attacks occur. The reason the second version doesn't work is because the the execute command escapes all of the arguments before replacing them. Example: sql = """SELECT * FROM table WHERE col = %s;""" cur.execute(sql, ('name',)) # The actual sql statement that gets executed is: # SELECT * FROM table WHERE col = 'name'; # Notice the single quotes. -- Bill From monkey at joemoney.net Thu Jul 14 13:00:07 2011 From: monkey at joemoney.net (monkeys paw) Date: Thu, 14 Jul 2011 13:00:07 -0400 Subject: How can I make a program automatically run once per day? In-Reply-To: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Message-ID: <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> On 7/9/2011 10:01 PM, John Salerno wrote: > Thanks everyone! I probably should have said something like "Python, > if possible and efficient, otherwise any other method" ! :) > > I'll look into the Task Scheduler. Thanks again! You could use the below code. time.sleep(# seconds in a day) where i == 30 would run once a day for a month import time i=0 while (1): print 'hello' time.sleep(2) # Change this to number of seconds in a day if (i == 3): # make this 30 for a month break i = i + 1 From ian.g.kelly at gmail.com Thu Jul 14 13:13:57 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2011 11:13:57 -0600 Subject: How can I make a program automatically run once per day? In-Reply-To: <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> Message-ID: On Thu, Jul 14, 2011 at 11:00 AM, monkeys paw wrote: > You could use the below code. time.sleep(# seconds in a day) > where i == 30 would run once a day for a month > > import time > i=0 > while (1): > ? ? ? ?print 'hello' > ? ? ? ?time.sleep(2) ? # Change this to number of seconds in a day > ? ? ? ?if (i == 3): ? ?# make this 30 for a month > ? ? ? ? ? ? ? ?break > ? ? ? ?i = i + 1 If the system ever gets rebooted during that month, then you would need to remember to manually restart the script. Or if the effective part of the script raises an exception, it could crash the whole script without some defensive coding. That's why it's better just to use the system scheduler service. From miki.tebeka at gmail.com Thu Jul 14 13:22:44 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 14 Jul 2011 10:22:44 -0700 (PDT) Subject: json decode issue Message-ID: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> Greetings, I'm trying to decode JSON output of a Java program (jackson) and having some issues. The cause of the problem is the following snippet: { "description": "... lives\uMOVE? OFFERS ", } Which causes ValueError: Invalid \uXXXX escape. Any ideas on how to fix this? Thanks, -- Miki From EEllerbee at BBandT.com Thu Jul 14 14:03:59 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 14:03:59 -0400 Subject: Please critique my script Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> I've been working on this for 3 weeks as a project while I'm learning python. It's ugly, only function in there is from a fellow lister, but it works perfectly and does what it is intended to do. I'd love to hear comments on how I could improve this code, what would be good to turn into a function/class etc. # The function of this script is to gather user data from the user to # build appropriate local dial-peers in a cisco voice gateway. # Data gathered from the user: # name of file to write dial-peers to # NPA # NXX # outbound port to send calls # question if home npa local calls are 7 digit # script navigates to nanpa.com, gathers the local calling area # and returns the data # the data is converted to beautiful soup (I had a problem with the xml format) # the data is parsed for the proper NPA/NXXs # list is sorted, duplicates removed # data from list is formatted and printed to the file specified #--------Import dependencies----------- import urllib2 from BeautifulSoup import BeautifulSoup import re #--------Define variables------------ count = 0 count2 = 0 count3 = 0 npalist = [] nxxlist = [] sortlist = [] sortedlist = [] npaReg = re.compile('(?<=)(...)(?=)') nxxReg = re.compile('(?<=)(...)(?=)') proxy = urllib2.ProxyHandler({'http': 'proxy.com:8080'}) # --actual proxy was removed for confidentiality-- opener = urllib2.build_opener(proxy) #----- function to concatenate numbers - thanks to Chris Angelico ----- def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result #-------Gather info from user-------- x = raw_input("please enter a filename: ") y = raw_input("please enter the npa: ") z = raw_input("please enter the nxx: ") p = raw_input("please enter the port: ") q = raw_input("Is home npa local dialing 7 digit?(y/n) ") #print x #-------Modify user data------------- o = open(x, 'w') y = str(y) z = str(z) p = str(p) pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa=" + y + "&nxx=" + z) print "Querying", pagedef #------Get info from NANPA.com ---------- urllib2.install_opener(opener) page = urllib2.urlopen(pagedef) soup = BeautifulSoup(page) soup = str(soup) #------Parse Gathered Data---------- for line in npaReg.findall(soup): npalist.insert(count,line) count = count + 1 for line2 in nxxReg.findall(soup): nxxlist.insert(count2,line2) count2 = count2 + 1 #-----Sort, remove duplicates, concatenate the last digits for similiar NPA/NXX ------ for makenewlist in range(0,count): sortlist.append(npalist.pop(0) + nxxlist.pop(0)) sortlist.sort() for sortednumber in sortlist: if sortednumber not in sortedlist: sortedlist.append(sortednumber) catlist = combine(sortedlist,5) catlist2 = combine(catlist,4) #------Print the dial-peers to file---- for line in catlist2: figureDpn = count3 + 1000 dpn = str(figureDpn) label = "dial-peer voice " + dpn o.write(label) o.write('\n') o.write("description *** local outbound dialpeer ***") o.write('\n') destpatt = "destination-pattern %s...." % line.rstrip() o.write(destpatt) o.write('\n') port = "port " + p o.write(port) o.write('\n') if line[0:3] == y and q == "y": o.write("forward-digits 7") o.write('\n') o.write('\n') count3 = count3 + 1 o.close() #------------------------------------------- Thanks! Edward Ellerbee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozric at web.de Thu Jul 14 14:10:48 2011 From: ozric at web.de (Christian) Date: Thu, 14 Jul 2011 11:10:48 -0700 (PDT) Subject: String formatting - mysql insert References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: <21c17ab7-c768-415d-9b18-606ea6066847@l28g2000yqc.googlegroups.com> On 14 Jul., 17:31, Billy Mays wrote: > On 07/14/2011 11:00 AM, Christian wrote: > > > > > > > > > > > Hi, > > > I get some problem ?when i like to set the table name dynamic. > > I'm appreciate for any help. > > > Christian > > > ### works #### > > newcur.execute ( ?""" INSERT INTO events (id1,id2) ? VALUES ?(%s,%s); > > """ , (rs[1],rs[2])) > > > ### works not > > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES ?(%s, > > %s); """ , (table_name,rs[1],rs[2])) > > > ### works but is not really perfect: None from rs list result in > > "None" instead of NULL. > > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES > > ('%s','%s'); """ ?% ?(table_name,rs[1],rs[2])) > > You shouldn't use The bottom form at all since that is how injection > attacks occur. > > The reason the second version doesn't work is because the the execute > command escapes all of the arguments before replacing them. ?Example: > > sql = """SELECT * FROM table WHERE col = %s;""" > cur.execute(sql, ('name',)) > # The actual sql statement that gets executed is: > # SELECT * FROM table WHERE col = 'name'; > # Notice the single quotes. > > -- > Bill thanks you guys! From gerald.britton at gmail.com Thu Jul 14 14:44:04 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Thu, 14 Jul 2011 14:44:04 -0400 Subject: Please critique my script Message-ID: For me, there are some things I don't like much. One-character variable names stand out (tend to make the code hard to read). Violation of PEP 8 guidelines, especially wrt spacing. e.g. result.append("%s[%s]%s" % (lastprefix, tails, lastsuffix)) not result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) Similarly for many of the assignments and expressions. I see that you initialize count3 at line 39 but don't use it until line 123. I'd suggest that you move the initialization closer to its use. I think that you should move the call to open closer to where you're going to write to the file. In fact, you can do the thing a bit neater with a context manager like this: #------Print the dial-peers to file---- with open(x, 'w') as o: for line in catlist2: figureDpn = count3 + 1000 dpn = str(figureDpn) label = "dial-peer voice " + dpn o.write(label) o.write('\n') ... Note that if you use this approach you don't need a separate call to close(). Also, you can do all the writing in one call to write(), something like this: o.write( label + '\n' + "description *** local outbound dialpeer ***" + '\n' + destpatt + '\n' + "port " + p + '\n' "forward-digits 7" if line[0:3] == y and q == "y" else "" '\n' ) Which keeps the eye focused on the data being written (at least for me). -- Gerald Britton From python at mrabarnett.plus.com Thu Jul 14 15:12:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 20:12:05 +0100 Subject: Please critique my script In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> Message-ID: <4E1F3F85.7020609@mrabarnett.plus.com> [snip] raw_input() returns a string, so there's no need for these 3 lines: > y = str(y) > z = str(z) > p = str(p) > pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa=" + y + "&nxx=" + z) > print "Querying", pagedef > > #------Get info from NANPA.com ---------- > urllib2.install_opener(opener) > page = urllib2.urlopen(pagedef) > soup = BeautifulSoup(page) > soup = str(soup) > > #------Parse Gathered Data---------- > for line in npaReg.findall(soup): > npalist.insert(count, line) > count = count + 1 > > for line2 in nxxReg.findall(soup): > nxxlist.insert(count2, line2) > count2 = count2 + 1 > enumerate will help you here: for count, line in enumerate(npaReg.findall(soup)): npalist.insert(count, line) for count2, line2 in enumerate(nxxReg.findall(soup)): nxxlist.insert(count2, line2) > #-----Sort, remove duplicates, concatenate the last digits for similiar NPA/NXX ------ > for makenewlist in range(0, count): > sortlist.append(npalist.pop(0) + nxxlist.pop(0)) > > sortlist.sort() > > for sortednumber in sortlist: > if sortednumber not in sortedlist: > sortedlist.append(sortednumber) > If you're going to sort them anyway (so you don't need to preserve the existing order), the easiest way to remove duplicates is to use a set: sortedlist = sorted(set(sortlist)) [snip] From python at mrabarnett.plus.com Thu Jul 14 15:20:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 20:20:20 +0100 Subject: json decode issue In-Reply-To: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> References: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> Message-ID: <4E1F4174.1070408@mrabarnett.plus.com> On 14/07/2011 18:22, Miki Tebeka wrote: > Greetings, > > I'm trying to decode JSON output of a Java program (jackson) and having some issues. > The cause of the problem is the following snippet: > { > "description": "... lives\uMOVE? OFFERS ", > } > Which causes ValueError: Invalid \uXXXX escape. > > Any ideas on how to fix this? > Is that valid JSON? If not, you'll either need to fix the program which generated it (or report it as a bug), or pre-process the JSON to correct the error, if you know what it should be. From noway at nohow.com Thu Jul 14 15:46:26 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 15:46:26 -0400 Subject: Possible File iteration bug Message-ID: I noticed that if a file is being continuously written to, the file generator does not notice it: def getLines(f): lines = [] for line in f: lines.append(line) return lines with open('/var/log/syslog', 'rb') as f: lines = getLines(f) # do some processing with lines # /var/log/syslog gets updated in the mean time # always returns an empty list, even though f has more data lines = getLines(f) I found a workaround by adding f.seek(0,1) directly before the last getLines() call, but is this the expected behavior? Calling f.tell() right after the first getLines() call shows that it isn't reset back to 0. Is this correct or a bug? -- Bill From ian.g.kelly at gmail.com Thu Jul 14 16:00:06 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2011 14:00:06 -0600 Subject: Possible File iteration bug In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: > def getLines(f): > ? ?lines = [] > ? ?for line in f: > ? ? ? ?lines.append(line) > ? ?return lines > > with open('/var/log/syslog', 'rb') as f: > ? ?lines = getLines(f) > ? ?# do some processing with lines > ? ?# /var/log/syslog gets updated in the mean time > > ? ?# always returns an empty list, even though f has more data > ? ?lines = getLines(f) > > > > > I found a workaround by adding f.seek(0,1) directly before the last > getLines() call, but is this the expected behavior? ?Calling f.tell() right > after the first getLines() call shows that it isn't reset back to 0. ?Is > this correct or a bug? This is expected. Part of the iterator protocol is that once an iterator raises StopIteration, it should continue to raise StopIteration on subsequent next() calls. From tjreedy at udel.edu Thu Jul 14 16:03:03 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jul 2011 16:03:03 -0400 Subject: json decode issue In-Reply-To: <4E1F4174.1070408@mrabarnett.plus.com> References: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> <4E1F4174.1070408@mrabarnett.plus.com> Message-ID: On 7/14/2011 3:20 PM, MRAB wrote: > On 14/07/2011 18:22, Miki Tebeka wrote: >> Greetings, >> >> I'm trying to decode JSON output of a Java program (jackson) and >> having some issues. >> The cause of the problem is the following snippet: >> { >> "description": "... lives\uMOVE? OFFERS ", >> } >> Which causes ValueError: Invalid \uXXXX escape. >> >> Any ideas on how to fix this? >> > Is that valid JSON? If not, you'll either need to fix the program which > generated it (or report it as a bug), or pre-process the JSON to > correct the error, if you know what it should be. If you delete or double the backslash in that one particular spot, the string will parse, even if it is not correct. -- Terry Jan Reedy From noway at nohow.com Thu Jul 14 16:15:42 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 16:15:42 -0400 Subject: Possible File iteration bug References: Message-ID: On 07/14/2011 04:00 PM, Ian Kelly wrote: > On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: >> def getLines(f): >> lines = [] >> for line in f: >> lines.append(line) >> return lines >> >> with open('/var/log/syslog', 'rb') as f: >> lines = getLines(f) >> # do some processing with lines >> # /var/log/syslog gets updated in the mean time >> >> # always returns an empty list, even though f has more data >> lines = getLines(f) >> >> >> >> >> I found a workaround by adding f.seek(0,1) directly before the last >> getLines() call, but is this the expected behavior? Calling f.tell() right >> after the first getLines() call shows that it isn't reset back to 0. Is >> this correct or a bug? > > This is expected. Part of the iterator protocol is that once an > iterator raises StopIteration, it should continue to raise > StopIteration on subsequent next() calls. Is there any way to just create a new generator that clears its `closed` status? -- Bill From hniksic at xemacs.org Thu Jul 14 16:39:52 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 14 Jul 2011 22:39:52 +0200 Subject: Possible File iteration bug References: Message-ID: <878vs0wq93.fsf@xemacs.org> Billy Mays writes: > Is there any way to just create a new generator that clears its > closed` status? You can define getLines in terms of the readline file method, which does return new data when it is available. def getLines(f): lines = [] while True: line = f.readline() if line == '': break lines.append(line) return lines or, more succinctly: def getLines(f): return list(iter(f.readline, '')) From tjreedy at udel.edu Thu Jul 14 16:43:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jul 2011 16:43:12 -0400 Subject: Possible File iteration bug In-Reply-To: References: Message-ID: On 7/14/2011 3:46 PM, Billy Mays wrote: > I noticed that if a file is being continuously written to, the file > generator does not notice it: Because it does not look, as Ian explained. > def getLines(f): > lines = [] > for line in f: > lines.append(line) > return lines This nearly duplicates .readlines, except for using f an an iterator. Try the following (untested): with open('/var/log/syslog', 'rb') as f: lines = f.readlines() # do some processing with lines # /var/log/syslog gets updated in the mean time lines = f.readlines() People regularly do things like this with readline, so it is possible. If above does not work, try (untested): def getlines(f): lines = [] while True: l = f.readline() if l: lines.append(l) else: return lines -- Terry Jan Reedy From __peter__ at web.de Thu Jul 14 16:53:36 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jul 2011 22:53:36 +0200 Subject: Please critique my script References: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> Message-ID: MRAB wrote: >> for line2 in nxxReg.findall(soup): >> nxxlist.insert(count2, line2) >> count2 = count2 + 1 >> > enumerate will help you here: > for count2, line2 in enumerate(nxxReg.findall(soup)): > nxxlist.insert(count2, line2) An insert() at the end of a list is usually spelt append() in Python ;) If you are looking for something less baroque nxxlist = nxxReg.findall(soup) will do, too. From lac at openend.se Thu Jul 14 16:59:01 2011 From: lac at openend.se (Laura Creighton) Date: Thu, 14 Jul 2011 22:59:01 +0200 Subject: PyCon Australia 2011: Schedule Announced In-Reply-To: Message from Ryan Kelly of "Thu, 14 Jul 2011 09:24:36 +1000." <1310599476.11156.13.camel@rambutan> References: <1310599476.11156.13.camel@rambutan> Message-ID: <201107142059.p6EKx1Ec031483@theraft.openend.se> Hi Ryan. Best of luck with the conference. >Thanks also to Linux Australia, who provide the overarching legal and >organisational structure for PyCon Australia. I want to talk to somebody from Linux Australia about this overarching legal and organisational structure. Do you have an email address of whom I should talk to? I think the structure that we have here in Europe could stand some refactoring, and I was talking with Stephen Thorne at Europython and what Linux Australia is doing looks very neat to me. There is nothing urgent about this, and in no way should this distract you from your conference, but sometime I would like to have an email. Thanks very much, Laura Creighton From brandon.harris at reelfx.com Thu Jul 14 18:15:40 2011 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 14 Jul 2011 17:15:40 -0500 Subject: Python threading/multiprocessing issue. Message-ID: <4E1F6A8C.30200@reelfx.com> I'm working on a tool that runs a number of process is separate thread. I've, up to this point, been using threading.Thread, but from what I read multiprocess will allow multiple processors to be used From the python docs on multiprocessing. I have run into an issue when modifying the thread object from the run method. Threading.thread allows me to change an attribute in the run method and it hold while multiprocessing.Process loses it. Here is an example illustrating the inconsistency that I've seen. ------------------------------------------------------------------------------ | import time import multiprocessing import threading def simple_process_call(): my_process = SimpleProcess() my_process.start() while not my_process.done.is_set(): pass print my_process.my_attribute class SimpleProcess(multiprocessing.Process): def __init__(self): super(SimpleProcess, self).__init__() self.my_attribute = 'Fail' self.done = multiprocessing.Event() def run(self): self.my_attribute = 'Success' time.sleep(5) self.done.set() def simple_thread_call(): my_thread = SimpleThread() my_thread.start() while not my_thread.done.is_set(): pass print my_thread.my_attribute class SimpleThread(threading.Thread): def __init__(self): super(SimpleThread, self).__init__() self.my_attribute = 'Fail' self.done = threading.Event() def run(self): self.my_attribute = 'Success' time.sleep(5) self.done.set() if __name__ == '__main__': # simple_process_call() simple_thread_call()| ------------------------------------------------------------------------------ The odd thing is that I can modify the multiprocessing.Event and it holds, but modifying any attribute on the class goes away. If I am super ignorant of something, please cure me of it. Thanks in advance! Brandon L. Harris -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Thu Jul 14 18:34:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 14 Jul 2011 15:34:50 -0700 (PDT) Subject: Multiplicity and Asininity in Tkinter Event API Message-ID: ############################################################ # Multiplicity and Asininity in Tkinter Event API! # ############################################################ The problems with Tkinter events are two fold: ------------------------------------------------------------ Problem 1: Number Of Sequences Is Obscene. ------------------------------------------------------------ The sheer number of exposed sequences and possible user combinations of sequences is overkill. You should never put the design of an API in the hands of users of said API. Designing rock solid API's is about giving users as much power as possible WITHOUT giving them too many choices. Unfortunately, not only did the authors of Tkinter give people choices, they gave them the power to create NEW choices... CRIKEY! ------------------------------------------------------------ Problem 2. No Uniform Naming Convention. ------------------------------------------------------------ The sequence names follow an intuitive naming convention. Not only that, but alias's exists for some of the combinations. Here are some examples... <1> | callback event inspection ------------------------------------------------------------ Examples Of "Possible" Sequence Combinations ------------------------------------------------------------ Bindings for a single letter: etc... Bindings for Mice:
") (delete-region p1 p2 ) (goto-char p1) (insert "
") (widen) ) ) ) ) (when (not (buffer-modified-p mybuff)) (kill-buffer mybuff) ) ) ) (require 'find-lisp) (let (outputBuffer) (setq outputBuffer "*xah img/figure replace output*" ) (with-output-to-temp-buffer outputBuffer (mapc 'my-process-file (find-lisp-find-files "~/web/xahlee_org/ emacs/" "\\.html$")) (princ "Done deal!") ) ) Seems pretty simple right? The ?p1? and ?p2? variables are the positions of start/end of
. The ?p3? and ?p4? is the start/end of it's closing tag . We also used a little trick with ?widen? and ?narrow-to-region?. It lets me see just the part that i'm interested. It narrows to the beginning/end of the div.img. This makes eye-balling a bit easier. The real time-saver is the ?sgml-skip-tag-forward? function from ?html- mode?. Without that, one'd have to write a mini-parser to deal with html's nested ways to be able to locate the proper ending tag. Using the above code, i can comfortably eye-ball and press ?y? at the rate of about 5 per second. That makes 300 replacements per minute. I have 5000+ files. If we presume there are 6k replacement to be made, then at 5 per second means 20 minutes sitting there pressing ?y?. Quite tiresome. So, now, the next step is simply to remove the asking (y-or-n-p "replace?"). Or, if i'm absolutely paranoid, i can make emacs write into a log buffer for every replacement it makes (together with the file path). When the batch replacement is done (probably under 3 minutes), i can simply scan thru the log to see if any replacement went wrong. For how to do that, see: Emacs Lisp: Multi-Pair String Replacement with Report. But what about replacing

?

with
?? I simply copy and pasted the above code into a new file, just made changes in 4 places. So, the replacing figcaption part is considered a separete batch job. Of course, one could spend extra hour or so to make the code do them both in one pass, but is that one extra hour of thinking ? coding worthwhile for this one-time job? I ? Emacs, do you? --------------------------------- PS perl and python solution welcome. I haven't looked at perl or python's html parser libs for 5+ years. Though, 2 little requirement: 1. it must be correct, of course. Cannot tolerate the possiblility that maybe one out of a thousand replacement it introduced a mismatched tag. (but you can assume that all the input html files are w3c valid) 2. it must not change the formatting of the html pages. i.e. adding/ removing spaces or tabs. Xah From nobody at nowhere.net.no Mon Jul 4 03:16:34 2011 From: nobody at nowhere.net.no (TheSaint) Date: Mon, 04 Jul 2011 15:16:34 +0800 Subject: Problem!! References: <4e10ff9b$0$21805$e4fe514c@news2.news.xs4all.nl> Message-ID: Irmen de Jong wrote: > No, I misplaced my crystal ball. I'm waiting mine, brand new in HD :D, with remote control :D :D -- goto /dev/null From greg.ewing at canterbury.ac.nz Mon Jul 4 03:36:54 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 19:36:54 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> Message-ID: <97d8spFg2nU1@mid.individual.net> rantingrick wrote: > I agree however i see merit in both approaches. But why must we have > completely different languages just for that those two approaches? We have different languages because different people have different ideas about what a language should be like. Ruby people like user defined control structures; Python people regard user defined control structures as an anti-feature. It's fundamentally impossible for one language to satisfy both sets of people. -- Greg From greg.ewing at canterbury.ac.nz Mon Jul 4 04:22:37 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:22:37 +1200 Subject: Why won't this decorator work? In-Reply-To: References: <8b8c3ca2-ae36-4009-842e-1dc90fb01b65@ct4g2000vbb.googlegroups.com> <98cca0c2-8d4f-4313-abed-3f34fa165c6d@u28g2000yqf.googlegroups.com> Message-ID: <97dbigF4d1U1@mid.individual.net> OKB (not okblacke) wrote: > A decorator basically modifies a function/method, so that ALL > subsequent calls to it will behave differently. Furthermore, usually a decorator is used when for some reason you *can't* achieve the same effect with code inside the function itself. For example, the classmethod() and staticmethod() decorators return descriptors that have different magical effects from a standard function object when looked up in a class or instance. Since that magic happens *before* the function is called, you can't do the same thing using an ordinary function. In this case, an ordinary function is quite sufficient, and there is no need to involve a decorator. -- Greg From hv at tbz-pariv.de Mon Jul 4 04:31:35 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 04 Jul 2011 10:31:35 +0200 Subject: HeaderParseError Message-ID: <97dc37F7gaU1@mid.individual.net> Hi, I get a HeaderParseError during decode_header(), but Thunderbird can display the name. >>> from email.header import decode_header >>> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header raise HeaderParseError email.errors.HeaderParseError How can I parse this in Python? Thomas Same question on Stackoverflow: http://stackoverflow.com/questions/6568596/headerparseerror-in-python -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From greg.ewing at canterbury.ac.nz Mon Jul 4 04:33:52 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:33:52 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: References: Message-ID: <97dc7iF9eiU1@mid.individual.net> rantingrick wrote: > Unlike most GUI libraries the Tkinter developers thought is would > "just wonderful" if the root GUI window just sprang into existence if > the programmer "somehow" forgot to create one. IMO the real problem here is the existence of a privileged "root" window at all. No GUI platform I know of has any such concept (except for a "desktop" window that represents the whole screen, which is not the same thing). All top-level windows should have equal status. -- Greg From greg.ewing at canterbury.ac.nz Mon Jul 4 04:43:35 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:43:35 +1200 Subject: Virtual functions are virtually invisible! In-Reply-To: References: Message-ID: <97dcpqFdndU1@mid.individual.net> rantingrick wrote: > what concerns me is the fact that virtual methods in derived > classes just blend in to the crowd. > I think we really need some > sort of visual cue in the form of forced syntactical notation (just > like the special method underscores). If you're suggesting that it should be impossible to override a method unless it is specially marked somehow in the base class, I think that would be a bad idea. One of the principles behind the design of Eiffel is that classes should *always* be open to modification in any way by a subclass. The reason is that the author of a class library can't anticipate all the ways people might want to use it. Consequently Eiffel has no equivalent of C++'s "private" declaration -- everything is at most "protected". It also has no equivalent of Java's "final". I like the fact that Python doesn't have these either. -- Greg From rosuav at gmail.com Mon Jul 4 04:44:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2011 18:44:48 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <97dc7iF9eiU1@mid.individual.net> References: <97dc7iF9eiU1@mid.individual.net> Message-ID: On Mon, Jul 4, 2011 at 6:33 PM, Gregory Ewing wrote: > rantingrick wrote: > >> Unlike most GUI libraries the Tkinter developers thought is would >> "just wonderful" if the root GUI window just sprang into existence if >> the programmer "somehow" forgot to create one. > > IMO the real problem here is the existence of a privileged > "root" window at all. No GUI platform I know of has any > such concept (except for a "desktop" window that represents > the whole screen, which is not the same thing). All top-level > windows should have equal status. I don't know Tkinter, but from the look of the example code, he's creating a Label that's not attached to a window, and then packing it into nothing. The toolkit kindly creates him a window. Is that the "root GUI window" that he means? A basic top-level window? Chris Angelico From greg.ewing at canterbury.ac.nz Mon Jul 4 04:48:16 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Jul 2011 20:48:16 +1200 Subject: Problem!! In-Reply-To: References: <4e10ff9b$0$21805$e4fe514c@news2.news.xs4all.nl> Message-ID: <97dd2jFfs7U1@mid.individual.net> TheSaint wrote: > On 4-7-2011 1:41, amir chaouki wrote: > >> No, I misplaced my crystal ball. > > I'm waiting mine, brand new in HD :D, with remote control :D :D The new digital models are great. But there's a distressing tendency for visions to come with DRM protection these days, so you can only share them with at most 5 other users. :-( -- Greg From fetchinson at googlemail.com Mon Jul 4 04:59:19 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 4 Jul 2011 10:59:19 +0200 Subject: web hosting, first hand experiences? In-Reply-To: <4E10E5BD.6050502@googlemail.com> References: <4E10E5BD.6050502@googlemail.com> Message-ID: >> Hi folks, I know this comes up regularly but the thing is that the >> quality of service changes also quite regularly with many of the >> hosting companies. What's currently the best option for shared hosting >> of a turbogears application? I'm thinking of dreamhost and webfaction >> does anyone have any recent experiences with these two? Or others? >> >> Cheers, >> Daniel >> > > Hi Daniel, > > I can wholeheartedly recommend WebFaction. I currently have an account > running 3 different CherryPy applications (so TurboGears shouldn't pose > any problems), and apart from initial teething problems, they have been > running for months without interruption. As well as an excellent > control panel, they give you full Linux command-line access to your > site(s). The level of support is as good as you will get anywhere > (short of having experts with you in the office!), and they know a huge > amount about Python web applications. Nothing seems to be too much > trouble for them. They also provide a 60-day money-back guarantee, so > you can try-before-you-buy. > > Best wishes, > Alan Harris-Reid Thanks for all the responses, based on the feedback I'll go with webfaction I guess. They were my first choice anyway but wanted to double check with people in the know about their current situation. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From __peter__ at web.de Mon Jul 4 05:51:41 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jul 2011 11:51:41 +0200 Subject: HeaderParseError References: <97dc37F7gaU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > I get a HeaderParseError during decode_header(), but Thunderbird can > display the name. > >>>> from email.header import decode_header >>>> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header > raise HeaderParseError > email.errors.HeaderParseError > > > How can I parse this in Python? Trying to decode as much as possible: >>> s = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>> for n in range(len(s), 0, -1): ... try: t = s[:n].decode("base64") ... except: pass ... else: break ... >>> n, t (49, 'Anmeldung Netzanschluss S\x19\x1c\x9a[\x99\xcc\xdc\x0b\x9a\x9c\x19') >>> print t.decode("iso-8859-1") Anmeldung Netzanschluss S[?? >>> s[n:] 'w==?=' The characters after "...Netzanschluss " look like garbage. What does Thunderbird display? From swavijay at gmail.com Mon Jul 4 06:06:14 2011 From: swavijay at gmail.com (vijay swaminathan) Date: Mon, 4 Jul 2011 15:36:14 +0530 Subject: Sending email in python Message-ID: Hi All, I read through the smtplib and email modules of python and have come up with a simple program to send a email as an attachment. This module sends out an email but not as an attachment but in the body of the email. Any problem with this code? any insight would be greatly appreciated. import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText testfile = 'test.txt' msg = MIMEMultipart() msg['Subject'] = 'Email with Attachment' msg['From'] = 'swavijay at gmail.com' msg['To'] = 'swavijay at gmail.com' with open(testfile,'rb') as f: # Open the files in binary mode. Let the MIMEImage class automatically # guess the specific image type. img = MIMEText(f.read()) f.close() msg.attach(img) try: s = smtplib.SMTP('localhost') s.sendmail(msg['From'],[msg['To']],msg.as_string()) print 'Email with attachment sent successfully' s.quit() except: print 'Email with attachment could not be sent !!' -- Vijay Swaminathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hv at tbz-pariv.de Mon Jul 4 06:38:39 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 04 Jul 2011 12:38:39 +0200 Subject: HeaderParseError In-Reply-To: References: <97dc37F7gaU1@mid.individual.net> Message-ID: <97djhfF10kU1@mid.individual.net> On 04.07.2011 11:51, Peter Otten wrote: > Thomas Guettler wrote: > >> I get a HeaderParseError during decode_header(), but Thunderbird can >> display the name. >> >>>>> from email.header import decode_header >>>>> > decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header >> raise HeaderParseError >> email.errors.HeaderParseError >> >> >> How can I parse this in Python? > > Trying to decode as much as possible: > >>>> s = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>>> for n in range(len(s), 0, -1): > ... try: t = s[:n].decode("base64") > ... except: pass > ... else: break > ... >>>> n, t > (49, 'Anmeldung Netzanschluss S\x19\x1c\x9a[\x99\xcc\xdc\x0b\x9a\x9c\x19') >>>> print t.decode("iso-8859-1") > Anmeldung Netzanschluss S[?? > >>>> s[n:] > 'w==?=' > > The characters after "...Netzanschluss " look like garbage. What does > Thunderbird display? Hi Peter, Thunderbird shows this: Anmeldung Netzanschluss S?dring3p.jpg Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From __peter__ at web.de Mon Jul 4 07:20:42 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jul 2011 13:20:42 +0200 Subject: HeaderParseError References: <97dc37F7gaU1@mid.individual.net> <97djhfF10kU1@mid.individual.net> Message-ID: Thomas Guettler wrote: > On 04.07.2011 11:51, Peter Otten wrote: >> Thomas Guettler wrote: >> >>> I get a HeaderParseError during decode_header(), but Thunderbird can >>> display the name. >>> >>>>>> from email.header import decode_header >>>>>> >> decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=') >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "/usr/lib64/python2.6/email/header.py", line 101, in >>> decode_header >>> raise HeaderParseError >>> email.errors.HeaderParseError >> The characters after "...Netzanschluss " look like garbage. What does >> Thunderbird display? > > Hi Peter, Thunderbird shows this: > > Anmeldung Netzanschluss S?dring3p.jpg >>> a = u"Anmeldung Netzanschluss S?dring3p.jpg".encode("iso-8859-1").encode("base64") >>> b = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=" >>> for i, (x, y) in enumerate(zip(a, b)): ... if x != y: print i, x, y ... 33 / _ 52 ? >>> b.decode("base64") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/encodings/base64_codec.py", line 42, in base64_decode output = base64.decodestring(input) File "/usr/lib/python2.6/base64.py", line 321, in decodestring return binascii.a2b_base64(s) binascii.Error: Incorrect padding >>> b.replace("_", "/").decode("base64") 'Anmeldung Netzanschluss S\xfcdring3p.jpg' Looks like you encountered a variant of base64 that uses "_" instead of "/" for chr(63). The wikipedia page http://en.wikipedia.org/wiki/Base64 calls that base64url. You could try and make the email package accept that with a monkey patch like the following: #untested import binascii def a2b_base64(s): return binascii.a2b_base64(s.replace("_", "/")) from email import base64mime base64mime.a2b_base64 = a2b_base64 Alternatively monkey-patch the binascii module before you import the email package. From k.sahithi2862 at gmail.com Mon Jul 4 08:38:03 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Mon, 4 Jul 2011 05:38:03 -0700 (PDT) Subject: ONLY FOR MEN` Message-ID: <3ec7c780-7243-4fe5-a6fb-009347f05ab0@q14g2000prh.googlegroups.com> FOR FAST UPDATED IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com/ PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html TAPSEE SISTER HOT STILLS FOR U http://allyouwants.blogspot.com/2011/06/tapsee-sister-shagun-pannu-hot-photo.html NAMITHA LATEST HOT PHOTO STILLS http://allyouwants.blogspot.com/2011/06/namithas-latest-stills-from-her.html FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html From rantingrick at gmail.com Mon Jul 4 11:19:40 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:19:40 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> Message-ID: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> On Jul 4, 3:33?am, Gregory Ewing wrote: > IMO the real problem here is the existence of a privileged > "root" window at all. No GUI platform I know of has any > such concept (except for a "desktop" window that represents > the whole screen, which is not the same thing). All top-level > windows should have equal status. I dunno, it's natural to create a parent-child hierarchy when GUI programming with any library. So i am not completely sure what you are implying here? When you close the main application widow you would expect all child windows to close. Or likewise when you iconify the main window you would expect the other windows to do the same. Sure you could do this yourself by sending messages to all the other windows but Tkinter does this for you automatically. And how does Tkinter know which windows to configure? A parent-child relationship that's how. >>> a = set(dir(Tkinter.Toplevel)) >>> b = set(dir(Tkinter.Tk)) >>> len(a), len(b) (222, 226) >>> a.difference(b) set(['_setup', '_do']) You say "root" windows are bad however any parent-child relationship has to BEGIN somewhere. For Tkinter the beginning of this dynasty is an instance of the Tkinter.Tk[1] window from which all other windows and widgets are made children. HOWEVER any of the windows ARE in fact instances of Tk.Toplevel[1]. So they ARE all equal because they all have the same methods available to them. >>> import Tkinter >>> Tkinter.Tk.__doc__ 'Toplevel widget of Tk which represents mostly the main window\n of an appliation. It has an associated Tcl interpreter.' >>> import inspect >>> inspect.getmro(Tkinter.Tk) (, , ) >>> inspect.getmro(Tkinter.Toplevel) (, , , ) But let's dig a little deeper here. Your comment suggests that you "personally" need to create multiple windows for your applications. Is this correct? If so i pity any users of such application as they would be thoroughly confused. Most applications consist of one main window (a Tkinter.Tk instance). The only need for extra Toplevel windows is in the form of modal dialogs (use tkSimpleDialog.Dialog) or tool windows (use Tk.Toplevel with attribute '-toolwindow'=True). I don't see how your statements carry any weight here. Could you explain please? [1] http://effbot.org/tkinterbook/tkinter-application-windows.htm [2] http://effbot.org/tkinterbook/toplevel.htm From rantingrick at gmail.com Mon Jul 4 11:29:31 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:29:31 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> Message-ID: On Jul 4, 3:44?am, Chris Angelico wrote: > I don't know Tkinter, but from the look of the example code, he's > creating a Label that's not attached to a window, and then packing it > into nothing. The toolkit kindly creates him a window. Is that the > "root GUI window" that he means? A basic top-level window? Yes. But to be specific the "root" is an instance of Tkinter.Tk which is a toplevel that has a TCL interpreter attached. From robin at reportlab.com Mon Jul 4 11:35:22 2011 From: robin at reportlab.com (Robin Becker) Date: Mon, 04 Jul 2011 16:35:22 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: References: Message-ID: <4E11DDBA.7020201@chamonix.reportlab.co.uk> On 03/07/2011 23:21, Chris Angelico wrote: ......... > > var(0x14205359) x # Don't forget to provide an address where the > object will be located > x=42 ........ did you forget to specify the memory bank and computer (and presumably planet etc etc....) -molly-coddled-ly yrs- Robin Becker From rosuav at gmail.com Mon Jul 4 11:40:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 01:40:02 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 1:19 AM, rantingrick wrote: > But let's dig a little deeper here. Your comment suggests that you > "personally" need to create multiple windows for your applications. Is > this correct? If so i pity any users of such application as they would > be thoroughly confused. Most applications consist of one main window > (a Tkinter.Tk instance). The only need for extra Toplevel windows is > in the form of modal dialogs (use tkSimpleDialog.Dialog) or tool > windows (use Tk.Toplevel with attribute '-toolwindow'=True). Uhh, sorry. No. There are plenty of good reasons for one application to make multiple top-level windows, and if I ever find myself using a toolkit that makes this difficult, I'll either be hacking the toolkit or using a different one. I've been building GUI applications for far too long to not want features like that. ChrisA From rantingrick at gmail.com Mon Jul 4 11:45:35 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:45:35 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: oops. should have used symmetric_difference! >>> a.symmetric_difference(b) set(['_w', '_setup', 'report_callback_exception', '_do', '__getattr__', 'loadtk', '_loadtk', 'readprofile']) From rantingrick at gmail.com Mon Jul 4 11:46:27 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 08:46:27 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Jul 4, 10:40?am, Chris Angelico wrote: > Uhh, sorry. No. There are plenty of good reasons for one application > to make multiple top-level windows, and if I ever find myself using a > toolkit that makes this difficult, I'll either be hacking the toolkit > or using a different one. I've been building GUI applications for far > too long to not want features like that. And those reasons are...? From rosuav at gmail.com Mon Jul 4 12:01:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 02:01:49 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 1:46 AM, rantingrick wrote: > On Jul 4, 10:40?am, Chris Angelico wrote: > >> Uhh, sorry. No. There are plenty of good reasons for one application >> to make multiple top-level windows, and if I ever find myself using a >> toolkit that makes this difficult, I'll either be hacking the toolkit >> or using a different one. I've been building GUI applications for far >> too long to not want features like that. > > And those reasons are...? As varied as the applications that call on them. One example that springs to mind: Our database front end has "table view" and "record view", where you get one table view and from that you can view as many records as you like. Users may choose to effectively switch from one view to the other, or they may open up two or more record views and have them and the table view all on screen simultaneously. This is not a modal dialog; it's not even a modeless dialog - it's a completely stand-alone window that can be moved around the Z order independently of the parent. There's a definite ownership based on process, though; terminate the process (by closing the table view) and it must close all record views first. I've done other applications where this has not been the case - where all top-level windows are truly equal - but not in this instance. As an aside, that particular program is one that we are currently using (I glance over and can see it running on one of our terminals here), and the interface has not changed since about 2002 (actually earlier - 2002 had a major code rewrite without much UI change). Multiple top-level windows fulfills the Law of Least Astonishment admirably, and has done so for a decade. Chris Angelico From rantingrick at gmail.com Mon Jul 4 12:35:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 09:35:13 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> Message-ID: <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> On Jul 4, 12:06?am, alex23 wrote: > rantingrick wrote: > > But why must we have > > completely different languages just for that those two approaches? > > Because monocultures die. That's an interesting statement Alex (even though you parrot it constantly). So what IS a mono culture exactly? Lemme see... """A single, homogeneous culture without diversity or dissension. """ Interesting. Would you consider the Python community to be a monoculture? We are working towards a singular goal so i would say so. We should be working towards the language that is best for all but instead we are working towards the language that is best for US. How about the Ruby community? Here's a good one; How about the programming community? These groups would ALL classify as monocultures Alex. So why are they NOT dying? Well maybe they are and you just cannot see past your own nose (it does get fairly long from time to time you know). I believe (unlike most people) that nature is striving for perfection NOT for diversity. Diversity is just a byproduct of feeble attempts to GUESS the correct answer. Here is a thought exercise for the advanced reader...Which is more efficient; Numerous groups working to create languages that satisfy their selfish needs OR one group of all the bright minds working to destroy multiplicity and bring about the one true language that meets the needs of productivity? In order to achieve perfection we must propagate unity within the system and we must destroy multiplicity with a vengeance. We must unite to defeat multiplicity and in doing so we create innovation. That is the job of intelligent agents, to BRING ORDER TO THE NATURAL CHAOS OF THIS UNIVERSE! Your natural instincts are of propagating diversity (read as selfishness) HOWEVER the future exists only in unity. What do you think will be the eventual outcome of the human existence Alex? Since you have no imagination i will tell you, a singular intelligence. However an intelligence that is the product of many "intelligent agents". A unity intelligence if you will. Just think of it as a botnet alex, i am sure you have plenty of experience in this area! > Because having broader diversity leads to more evolutionary leaps. Do you think that if we combine all the worthwhile attributes of the high level languages that somehow everyone is just going to accept that forever? No, of course not. HOWEVER instead of splitting off into sects (and damaging our hive mind capabilities) we need to focus our efforts on one goal... CREATING THE BEST LANGUAGE WE CAN AT ANY ONE TIME IN HISTORY... and we will all learn TOGETHER not APART. Diversity only propagates multiplicity and slows our evolution Alex. It is selflessness on a grand scale. > Because the implementations are so fundamentally different. In the big picture that's untrue. Between say Ruby and Python you a few LARGE differences and many SMALL differences (and even some replication). I propose that we combine the Ruby and Python languages using all the best ideas, however dropping the multiplicity. > Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > different implementations. Why can they not explore within the hive mind? Why must they hide their explorations from the greater group. SELFISHNESS Here is another thought exercise for the advanced reader. Remember in the old days when furniture was crafted by hand? Not only was the furniture EXPENSIVE it was also scarce to come by. Why was this the case. Because human nature is to be selfish. And our selfishness slows evolution. But one day some very intelligent chap realized that he could build furniture not only faster but cheaper by using the assembly line. Now we have furniture stores on practically every corner at prices almost anyone can afford. Yes i realize "some" of the products are not of good quality but that is a result of economics (and greed) not unity. > Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > different syntax & semantics. We should have nailed down syntax and semantics long ago alex! This should have been step one. No instead we have groupA, groupB, and groupC still fighting about what is best for their selfish needs without concerning themselves wit the big picture. It's not what is best for ME, NO, it's what is best for US. * What syntax is most widely intuitive? * What semantics are the best for productivity? * etc... > Because learning different approaches expands your appreciation of & > informs your understanding of both. Yes, and i agree. But instead of learning in small groups we need to learn together. Of course we are going to make mistakes along the way. Heck we may even have to re write the whole spec a time or two. But i would argue that the chances of making mistakes decrease as the number of agents increase. I dunno, have you ever heard of a little thing called Open Source Software. Where people from all over the world maintain a piece of software. AMAZING HUH? Just imagine if we combined all the best people from all the current languages. There is your diversity Alex, however sadly, you have no imagination to see it. From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Jul 4 12:37:22 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Mon, 4 Jul 2011 16:37:22 +0000 (UTC) Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: John Salerno wrote: > On Jul 3, 1:06?pm, "OKB (not okblacke)" > wrote: > >> > Yeah, I considered that, but I just hate the way it looks when the >> > line wraps around to the left margin. I wanted to line it all up >> > under the opening quotation mark. The wrapping may not be as much >> > of an issue when assigning a variable like this, but I especially >> > don't like triple-quoted strings that wrap around inside function >> > definitions. That seems to completely throw off the indentation. Do >> > people still use triple-quotes in that situation? >> >> ? ? ? ? I do, because I use an editor that intelligently indents >> wrapped text to the same indent level as the beginning of the line, >> instead of wrapping it all the way back to the margin. > > But isn't wrapped text something different than text that is purposely > split across multiple lines with a newline character? That's usually > the case when I need to split up a long string. Well, what I'm saying is I use an editor that lets me make the lines as long as I want, and it still wraps them right, so I never explicitly hit enter to break a line except at the end of a string (or paragraph). -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From rantingrick at gmail.com Mon Jul 4 13:09:25 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 10:09:25 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Jul 4, 11:01?am, Chris Angelico wrote: > On Tue, Jul 5, 2011 at 1:46 AM, rantingrick wrote: > > On Jul 4, 10:40?am, Chris Angelico wrote: > > >> Uhh, sorry. No. There are plenty of good reasons for one application > >> to make multiple top-level windows, and if I ever find myself using a > >> toolkit that makes this difficult, I'll either be hacking the toolkit > >> or using a different one. I've been building GUI applications for far > >> too long to not want features like that. > > > And those reasons are...? > > As varied as the applications that call on them. One example that > springs to mind: Our database front end has "table view" and "record > view", where you get one table view and from that you can view as many > records as you like. Users may choose to effectively switch from one > view to the other, or they may open up two or more record views and > have them and the table view all on screen simultaneously. > This is not > a modal dialog; it's not even a modeless dialog - it's a completely > stand-alone window that can be moved around the Z order independently > of the parent. You can do the exact same thing with Tkinter's windows. > There's a definite ownership based on process, though; > terminate the process (by closing the table view) and it must close > all record views first. I've done other applications where this has > not been the case - where all top-level windows are truly equal - but > not in this instance. Tkinters Toplevels ARE equal! However in this case you should spawn a new instance of the application "opened" at that particular table view. It's as simple as a few command line arguments in your script. It's like a text editor, you never want a "New" command that resets the current document or an open command that resets the current document and loads the file into the existing editor. Each application instance should only create one document and stick with it until it is closed. Instead you want to spawn a new instance of the editor and tell the editor (via command line arguments) to load file data (if applicable). Simple command line arguments (of which you should be using anyway) are the key here. All part of proper software design. From rosuav at gmail.com Mon Jul 4 13:19:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:19:24 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 2:35 AM, rantingrick wrote: > I believe (unlike most people) that nature is striving for perfection > NOT for diversity. Diversity is just a byproduct of feeble attempts to > GUESS the correct answer. Here is a thought exercise for the advanced > reader...Which is more efficient; Numerous groups working to create > languages that satisfy their selfish needs OR one group of all the > bright minds working to destroy multiplicity and bring about the one > true language that meets the needs of productivity? You assume that there is one right answer. I'm not sure whether this is provably wrong or just utterly unfounded, but I see no reason to believe that it is so. > In order to achieve perfection we must propagate unity within the > system and we must destroy multiplicity with a vengeance. We must > unite to defeat multiplicity and in doing so we create innovation. > That is the job of intelligent agents, to BRING ORDER TO THE NATURAL > CHAOS OF THIS UNIVERSE! You join a long line of Lawful Evil villains who have made that statement. Look at such as Darth Vader, is that your goal? Bringing order to the universe even if it means choking it to death? Yes, humans will tend to bring orderliness to what used to be chaotic. But this cannot be the ultimate goal; order is but a means to an end. What end? What IS the end of programming? Is it not productivity? > What do you think will be the eventual outcome of the human existence > Alex? Since you have no imagination i will tell you, a singular > intelligence. However an intelligence that is the product of many > "intelligent agents". A unity intelligence if you will. Just think of > it as a botnet alex, i am sure you have plenty of experience in this > area! Thanks. Mind if I borrow your crystal ball for a moment? Seems to be a good one, since you can see *with certainty* the eventual outcome of all humans. I can't help thinking, though, that you're aligning yourself with villains again - in this case the Borg. > Do you think that if we combine all the worthwhile attributes of the > high level languages that somehow everyone is just going to accept > that forever? No, of course not. HOWEVER instead of splitting off into > sects (and damaging our hive mind capabilities) we need to focus our > efforts on one goal... CREATING THE BEST LANGUAGE WE CAN AT ANY ONE > TIME IN HISTORY... and we will all learn TOGETHER not APART. Diversity > only propagates multiplicity and slows our evolution Alex. It is > selflessness on a grand scale. Once again, you assume that there is one ultimate language, just waiting to be discovered/developed. One language which will be perfect in every way, for every purpose. > Why can they not explore within the hive mind? Why must they hide > their explorations from the greater group. SELFISHNESS If they explore anything that the whole hive isn't doing, they're making that disagreement again. Suppose we had that one language that I described earlier - the "clean slate representation" (CSR, but that's just syntactic sugar - if you'll pardon the awful pun) one where the only thing you have is "define operator". We then, as a single unified collective hive mind unity, develop a Standard Library for this language. Putting "#include std" or "import std" or whatever at the top of your code gives you a fairly normal set of things you can do. Well and good; we all use the same language. As soon as anyone explores anything within that language that hasn't yet been done, he has created a new dialect - a new language, if you will. It's right back with what you are ripping on, except that we now call it the same language. > We should have nailed down syntax and semantics long ago alex! This > should have been step one. No instead we have groupA, groupB, and > groupC still fighting about what is best for their selfish needs > without concerning themselves wit the big picture. It's not what is > best for ME, NO, it's what is best for US. Actually no. It's still about what's best for ME. I can't think of what would be best for you - you're the best one to think about that. Open source actually encourages and allows selfishness in ways that are far too awkward else; groupA can code to groupA's needs, then groupB adds code to that to make it do what groupB needs, and offers their enhancements back to the world, meaning that groupC need only code what groupC needs. > ?* What syntax is most widely intuitive? > ?* What semantics are the best for productivity? > ?* etc... These are subjective questions. I happen to be able to work very well with a bracey language, but other people can't. To me, Pike was incredibly intuitive, because it has so many similarities to languages I already know. To someone who knows only lisp, that would not be the case. Incidentally, your questions cross-multiply too: What semantics are more intuitive, and what syntax is best for productivity? Four good questions. > Yes, and i agree. But instead of learning in small groups we need to > learn together. Do you mean literally? Huge classrooms good, individual/small-group learning bad? That's provably empirically wrong. But if not that, then what? > Of course we are going to make mistakes along the way. > Heck we may even have to re write the whole spec a time or two. Yep, and code will be written for older versions of the spec. The way you're talking, it'd likely be a LOT more than Py2 vs Py3, with lots of installations and lots of programmers preferring to stick to the old language. Or are you planning to somehow force everyone to upgrade to the latest? > But i > would argue that the chances of making mistakes decrease as the number > of agents increase. I dunno, have you ever heard of a little thing > called Open Source Software. Where people from all over the world > maintain a piece of software. AMAZING HUH? Just imagine if we combined > all the best people from all the current languages. There is your > diversity Alex, however sadly, you have no imagination to see it. I'd say all the best people for Language X are already there. And all the best people for Language Y are already _there_. There's a lot of people who would be good in multiple communities, and guess what? They're already IN multiple communities. These things have a way of sorting themselves out. There cannot be one perfect language for everything, unless that language is so flexible that it is nothing. I retract my earlier statement that the "universal language" is C; no, it goes back further. The universal language is a text editor where you write your source code. You then run it through the universal compiler called "make", which figures out what to do with your source. You then run it on the universal hardware... oh. Well, make can figure out the hardware too, so we'll pretend it's universal. Is this one language? At work, I have SciTE holding several files in separate tabs - they might be C++, Python, Lua, Javascript, Pike, the Makefile, and a plain text file where I keep my notes. SciTE edits all of them (although it's less intelligent with the languages it doesn't know). In any of them, I can hit F7 to compile the current file and deploy it to my test-box. Does that mean they're all one language? Different languages have different purposes. As I found out recently, trying to use Python in a situation where you need to sandbox user-supplied code is a bad idea; I ended up with a p0wned test-box and a lot of egg on my face, and it's only because the Python community is intelligent adults that we didn't have some rather nasty consequences. (That box failed the test, but it was an incredibly successful test. We learned the painful truth that we needed to hear.) Has anyone ever used a very-high-level language (like Python or Ruby or Lua) to write, say, a video driver? There is a place for the languages that take most of the work away from the programmer, and a place for languages that basically give you the hardware and say "have fun". There will never be a universal language that does both jobs perfectly. *returns the crystal ball* Chris Angelico From rosuav at gmail.com Mon Jul 4 13:21:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:21:08 +1000 Subject: Anyone want to critique this program? In-Reply-To: References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 2:37 AM, OKB (not okblacke) wrote: > ? ? ? ?Well, what I'm saying is I use an editor that lets me make the > lines as long as I want, and it still wraps them right, so I never > explicitly hit enter to break a line except at the end of a string (or > paragraph). In this instance, I believe the OP was paragraphing his text. Is there a convenient way to do that in a triple-quoted string? My personal inclination would be to simply back-tab it. It looks ugly, but at least it works, and doesn't require a run-time re-parse. The run-time translation is good for docstrings, though (which are syntactically the same thing as this situation). ChrisA From liu.liuwei.wei at gmail.com Mon Jul 4 13:33:31 2011 From: liu.liuwei.wei at gmail.com (=?GB2312?B?s8m2vMbf1tAyMDAyvLY3sOBftPO80ra8ysfM7LLFoas=?=) Date: Mon, 4 Jul 2011 10:33:31 -0700 (PDT) Subject: i have configured proxy but fiddler can't capture python's network requests Message-ID: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> here's my code. I've change the port from 8888 to 1111. import urllib2 proxy_support = urllib2.ProxyHandler({'http':'http://127.0.0.1:1111'}) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) urllib2.install_opener(opener) content = urllib2.urlopen('http://www.google.com').read() print content The weird thing is: 1. If I close fiddler, python throws error when running Traceback (most recent call last): File "C:\Users\Micky\test.py", line 5, in content = urllib2.urlopen('http://www.google.com').read() File "D:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "D:\Python27\lib\urllib2.py", line 394, in open response = self._open(req, data) File "D:\Python27\lib\urllib2.py", line 412, in _open '_open', req) File "D:\Python27\lib\urllib2.py", line 372, in _call_chain result = func(*args) File "D:\Python27\lib\urllib2.py", line 1199, in http_open return self.do_open(httplib.HTTPConnection, req) File "D:\Python27\lib\urllib2.py", line 1174, in do_open raise URLError(err) URLError: 2. If I open fiddler, everything works great. But I can't see the traffic in fiddler. And if I change port from 1111 to any other number, it works find too. Any clues? From rosuav at gmail.com Mon Jul 4 13:41:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:41:44 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 3:09 AM, rantingrick wrote: > On Jul 4, 11:01?am, Chris Angelico wrote: >> This is not >> a modal dialog; it's not even a modeless dialog - it's a completely >> stand-alone window that can be moved around the Z order independently >> of the parent. > > You can do the exact same thing with Tkinter's windows. I didn't say Tkinter couldn't do this; I said that it was a good thing to be able to do, which you earlier decried. > However in this case you should spawn a new instance of the > application "opened" at that particular table view. It's as simple as > a few command line arguments in your script. No! Definitely not. Initializing the application includes logging in to the database. Suppose the user had to log in again... or, worse, suppose I transmitted the username and password via command line arguments. No, forcing programmers into a particular coding model is a bad idea. Let the individual programmer decide what tool is best for what job. > It's like a text editor, you never want a "New" command that resets > the current document or an open command that resets the current > document and loads the file into the existing editor. Each application > instance should only create one document and stick with it until it is > closed. What, never? Well, hardly ever! (As per HMS Pinafore, if you're wondering.) Actually, I quite frequently do want exactly that. Replace the current buffer with a new document. Keeping the previous document involves one of two choices (maybe more, but I can't think of any off hand): * Leave the other document visible on the screen, cluttering things up and forcing the user to switch to the other window, close it, and then return to his work; or * Have the new window completely and exactly mask the old one, making it unobvious that the previous document is actually still open, leaving enormous possibilities for confusion. Audacity takes the first option (at least, the Windows version that I used five years ago did). You choose New or Open, it brings up another window. This astonished me when I first saw it (strike one), annoys me 85% of the time and is useful only 15% (strike two), and tends to get in the way of rapid keyboard-oriented navigation (strike three and out). I'd much rather Audacity kept all its "stuff" in one window, unless I explicitly asked it for another window. For another example, look at where web browsers are going. By your description, one instance of a browser should work with precisely one "document" (which in this case would be a web page). That's how browsers were in the early days, but by the early 2000s most browsers had some form of tabs, letting you keep that application in one window. > Instead you want to spawn a new instance of the editor and tell the > editor (via command line arguments) to load file data (if applicable). > Simple command line arguments (of which you should be using anyway) > are the key here. All part of proper software design. Of course I could spawn a new instance. But why? Why do it? And if I have to have a completely new copy of all the editor's state, this is hopelessly inefficient on memory and startup work. Why should File|Open incur such a cost? (Ameliorated if you fork() but that has its own consequences.) But the memory cost is nothing compared to the extra interference it puts on "mindspace". I currently have precisely two slots in mindspace for web browsers: Chrome and Firefox. Chrome currently has about a dozen tabs up; Firefox about the same, but most of them are long-term status reports that I keep handy. If I had to have 20-30 separate windows, I would not be able to use alt-tab to find the one I want, but would have to use some other kind of "window picker". How would you write a user-friendly picker that can cope with myriad instances of everything? My guess is that it'd use some kind of tree structure with applications at one level and windows at the next. Is this not exactly what we already have? Chris Angelico From georg at python.org Mon Jul 4 13:48:50 2011 From: georg at python.org (Georg Brandl) Date: Mon, 04 Jul 2011 19:48:50 +0200 Subject: [RELEASED] Python 3.2.1 rc 2 Message-ID: <4E11FD02.3040205@python.org> On behalf of the Python development team, I am pleased to announce the second release candidate of Python 3.2.1. Python 3.2.1 will the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a testing release: Please consider trying Python 3.2.1 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) From rosuav at gmail.com Mon Jul 4 13:50:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 03:50:28 +1000 Subject: i have configured proxy but fiddler can't capture python's network requests In-Reply-To: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> References: <163b004e-5e86-4fe1-912c-1305ce2b753c@35g2000prp.googlegroups.com> Message-ID: 2011/7/5 ????2002?7?_??????? : > 2. If I open fiddler, everything works great. But I can't see the > traffic in fiddler. And if I change port from 1111 to any other > number, it works find too. > It sounds to me like the traffic's going through fiddler, but you're just not seeing any log entries. The reactions from the Python end are exactly what I'd expect. Look at fiddler's documentation to see if you can enable verbose logging, or something of the sort. Chris Angelico From tim at johnsons-web.com Mon Jul 4 14:11:33 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 10:11:33 -0800 Subject: Testing if a global is defined in a module Message-ID: <20110704181133.GH1971@johnsons-web.com> Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. ## A module has been imported, and we call `getmembers' members = inspect.getmembers(mod) ## While iterating thru `members', we test to see ## if an object is defined in the module. for m in members: obj = m[1] res = inspect.getmodule(obj) ## It appears that getmodule returns None for ## all but functions and classes. Example, for a module name `mvcInstall', when a class name `Install' that is defined in the module is passed as an argument to inspect.getmodule, the values returned is something like "" Likewise for functions defined in the module. ** But ** when global variables such as strings, booleans, integers are passed as an argument to getmodule, the value returned is `None'. What else can I do here? thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From StefanMandl at web.de Mon Jul 4 15:13:56 2011 From: StefanMandl at web.de (S.Mandl) Date: Mon, 4 Jul 2011 12:13:56 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: Nice. I guess that XSLT would be another (the official) approach for such a task. Is there an XSLT-engine for Emacs? -- Stefan From rantingrick at gmail.com Mon Jul 4 15:30:52 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 12:30:52 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> On Jul 4, 12:41?pm, Chris Angelico wrote: > For another example, look at where web browsers are going. By your > description, one instance of a browser should work with precisely one > "document" (which in this case would be a web page). That's how > browsers were in the early days, but by the early 2000s most browsers > had some form of tabs, letting you keep that application in one > window. Umm, if you want to see where things are "going" you should learn about the inner workings of chrome which actually spawns a new process for every tab created; which has the benefit of avoiding application lock up when one page decides to crash. > I currently have precisely two slots in mindspace for web browsers: > Chrome and Firefox. Chrome currently has about a dozen tabs up; > Firefox about the same, but most of them are long-term status reports > that I keep handy. If I had to have 20-30 separate windows, I would > not be able to use alt-tab to find the one I want, but would have to > use some other kind of "window picker". How would you write a > user-friendly picker that can cope with myriad instances of > everything? psst: it's called a notebook in GUI jargon. Again, study up on chrome internals. From rantingrick at gmail.com Mon Jul 4 15:40:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 12:40:18 -0700 (PDT) Subject: Testing if a global is defined in a module References: Message-ID: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> On Jul 4, 1:11?pm, Tim Johnson wrote: > Using Python 2.6 on ubuntu 10.04. > inspect module : > I want to 'inspect' a module and get a list of all > functions, classes and global variables in that module. > > ## A module has been imported, and we call `getmembers' > members = inspect.getmembers(mod) > > ## While iterating thru `members', we test to see > ## if an object is defined in the module. > for m in members: > ? obj = m[1] > ? res = inspect.getmodule(obj) > ## It appears that getmodule returns None for > ## all but functions and classes. > > Example, for a module name `mvcInstall', when a class > name `Install' that is defined in the module > is passed as an argument to inspect.getmodule, the > values returned is something like > " '/home/tim/prj/cgi/libraries/python/mvcInstall.py'>" > Likewise for functions defined in the module. > > ** But ** when global variables such as strings, booleans, > integers are passed as an argument to getmodule, the > value returned is `None'. > > What else can I do here? > thanks > -- > Tim > tim at johnsons-web dot com or akwebsoft dot comhttp://www.akwebsoft.com Well if you follow the python style guide (and most accepted styles for global notation) then it's a trial exercise. You don't even have to import anything!!! :) >>> GLOBAL_STR = 'str' >>> GLOBAL_FLOAT = 1.33333 >>> GLoBaL_Bs = '' >>> dir() ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', '__name__', '__package__', 'item'] >>> for item in dir(): if item.isupper(): print 'Found Global!', item Found Global! GLOBAL_FLOAT Found Global! GLOBAL_STR ;-) From aly.tawfik at gmail.com Mon Jul 4 15:44:48 2011 From: aly.tawfik at gmail.com (Aly Tawfik) Date: Mon, 4 Jul 2011 12:44:48 -0700 (PDT) Subject: Compiling Python 3.2 on Cygwin fails References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> Message-ID: <8759432d-6b53-4021-8992-2213624762f0@u30g2000vby.googlegroups.com> On Jun 20, 12:44?pm, sewpafly wrote: > I was able to a little further by changing 2 lines in Makefile.pre.in. > > On line 170, changed: > ? ? DLLLIBRARY= @DLLLIBRARY@ > to: > ? ? DLLLIBRARY= libpython$(VERSION).dll > > On line 509 it had: > ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) > > which I changed to: > ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) > > Compile finishes with: > Python build finished, but the necessary bits to build these modules > were not found: > _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter > nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd > To find the necessary bits, look in setup.py in detect_modules() for > the module's name. > > Failed to build these modules: > _curses ? ? ? ? ? ?_curses_panel > > But 'make test' returns many errors. > > I'm thinking I'll try Python 3.1 instead. Yes! I am facing the same problem. I, too, will try to install Python 3.1.4 instead. Did it work for you? From aly.tawfik at gmail.com Mon Jul 4 15:49:41 2011 From: aly.tawfik at gmail.com (Aly Tawfik) Date: Mon, 4 Jul 2011 12:49:41 -0700 (PDT) Subject: Compiling Python 3.2 on Cygwin fails References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> Message-ID: <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> On Jun 20, 12:44?pm, sewpafly wrote: > I was able to a little further by changing 2 lines in Makefile.pre.in. > > On line 170, changed: > ? ? DLLLIBRARY= @DLLLIBRARY@ > to: > ? ? DLLLIBRARY= libpython$(VERSION).dll > > On line 509 it had: > ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) > > which I changed to: > ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) > > Compile finishes with: > Python build finished, but the necessary bits to build these modules > were not found: > _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter > nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd > To find the necessary bits, look in setup.py in detect_modules() for > the module's name. > > Failed to build these modules: > _curses ? ? ? ? ? ?_curses_panel > > But 'make test' returns many errors. > > I'm thinking I'll try Python 3.1 instead. I, too, am facing the same problem. Which version of Python 3.1 did you install, and did it work? Thanks! From python at mrabarnett.plus.com Mon Jul 4 15:53:47 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 04 Jul 2011 20:53:47 +0100 Subject: [Python-ideas] Allow isinstance second argument to be a set of types In-Reply-To: References: <4E11656B.4050908@canterbury.ac.nz> <20110704172843.50c5b445@pitrou.net> <1309802125.3688.54.camel@localhost.localdomain> Message-ID: <4E121A4B.2040008@mrabarnett.plus.com> On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote: > Hi, > > 2011/7/4 Antoine Pitrou: >> Le lundi 04 juillet 2011 ? 10:52 -0700, Gregory P. Smith a ?crit : >>> note that a fast lookup implies exact type and not subclass making my >>> point silly... at which point you're back to iterating so I suspect >>> supporting arbitrary iterables is actually how this will be >>> implemented regardless. >> >> Indeed. Note that the tuple case should remain fast, and therefore >> special-cased (or the general list/tuple case, since the difference in C >> is rather small). > > Arbitrary iterables, arbitrarily nested... > beware of objects which are also their first element, like str('a')... > Probably not arbitrarily nested, just a type (type(t) is type) or an iterable yielding types. Anything else would raise an exception. From clp2 at rebertia.com Mon Jul 4 16:09:52 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 4 Jul 2011 13:09:52 -0700 Subject: [Python-ideas] Allow isinstance second argument to be a set of types In-Reply-To: <4E121A4B.2040008@mrabarnett.plus.com> References: <4E11656B.4050908@canterbury.ac.nz> <20110704172843.50c5b445@pitrou.net> <1309802125.3688.54.camel@localhost.localdomain> <4E121A4B.2040008@mrabarnett.plus.com> Message-ID: On Mon, Jul 4, 2011 at 12:53 PM, MRAB wrote: > On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote: >>> Le lundi 04 juillet 2011 ? 10:52 -0700, Gregory P. Smith a ?crit : >>>> >>>> note that a fast lookup implies exact type and not subclass making my >>>> point silly... at which point you're back to iterating so I suspect >>>> supporting arbitrary iterables is actually how this will be >>>> implemented regardless. >> >> Arbitrary iterables, arbitrarily nested... >> beware of objects which are also their first element, like str('a')... >> > Probably not arbitrarily nested, just a type (type(t) is type) or an > iterable yielding types. Anything else would raise an exception. What about a type that is itself iterable (via metaclass magic)? Gotta consider the wacky edge cases. Cheers, Chris From tim at johnsons-web.com Mon Jul 4 16:30:39 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 12:30:39 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <20110704203039.GJ1971@johnsons-web.com> * rantingrick [110704 12:00]: > On Jul 4, 1:11?pm, Tim Johnson wrote: > > Well if you follow the python style guide (and most accepted styles > for global notation) then it's a trial exercise. You don't even have > to import anything!!! :) > > >>> GLOBAL_STR = 'str' > >>> GLOBAL_FLOAT = 1.33333 > >>> GLoBaL_Bs = '' > >>> dir() > ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', > '__name__', '__package__', 'item'] > >>> for item in dir(): > if item.isupper(): > print 'Found Global!', item Thanks for the reply: *but* dir() will also show globals from other modules imported by the target module. So I would need a way to distinguish between those imported and those defined in print(dir(targetmodule)) => ['Install', 'TestAddresses', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] where 'TestAddresses' is a member of an imported module and 'usingCgi' is the only data variable defined in regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From clp2 at rebertia.com Mon Jul 4 17:03:32 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 4 Jul 2011 14:03:32 -0700 Subject: Testing if a global is defined in a module In-Reply-To: <20110704181133.GH1971@johnsons-web.com> References: <20110704181133.GH1971@johnsons-web.com> Message-ID: On Mon, Jul 4, 2011 at 11:11 AM, Tim Johnson wrote: > Using Python 2.6 on ubuntu 10.04. > inspect module : > I want to 'inspect' a module and get a list of all > functions, classes and global variables in that module. You meant "first defined in" that module. > Example, for a module name `mvcInstall', when a class > name `Install' that is defined in the module > is passed as an argument to inspect.getmodule, the > values returned is something like > " '/home/tim/prj/cgi/libraries/python/mvcInstall.py'>" > Likewise for functions defined in the module. > > ** But ** when global variables such as strings, booleans, > integers are passed as an argument to getmodule, the > value returned is `None'. > > What else can I do here? Look at the names in the module's import statements using the `ast` module, and exclude those from the set of names defined in the module. Won't work for `from foo import *`, but that's bad practice and should be refactored anyway. Cheers, Chris -- http://rebertia.com From rantingrick at gmail.com Mon Jul 4 17:30:16 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 4 Jul 2011 14:30:16 -0700 (PDT) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: On Jul 4, 3:30?pm, Tim Johnson wrote: > > ? Thanks for the reply: *but* > ? dir() will also show globals from other modules imported > ? by the target module. So I would need a way to distinguish between > ? those imported and those defined in Okay, then do some processing on the source. You can use regexps or the module mentioned earlier by Chris. From tim at johnsons-web.com Mon Jul 4 17:39:36 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 13:39:36 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <20110704181133.GH1971@johnsons-web.com> Message-ID: <20110704213936.GK1971@johnsons-web.com> * Chris Rebert [110704 13:16]: > > > > What else can I do here? > > Look at the names in the module's import statements using the `ast` > module, and exclude those from the set of names defined in the module. > Won't work for `from foo import *`, but that's bad practice and should > be refactored anyway. I'm completely new to the `ast' module, so I will have to research that one. Thanks for the tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From rosuav at gmail.com Mon Jul 4 17:43:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 07:43:55 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <0749620a-f405-4b06-a096-7211df0d5fcc@q5g2000yqj.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 5:30 AM, rantingrick wrote: > Umm, if you want to see where things are "going" you should learn > about the inner workings of chrome which actually spawns a new process > for every tab created; which has the benefit of avoiding application > lock up when one page decides to crash. There is still one application. There's a single process which is the master; all the other processes die if the master dies. Chrome's isolation of tab-groups has nothing to do with the GUI design question of whether one top-level window is allowed to do more than one thing, which you claimed it should not. >> How would you write a >> user-friendly picker that can cope with myriad instances of >> everything? > > psst: it's called a notebook in GUI jargon. Again, study up on chrome > internals. No, that would not be what it would be called. Also, a notebook is a very specific widget, and it's not quite identical to Chrome's or Firefox's tabbed browsing setup; but again, that has nothing to do with the case. The question is one of UI design. ChrisA From tim at johnsons-web.com Mon Jul 4 17:59:13 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 13:59:13 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <20110704215913.GL1971@johnsons-web.com> * rantingrick [110704 13:47]: > On Jul 4, 3:30?pm, Tim Johnson wrote: > > > > ? Thanks for the reply: *but* > > ? dir() will also show globals from other modules imported > > ? by the target module. So I would need a way to distinguish between > > ? those imported and those defined in > > Okay, then do some processing on the source. You can use regexps or > the module mentioned earlier by Chris. I think I'm making this unnecessarily complicated. I had used something like: from spam import TestAddresses ## just for grins Which is something that I almost never do in practice. Also, you pointed out the UC naming convention, which I was unacquainted with, being self-employed, self-taught and a one-man crew who doesn't spend as much time as he should reading PEPs. I'm going to go for the predicate test as second argument to getmembers with something like: def isdata(self,obj,name): """Check if an object is of a type that probably means it's data.""" return (not (inspect.ismodule(obj) or inspect.isclass(obj) or inspect.isroutine(obj) or inspect.isframe(obj) or inspect.istraceback(obj) or inspect.iscode(obj))) and name.issupper() ## Untested code thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From steve+comp.lang.python at pearwood.info Mon Jul 4 19:13:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:13:25 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> Message-ID: <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Tim Johnson wrote: > dir() will also show globals from other modules imported > by the target module. So I would need a way to distinguish between > those imported and those defined in Why would you want to do that? Importing *is* a definition in . Consider these two code snippets: #1 from math import pi #2 import math tau = 2*math.pi del math Why do you think it is necessary to distinguish pi from tau? Both names are local to the current namespace. > print(dir(targetmodule)) => > ['Install', 'TestAddresses', '__builtins__', '__doc__', > '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', > 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', > 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] > where 'TestAddresses' is a member of an imported module and You are mistaken. TestAddresses is *not* a member of an imported module. It is a member of the current module, which may or may not happen to point to the same object as the other module as well. > 'usingCgi' is the only data variable defined in It seems to me that your approach here is unnecessarily complex and fragile. I don't know what problem you are trying to solve, but trying to solve it by intraspecting differences that aren't differences is surely the wrong way to do it. -- Steven From steve+comp.lang.python at pearwood.info Mon Jul 4 19:24:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:24:00 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 4, 12:06?am, alex23 wrote: >> rantingrick wrote: >> > But why must we have >> > completely different languages just for that those two approaches? >> >> Because monocultures die. > > That's an interesting statement Alex (even though you parrot it > constantly). So what IS a mono culture exactly? Lemme see... > > """A single, homogeneous culture without diversity or dissension. > """ > > Interesting. Would you consider the Python community to be a > monoculture? We are working towards a singular goal so i would say so. We are? Certainly not. Some people want to make Python more dynamic. Some want it to be less dynamic. Some care about integrating it with Java or .Net, some don't care about either. Some are interested in clever optimization tricks, some oppose adding any more complexity. Some want it to be faster, and are happy to throw more memory at it to do so. Some want it to use less memory, because on embedded devices and smart phones memory is the bottleneck, not time. Some only program in Python. Some treat Python as merely one language out of many that they use. Some come to Python from the C/C++ community, and their wants are influenced by C. Some come to Python from Lisp, Scheme or Haskell, and their wants are influenced by functional programming ideas. Some have never programmed before, and don't know want they want. > We should be working towards the language that is best for all but Define "best for all", and try not to make it "what Rick wants". No, Python is not a monoculture. There are the Stackless, Jython, PyPy and IronPython sub-cultures, all with their own needs, wants and desires. There are sub-cultures for embedded devices and smart phones, sub-cultures for those who use Python as a teaching language, for web development, for GUI development, and for system administration. There are the Numpy and Scipy sub-cultures, sub-cultures in the fields of linguistics and biology. > I believe (unlike most people) that nature is striving for perfection > NOT for diversity. Nature isn't striving for anything. Rick, you think that you're an iconoclast bravely swimming against the tide of wrong-headed public opinion, but what you believe is not new and it is not a minority view. It is old, obsolete, and the vast majority of people with no modern biology education believe something like it. It is, essentially, just the Victorian concept of the "Great Chain of Being" -- not that it was unique to the Victorians, of course. > Diversity is just a byproduct of feeble attempts to > GUESS the correct answer. Here is a thought exercise for the advanced > reader...Which is more efficient; Numerous groups working to create > languages that satisfy their selfish needs OR one group of all the > bright minds working to destroy multiplicity and bring about the one > true language that meets the needs of productivity? The first: numerous groups. Anything else is false efficiency. If you think otherwise, you have seriously missed the point. Efficiency requires that all needs are met first. "The most efficient way to build a house" is NOT "Don't build a house, live in a cardboard box, it's cheaper". Who cares if it is cheaper or not, it's not a house, and doesn't meet the required needs. Since needs are frequently in opposition (e.g. the speed/memory trade-off), a single "true language" must be a compromise language that leaves nobody happy. Or some dictator (Rick?) declares that such-and-such a set of features is, by definition, the "perfect" language and those who want something else have to miss out. Imagine a world where *every* shop was Walmart. That would be good for Walmart, but terrible for everyone else. That's Rick's plan for programming. Screw that. We don't want "the perfect language", because there is no such thing and there is no point in wanting square circles or five-sided triangles or invisible pink unicorns. And even if we did, we wouldn't want YOUR idea of the perfect language. Rick, stop trying to "help" the community with these over-reaching grand schemes that nobody but you wants, that always involve you telling everyone else that they have to build the system you think you want. Go do something useful. -- Steven From tim at johnsons-web.com Mon Jul 4 19:26:47 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 15:26:47 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110704232647.GM1971@johnsons-web.com> * Steven D'Aprano [110704 15:18]: > > You are mistaken. TestAddresses is *not* a member of an imported module. It > is a member of the current module, which may or may not happen to point to > the same object as the other module as well. You are correct. I mispoke or misapplied. See my last post. > > > 'usingCgi' is the only data variable defined in > > It seems to me that your approach here is unnecessarily complex and fragile. > I don't know what problem you are trying to solve, but trying to solve it > by intraspecting differences that aren't differences is surely the wrong > way to do it. See my last post... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From steve+comp.lang.python at pearwood.info Mon Jul 4 19:30:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:30:12 +1000 Subject: Problem!! References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results What do you mean "false results"? What does this even mean? Please show us: * what you do * what result you expect * what result you actually get -- Steven From steve+comp.lang.python at pearwood.info Mon Jul 4 19:33:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2011 09:33:04 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> Tim Johnson wrote: >> It seems to me that your approach here is unnecessarily complex and >> fragile. I don't know what problem you are trying to solve, but trying to >> solve it by intraspecting differences that aren't differences is surely >> the wrong way to do it. > See my last post... Yes, but what are you actually *trying to do*? "Detecting data members" is not an end in itself. Why do you think you need to detect data members? -- Steven From tim at johnsons-web.com Mon Jul 4 20:01:31 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 16:01:31 -0800 Subject: Testing if a global is defined in a module In-Reply-To: <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110705000131.GN1971@johnsons-web.com> * Steven D'Aprano [110704 15:48]: > Tim Johnson wrote: > > >> It seems to me that your approach here is unnecessarily complex and > >> fragile. I don't know what problem you are trying to solve, but trying to > >> solve it by intraspecting differences that aren't differences is surely > >> the wrong way to do it. > > See my last post... > > > Yes, but what are you actually *trying to do*? "Detecting data members" is > not an end in itself. Why do you think you need to detect data members? Steven, I'm building a documentation system. I have my own MVC framework and the goal is to have a documentation module for each project. Thanks again for the clarifications. I always learn a lot from you. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From ben+python at benfinney.id.au Mon Jul 4 20:03:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jul 2011 10:03:49 +1000 Subject: Anyone want to critique this program? References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> Message-ID: <8762nhk2ze.fsf@benfinney.id.au> Chris Angelico writes: > In this instance, I believe the OP was paragraphing his text. What is ?paragraphing?? > Is there a convenient way to do that in a triple-quoted string? Did I answer this earlier in the thread (also at )? > My personal inclination would be to simply back-tab it. It looks ugly, > but at least it works, and doesn't require a run-time re-parse. Readability counts. Why is ?doesn't require a run-time re-parse? more valuable than readability? -- \ ?Because of the impropriety of entertaining guests of the | `\ opposite sex in the bedroom, it is suggested that the lobby be | _o__) used for this purpose.? ?hotel, Zurich | Ben Finney From rosuav at gmail.com Mon Jul 4 20:08:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 10:08:26 +1000 Subject: Testing if a global is defined in a module In-Reply-To: <20110705000131.GN1971@johnsons-web.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: > ?Steven, I'm building a documentation system. I have my own MVC framework > ?and the goal is to have a documentation module for each project. > Is there a reason for not using Doxygen / Autodoc / etc, or at least something in the same style? They work from specially-formatted comments in the source code, rather than the compiled module object. ChrisA From drsalists at gmail.com Mon Jul 4 20:09:44 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 4 Jul 2011 17:09:44 -0700 Subject: Problem!! In-Reply-To: <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> <4e124d06$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: It turned out that switching to binary I/O made seek do what he was expecting. I'm guessing the transparent crlf to lf conversions in windows text I/O get seek() a bit perplexed, because it transparently changes the number of bytes. On Mon, Jul 4, 2011 at 4:30 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > amir chaouki wrote: > > > the problem is when i use the seek function on windows it gives me > > false results > > What do you mean "false results"? What does this even mean? > > Please show us: > > * what you do > * what result you expect > * what result you actually get > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jul 4 20:11:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2011 10:11:41 +1000 Subject: Anyone want to critique this program? In-Reply-To: <8762nhk2ze.fsf@benfinney.id.au> References: <4be432d4-5185-4101-9699-de5524c3fa57@x3g2000yqj.googlegroups.com> <5c3aba69-fddd-45ed-bf0c-8fa98df7aa73@r2g2000vbj.googlegroups.com> <75474208-0a8f-4ac1-8e26-18d8fe6b9efc@u26g2000vby.googlegroups.com> <8762nhk2ze.fsf@benfinney.id.au> Message-ID: On Tue, Jul 5, 2011 at 10:03 AM, Ben Finney wrote: > Chris Angelico writes: > >> In this instance, I believe the OP was paragraphing his text. > > What is ?paragraphing?? If you look at the original code, you'll see embedded newlines used to create multiple paragraphs. Hence, paragraphing as opposed to simply wrapping in order to keep his source lines <80 chars. >> My personal inclination would be to simply back-tab it. It looks ugly, >> but at least it works, and doesn't require a run-time re-parse. > > Readability counts. Why is ?doesn't require a run-time re-parse? more > valuable than readability? Readability definitely counts. But having a string literal require an extra call to make it what you want also costs readability. It's like pushing your literals off to an i18n file - what you gain in flexibility, you lose in simplicity. ChrisA From tim at johnsons-web.com Mon Jul 4 22:01:03 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 4 Jul 2011 18:01:03 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <20110705020103.GO1971@johnsons-web.com> * Chris Angelico [110704 16:19]: > On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: > > ?Steven, I'm building a documentation system. I have my own MVC framework > > ?and the goal is to have a documentation module for each project. > > > > Is there a reason for not using Doxygen / Autodoc / etc, or at least > something in the same style? They work from specially-formatted > comments in the source code, rather than the compiled module object. I want this as a component of my system. It will be bound to a relational data-structure-based 'core' that defines relationships between all files in the project. :) It's called *collateral* And yes, I have worked with comment-based systems, including my own, that worked with multi-language projects. Best regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From davea at ieee.org Mon Jul 4 22:26:53 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 04 Jul 2011 22:26:53 -0400 Subject: Problem!! In-Reply-To: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: <4E12766D.6030001@ieee.org> On 01/-10/-28163 02:59 PM, amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results other then the results on *ux. the file that i work with > are very large about 10mb. > If you still care about this problem, you should take some of the other suggestions to heart; post some code, state what you expected, and what actually happened, and how they're different. But my crystal ball says you're trying to do a seek on a text file, which has restrictions. Once you've called it a text file, you're telling the system to translate cr/lf pairs into lf, which changes the apparent size. So seek has no way to reproduce what reading lines does. To quote the docs at http://docs.python.org/library/stdtypes.html : "If the file is opened in text mode (without 'b'), only offsets returned by tell() are legal. Use of other offsets causes undefined behavior." DaveA -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Mon Jul 4 22:31:01 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 4 Jul 2011 19:31:01 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: rantingrick wrote: > I believe (unlike most people) that nature is striving for perfection Your belief is wrong. "Nature" doesn't "strive" for _anything_. Things in the world are either fit enough to continue their existence or not. As circumstances change, some things that were once suitably fit for the environment are no longer so and are replaced. Same with ideas. There is no "perfection", there is only "what works best now". > What do you think will be the eventual outcome of the human existence > Alex? Since you have no imagination i will tell you, a singular > intelligence. Firstly: cite some kind of evidence that this "will be the eventual outcome" or admit you're talking shit. Secondly: I can imagine humanity evolving into a great many things and something as limited as a 'botnet' is certainly nothing to be proud of as a species. > It is selflessness on a grand scale. I don't really know if you're a troll, have no self-reflective capability, delusionally believe what you're spouting, or are on or off medication, but sometimes your hypocrisy is just funny as hell. >> Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore >> different implementations. > Why can they not explore within the hive mind? Why must they hide > their explorations from the greater group. SELFISHNESS You mean like how Guido hid the Python code base and never let anyone else touch or influence it in any way? Rick, you remind me a lot of Bill Hicks yelling, "You are free to do as we tell you! YOU ARE FREE TO DO AS WE TELL YOU!!" Using terms like "hive mind" kinda shows that I'm wasting my time pushing the value of diversity to you. > * What syntax is most widely intuitive? > * What semantics are the best for productivity? You're inability to recognise the importance of the context in which a language is used explains your misguided position a lot. What if a particular language syntax is the best fit for the way 52% of the population think? What about the other 48%? What if it's a 80/20 split? 90/10? 99/1? At what point are you prepared to sacrifice the needs and best interests of others for your quest for mythical perfection? No need to answer that last one, we already know the answer: from the very beginning. From wuwei23 at gmail.com Mon Jul 4 22:36:25 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 4 Jul 2011 19:36:25 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <4fb6c152-0bb5-4497-b182-14518f18d5eb@s33g2000prg.googlegroups.com> rantingrick wrote: > CREATING THE BEST LANGUAGE WE CAN AT ANY ONE > TIME IN HISTORY... Incidentally, Umberto Eco's "The Search for the Perfect Language" pretty readily exposes this desire as a lingering vestige of the Biblical belief in the one true language that was spoken by God. It also covers in some depth the persistent failure to ever create such a language. Fools, history, rinse & repeat. From ian.g.kelly at gmail.com Tue Jul 5 00:28:42 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jul 2011 22:28:42 -0600 Subject: Testing if a global is defined in a module In-Reply-To: <20110705000131.GN1971@johnsons-web.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On Mon, Jul 4, 2011 at 6:01 PM, Tim Johnson wrote: >> Yes, but what are you actually *trying to do*? "Detecting data members" is >> not an end in itself. Why do you think you need to detect data members? > > ?Steven, I'm building a documentation system. I have my own MVC framework > ?and the goal is to have a documentation module for each project. It sounds like what you really want is to detect the names *exported* by the module, then. Why not do it the same way Python does it? If the module defines an "__all__" attribute, then it is taken to be a sequence of strings which are the exported names. Otherwise, the exported names are taken to be all the names in the module dict that don't begin with an underscore. Cheers, Ian From gagsl-py2 at yahoo.com.ar Tue Jul 5 00:51:49 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 05 Jul 2011 01:51:49 -0300 Subject: from module import * using __import__? References: Message-ID: En Sat, 02 Jul 2011 16:52:11 -0300, Dan Stromberg escribi?: > Is there a decent way of running "from import *"? Perhaps > using > __import__? > > Does it mean using the copy module or adding an element to globals() > somehow? > > Yes, I think I do have a good use for this: importing either pure python > or > cython versions of a module into a single namespace that can provide the > same interface (transparent to the caller), whether C extension modules > are > viable in the current interpreter or not. So you have a stub module that > provides one or the other, depending on availability and suitability. See pickle.py in Python 3 as an example: the slow (pure Python) code resides in pickle.py; the fast (C code) in _pickle.so (on Windows, a built-in module). Near the end of pickle.py, there is a line "from _pickle import *" which, if successful, overrides (replaces) any previous definitions; if not, the ImportError is trapped and the previously defined Python code remains valid. Unlike the 2.x series, where you should decide to "import cPickle" or "import pickle" (or attempt both, cathcing the ImportError), here you only have to "import pickle" in your code; if the fast module is present, it is automatically loaded and used; else, the slow but compatible version is used. You don't even have to know that an alternative implementation exists. -- Gabriel Genellina From lucio.wal at gmail.com Tue Jul 5 02:28:49 2011 From: lucio.wal at gmail.com (victor lucio) Date: Tue, 5 Jul 2011 01:28:49 -0500 Subject: Embedding a thin python Message-ID: Hi All, I would like to remove some modules for embedding a thin python. how to do that? I would be grateful for your suggestions -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane at harobed.org Tue Jul 5 03:36:59 2011 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Tue, 05 Jul 2011 09:36:59 +0200 Subject: =?windows-1252?Q?imp=2Efind=5Fmodule_don=27t_found_my_mo?= =?windows-1252?Q?dule_but_standard_import_statement_can_impo?= =?windows-1252?Q?rt_this_module=85_why_=3F?= Message-ID: Hi, I would like import some module dynamically. First, I install "js.jquery" $ pip install js.jquery Here, I would like import "js" module. >>> import imp >>> imp.find_module("js") Traceback (most recent call last): File "", line 1, in ImportError: No module named js >>> import js >>> I can't found module with "imp.find_module" but I can import it with standard "import" statement. Where is my mistake ? Regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From gandalf at shopzeus.com Tue Jul 5 04:02:13 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 05 Jul 2011 10:02:13 +0200 Subject: wx MenuItem - icon is missing Message-ID: <4E12C505.3020300@shopzeus.com> def onPopupMenu(self,evt): menu = wx.Menu() for title,bitmap in self.getPopupMenuItems(): item = wx.MenuItem(None,-1,title) if bitmap: item.SetBitmap(bitmap) menu.AppendItem(item) menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) self.PopupMenu( menu, evt.GetPoint()) menu.Destroy() I have read somewhere that under GTK, I have to assign the bitmap before Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu item icons are not showing up in Ubuntu. On Windows 7, everything is fine. What am I doing wrong? System: Ubuntu 11 amd64 Python: 2.7.1+ wx.__version__ '2.8.11.0' Thanks, Laszlo From nobody at nowhere.com Tue Jul 5 04:14:13 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 05 Jul 2011 09:14:13 +0100 Subject: Problem!! References: <07867699-7031-4337-abb0-7aa339fc418f@x10g2000vbl.googlegroups.com> Message-ID: On Sun, 03 Jul 2011 16:58:24 -0700, amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results other then the results on *ux. the file that i work with > are very large about 10mb. This is probably an issue with how the underlying C functions behave on Windows, related to the CRLF<->LF conversions when a file is opened in text mode. The Python library documention for the .seek() method says: > If the file is opened in text mode (without 'b'), only offsets returned > by tell() are legal. Use of other offsets causes undefined behavior. IOW, you can't use computed offsets with files opened in text mode (although in practice this will work for platforms other than Windows). If you want to use computed offsets, open the file in binary mode and strip the trailing CRs yourself. And 10MB isn't "very large"; it's not even "large". You normally only start running into problems with files which are 2GiB (2,147,483,648 bytes) or more (i.e. if you can't fit the size into a signed 32-bit integer). From anddimario at gmail.com Tue Jul 5 04:52:57 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Tue, 5 Jul 2011 10:52:57 +0200 Subject: Secure ssl connection with wrap_socket Message-ID: Hi, I'm a new python user and I'm writing a small web service with ssl. I want use a self-signed certificate like in wiki: http://docs.python.org/dev/library/ssl.html#certificates I've used wrap_socket, but if i try to use cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: urllib2.URLError: It works only with CERT_NONE (the default) but with this option i could access to the service in insicure mode. Have you some suggestions for my service? Thanks. Regards. -- Andrea Di Mario From greg.ewing at canterbury.ac.nz Tue Jul 5 07:11:15 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2011 23:11:15 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <97g9qlFootU1@mid.individual.net> rantingrick wrote: > You say "root" windows are bad however any parent-child relationship > has to BEGIN somewhere. There's no need for *toplevel* windows to be children of anything, though. > HOWEVER any of the windows ARE in fact > instances of Tk.Toplevel[1]. So they ARE all equal because they all > have the same methods available to them. No, they're not -- the root window is special, because if you kill it, the whole application exits. Often that is inconvenient. -- Greg From greg.ewing at canterbury.ac.nz Tue Jul 5 07:14:24 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2011 23:14:24 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> Message-ID: <97ga0jFq2lU1@mid.individual.net> rantingrick wrote: > Most applications consist of one main window > (a Tkinter.Tk instance). You've obviously never used a Macintosh. On the Mac, it's perfectly normal for an application to open multiple documents, each in its own window, with no one window being the "main" window. Any of them can be closed (or even *all* of them) and the application continues to run until you explicitly quit it. -- Greg From rantingrick at gmail.com Tue Jul 5 07:42:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 04:42:39 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> Message-ID: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> On Jul 4, 2:36?am, Gregory Ewing wrote: > We have different languages because different people have different > ideas about what a language should be like. Ruby people like user > defined control structures; Python people regard user defined > control structures as an anti-feature. It's fundamentally > impossible for one language to satisfy both sets of people. I was thinking more about this comment and it occurred to me that Python does have user controlled data structures. Just because there is no "top level syntax" like ruby does not mean these do not exists. You only have to look below the surface. Take the sort methods of lists for example... >>> lst = [ (100, 0), (25, 2), (10,1), ] >>> lst [(100, 0), (25, 2), (10, 1)] >>> lst.sort() >>> lst [(10, 1), (25, 2), (100, 0)] >>> lst.sort(lambda x,y: cmp(x[1], y[1])) >>> lst [(100, 0), (10, 1), (25, 2)] ...that looks like a "user defined control" structure to me. So how can an anti-feature become part of the language proper? (devils advocate here) :) I leave the discovery of other user defined control structures for the advanced readers. From hv at tbz-pariv.de Tue Jul 5 08:02:32 2011 From: hv at tbz-pariv.de (Thomas Guettler) Date: Tue, 05 Jul 2011 14:02:32 +0200 Subject: HeaderParseError In-Reply-To: References: <97dc37F7gaU1@mid.individual.net> <97djhfF10kU1@mid.individual.net> Message-ID: <97gcqoFfd1U1@mid.individual.net> On 04.07.2011 13:20, Peter Otten wrote: > Thomas Guettler wrote: > >> On 04.07.2011 11:51, Peter Otten wrote: >>> Thomas Guettler wrote: >>> >>>> I get a HeaderParseError during decode_header(), but Thunderbird can >>>> display the name. >>>> >>>>>>> from email.header import decode_header >>>>>>> >>> Hi, I created a ticket: http://bugs.python.org/issue12489 Thomas G?ttler -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From ulrich.eckhardt at dominolaser.com Tue Jul 5 08:50:11 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 05 Jul 2011 14:50:11 +0200 Subject: embedding: how do I redirect print output? Message-ID: Hi! I'm trying to add some scripting capabilities to an application. Since it is a GUI application, I need some way to display output from Python. For 3.x, where "print" is a function, I'd just exchange this function with one that redirects the output to a log window, right. However, I'm using 2.6 here, where that can't work. So, what I was thinking was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly replace "sys.stdin" with something that causes meaningful errors if some code tries to use it, but that last point is just icing on the cake. What seems cumbersome is that I'll need to write something that supports the file interface using C, which is still a bit awkward. I'm wondering, isn't there an easier way to achieve this? How would you do it? Thank you! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From philip at semanchuk.com Tue Jul 5 08:50:23 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 5 Jul 2011 08:50:23 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E12C505.3020300@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> Message-ID: <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> On Jul 5, 2011, at 4:02 AM, Laszlo Nagy wrote: > def onPopupMenu(self,evt): > menu = wx.Menu() > for title,bitmap in self.getPopupMenuItems(): > item = wx.MenuItem(None,-1,title) > if bitmap: > item.SetBitmap(bitmap) > menu.AppendItem(item) > menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) > self.PopupMenu( menu, evt.GetPoint()) > menu.Destroy() > > I have read somewhere that under GTK, I have to assign the bitmap before Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu item icons are not showing up in Ubuntu. On Windows 7, everything is fine. What am I doing wrong? > > System: Ubuntu 11 amd64 > Python: 2.7.1+ > wx.__version__ '2.8.11.0' Hi Laszlo, Two suggestions -- 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. 2. Ask on the wxPython mailing list. Good luck Philip From ericsnowcurrently at gmail.com Tue Jul 5 09:44:00 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Tue, 5 Jul 2011 07:44:00 -0600 Subject: =?windows-1252?Q?Re=3A_imp=2Efind=5Fmodule_don=27t_found_my_module_but_standa?= =?windows-1252?Q?rd_import_statement_can_import_this_module=85_why_=3F?= In-Reply-To: References: Message-ID: On Tue, Jul 5, 2011 at 1:36 AM, St?phane Klein wrote: > Hi, > > I would like import some module dynamically. > To import a module dynamically, you can use the built-in __import__ function: module = __import__("js") Even better, use importlib's import_module, which is available in 2.7/3.2. A backport is available on PyPI. module = importlib.import_module("js") -eric > First, I install "js.jquery" > > $ pip install js.jquery > > Here, I would like import "js" module. > >>>> import imp >>>> imp.find_module("js") > Traceback (most recent call last): > ?File "", line 1, in > ImportError: No module named js >>>> import js >>>> > > I can't found module with "imp.find_module" but I can import it with > standard "import" statement. > > Where is my mistake ? > > Regards, > Stephane > -- > St?phane Klein > blog: http://stephane-klein.info > Twitter: http://twitter.com/klein_stephane > pro: http://www.is-webdesign.com > > -- > http://mail.python.org/mailman/listinfo/python-list > From stephane at harobed.org Tue Jul 5 09:47:11 2011 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Tue, 05 Jul 2011 15:47:11 +0200 Subject: =?windows-1252?Q?Re=3A_imp=2Efind=5Fmodule_don=27t_found_?= =?windows-1252?Q?my_module_but_standard_import_statement_can?= =?windows-1252?Q?_import_this_module=85_why_=3F?= In-Reply-To: References: Message-ID: Le 05/07/2011 15:44, Eric Snow a ?crit : > On Tue, Jul 5, 2011 at 1:36 AM, St?phane Klein wrote: >> Hi, >> >> I would like import some module dynamically. >> > > To import a module dynamically, you can use the built-in __import__ function: > > module = __import__("js") > > Even better, use importlib's import_module, which is available in > 2.7/3.2. A backport is available on PyPI. > > module = importlib.import_module("js") > Thanks ! It's work very well. Regards, Stephane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From michael at stroeder.com Tue Jul 5 10:02:39 2011 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Tue, 05 Jul 2011 16:02:39 +0200 Subject: ANN: python-ldap 2.4.1 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.1 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.1 2011-07-05 Changes since 2.4.0: Modules: * New LDAP option OPT_X_TLS_PACKAGE available in OpenLDAP 2.4.26+ to determine the name of the SSL/TLS package OpenLDAP was built with Lib/ * ldap.modlist.modifyModlist(): New key-word argument case_ignore_attr_types used to define attribute types for which comparison of old and new values should be case-insensitive * Minor changes to which data is sent to debug output for various trace levels * Now tag [1] is used in ldap.extop.dds.RefreshResponse in compliance with RFC 2589 (fix available for OpenLDAP ITS#6886) * New sub-module ldap.controls.sessiontrack implements request control as described in draft-wahl-ldap-session (needs pyasn1_modules) From calderone.jeanpaul at gmail.com Tue Jul 5 10:08:59 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 5 Jul 2011 07:08:59 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: Message-ID: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> On Jul 5, 4:52?am, Andrea Di Mario wrote: > Hi, I'm a new python user and I'm writing a small web service with ssl. > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > I've used wrap_socket, but if i try to use > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > urllib2.URLError: specified for verification of other-side certificates.> > > It works only with CERT_NONE (the default) but with this option i > could access to the service in insicure mode. > > Have you some suggestions for my service? > Also specify some root certificates to use in verifying the peer's certificate. Certificate verification works by proceeding from a collection of "root" certificates which are explicitly trusted. These are used to sign other certificates (which may in turn be used to sign others, which in turn...). The process of certificate verification is the process of following the signatures from the certificate in use by the server you connect to back up the chain until you reach a root which you have either decided to trust or not. If the signatures are all valid and the root is one you trust, then you have established a connection to a trusted entity. If any signature is invalid, or the root is not one you trust, then you have not. The root certificates are also called the "ca certificates" or "certificate authority certificates". `wrap_socket` accepts a `ca_certs` argument. See http://docs.python.org/library/ssl.html#ssl-certificates for details about that argument. Jean-Paul From invalid at invalid.invalid Tue Jul 5 10:11:56 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 14:11:56 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Chris Angelico wrote: > On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: >>>Steven, I'm building a documentation system. I have my own MVC >>>framework and the goal is to have a documentation module for each >>>project. >> > > Is there a reason for not using Doxygen / Autodoc / etc, or at least > something in the same style? They work from specially-formatted > comments in the source code, rather than the compiled module object. Because those specially-formatted comments are wrong. -- Grant Edwards grant.b.edwards Yow! I have many CHARTS at and DIAGRAMS.. gmail.com From t at jollybox.de Tue Jul 5 10:18:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:18:20 +0200 Subject: embedding: how do I redirect print output? In-Reply-To: References: Message-ID: <4E131D2C.5010904@jollybox.de> On 07/05/2011 02:50 PM, Ulrich Eckhardt wrote: > I'm trying to add some scripting capabilities to an application. Since it is > a GUI application, I need some way to display output from Python. For 3.x, > where "print" is a function, I'd just exchange this function with one that > redirects the output to a log window, right. > > However, I'm using 2.6 here, where that can't work. So, what I was thinking > was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly > replace "sys.stdin" with something that causes meaningful errors if some > code tries to use it, but that last point is just icing on the cake. > > What seems cumbersome is that I'll need to write something that supports the > file interface using C, which is still a bit awkward. I'm wondering, isn't > there an easier way to achieve this? How would you do it? You can mess with low-level file descriptors. Example: # create new stdout: fout = file('out.txt', 'w') # close stdout (fd 1) import os os.close(1) # use fout as new stdout os.dup2(fout.fileno(), 1) # test. This will end up in out.txt print "Testing." # do the same for stdin (0) and stderr (2) # - EOF - However, I suggest you consider isolating your scripts from you main program and run them in a separate interpreter. You can provide dummy modules that communicate with your application via sockets to the scripts. Setting the standard files in the child process is easy: the Popen constructor takes stdin/stdout/stderr arguments. -T From drobinow at gmail.com Tue Jul 5 10:25:15 2011 From: drobinow at gmail.com (David Robinow) Date: Tue, 5 Jul 2011 10:25:15 -0400 Subject: Compiling Python 3.2 on Cygwin fails In-Reply-To: <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> References: <0a6de4fa-aa64-4485-a6da-72cf1bdad739@m9g2000yqe.googlegroups.com> <4e40b036-e232-45d5-be9d-b9019fe4b414@gh5g2000vbb.googlegroups.com> Message-ID: On Mon, Jul 4, 2011 at 3:49 PM, Aly Tawfik wrote: > On Jun 20, 12:44?pm, sewpafly wrote: >> I was able to a little further by changing 2 lines in Makefile.pre.in. >> >> On line 170, changed: >> ? ? DLLLIBRARY= @DLLLIBRARY@ >> to: >> ? ? DLLLIBRARY= libpython$(VERSION).dll >> >> On line 509 it had: >> ? ? $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) >> >> which I changed to: >> ? ? $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) >> >> Compile finishes with: >> Python build finished, but the necessary bits to build these modules >> were not found: >> _gdbm ? ? ? ? ? ? ?_sqlite3 ? ? ? ? ? _tkinter >> nis ? ? ? ? ? ? ? ?ossaudiodev ? ? ? ?spwd >> To find the necessary bits, look in setup.py in detect_modules() for >> the module's name. >> >> Failed to build these modules: >> _curses ? ? ? ? ? ?_curses_panel >> >> But 'make test' returns many errors. >> >> I'm thinking I'll try Python 3.1 instead. > > I, too, am facing the same problem. Which version of Python 3.1 did > you install, and did it work? Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > Cygwin is not really a supported platform. Reverting to Python 3.1 won't help at all. Download the 2.6.5 source version (i.e., click the Src box) using cygwin setup. Apply the included patches [some don't apply cleanly any more]. That will get you most of the way there. There are a few other issues the details of which I don't remember. I'm not sure why there hasn't been a cygwin distribution lately. You might ask on the cygwin mailing list. [Ultimately somebody with an interest in cygwin will need to get active in python development. I've been meaning to do this but life gets in the way.] DR From t at jollybox.de Tue Jul 5 10:25:29 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:25:29 +0200 Subject: Embedding a thin python In-Reply-To: References: Message-ID: <4E131ED9.3000408@jollybox.de> On 07/05/2011 08:28 AM, victor lucio wrote: > Hi All, > > I would like to remove some modules for embedding a thin python. > how to do that? > I would be grateful for your suggestions > > > Start your favourite file manager and delete them. From steve+comp.lang.python at pearwood.info Tue Jul 5 10:25:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 00:25:58 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> Message-ID: <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Gregory Ewing wrote: > rantingrick wrote: >> Most applications consist of one main window >> (a Tkinter.Tk instance). > > You've obviously never used a Macintosh. On the Mac, it's > perfectly normal for an application to open multiple > documents, each in its own window, with no one window > being the "main" window. Any of them can be closed (or > even *all* of them) and the application continues to run > until you explicitly quit it. Or a Linux GUI. I have kwrite running with 15 open windows. The application doesn't exit until the last window is closed, and no window is privileged over the others. Even in Windows, the sort of MDI interface Rick seems to be describing is less common now than it used to be -- possibly even rare. http://en.wikipedia.org/wiki/Multiple_document_interface -- Steven From t at jollybox.de Tue Jul 5 10:35:27 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:35:27 +0200 Subject: from module import * using __import__? In-Reply-To: References: Message-ID: <4E13212F.2030005@jollybox.de> On 07/02/2011 09:52 PM, Dan Stromberg wrote: > > Is there a decent way of running "from import *"? Perhaps > using __import__? > > Does it mean using the copy module or adding an element to globals() > somehow? Yes, exactly. That's what `from x import *` does: Get the module, and then add all members to the global namespace. def import_all_from (module_name): mod = __import__(module_name) for member_name in dir(mod): globals()[member_name] = getattr(mod, member_name) Of course, don't do this, do what Gabriel said. -T From steve+comp.lang.python at pearwood.info Tue Jul 5 10:36:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 00:36:43 +1000 Subject: embedding: how do I redirect print output? References: Message-ID: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Ulrich Eckhardt wrote: > Hi! > > I'm trying to add some scripting capabilities to an application. Since it > is a GUI application, I need some way to display output from Python. For > 3.x, where "print" is a function, I'd just exchange this function with one > that redirects the output to a log window, right. > > However, I'm using 2.6 here, where that can't work. So, what I was > thinking was to redirect "sys.stdout" and "sys.stderr" to a log window and > possibly replace "sys.stdin" with something that causes meaningful errors > if some code tries to use it, but that last point is just icing on the > cake. > > What seems cumbersome is that I'll need to write something that supports > the file interface using C, which is still a bit awkward. I'm wondering, > isn't there an easier way to achieve this? How would you do it? Why do you think it needs to be in C? As far as I can tell, so long as it quacks like a file object (that is, has a write method), it should work. >>> import StringIO, sys >>> class Test: ... def __init__(self): ... self.out = sys.stdout ... self.log = StringIO.StringIO() ... def write(self, text): ... self.log.write(text.upper()) ... self.out.write(''.join(reversed(text))) ... >>> fake_out = Test() >>> sys.stdout = fake_out >>> print "Hello world" dlrow olleH >>> print "Goodbye cruel world!!!" !!!dlrow leurc eybdooG >>> sys.stdout = sys.__stdout__ >>> fake_out.log.getvalue() 'HELLO WORLD\nGOODBYE CRUEL WORLD!!!\n' -- Steven From t at jollybox.de Tue Jul 5 10:49:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 16:49:20 +0200 Subject: can I package a distutil based python app in deb? In-Reply-To: <4E07737C.7090900@gmail.com> References: <4E07737C.7090900@gmail.com> Message-ID: <4E132470.7080609@jollybox.de> On 06/26/2011 07:59 PM, hackingKK wrote: > Hello all, > I guess the subject line says it all. > I want to package a python app to deb. > I have 3 interesting issues with it. > 1, I would want it to run on Ubuntu 10.04, Ubuntu 10.10, Ubuntu 11.04 > and Debian 5. > 2, the package depends on another python package which is also distutil > based. > 3, The second package needs to run in a virtual environment. > This means that I not only have to figure out the dependencies but also > have the deb to include a script to get the virtual environment script, > then create one for the package, then download all dependencies (Pylons > 0.9.7 in this case along with report lab) and finally put the package > into this virtual environment. > Is this all possible? Yes, it is possible. Refer to , particularly the New Maintainer's Guide: From t at jollybox.de Tue Jul 5 11:05:11 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 05 Jul 2011 17:05:11 +0200 Subject: module problem on windows 64bit In-Reply-To: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> References: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> Message-ID: <4E132827.90101@jollybox.de> On 06/27/2011 06:59 PM, miamia wrote: > Hello, > > on 32-bit windows everything works ok but on 64-bit win I am getting > this error: > Traceback (most recent call last): > File "app.py", line 1040, in do_this_now > File "kinterbasdb\__init__.pyc", line 119, in > File "kinterbasdb\_kinterbasdb.pyc", line 12, in > File "kinterbasdb\_kinterbasdb.pyc", line 10, in __load > ImportError: DLL load failed: This application has failed to start > because the application configuration is incorrect. Reinstalling the > application may fix this problem. > > How to get it work on 64bit windows as well? many thanks A process can only link to a shared library compiled for the same architecture as the process. In layman's terms: A 32-bit DLL won't work with a 64-bit program. It looks like this package is attempting to load a 32-bit DLL. That's not going to work. Either procure a 64-bit version of the DLL, or use a 32-bit version of Python. From rosuav at gmail.com Tue Jul 5 11:17:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 01:17:30 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:25 AM, Steven D'Aprano wrote: > Gregory Ewing wrote: > >> You've obviously never used a Macintosh. On the Mac, it's >> perfectly normal for an application to open multiple >> documents, each in its own window, with no one window >> being the "main" window. Any of them can be closed (or >> even *all* of them) and the application continues to run >> until you explicitly quit it. > > Or a Linux GUI. I have kwrite running with 15 open windows. The application > doesn't exit until the last window is closed, and no window is privileged > over the others. It's actually quite easy to implement this, even if you _are_ forced to have one primary window. You just have an invisible primary whose sole purpose is to "be the application", and then everything else is secondary windows. Kinda defeats the purpose of forcing applications to have one primary window, though. To my thinking, there will always be one primary *thread*, and GUI facilities are secondary to the process, never the other way around. When the main thread exits, the process ends. ChrisA From rosuav at gmail.com Tue Jul 5 11:20:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 01:20:07 +1000 Subject: embedding: how do I redirect print output? In-Reply-To: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:36 AM, Steven D'Aprano wrote: >>>> print "Hello world" > dlrow olleH > You, sir, have a warped and twisted mind. And I love it!! Now to secretly put code into some module somewhere and wait for people to start tearing their hair out.... wait, did I say that out loud? ChrisA From steve+comp.lang.python at pearwood.info Tue Jul 5 11:26:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 01:26:06 +1000 Subject: Implicit initialization is EXCELLENT Message-ID: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> This is not strictly Python, although it is peripherally relevant. Some month or three ago, I read an article or blog post about API design, specifically the wrong-headedness of insisting that callers manually initialise instances using a separate step after creation. The argument goes, if your API looks something like this: instance = Spaminator(extra_truffles=False) instance.activate() instance.nom_nom_nom() => prints "yummy spam, the food of the Gods!!!" chances are that you are doing it wrong and your users will hate you. Why force the user to manually "flip the switch" (so to speak)? It's not like they can possibly avoid it: another_instance = Spaminator(with_extra_cheese=True) another_instance.nom_nom_nom() => raises InactiveInstanceError("you must activate the instance first") What? No! Just activate yourself! Exceptions to this rule are if the Spaminator has side-effects (e.g. files, in which case the user may want finer control in when they are opened and closed), or if there are meaningful operations you can perform on an inactive Spaminator. Python generally follows this design. Apart from files, I can't easily think off the top of my head of any types that require a separate open/start/activate call before they are usable. It's also relevant to tkinter, which will implicitly create a root window for you when needed. Since you can't do anything without a root window, I don't see the benefit in forcing the user to do so. When they need to learn about root windows, they will in their own good time. Now, I have an ulterior motive in raising this issue... I can't find the original article I read! My google-fu has failed me (again...). I don't suppose anyone can recognise it and can point me at it? -- Steven From tim at johnsons-web.com Tue Jul 5 11:30:30 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 5 Jul 2011 07:30:30 -0800 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <20110705153029.GP1971@johnsons-web.com> * Ian Kelly [110704 20:37]: > > It sounds like what you really want is to detect the names *exported* > by the module, then. i Yes! > Why not do it the same way Python does it? If > the module defines an "__all__" attribute, then it is taken to be a > sequence of strings which are the exported names. Otherwise, the > exported names are taken to be all the names in the module dict that > don't begin with an underscore. :) Oh here we go again. Another python feature I didn't know about or have forgotten. Thanks very much for that. Good tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From pruebauno at latinmail.com Tue Jul 5 11:33:09 2011 From: pruebauno at latinmail.com (nn) Date: Tue, 5 Jul 2011 08:33:09 -0700 (PDT) Subject: Implicit initialization is EVIL! References: Message-ID: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> On Jul 4, 11:35?am, Robin Becker wrote: > On 03/07/2011 23:21, Chris Angelico wrote: > ......... > > > var(0x14205359) x ? # Don't forget to provide an address where the > > object will be located > > x=42 > > ........ > did you forget to specify the memory bank and computer (and presumably planet > etc etc....) > -molly-coddled-ly yrs- > Robin Becker Ah, I see we have a mainframe programmer among us ... :-) From invalid at invalid.invalid Tue Jul 5 11:43:02 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 15:43:02 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Tim Johnson wrote: > * Ian Kelly [110704 20:37]: >> >> It sounds like what you really want is to detect the names *exported* >> by the module, then. i > Yes! >> Why not do it the same way Python does it? If >> the module defines an "__all__" attribute, then it is taken to be a >> sequence of strings which are the exported names. Otherwise, the >> exported names are taken to be all the names in the module dict that >> don't begin with an underscore. > > :) Oh here we go again. Another python feature I didn't know about > or have forgotten. You could probably implement at least two more languages using nothing but Python features I don't know about or have forgotten. :) Yet I still manage to get a lot accomplished using Python. -- Grant Edwards grant.b.edwards Yow! I don't know WHY I at said that ... I think it gmail.com came from the FILLINGS in my rear molars ... From kb1pkl at aim.com Tue Jul 5 12:04:32 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 05 Jul 2011 12:04:32 -0400 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <1309881085-sup-1096@dalek> Excerpts from rantingrick's message of Tue Jul 05 07:42:39 -0400 2011: > > I was thinking more about this comment and it occurred to me that > Python does have user controlled data structures. Just because there > is no "top level syntax" like ruby does not mean these do not exists. > You only have to look below the surface. Take the sort methods of > lists for example... > > >>> lst = [ > (100, 0), > (25, 2), > (10,1), > ] > >>> lst > [(100, 0), (25, 2), (10, 1)] > >>> lst.sort() > >>> lst > [(10, 1), (25, 2), (100, 0)] > >>> lst.sort(lambda x,y: cmp(x[1], y[1])) > >>> lst > [(100, 0), (10, 1), (25, 2)] > > ...that looks like a "user defined control" structure to me. So how > can an anti-feature become part of the language proper? (devils > advocate here) :) > How is giving the sort method a function by which to determine the relative value of objects a control structure? Do you know what a control structure is? It's something that you use to modify control flow: if foo <= bar: foo += 1 else: bar += 1 That's a control structurem the "if-else". I don't know what Ruby calls a control structure, but that's what it is. for and while are in there too. When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? We'll call that argument srt, here's a sample (naive) implementation: def sort(key): lst = self.internal_list for n in range(len(self.internal_list) - 1): for i in range(len(self.internal_list) - 1): if srt(lst[i], lst[i+1]) < 0: lst[i], lst[i+1] = lst[i+1], lst[i] Untested, probably doesn't work either. See what's in there? An if. Nothing "user-defined" at all. Sure, WHAT the if does is user-controlled with the key, but that doesn't make that particular if a new control structure, and it certainly doesn't make the key a control structure. You can pass a key to a sort even in C and that certainly doesn't have user defined control structures. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From robin at reportlab.com Tue Jul 5 12:23:42 2011 From: robin at reportlab.com (Robin Becker) Date: Tue, 05 Jul 2011 17:23:42 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> References: <6a347e5e-fc28-42f6-acc4-dede5547205f@m18g2000vbl.googlegroups.com> Message-ID: <4E133A8E.7020602@chamonix.reportlab.co.uk> On 05/07/2011 16:33, nn wrote: ...... > Ah, I see we have a mainframe programmer among us ... :-) so long since I manipulated the switches of that old pdp-8 -anciently yrs- Robin Becker From k.sahithi2862 at gmail.com Tue Jul 5 12:28:50 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 5 Jul 2011 09:28:50 -0700 (PDT) Subject: VIDEOS FOR HOT GUYS Message-ID: <253bb1c2-3493-4ce4-9849-8d6bb13be2bb@f39g2000prb.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From wm at localhost.localdomain Tue Jul 5 12:35:22 2011 From: wm at localhost.localdomain (Waldek M.) Date: Tue, 5 Jul 2011 18:35:22 +0200 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): > Because those specially-formatted comments are wrong. ... because? Not in sarcasm mode; just curious why you don't like them. Br. Waldek From steve+comp.lang.python at pearwood.info Tue Jul 5 13:36:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 03:36:24 +1000 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Waldek M. wrote: > Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): >> Because those specially-formatted comments are wrong. > > ... because? > Not in sarcasm mode; just curious why you don't like them. Because unless you are extremely disciplined, code and the comments describing them get out of sync. Quote: "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. " --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 -- Steven From salmig99 at gmail.com Tue Jul 5 14:14:11 2011 From: salmig99 at gmail.com (sal migondis) Date: Tue, 5 Jul 2011 11:14:11 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> Message-ID: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> On Jul 4, 10:31?pm, alex23 wrote: > rantingrick wrote: > > I believe (unlike most people) that nature is striving for perfection > > Your belief is wrong. "Nature" doesn't "strive" for _anything_. Things > in the world are either fit enough to continue their existence or not. > As circumstances change, some things that were once suitably fit for > the environment are no longer so and are replaced. Same with ideas. > There is no "perfection", there is only "what works best now". How could a belief be wrong? > > What do you think will be the eventual outcome of the human existence > > Alex? Since you have no imagination i will tell you, a singular > > intelligence. All from the land of creationism. > Firstly: cite some kind of evidence that this "will be the eventual > outcome" or admit you're talking shit. > > Secondly: I can imagine humanity evolving into a great many things and > something as limited as a 'botnet' is certainly nothing to be proud of > as a species. > > > It is selflessness on a grand scale. > > I don't really know if you're a troll, Beats me... I think everybody else does.. > have no self-reflective > capability, delusionally believe what you're spouting, or are on or > off medication, but sometimes your hypocrisy is just funny as hell. > > >> Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore > >> different implementations. > > Why can they not explore within the hive mind? Why must they hide > > their explorations from the greater group. SELFISHNESS > > You mean like how Guido hid the Python code base and never let anyone > else touch or influence it in any way? > > Rick, you remind me a lot of Bill Hicks yelling, "You are free to do > as we tell you! YOU ARE FREE TO DO AS WE TELL YOU!!" Using terms like > "hive mind" kinda shows that I'm wasting my time pushing the value of > diversity to you. Now you're taking a troll as an excuse for your own trolling. > No need to answer that last one, we already know the answer: from the > very beginning. In the beginning was a singularity... and Albert Einstein was a chain- smoker. Sal. From steveo at syslang.net Tue Jul 5 14:31:07 2011 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 05 Jul 2011 14:31:07 -0400 Subject: Question about how to get line buffering from paramiko Message-ID: <4E13586B.4040109@syslang.net> I'm writing a program that uses paramiko to run a lot of commands over ssh. Some of the commands take time to run and they write to stdout and stderr as a normal part of their operation so that we can see progress happening. I can't seem to get the output from the remote commands (which is input to me) to be line buffered. If I run the commands using ssh, they line buffer nicely. If I run them through paramiko, they end up fully buffered. I stole this code I found as a base. The code that I got looked like the execute_capture method (below). I added the execute method so that I could poll for the result from both stderr and stdout. Note that I am calling channel.get_pty, but that doesn't change the fact that the results are not line buffered. Can anyone suggest a way to solve this? The code I'm using follows: #! /usr/bin/python """ Friendly Python SSH2 interface using paramiko """ import os import sys import tempfile import paramiko import select from collections import namedtuple ExecStatus = namedtuple('ExecStatus', 'status stdout stderr') class Connection(object): """ Connects and logs into the specified hostname. Arguments that are not given are guessed from the environment. """ def __init__(self, host, username = None, private_key = None, password = None, port = 22, blocking_cmds = True, verbose = False, ): self._sftp_live = False self._sftp = None if not username: username = os.environ['LOGNAME'] # Log to a temporary file if requested. if verbose: self.templog = tempfile.mkstemp('.txt', 'ssh-')[1] paramiko.util.log_to_file(self.templog) else: self.templog = False # Begin the SSH transport. self._transport = paramiko.Transport((host, port)) self._tranport_live = True # Authenticate the transport. if password: # Using Password. self._transport.connect(username = username, password = password) else: # Use Private Key. if not private_key: # Try to use default key. if os.path.exists(os.path.expanduser('~/.ssh/id_rsa')): private_key = '~/.ssh/id_rsa' elif os.path.exists(os.path.expanduser('~/.ssh/id_dsa')): private_key = '~/.ssh/id_dsa' else: raise TypeError, "You have not specified a password or key." private_key_file = os.path.expanduser(private_key) rsa_key = paramiko.RSAKey.from_private_key_file(private_key_file) self._transport.connect(username = username, pkey = rsa_key) def _sftp_connect(self): """Establish the SFTP connection.""" if not self._sftp_live: self._sftp = paramiko.SFTPClient.from_transport(self._transport) self._sftp_live = True def get(self, remotepath, localpath = None): """Copies a file between the remote host and the local host.""" if not localpath: localpath = os.path.split(remotepath)[1] self._sftp_connect() self._sftp.get(remotepath, localpath) def put(self, localpath, remotepath = None): """Copies a file between the local host and the remote host.""" if not remotepath: remotepath = os.path.split(localpath)[1] self._sftp_connect() self._sftp.put(localpath, remotepath) def execute(self, command): """ Execute the given commands on a remote machine. Return value is exit status of the remote command. """ # This execute method is similar to execute_capture below. The # difference is that this method gets the stdout and stderr of # the runnning command and forwards it on to the correct # channel within this process. # To do this, we use the poll(2) system call which comes from # the select package. def _write(fd, chan, syschan): """ _write internal method to check an fd from the list of fds for a POLLIN event, read the data that's there, and if there's anything there, then write it to the correct channel. Return True if there was something to read. """ ret = False if fd[1] & select.POLLIN: if fd[0] == chan.channel.fileno(): ss = chan.readline() ret = len(ss) != 0 if ret: # No need to strip and then print with a newline. # because every line is newline terminated. print >> syschan, ss[:-1] return ret # Open a channel of type session. Same as open_channel('session') channel = self._transport.open_session() # Calling get_pty does get us a pty # If the 2nd arg is 1, then it should be line buffered. Apparently, # in this context, line buffering refers to output to the process, # not input from the process. channel.get_pty() # Run command on the session of type channel. This returns immediately. channel.exec_command(command) # Get the stdout and stderr file descriptors. In this context, makefile # has nothing to do with the make utility. It's about making # file descriptors. stdout = channel.makefile('rb', 1) stderr = channel.makefile_stderr('rb', 1) # Create a polling object. We really only care about POLLIN events. po = select.poll() po.register(stdout.channel, select.POLLIN) po.register(stderr.channel, select.POLLIN) # Set found_output tto True to start the loop. Set it to False # as an initial value inside the loop, and OR the value on if any data # got written by either channel. found_output = True while found_output == True: found_output = False fds = po.poll() for fd in fds: found_output |= _write(fd, stdout, sys.stdout) found_output |= _write(fd, stderr, sys.stderr) status = channel.recv_exit_status() channel.close() return status def execute_capture(self, command): """ Execute the given commands on a remote machine. Return value is a 3-tuple: exit status, stdout and stderr Output is not written out. """ # Open a channel of type session. Same as open_channel('session') channel = self._transport.open_session() # Run command on the session of type channel. This returns immediately. channel.exec_command(command) # Collect stdout and stderr into lists. # The alternative would be to harvest the 3-tuple std{in,out,err} # of file descriptors returned by exec_command. stdout = channel.makefile('rb', -1).readlines() stderr = channel.makefile_stderr('rb', -1).readlines() # Not well documented, but recv_exit_status will block until # the command completes. Return value is the exit status. status = channel.recv_exit_status() channel.close() return ExecStatus(status, stdout, stderr) def close_transport(self): # Close the SSH Transport. if self._tranport_live: self._transport.close() self._tranport_live = False def close_sftp(self): # Close SFTP Connection. if self._sftp_live: self._sftp.close() self._sftp_live = False def close(self): """Closes the connection and cleans up.""" self.close_transport() self.close_sftp() # start the ball rolling. if __name__ == "__main__": def proc_exec(cmd): status = myssh.execute(cmd) print "Just ran %s with exit status %d"%(cmd, status) # Another choice is to call # def proc_exec(cmd): # run = myssh.execute_capture(cmd) # print "Just ran %s with exit status %d"%(cmd, status) # if run.stdout: # print "output:\n", ''.join(run.stdout)[:-1] # if run.stderr: # print "error:\n", ''.join(run.stderr)[:-1] # Little test when called directly. # Set these to your own details. myssh = Connection('host', username='user') proc_exec('pwd') proc_exec('false') proc_exec('xxx.sh') proc_exec('cd sorr; pwd') proc_exec('pwd') proc_exec('tty') myssh.close() -- 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 enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Jul 5 15:04:46 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 05 Jul 2011 21:04:46 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e136051$0$18782$ba4acef3@reader.news.orange.fr> Hi! +1 @-salutations -- Michel Claveau From ian.g.kelly at gmail.com Tue Jul 5 15:17:25 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2011 13:17:25 -0600 Subject: emacs lisp text processing example (html5 figure/figcaption) In-Reply-To: References: Message-ID: On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > So, a solution by regex is out. Actually, none of the complications you listed appear to exclude regexes. Here's a possible (untested) solution:
((?:\s*[^)+) \s*

((?:[^<]|<(?!/p>))+)

\s*
and corresponding replacement string:
\1
\2
I don't know what dialect Emacs uses for regexes; the above is the Python re dialect. I assume it is translatable. If not, then the above should at least work with other editors, such as Komodo's "Find/Replace in Files" command. I kept the line breaks here for readability, but for completeness they should be stripped out of the final regex. The possibility of nested HTML in the caption is allowed for by using a negative look-ahead assertion to accept any tag except a closing

. It would break if you had nested

tags, but then that would be invalid html anyway. Cheers, Ian From mwilson at the-wire.com Tue Jul 5 15:27:39 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 05 Jul 2011 15:27:39 -0400 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: [ ... ] > Python generally follows this design. Apart from files, I can't easily > think off the top of my head of any types that require a separate > open/start/activate call before they are usable. It's also relevant to > tkinter, which will implicitly create a root window for you when needed. > Since you can't do anything without a root window, I don't see the benefit > in forcing the user to do so. When they need to learn about root windows, > they will in their own good time. In wx, many of the window classes have Create methods, for filling in various attributes in "two-step construction". I'm not sure why, because it works so well to just supply all the details when the class is called and an instance is constructed. Maybe there's some C++ strategy that's being supported there. Mel. From stefaan.himpe at gmail.com Tue Jul 5 15:31:44 2011 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Tue, 05 Jul 2011 21:31:44 +0200 Subject: Implicit initialization is EXCELLENT In-Reply-To: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hello, I agree with the contents of this post. I see a similar problem with API's requiring to initialize all kinds of data using setters/properties instead of receiving it in the initializer (or constructor). > Python generally follows this design. Apart from files, I can't easily think > off the top of my head of any types that require a separate > open/start/activate call before they are usable. database connections, network connections, spawning expensive processes/threads, things that benefit from lazy evaluation... > Now, I have an ulterior motive in raising this issue... I can't find the > original article I read! My google-fu has failed me (again...). I don't > suppose anyone can recognise it and can point me at it? My sarcasm detector warns me not to add a link, although perhaps it's time for recalibration (after all, summer season started) :-) Best regards, Stefaan. From gandalf at shopzeus.com Tue Jul 5 15:32:37 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 05 Jul 2011 21:32:37 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> Message-ID: <4E1366D5.6030208@shopzeus.com> > 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. import sys import wx from wx.lib.embeddedimage import PyEmbeddedImage img = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAAAAAAAD5Q7t/AAAA" "CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QYGDS8dXc5KpwAAADV0RVh0Q29tbWVudAAo" "YykgMjAwNCBKYWt1YiBTdGVpbmVyCgpDcmVhdGVkIHdpdGggVGhlIEdJTVCQ2YtvAAAB+klE" "QVQ4y52TwWpTQRSGvzkzwV7S1pI2CFptC3VhUkjabsSlrxBKF0UQdONW3BsK7sQnUPA9pLos" "WtskzW3AgopKi6jtxYQSY3LnuEi8pYsidjbD8M98c/7/zJil5dJDoMzZRtksLZf0zt3bZzr9" "7Olz3N/F5tbLUze2Wkek0wHtdgdrhaGhcywu3AQ4BjSbB6cCPrzfw1ohOmzRbB5x/cZcoiWA" "mZm5UwFTUzmMMagqxhiMMYlmlpZLGjXbPLh/77/8rz56wqULmX4F3W6P8upjfnU6fVUV/QdA" "RI4t3FpZ4dXaC7yHi5OTfN3fx/uYkfNjtH5GqPcE6RGMCNHhASKG/g0eFwQBla03XJ2dRVUJ" "w5B8Po+1ljAMyeVyiAiNRgPFsDhfJJVK0e12qdUrSLvdxsceVU1CAojjGDB0Oh289wB4Vay1" "6GBOLFyZmuH1+joYw0Q2y85OA+9jxjLjvNvdBVXGMhMoUKvVEkgC+PzpI8VioW+h0SCXu4Zz" "jnq9znyxiIhQrdZwzlEoFJIqNysbyCB2nHN47/G9HtZanHOISNJ3EQP0S0+lUie7MHl5msrm" "W8Awns2yXa/jrCU9PMx2GGJUGQoCfg/aPDo6ShRFJ1/i/MICANZa4ulpDGBE0EGARoS9vS98" "//GNw+hgEHIfUK5WN878nf8AhFzLEABZzNIAAAAASUVORK5CYII=") class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='Popup image test', pos=wx.DefaultPosition, size=(200, 200), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) lst = wx.ListCtrl(self,-1,style=wx.LC_REPORT) lst.InsertColumn(0, "Column 01") for i in range(100): lst.InsertStringItem(sys.maxint, "Right click me %s"%i) lst.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onPopupMenu, lst) self.Bind(wx.EVT_CLOSE, self.OnClose) def OnClose(self, event): self.Destroy() def onPopupMenu(self,evt): global img menu = wx.Menu() item = wx.MenuItem(None,-1,u"Test") item.SetBitmap(img.GetBitmap()) menu.AppendItem(item) #menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item) self.PopupMenu( menu, evt.GetPoint()) menu.Destroy() app = wx.App() frame = MyFrame(None) frame.Show() app.MainLoop() Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. Thanks L From xahlee at gmail.com Tue Jul 5 15:46:20 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 12:46:20 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: <77912925-c870-43ac-b405-68ded8748d05@34g2000pru.googlegroups.com> On Jul 5, 12:17?pm, Ian Kelly wrote: > On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > > So, a solution by regex is out. > > Actually, none of the complications you listed appear to exclude > regexes. ?Here's a possible (untested) solution: > >

> ((?:\s*[^ height="[0-9]+">)+) > \s*

((?:[^<]|<(?!/p>))+)

> \s*
> > and corresponding replacement string: > >
> \1 >
\2
>
> > I don't know what dialect Emacs uses for regexes; the above is the > Python re dialect. ?I assume it is translatable. ?If not, then the > above should at least work with other editors, such as Komodo's > "Find/Replace in Files" command. ?I kept the line breaks here for > readability, but for completeness they should be stripped out of the > final regex. > > The possibility of nested HTML in the caption is allowed for by using > a negative look-ahead assertion to accept any tag except a closing >

. ?It would break if you had nested

tags, but then that would > be invalid html anyway. > > Cheers, > Ian that's fantastic. Thanks! I'll try it out. Xah From xahlee at gmail.com Tue Jul 5 15:47:21 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 12:47:21 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: On Jul 4, 12:13?pm, "S.Mandl" wrote: > Nice. I guess that XSLT would be another (the official) approach for > such a task. > Is there an XSLT-engine for Emacs? > > -- Stefan haven't used XSLT, and don't know if there's one in emacs... it'd be nice if someone actually give a example... Xah From xahlee at gmail.com Tue Jul 5 16:37:18 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 5 Jul 2011 13:37:18 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: On Jul 5, 12:17?pm, Ian Kelly wrote: > On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > > So, a solution by regex is out. > > Actually, none of the complications you listed appear to exclude > regexes. ?Here's a possible (untested) solution: > >

> ((?:\s*[^ height="[0-9]+">)+) > \s*

((?:[^<]|<(?!/p>))+)

> \s*
> > and corresponding replacement string: > >
> \1 >
\2
>
> > I don't know what dialect Emacs uses for regexes; the above is the > Python re dialect. ?I assume it is translatable. ?If not, then the > above should at least work with other editors, such as Komodo's > "Find/Replace in Files" command. ?I kept the line breaks here for > readability, but for completeness they should be stripped out of the > final regex. > > The possibility of nested HTML in the caption is allowed for by using > a negative look-ahead assertion to accept any tag except a closing >

. ?It would break if you had nested

tags, but then that would > be invalid html anyway. > > Cheers, > Ian emacs regex supports shygroup (the ?(?:?)?) but it doesn't support the negative assertion ??!?? though. but in anycase, i can't see how this part would work

((?:[^<]|<(?!/p>))+)

? Xah From bahamutzero8825 at gmail.com Tue Jul 5 17:01:57 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 16:01:57 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: <4E137BC5.2080401@gmail.com> On 2011.07.05 01:14 PM, sal migondis wrote: > How could a belief be wrong? Beliefs aren't subjective. One's taste in music, for example, is largely subjective and can't be right or wrong, but a belief (which has to do with facts) certainly can be. > > > What do you think will be the eventual outcome of the human existence > > > Alex? Since you have no imagination i will tell you, a singular > > > intelligence. > > All from the land of creationism. That's from rantingrick, not alex23. > > No need to answer that last one, we already know the answer: from the > > very beginning. > > In the beginning was a singularity... and Albert Einstein was a chain- > smoker. Either you're taking that statement out of context, or you're making an esoteric joke. If it's not the latter, I suggest you read the sentence before it. From gordon at panix.com Tue Jul 5 17:02:49 2011 From: gordon at panix.com (John Gordon) Date: Tue, 5 Jul 2011 21:02:49 +0000 (UTC) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Stefaan Himpe writes: > > Now, I have an ulterior motive in raising this issue... I can't find the > > original article I read! My google-fu has failed me (again...). I don't > > suppose anyone can recognise it and can point me at it? > My sarcasm detector warns me not to add a link, although perhaps it's > time for recalibration (after all, summer season started) :-) He's not asking for a link to the "Implicit initialization is EVIL" thread; he's asking for a link to the original article he read elsewhere which praised the bendfists of implicit initialization. -- 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 bahamutzero8825 at gmail.com Tue Jul 5 17:04:18 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 16:04:18 -0500 Subject: embedding: how do I redirect print output? In-Reply-To: References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E137C52.9020905@gmail.com> On 2011.07.05 10:20 AM, Chris Angelico wrote: > You, sir, have a warped and twisted mind. > > And I love it!! > > Now to secretly put code into some module somewhere and wait for > people to start tearing their hair out.... wait, did I say that out > loud? from pytroll import print From klica_sk8 at hotmail.com Tue Jul 5 17:25:22 2011 From: klica_sk8 at hotmail.com (miguel olivares varela) Date: Tue, 5 Jul 2011 14:25:22 -0700 Subject: write file Message-ID: Hi, i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. this is my an example of source file: [test.csv] Name;Lastname;Age;ContractDate;PhoneNumber John;Smith;20110128 105840;33611111111 Mike;Brown;20110128 105842;33622222222 James;Ryan;20110128 105850;33633333333 Barry;Jackson;20110128 105847;33644444444 [here my code:] import sys import csv import os import glob import time dir_cdr = "/tmp" #loop to find files csv in a directory and read thoses files for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): file_source = open(cdr_files_in, 'r') reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) try: for data in reader: if data: firstname = data[0] lastname = data[1] date_source = data[2] phone = data[3] #Date to epoch timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) fout = open("out.csv", "w") print >>fout, lastname, firstname, timestamp, phone fout.close() sys.exit() file_source.close() except csv.Error, e: print e file_source.close() sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) [out.csv] Smith John 1296208720 33611111111 Could you help me? Best Regards, Miguel -------------- next part -------------- An HTML attachment was scrubbed... URL: From StefanMandl at web.de Tue Jul 5 17:30:13 2011 From: StefanMandl at web.de (S.Mandl) Date: Tue, 5 Jul 2011 14:30:13 -0700 (PDT) Subject: emacs lisp text processing example (html5 figure/figcaption) References: Message-ID: > haven't used XSLT, and don't know if there's one in emacs... > > it'd be nice if someone actually give a example... > Hi Xah, actually I have to correct myself. HTML is not XML. If it were, you could use a stylesheet like this:
which applied to this document:

Just having fun

with all the
my cat my cat

my 2 cats

cats here:

Just fooling around

jamie's cat

jamie's cat! Her blog is http://example.com/jamie/

would yield:

Just having fun

with all the
my cat my cat
my 2 cats
cats here:

Just fooling around

jamie's cat
jamie's cat! Her blog is http://example.com/jamie/
But well, as you don't have XML as input ... there really was no point to my remark. Best, Stefan From drsalists at gmail.com Tue Jul 5 17:37:07 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Jul 2011 14:37:07 -0700 Subject: write file In-Reply-To: References: Message-ID: What's date_cdr supposed to be? Is your exception handler doing unusual things with sys.exit? Did you try to run this? When I try to run it, it fails to compile. You might want to try opening your output file once and writing to it repeatedly, then close()ing it after all your writes are completed. Or use "with": http://effbot.org/zone/python-with-statement.htm On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela < klica_sk8 at hotmail.com> wrote: > > Hi, > > i got a csv file that i need to modify and create a new one, i have no > problem to read mi 'test.cvs' which is the source file but when i try to > create a new one with the modifications i only got the first row in my > 'out.csv' file. I think there is somethng wrong in my loop because i can't > put into the rest. > > > this is my an example of source file: > [test.csv] > Name;Lastname;Age;ContractDate;PhoneNumber > John;Smith;20110128 105840;33611111111 > Mike;Brown;20110128 105842;33622222222 > James;Ryan;20110128 105850;33633333333 > Barry;Jackson;20110128 105847;33644444444 > > > [here my code:] > > import sys > import csv > import os > import glob > import time > > dir_cdr = "/tmp" > #loop to find files csv in a directory and read thoses files > for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): > file_source = open(cdr_files_in, 'r') > reader = csv.reader(file_source, delimiter=';', > quoting=csv.QUOTE_NONE) > try: > for data in reader: > if data: > firstname = data[0] > lastname = data[1] > date_source = data[2] > phone = data[3] > #Date to epoch > > timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) > fout = open("out.csv", "w") > print >>fout, lastname, firstname, > timestamp, phone > fout.close() > sys.exit() > file_source.close() > except csv.Error, e: > print e > file_source.close() > sys.exit('file %s, line %d: %s' % (file_source, > reader.line_num, e) > > [out.csv] > Smith John 1296208720 33611111111 > > > Could you help me? > > Best Regards, > Miguel > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean.m.ochoa at gmail.com Tue Jul 5 17:52:49 2011 From: sean.m.ochoa at gmail.com (bitcycle) Date: Tue, 5 Jul 2011 14:52:49 -0700 (PDT) Subject: How do twisted and multiprocessing.Process create zombies? Message-ID: In python, using twisted loopingcall, multiprocessing.Process, and multiprocessing.Queue; is it possible to create a zombie process. And, if so, then how? From gordon at panix.com Tue Jul 5 17:58:01 2011 From: gordon at panix.com (John Gordon) Date: Tue, 5 Jul 2011 21:58:01 +0000 (UTC) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In John Gordon writes: > which praised the bendfists of implicit initialization. Wow, that's quite a typo! I meant "benefits", of course. -- 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 benjamin.kaplan at case.edu Tue Jul 5 18:09:09 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 5 Jul 2011 15:09:09 -0700 Subject: write file In-Reply-To: References: Message-ID: On Jul 5, 2011 2:28 PM, "miguel olivares varela" wrote: > > > Hi, > > i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. > > > > [here my code:] > > import sys > import csv > import os > import glob > import time > > dir_cdr = "/tmp" > #loop to find files csv in a directory and read thoses files > for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): > file_source = open(cdr_files_in, 'r') > reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) > try: > for data in reader: > if data: > firstname = data[0] > lastname = data[1] > date_source = data[2] > phone = data[3] > #Date to epoch > timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S"))) > fout = open("out.csv", "w") > print >>fout, lastname, firstname, timestamp, phone Do you understand what these next two lines are doing? They are closing the file and then exiting the program. I'm pretty sure that's not what you want to do here. > fout.close() > sys.exit() > file_source.close() > except csv.Error, e: > print e > file_source.close() > sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) > > [out.csv] > Smith John 1296208720 33611111111 > > > Could you help me? > > Best Regards, > Miguel > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Jul 5 18:09:46 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2011 16:09:46 -0600 Subject: emacs lisp text processing example (html5 figure/figcaption) In-Reply-To: References: Message-ID: On Tue, Jul 5, 2011 at 2:37 PM, Xah Lee wrote: > but in anycase, i can't see how this part would work >

((?:[^<]|<(?!/p>))+)

It's not that different from the pattern ?alt="[^"]+"? earlier in the regex. The capture group accepts one or more characters that either aren't '<', or that are '<' but are not immediately followed by '/p>'. Thus it stops capturing when it sees exactly '

' without consuming the '<'. Using my regex with the example that you posted earlier demonstrates that it works: >>> import re >>> s = '''
... jamie's cat ...

jamie's cat! Her blog is http://example.com/jamie/

...
''' >>> print re.sub(pattern, replace, s)
jamie's cat
jamie's cat! Her blog is http://example.com/jamie/
Cheers, Ian From klica_sk8 at hotmail.com Tue Jul 5 18:09:53 2011 From: klica_sk8 at hotmail.com (miguel olivares varela) Date: Tue, 5 Jul 2011 15:09:53 -0700 Subject: write file In-Reply-To: References: , Message-ID: What's date_cdr supposed to be? It was a mistake it should be date_source Is your exception handler doing unusual things with sys.exit? Not really Did you try to run this? When I try to run it, it fails to compile. it compiles i have no problems with the compilation. The issue is the result 'out.csv', what i want is to save all the modified rows from 'test.csv' into 'out.csv' but i only can save the firs row. You might want to try opening your output file once and writing to it repeatedly, then close()ing it after all your writes are completed. Or use "with": http://effbot.org/zone/python-with-statement.htm On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela wrote: Hi, i got a csv file that i need to modify and create a new one, i have no problem to read mi 'test.cvs' which is the source file but when i try to create a new one with the modifications i only got the first row in my 'out.csv' file. I think there is somethng wrong in my loop because i can't put into the rest. this is my an example of source file: [test.csv] Name;Lastname;Age;ContractDate;PhoneNumber John;Smith;20110128 105840;33611111111 Mike;Brown;20110128 105842;33622222222 James;Ryan;20110128 105850;33633333333 Barry;Jackson;20110128 105847;33644444444 [here my code:] import sys import csv import os import glob import time dir_cdr = "/tmp" #loop to find files csv in a directory and read thoses files for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ): file_source = open(cdr_files_in, 'r') reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE) try: for data in reader: if data: firstname = data[0] lastname = data[1] date_source = data[2] phone = data[3] #Date to epoch timestamp=int(time.mktime(time.strptime(date_source, "%Y%m%d %H%M%S"))) fout = open("out.csv", "w") print >>fout, lastname, firstname, timestamp, phone fout.close() sys.exit() file_source.close() except csv.Error, e: print e file_source.close() sys.exit('file %s, line %d: %s' % (file_source, reader.line_num, e) [out.csv] Smith John 1296208720 33611111111 Could you help me? Best Regards, Miguel -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 5 18:35:01 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:35:01 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: On Jul 5, 11:04?am, Corey Richardson wrote: > How is giving the sort method a function by which to determine the relative > value of objects a control structure? Do you know what a control structure is? > It's something that you use to modify control flow: > > if foo <= bar: > ? ? ? ? foo += 1 > else: > ? ? ? ? bar += 1 Interesting, corey. Very interesting. However the fun is yet to come so stay tuned... > That's a control structurem the "if-else". I don't know what Ruby calls a > control structure, but that's what it is. for and while are in there too. > When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? So are you suggesting that a control structure must have at minimum one of "for", "while", or "if"? Okay, i listening. Go on... > We'll call that argument srt, here's a sample (naive) implementation: > > def sort(key): > ? ? ? ? lst = self.internal_list > ? ? ? ? for n in range(len(self.internal_list) - 1): > ? ? ? ? ? ? ? ? for i in range(len(self.internal_list) - 1): > ? ? ? ? ? ? ? ? ? ? ? ? if srt(lst[i], lst[i+1]) < 0: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lst[i], lst[i+1] = lst[i+1], lst[i] > > See what's in there? An if. Yes there IS and "if" in there and IF you look closely enough you may see two "for"'s also. So by your own definition this (naive) code qualifies as a control structure. Interesting Corey, very interesting. But wait just a second Corey. My statement has nothing to do with sort. sort is just the vehicle. My statement is that the cmp argument to sort IS a user defined control structure (the code block to be exact). It doesn't matter that the code is contained in a function object. That's like saying a cake is not a cake because it was packaged in a shoe box instead of a cake box. > Sure, WHAT the if does is user-controlled with the > key, Well as long as you can admit that fact. > but that doesn't make that particular if a new control structure, Oh i see. Change the rules as we go eh? > and > it certainly doesn't make the key a control structure. You can pass a key > to a sort even in C and that certainly doesn't have user defined control > structures. What the hell does C have to do with Python Corey? One thing is for sure, i always get a giggle from your self defeating posts. You're the best enemy a person could have. Thank you. *bows* From rosuav at gmail.com Tue Jul 5 18:36:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:36:56 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 4:14 AM, sal migondis wrote: > On Jul 4, 10:31?pm, alex23 wrote: >> rantingrick wrote: >> > What do you think will be the eventual outcome of the human existence >> > Alex? Since you have no imagination i will tell you, a singular >> > intelligence. > > All from the land of creationism. I don't see the connection between creationism and a Borg-like "singularity of intelligence" where we all lose individuality. But this is now decidedly off-topic for a Python mailing list. ChrisA From rantingrick at gmail.com Tue Jul 5 18:38:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:38:49 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 5, 10:17?am, Chris Angelico wrote: > It's actually quite easy to implement this, even if you _are_ forced > to have one primary window. You just have an invisible primary whose > sole purpose is to "be the application", and then everything else is > secondary windows. Kinda defeats the purpose of forcing applications > to have one primary window, though. > > To my thinking, there will always be one primary *thread*, and GUI > facilities are secondary to the process, never the other way around. > When the main thread exits, the process ends. Chris are you playing devils advocate (for my team). I am confused? :-) From invalid at invalid.invalid Tue Jul 5 18:39:11 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 5 Jul 2011 22:39:11 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> Message-ID: On 2011-07-05, Waldek M. wrote: > Dnia Tue, 5 Jul 2011 14:11:56 +0000 (UTC), Grant Edwards napisa?(a): >> Because those specially-formatted comments are wrong. > > ... because? In my experience, they're wrong because somebody changes the code and not the comments. > Not in sarcasm mode; just curious why you don't like them. There've been too many times when I couldn't trust them. -- Grant Edwards grant.b.edwards Yow! I'm totally DESPONDENT at over the LIBYAN situation gmail.com and the price of CHICKEN ... From rantingrick at gmail.com Tue Jul 5 18:42:17 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:42:17 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> Message-ID: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> On Jul 5, 11:00?am, Web Dreamer wrote: > What he means is that On Mac, if you close "all" windows, the application is > still running. Then that is NOT closing windows that is only ICONIFIYING/HIDING them. Let's use the correct lingo people! From rosuav at gmail.com Tue Jul 5 18:45:00 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:45:00 +1000 Subject: Testing if a global is defined in a module In-Reply-To: <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 3:36 AM, Steven D'Aprano wrote: > > Because unless you are extremely disciplined, code and the comments > describing them get out of sync. Quote: > > "At Resolver we've found it useful to short-circuit any doubt and just > refer to comments in code as 'lies'. " > --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 And yet, as I have found out by trying to embed V8 (Google's Javascript engine), those little comments can (a) prove the difference between a bug and a misfeature, and (b) be all the documentation there is. Okay, it's not QUITE the latter, but most things are not documented outside of the source, and I greatly appreciate those little comments! ChrisA From rantingrick at gmail.com Tue Jul 5 18:47:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 15:47:09 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> Message-ID: <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> On Jul 5, 6:14?am, Gregory Ewing wrote: > rantingrick wrote: > > Most applications consist of one main window > > (a Tkinter.Tk instance). > > You've obviously never used a Macintosh. On the Mac, it's > perfectly normal for an application to open multiple > documents, each in its own window, with no one window > being the "main" window. Any of them can be closed (or > even *all* of them) and the application continues to run > until you explicitly quit it. And how do you EXPLICITY quit the application? Because the interface for window management(on windows box) is three buttons "minimize", "maximize", and "destroy". If closing the window only "hides" the window then you are just "managing" a window's "visibility". We are talking about destroying GUI processes here. From rosuav at gmail.com Tue Jul 5 18:49:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 08:49:36 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 8:35 AM, rantingrick wrote: > You're the > best enemy a person could have. Thank you. *bows* Compliments are made to be returned, and this one is particularly well suited. *bow* Chris Angelico From rosuav at gmail.com Tue Jul 5 19:20:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 09:20:53 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 8:42 AM, rantingrick wrote: > Chris are you playing devils advocate (for my team). I am confused? :-) I say whatever I choose to say. Don't pigeon-hole me into "on your team" or "not on your team" or "devil's advocate" or whatever. And at two in the morning, "whatever I choose to say" can be quite random. :) > On Jul 5, 11:00?am, Web Dreamer wrote: > >> What he means is that On Mac, if you close "all" windows, the application is >> still running. > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > Let's use the correct lingo people! Actually, it IS closing those windows. Why wouldn't it be? 1) User presses Alt-F4, or clicks the X, or opens the system menu and chooses 'Close Window'. 2) Windowing manager sends a message to the appropriate thread's queue (on MS Windows, that's WM_CLOSE; not sure how on Linux as I haven't bothered to dig that deep - interface layers like Tkinter and GTK don't count). 2a) Toolkit passes message to application code, if applicable. 3) Application destroys this window, leaving the other windows alive. The memory used by that window can be reclaimed. Handles to its objects are no longer valid. The window really is closed. The application might not have terminated, but that window has not been minimized - the *window* is closed. > And how do you EXPLICITY quit the application? Because the interface > for window management(on windows box) is three buttons "minimize", > "maximize", and "destroy". If closing the window only "hides" the > window then you are just "managing" a window's "visibility". We are > talking about destroying GUI processes here. Presumably you would right-click it and choose "Exit" or something. Up to the application. If all else fails, kill -9 it. The interface for window management does not actually have "destroy", it has "close". The normal handling of a close message is to destroy the window; and in many applications, once all windows have been destroyed, the process terminates. These are three quite separate concepts. The separation of "close" and "destroy" is most easily seen in "Are you sure" prompts - you send a Close signal to the window, but the application queries you before going through with the destruction. And even once the last window has been destroyed, that has nothing to do with process termination. I could conceivably write a program that sits invisibly in the background until a network message arrives. Upon receipt of such a message, the program initializes the GUI subsystem and opens a window. When the user closes the window, the program flushes all GUI code out of memory and waits for the next message. While it's waiting, is there any "main window" that exists but has just been hidden? No. But is the application still running? Of course! Completely separate. ChrisA From python.list at tim.thechases.com Tue Jul 5 19:21:02 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 05 Jul 2011 18:21:02 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <4E139C5E.2020003@tim.thechases.com> On 07/05/2011 05:35 PM, rantingrick wrote: > One thing is for sure, i always get a giggle from your self > defeating posts. You're the best enemy a person could have. > Thank you. *bows* Every time I see a rantingrick post, it's like watching the Black Knight scene from the Holy Grail yet again. You know what's going to happen; you know he has a purposeless fight; you know he's going to laughably lose; and you know he's going to *think* that he is invincible & has won. ARTHUR: What are you going to do, bleed on me? BLACK KNIGHT: I'm invincible! ARTHUR: You're a looney. Sigh...ready for an intermission... -tkc From philip at semanchuk.com Tue Jul 5 19:33:47 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 5 Jul 2011 19:33:47 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E1366D5.6030208@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> Message-ID: On Jul 5, 2011, at 3:32 PM, Laszlo Nagy wrote: > >> 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code. > [code sample snipped] > > Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. I get different results than you. Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- Traceback (most recent call last): File "x.py", line 46, in onPopupMenu item = wx.MenuItem(None,-1,u"Test") File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu Hope this helps more than it confuses. Cheers Philip From rantingrick at gmail.com Tue Jul 5 19:47:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 16:47:53 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> On Jul 5, 6:20?pm, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 8:42 AM, rantingrick wrote: > [...] > > On Jul 5, 11:00?am, Web Dreamer wrote: > >> What he means is that On Mac, if you close "all" windows, the application is > >> still running. > > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > > Let's use the correct lingo people! > > Actually, it IS closing those windows. Why wouldn't it be? > [...] > The memory used by that window can be reclaimed. Handles to its > objects are no longer valid. The window really is closed. The > application might not have terminated, but that window has not been > minimized - the *window* is closed. And you need the OS to that for you!?!? Are you joking? > I could conceivably write a program that sits invisibly in the > background until a network message arrives. Upon receipt of such a > message, the program initializes the GUI subsystem and opens a window. > When the user closes the window, the program flushes all GUI code out > of memory and waits for the next message. While it's waiting, is there > any "main window" that exists but has just been hidden? No. But is the > application still running? Of course! Completely separate. And so could i using Tkinter and it's "supposedly" flawed window hierarchy. Remind me again why we are discussing this? From rosuav at gmail.com Tue Jul 5 19:54:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 09:54:09 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 9:47 AM, rantingrick wrote: >> > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. >> > Let's use the correct lingo people! >> >> Actually, it IS closing those windows. Why wouldn't it be? >> [...] >> The memory used by that window can be reclaimed. Handles to its >> objects are no longer valid. The window really is closed. The >> application might not have terminated, but that window has not been >> minimized - the *window* is closed. > > And you need the OS to that for you!?!? Are you joking? > To do what for me? Close windows? Reclaim memory? Terminate applications? I don't understand your bogglement. ChrisA From rantingrick at gmail.com Tue Jul 5 20:15:44 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 17:15:44 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> Message-ID: <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> On Jul 5, 6:54?pm, Chris Angelico wrote: > To do what for me? Close windows? Reclaim memory? Terminate > applications? I don't understand your bogglement. ClaimA: I made claim that Tkinter's window hierarchy is not only normal, but justified in modern GUI programming. ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's system of window management was superior and did not need such a "window hierarchy" simply because; 1. You can create a program that twiddles it's thumbs (using very little memory) until a message is received. 2. Upon receiving a message the program can open a GUI window. 3. When the user closes the GUI window (definition of "close" is not nailed down yet!) the program will free the GUI memory and start twiddling it's thumbs again until the next message arrives. 4. rinse and repeat until you are happy. It's obvious that yours and my claims are contradicting. So with that said, at what point does Tkinter or Windows fail in this example you provide? Because, i can recreate the exact same functionality on a windows box without need of the underlying window manager's help. 1. What is your point? 2. And how does it prove my position incorrect? From rosuav at gmail.com Tue Jul 5 20:34:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 10:34:08 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 10:15 AM, rantingrick wrote: > On Jul 5, 6:54?pm, Chris Angelico wrote: > >> To do what for me? Close windows? Reclaim memory? Terminate >> applications? I don't understand your bogglement. > > ClaimA: I made claim that Tkinter's window hierarchy is not only > normal, but justified in modern GUI programming. > > ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's > system of window management was superior and did not need such a > "window hierarchy" simply because; I never said "better". I just said that it's possible to create an application that *to the user* has no main window, even though *to the system* it does. And I'm also pointing out that in most good toolkits, there's no "main window", but instead a "main thread". > 1. You can create a program that twiddles it's thumbs (using very > little memory) until a message is received. > 2. Upon receiving a message the program can open a GUI window. > 3. When the user closes the GUI window (definition of "close" is not > nailed down yet!) the program will free the GUI memory and start > twiddling it's thumbs again until the next message arrives. > 4. rinse and repeat until you are happy. Again, pointing out that it's possible, not that it's good. (Most messenger programs will have a means of *sending* messages too, which makes a good basis for a main window.) It's not efficient to keep loading up GUI libraries and discarding them again. But it's possible, and it would mean that you genuinely have multiple equal main windows. > It's obvious that yours and my claims are contradicting. So with that > said, at what point does Tkinter or Windows fail in this example you > provide? Because, i can recreate the exact same functionality on a > windows box without need of the underlying window manager's help. Actually, everything you do requires the underlying window manager, otherwise you're just painting your own pixels on the screen. And I never said that this model was possible in some and not others. (Although it's a bit harder with Windows; there's no explicit call to finalize windowing, so most likely the application will hold GUI memory until termination.) ChrisA From stefan_ml at behnel.de Tue Jul 5 20:47:55 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 06 Jul 2011 02:47:55 +0200 Subject: How do twisted and multiprocessing.Process create zombies? In-Reply-To: References: Message-ID: bitcycle, 05.07.2011 23:52: > In python, using twisted loopingcall, multiprocessing.Process, and multiprocessing.Queue; is it possible to create a zombie process. And, if so, then how? I think it's best to consult your local Voodoo master on the matter of zombie creation processes. That being said, there are far too many zombies around already, so please don't add to that. Stefan From rantingrick at gmail.com Tue Jul 5 21:07:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:07:43 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 4, 6:24?pm, Steven D'Aprano wrote: > rantingrick wrote: > Some people want to make Python more dynamic. Some want it to be less > dynamic. Some care about integrating it with Java or .Net, some don't care > about either. Some are interested in clever optimization tricks, some > oppose adding any more complexity. > > Some want it to be faster, and are happy to throw more memory at it to do > so. Some want it to use less memory, because on embedded devices and smart > phones memory is the bottleneck, not time. > > Some only program in Python. Some treat Python as merely one language out of > many that they use. > > Some come to Python from the C/C++ community, and their wants are influenced > by C. Some come to Python from Lisp, Scheme or Haskell, and their wants are > influenced by functional programming ideas. Some have never programmed > before, and don't know want they want. And are any of them getting what they want? No. And they should not. (stay tuned for the reason "why not") > Define "best for all", and try not to make it "what Rick wants". You want features? And remember i am talking about scripting/glue level languages here. Something to replace Python, Ruby, Perl, JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- our-problems" pipe dream language. * Intuitive syntax. * Productivity friendly. * Complex enough to solve large problems but simple enough for simple problems (that does include extending into C when needed) * Multi paradigm (problem * Promotes a culture of code readability (because people read source; not just machines!). * there is always more. * we all know this list steven! > No, Python is not a monoculture. There are the Stackless, Jython, PyPy and > IronPython sub-cultures, all with their own needs, wants and desires. There > are sub-cultures for embedded devices and smart phones, sub-cultures for > those who use Python as a teaching language, for web development, for GUI > development, and for system administration. There are the Numpy and Scipy > sub-cultures, sub-cultures in the fields of linguistics and biology. Hmm. Just think how far ahead we would be if these folks would stop trying to support petty differences and focus on a singular Python language? But let's not kid ourselves here! This problem is far bigger than python. Selfishness infests every group of humans on this planet. Why do we need multiple OS's? Just so one can say "\" is the proper file path sep and someone else can say "/" is the proper one! Are you kidding me? Look at the multiplicity. Look at the asinine nature of it all and for once in your life join the group that is the future of human evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello! > Nature isn't striving for anything. > [...] > what you believe is not new and it is > not a minority view. It is old, obsolete, Before you go out babbling about "concepts" you should understand what these "concepts" are; or at least at the minimum read the freaking Wiki! My statements are in no way remotely related to "Great Chain of Being" and this feeble attempt to prove so is obviously another one of your half stuffed straw-men arguments. > and the vast majority of people > with no modern biology education believe something like it. You sure presume to know quite a lot about "uneducated people". Do you know these folks personally? Do you chit-chat with them on the subway or whilst sharing a Frappuccino? > Since needs are frequently in opposition (e.g. the speed/memory trade-off), > a single "true language" must be a compromise language that leaves nobody > happy. Oh Steven, that's just your fear of unity acting out again. Yes, what's good for the group will not *always* be good for you, or me, or xah lee! But what matters is progress. Not your selfish needs Steven. > Or some dictator (Rick?) declares that such-and-such a set of > features is, by definition, the "perfect" language and those who want > something else have to miss out. I have never held myself out as some sort of dictator. These decisions must be made in a democratic manner. This is FUD. > Imagine a world where *every* shop was Walmart. That would be good for > Walmart, but terrible for everyone else. That's Rick's plan for > programming. You know Steven, wal-mart is a very successful company. And wal-mart meets the needs of the many. Again you fail to see the truth behind the curtain. If (as you say) wal-mart really is such a bad company and it's existence is hurting "the many"... then explain to the class (if you can) why wal mart is the most successful retail chain in the history of the world? We are listening... Do you realize that without customers buying products that wal-mart could never get to this pinnacle of retail success? If you are correct, then people buy from wal-mart even though wal-mart is "bad" for them. Please explain this reversal of reality Steven because i think you are watching too much MTV and it's rotting your brain. > Go do something useful. Well i might just go to wal-mart! From rantingrick at gmail.com Tue Jul 5 21:10:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:10:43 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <8e2cfeb0-ddbd-4cb5-ac88-91cc53394ac6@d7g2000vbv.googlegroups.com> <48efc27f-7dc7-4980-a00a-74f42670c683@fv14g2000vbb.googlegroups.com> Message-ID: On Jul 5, 7:34?pm, Chris Angelico wrote: > Actually, everything you do requires the underlying window manager, > otherwise you're just painting your own pixels on the screen. And I > never said that this model was possible in some and not others. > (Although it's a bit harder with Windows; there's no explicit call to > finalize windowing, so most likely the application will hold GUI > memory until termination.) Ah ha. I think we are getting somewhere now. Everything up to this point has been mostly exposition :-) From dustin299 at gmail.com Tue Jul 5 21:30:57 2011 From: dustin299 at gmail.com (Dustin Cheung) Date: Tue, 5 Jul 2011 18:30:57 -0700 Subject: web browsing short cut In-Reply-To: References: Message-ID: Hey, I am looking into Tkinter. But i am not sure if it will actually work. This maybe a crazy idea but i was wondering if i can put a web browser in the frame. I have tried to use Tkinter to resize and place the windows to certain areas of the screen but that's not working or the way im approaching this problem is completely wrong. I want to make a program that will have websites displayed in specific areas of the screen. I was planning on using the program on the big screen. So is it possible to put the web browser inside the frame in Tkinter? On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert wrote: > On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung wrote: > > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > > and re-sizes them to display on different areas on the screen. I looked > > around but i had no luck. Is that possible with python? if so can someone > > point to to the right direction? Here is what I came up with so far.. > > The window positioning+resizing bit will likely require using > platform-specific APIs. Since you appear to be on Windows, the > relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 > ). You would use it to invoke some COM API that does window > positioning+resizing. I am unable to give more details as I'm on a > Mac. > > Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? > > Cheers, > Chris > -- Dustin Cheung -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 5 21:53:23 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 18:53:23 -0700 (PDT) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> On Jul 5, 10:26?am, Steven D'Aprano wrote: > This is not strictly Python, although it is peripherally relevant. > > Some month or three ago, I read an article or blog post about API design, > specifically the wrong-headedness of insisting that callers manually > initialise instances using a separate step after creation. > > The argument goes, if your API looks something like this: > > instance = Spaminator(extra_truffles=False) > instance.activate() > instance.nom_nom_nom() > => prints "yummy spam, the food of the Gods!!!" > > chances are that you are doing it wrong and your users will hate you. Why > force the user to manually "flip the switch" (so to speak)? It's not like > they can possibly avoid it: I completely agree! > Exceptions to this rule are if the Spaminator has side-effects (e.g. files, > in which case the user may want finer control in when they are opened and > closed), or if there are meaningful operations you can perform on an > inactive Spaminator. Agreed again! > It's also relevant to > tkinter, which will implicitly create a root window for you when needed. WRONG. Oh wait, of course, you are correct! YES! Maybe we should have library modules import only when needed! i mean, who needs those pesky import statements anyways! Sure it will slow down run time BUT WHO CARES! My gawd, you just opened my mind to so many possibilities! Why stop at library modules, if it is not there just download the source at run time! Guido really dropped the ball on this one folks. > Since you can't do anything without a root window, I don't see the benefit > in forcing the user to do so. The reason is simple. It's called order. It's called learning from day one how the order of things exists. Widgets are part of windows, not the other way around. Saving a few keystrokes is not acceptable if you jumble the understanding of a new student. To understand and use Tkinter properly you must understand the order of window->widget. > When they need to learn about root windows, > they will in their own good time. So you would start drivers education class with road construction? Or the history of the internal combustion engine? Who cares about actually *driving* the car. From rosuav at gmail.com Tue Jul 5 22:31:02 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 12:31:02 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 11:07 AM, rantingrick wrote: > On Jul 4, 6:24?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Define "best for all", and try not to make it "what Rick wants". > > You want features? And remember i am talking about scripting/glue > level languages here. Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", ?"single-answer-to-all- > our-problems" pipe dream language. > > ?* Intuitive syntax. Subjective. > ?* Productivity friendly. Depends heavily on the task at hand. HQ9+ is extremely productivity friendly if you're trying to write a quine. > ?* Complex enough to solve large problems but simple enough for simple > problems (that does include extending into C when needed) Subjective. Any Turing-complete language is technically complex enough to solve large problems, but would you care to write a web browser in Ook? > ?* Multi paradigm (problem ? > ?* Promotes a culture of code readability (because people read source; > not just machines!). from __future__ import braces # this'll make it more readable for C programmers >> No, Python is not a monoculture. There are the Stackless, Jython, PyPy and >> etc etc > > Hmm. Just think how far ahead we would be if these folks would stop > trying to support petty differences and focus on a singular Python > language? Imagine how much faster we'd all reach our destinations if whenever I push my car's accelerator, it moves every car in the world the same distance in the same direction! > This problem is far bigger than python. Selfishness infests every > group of humans on this planet. Why do we need multiple OS's? Just so > one can say "\" is the proper file path sep and someone else can say > "/" is the proper one! Are you kidding me? I've said for a while that Microsoft could do far worse than to turn Windows into a GUI that sits on top of a Unix-derived kernel. They won't do it, though, because it would be tantamount to admitting both that Unix is superior to Windows, AND that Apple got it right. However, if the entire world moved to one kernel, that would be a spof. That's why the DNS root servers don't all run the same software; if a flaw were found in BIND that brought everything down, there would still be three root servers (two of them anycasted) which would be unaffected. There's another good reason for diversity, too. Suppose you know only one language, and you want to verify that your program is producing correct results. What do you do? You're forced to do the job manually. If you have a completely different system, you could verify it against that - for instance, check your Python program by implementing equivalent functionality in Lua. > Look at the multiplicity. Look at the asinine nature of it all and for > once in your life join the group that is the future of human > evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello! You can't know what the future of human evolution is, unless it involves time travel. >> Since needs are frequently in opposition (e.g. the speed/memory trade-off), >> a single "true language" must be a compromise language that leaves nobody >> happy. > > Oh Steven, that's just your fear of unity acting out again. Yes, > what's good for the group will not *always* be good for you, or me, or > xah lee! But what matters is progress. Not your selfish needs Steven. And there you have the nub. Your idea of a perfect language is one that won't always be good for any particular person. This is where diversity comes to the fore. I'm currently using Google's V8 engine as my scripting engine, but I need it to be slightly different - so I modified it. I have offered the patch back to the community, and it may or may not end up being accepted, but that is immaterial. Right here, right now, I am running a modified V8, and it works FOR ME. What you're saying is that "progress" is more important than any individual... >> Or some dictator (Rick?) declares that such-and-such a set of >> features is, by definition, the "perfect" language and those who want >> something else have to miss out. > > I have never held myself out as some sort of dictator. These decisions > must be made in a democratic manner. This is FUD. ... which is exactly what many dictators have said. However, that is immaterial. Democracy DOES NOT WORK. Plain and simple. You cannot build a programming language democratically. Python has a BDFL. Open Office has had a variety of owners, and when enough people dislike the current owner, the project forks (eg LibreOffice). Savoynet is run by Marc Shepherd, who took over in 1998. All the best commanders listen to people, but ultimately, they make the decisions. Even in USA politics, where people talk proudly of living in a democracy, what you actually have is a President who wields a lot of power. >> Imagine a world where *every* shop was Walmart. That would be good for >> Walmart, but terrible for everyone else. That's Rick's plan for >> programming. > > You know Steven, wal-mart is a very successful company. And wal-mart > meets the needs of the many. They're cheap, ubiquitous, and convenient. They are NOT the ideal for every situation. Of course they're successful - that's because they buy and sell things at a profit. Steven never recommended abolishing Walmart, just said that it would be bad for people if Walmart were the only shop anywhere. > Again you fail to see the truth behind > the curtain. If (as you say) wal-mart really is such a bad company and > it's existence is hurting "the many"... then explain to the class (if > you can) why wal mart is the most successful retail chain in the > history of the world? Success just means they're able to make money. Fake pharmaceuticals companies can make money too; they send out roughly twelve million emails for every sale they get, but it's still a rip-roaring business. I doubt you would want all businesses in the world to follow THAT model. Walmart may and may not be hurting "the many". They certainly are not serving "the all". Other shops are also able to make a profit, which strongly suggests that they, too, are wanted. > Do you realize that without customers buying products that wal-mart > could never get to this pinnacle of retail success? If you are > correct, then people buy from wal-mart even though wal-mart is "bad" > for them. Please explain this reversal of reality Steven because i > think you are watching too much MTV and it's rotting your brain. If Steven is correct, then people buy from other shops because they are better for them than Walmart is. And that means that trying to unify ALL shopping under the one company name will be a disaster. I hope I make myself clear? ChrisA From rosuav at gmail.com Tue Jul 5 22:44:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 12:44:52 +1000 Subject: Implicit initialization is EXCELLENT In-Reply-To: <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 11:53 AM, rantingrick wrote: > So you would start drivers education class with road construction? Or > the history of the internal combustion engine? Who cares about > actually *driving* the car. > I believe that starting driver ed with some basics of how an internal combustion engine works would be a Good Thing. If you're going to be in control of a ton of steel that's capable of moving at a hundred kays, you ought to know at least a bit about what provides the kinetic energy. There's a difference between comprehension and jumping through hoops. In your driver ed example, I don't believe that the accelerator pedal should be replaced with a flexible fuel-line that the driver squeezes to control flow to the engine; but on the other hand, I don't think the brake pedal should be replaced by a single button saying "stop car" either. Arrogance is a normal part of designing programming languages (see Larry Wall's comments regarding Perl, for instance). But arrogance to the extent of forcing your views on programmers is generally resented, and with good reason. If you force too much on people, they'll go elsewhere. ChrisA From mozbugbox at yahoo.com.au Tue Jul 5 23:12:47 2011 From: mozbugbox at yahoo.com.au (Just Fill Bugs) Date: Wed, 06 Jul 2011 11:12:47 +0800 Subject: Should ctypes handle mis-matching structure return ABI between mingw and MSVC? Message-ID: According the Bug 36834 of gcc, there is a mis-matching between mingw and MSVC when a struct was returned by value from a C function. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834 Should ctypes handle this situation automatically somehow? A ctypes discussion on 2009: http://thread.gmane.org/gmane.comp.python.ctypes.user/4439 From rantingrick at gmail.com Tue Jul 5 23:45:06 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 5 Jul 2011 20:45:06 -0700 (PDT) Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Jul 5, 9:44?pm, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 11:53 AM, rantingrick wrote: > > So you would start drivers education class with road construction? Or > > the history of the internal combustion engine? Who cares about > > actually *driving* the car. > > I believe that starting driver ed with some basics of how an internal > combustion engine works would be a Good Thing. If you're going to be > in control of a ton of steel that's capable of moving at a hundred > kays, you ought to know at least a bit about what provides the kinetic > energy. How about kinetic energy itself? If you know *what* produces power to induce kinetic energy into the vehicle but not *how* the laws of physics govern kinetic energy; what damn good is that going to do for you? How about some basics of safe/defensive driving? How about considering the good of the many instead of the you? > There's a difference between comprehension and jumping through hoops. Likewise for priorities and acting aloof. > If you force too much on people, they'll go > elsewhere. Why all this running away with tail between legs? Do these these people have extremely small eggs? I wish they would stand firm and put up a fight instead they're just cowards spewing more endless tripe. From latheefb2 at gmail.com Tue Jul 5 23:45:47 2011 From: latheefb2 at gmail.com (http://123maza.com/65/chill155/) Date: Tue, 5 Jul 2011 20:45:47 -0700 (PDT) Subject: hai Message-ID: http://123maza.com/65/chill155/ From rosuav at gmail.com Tue Jul 5 23:54:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 13:54:22 +1000 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 1:45 PM, rantingrick wrote: >> If you force too much on people, they'll go >> elsewhere. > > ?Why all this running away with tail between legs? > ?Do these these people have extremely small eggs? > ?I wish they would stand firm and put up a fight > ?instead they're just cowards spewing more endless tripe. Standing up and fighting takes effort. It's a lot easier - and a lot more time-efficient - to ignore idiots and trolls and just get some work done. I think I'll do that, right now. Chris Angelico From bahamutzero8825 at gmail.com Wed Jul 6 00:13:36 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 23:13:36 -0500 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E13E0F0.20705@gmail.com> On 2011.07.05 09:31 PM, Chris Angelico wrote: > I've said for a while that Microsoft could do far worse than to turn > Windows into a GUI that sits on top of a Unix-derived kernel. They > won't do it, though, because it would be tantamount to admitting both > that Unix is superior to Windows, AND that Apple got it right. In my experience, it's been the GUIs that are awful and the backend stuff that's been good in Windows. Yes, the NT kernel still has some long standing bugs, but MS has done well with things that matter to sysadmins. chkdsk, for example, has been around for ages, but I still don't know of anything that really beats it. It's certainly saved my ass on several occasions. MS also bought the Sysinternals suite of software, and those programs continue to be very good. I've only had a small amount of experience with it so far, but Powershell seems to be an excellent tool for admin scripting since it interfaces with WMI so well. When it comes to things that interface with your average idiot, however, MS consistently drops the ball. The new interface design they've imposed on their office suite and Explorer is not only just plain bad, but it's infectious (and it's the reason the Firefox and Thunderbird default GUI configurations look horrendous). Another area MS fails it is sensible defaults. They put tons of effort into increasing security in the kernel, but don't use the security features (I'll try to come up with more detail on this later). Explorer /still/ hides known extensions by default, which /still/ makes it easier for bad people to get their victims to execute malware. What I think is that MS should focus on the kernel and encourage others to do their GUIs. From rosuav at gmail.com Wed Jul 6 00:25:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 14:25:56 +1000 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: <4E13E0F0.20705@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 2:13 PM, Andrew Berg wrote: > On 2011.07.05 09:31 PM, Chris Angelico wrote: >> I've said for a while that Microsoft could do far worse than to turn >> Windows into a GUI that sits on top of a Unix-derived kernel. They >> won't do it, though, because it would be tantamount to admitting both >> that Unix is superior to Windows, AND that Apple got it right. > In my experience, it's been the GUIs that are awful and the backend > stuff that's been good in Windows. Suppose I gave you a computer that had GNOME ported to Windows, and used the purplish palette that Ubuntu 10.10 uses, and had a Windows port of bash as its most convenient terminal. Members of this list will doubtless have no problem duck-typing that as a Linux box (to the extent of being quite surprised on seeing something that functions differently). What is Microsoft selling? They're a company, which means they need to keep selling stuff year after year. What's saleable in Windows? Is it the kernel? Maybe, but only by its specs. Far more saleable is the user-facing parts of the system. Sell them a pretty new GUI with transparent windows. Sell 'em a fancy new Office that looks and feels different. Sell a development package that lets programmers use these same facilities in their own code. (And of course, sell them bug fixes, by declaring end-of-life on older products and forcing everyone to move up. But that's different.) Since XP, the Windows kernel has been mostly reliable. I've had programs go wrong, and (eventually) managed to kill the process, upon which everything cleans up fairly nicely. Not that that's really a boast-worthy feature; I'd call it mandatory these days. The main reason I would recommend unifying kernels is simplicity. Let Microsoft play with, and sell, pretty GUIs and pretty apps. Let someone else worry about what's underneath. As an advantage, it would then become possible to buy a copy of Windows, run it *under Linux*, and treat it like a VMWare window. But it's not likely to happen, and I'm not 100% convinced it'd really be a good idea (see DNS root servers argument from earlier). It would make cross-compilation a lot easier, though! Chris Angelico From bahamutzero8825 at gmail.com Wed Jul 6 00:53:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 05 Jul 2011 23:53:33 -0500 Subject: Microsoft GUIs In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: <4E13EA4D.3040504@gmail.com> On 2011.07.05 11:25 PM, Chris Angelico wrote: > Suppose I gave you a computer that had GNOME ported to Windows, and > used the purplish palette that Ubuntu 10.10 uses, and had a Windows > port of bash as its most convenient terminal. Members of this list > will doubtless have no problem duck-typing that as a Linux box (to the > extent of being quite surprised on seeing something that functions > differently). I would love to see a fully functional KDE running on Windows (this is being worked on, but development has been slow and rough). I was talking about GUI design, though, not just the aesthetics of a window manager and widgets. A recent version of bash working on Windows would be nice too, but IMO, MS should be actively promoting PowerShell. It's not that PowerShell is a superior scripting language to bash, but that it's integrated with WMI and is therefore much more convenient for admin stuff. > What is Microsoft selling? They're a company, which means they need to > keep selling stuff year after year. What's saleable in Windows? Is it > the kernel? Maybe, but only by its specs. Far more saleable is the > user-facing parts of the system. Sell them a pretty new GUI with > transparent windows. Sell 'em a fancy new Office that looks and feels > different. Sell a development package that lets programmers use these > same facilities in their own code. I think the reason MS has been creating good sysadmin tools lately is that it's feeling competition from Linux/Unix server solutions. If they can make a Windows domain admin's job easier, they're more likely to sell their OS. As for the end-user side of Windows (and their office suite), AFAICT, they're still pretty complacent with their market share and only change things up for the sake of difference. Since the GUI is the most noticeable part of the software, that's what gets changed. > Since XP, the Windows kernel has been mostly reliable. I've had > programs go wrong, and (eventually) managed to kill the process, upon > which everything cleans up fairly nicely. Not that that's really a > boast-worthy feature; I'd call it mandatory these days. I agree. > Let > Microsoft play with, and sell, pretty GUIs and pretty apps. I completely disagree. MS sucks at making GUIs. From drsalists at gmail.com Wed Jul 6 01:03:04 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Jul 2011 22:03:04 -0700 Subject: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT) In-Reply-To: <4E13E0F0.20705@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: On Tue, Jul 5, 2011 at 9:13 PM, Andrew Berg wrote: > On 2011.07.05 09:31 PM, Chris Angelico wrote: > > I've said for a while that Microsoft could do far worse than to turn > > Windows into a GUI that sits on top of a Unix-derived kernel. They > > won't do it, though, because it would be tantamount to admitting both > > that Unix is superior to Windows, AND that Apple got it right. > Supposedly when Microsoft sold Xenix to SCO, Microsoft signed a legal document that barred them from competing in the *ix space. I do not know if it remains in effect now or not. > In my experience, it's been the GUIs that are awful and the backend > stuff that's been good in Windows. I disagree. The stuff endusers tend to use is polished to some extent, but the backend is verging on hideous. If a developer complains about the ugly internal structure "yeah, but you say that just because you're a computer person / geek." > Yes, the NT kernel still has some > long standing bugs, but MS has done well with things that matter to > sysadmins. chkdsk, for example, has been around for ages, but I still > don't know of anything that really beats it. How about FreeBSD's ability to check a filesystem while it's in use? > I've only had a small > amount of experience with it so far, but Powershell seems to be an > excellent tool for admin scripting since it interfaces with WMI so well. > I worked with PowerShell for about a year (after an acquisition by Microsoft), before eagerly diving back to Python. Here are some of my notes about the problems in PowerShell: 1) If you have a script that expects an array, and you don?t declare it as an array (type declarations are generally optional in PS), things will work fine until you get an array of length 1. Then your code breaks. 1.5) If you have a function that returns an array, you must return it with ,@{$a} to make it always be an array in the caller - it's ostensibly novice friendly, but it seems both novice and sophisticate hostile. 2) Options can be abbreviated, which may cause problems for what-was-working code on PowerShell upgrades, when something that was unique becomes ambiguous due to the addition of a new option having a common prefix with another option. 3) You can throw a string exception in PowerShell; this is disallowed in C# because it?s considered a poor practice. They?re deprecated in Python 2.x too - not sure if they were removed in Python 3. 4) Empty strings and nulls are kind of conflated, which is perhaps simpler in a way in native powershell stuff, but when you call something like a COM method that expects the two to be different, you run into problems that appear to require C# to get around. 5) If you try to invoke an external command having an option with double quotes and blanks in it, the single option will be converted into n+1 options, where n is the number of blanks inside double quotes. Granted, this is probably a problem that PowerShell inherited from one of its dependencies 6) no generators. C#, a supposedly lower-level language, has generators, but generators are a really nice high-level construct 7) Not a big deal, but what's up with the not operator? You Always seem to have to parenthesize, whether using ! or -not 8) If you pass an array of arrays, for EG 2x10, from one host to another using invoke-command, you actually end up with a single 20 element array 9) If you foreach ($foo in $bar), and $bar is empty, you still enter the script block once for $null 10) Sometimes you need comma separated parameters in parens. Sometimes you can't have them. When you can't have them and you're passing to a function that accepts multiple arguments, you end up with the 1st having an array of your arguments, and the 2..nth having $null. That's pretty far from the principle of least surprise 11) To pipe a 2-d array, you need to first convert it to a 3-d array, where the outermost array-ing is a single element - using the comma operator out front. Then send it into the pipeline as a 2-d array 12) DarkYellow is white and DarkMagenta is dark bluish. "It?s a feature. The default colours used by PowerShell are not in the standard console palette. To get the desired colours, we redefine DarkYellow and DarkMagenta and use them instead." 13) ?continue? is not really supported for a Foreach-Object loop, but at least return does what you'd expect continue to do 14) ?break? doesn?t do what it looks like it does in a foreach-object. It?s ending the script like ?continue?. 15) Sometimes foreach is foreach. Sometimes it's foreach-object. 16) break inside a foreach inside a pipeline breaks the whole pipeline > When it comes to things that interface with your average idiot, however, > MS consistently drops the ball. The new interface design they've imposed > on their office suite and Explorer is not only just plain bad, but it's > infectious (and it's the reason the Firefox and Thunderbird default GUI > configurations look horrendous). Hmmmm. Wonder why that is? > Another area MS fails it is sensible > defaults. They put tons of effort into increasing security in the > kernel, but don't use the security features (I'll try to come up with > more detail on this later). The newer security features in Windows are extremely baroque. Communication about them is lacking, even inside the company. I literally think it's more secure to use traditional *ix permissions despite the obvious effort Microsoft has put in on security - *ix permissions aren't as comprehensive, but they're also a simple model that works better. Sometime when you're in a puckish mood, ask a Microsoft expert how many different kinds of "delegation" Windows has, and what they're each good for. It's kind of like asking a *ix expert how many IOCTL's there are, and what they are each for. (Linux has moved away from IOCTL quite a bit because there were far too many in *ix historically). > Explorer /still/ hides known extensions by > default, which /still/ makes it easier for bad people to get their > victims to execute malware. What I think is that MS should focus on the > kernel and encourage others to do their GUIs. Oh my. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed Jul 6 01:29:43 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 00:29:43 -0500 Subject: Microsoft GUIs In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> Message-ID: <4E13F2C7.40704@gmail.com> On 2011.07.06 12:03 AM, Dan Stromberg wrote: > I disagree. The stuff endusers tend to use is polished to some > extent, but the backend is verging on hideous. If a developer > complains about the ugly internal structure "yeah, but you say that > just because you're a computer person / geek." Admittedly, I haven't tried to do a whole lot of development with the Windows APIs, and I certainly haven't tried to develop any software that's heavily tied to the kernel, so I could be wrong in this area. Could you elaborate? > > Yes, the NT kernel still has some > long standing bugs, but MS has done well with things that matter to > sysadmins. chkdsk, for example, has been around for ages, but I still > don't know of anything that really beats it. > > > How about FreeBSD's ability to check a filesystem while it's in use? Actually, I meant in Windows, as in there aren't any 3rd-party tools that really trump chkdsk for repairing NTFS volumes. I should've clarified that. However, that sounds like an awesome feature (though I'm not going to switch to FreeBSD just for that). > > I've only had a small > amount of experience with it so far, but Powershell seems to be an > excellent tool for admin scripting since it interfaces with WMI so > well. > > > I worked with PowerShell for about a year (after an acquisition by > Microsoft), before eagerly diving back to Python. Here are some of my > notes about the problems in PowerShell: Did you encounter these issues with PowerShell 2? I know MS put a lot of work into fixing and adding features to PowerShell 1, but like I said, I haven't had much experience with it. From bahamutzero8825 at gmail.com Wed Jul 6 01:37:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 00:37:55 -0500 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4E137BC5.2080401@gmail.com> Message-ID: <4E13F4B3.4070907@gmail.com> On 2011.07.06 12:26 AM, Dennis Lee Bieber wrote: > On Tue, 05 Jul 2011 16:01:57 -0500, Andrew Berg > declaimed the following in > gmane.comp.python.general: > > > On 2011.07.05 01:14 PM, sal migondis wrote: > > > How could a belief be wrong? > > Beliefs aren't subjective. One's taste in music, for example, is > > largely subjective and can't be right or wrong, but a belief (which has > > to do with facts) certainly can be. > > Pardon???? > > Most "beliefs" that I've encountered do their best to ignore any > facts that contradict the belief. "Facts" imply testable evidence, > hypotheses, eventual theorems... I didn't say people were objective. A belief is quite similar to a statement of fact. Whether the statement is true or false or even objectively reached isn't relevant to the definition. From rosuav at gmail.com Wed Jul 6 01:43:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 15:43:38 +1000 Subject: Microsoft GUIs In-Reply-To: <4E13EA4D.3040504@gmail.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> <4E13E0F0.20705@gmail.com> <4E13EA4D.3040504@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 2:53 PM, Andrew Berg wrote: >> Let Microsoft play with, and sell, pretty GUIs and pretty apps. > I completely disagree. MS sucks at making GUIs. > I never said they were good at making GUIs. I said they were good at selling GUIs. Dan is right about the ugliness of the Windows APIs. There are innumerable anomalies between otherwise-similar functions, weird behaviours that may and may not have historical precedent, and enough hair-pulling fuel to turn you bald in a week. Also, and possibly more serious, the security features that Windows has mostly seem to have been monkey-patched in; and there are ridiculous vulnerabilities just waiting to be exploited. The WM_TIMER message can be sent by any process to any process, and one of its parameters is the address of a callback - and voila, other process starts executing code at that address. And this works even if the program doesn't use timers. ChrisA From rosuav at gmail.com Wed Jul 6 01:47:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 15:47:05 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 3:26 PM, Dennis Lee Bieber wrote: > On Wed, 6 Jul 2011 12:31:02 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: >> Democracy DOES NOT WORK. Plain and simple. You cannot build a >> programming language democratically. >> > ? ? ? ?Uhm... COBOL and Ada may be close... They were committee/competition > where the best (compromise) aspect was selected for inclusion... And are they what you would call good languages? A committee isn't the same as democracy, although it is related. If you have two people making a decision, you potentially pull things in two directions. If you have two million people making a decision, you tear it to pieces. Vision for a language (or any other project) cannot come from a mandate from the masses. I'm waiting for my aquatic ceremony before I start building a language. ChrisA From phlip2005 at gmail.com Wed Jul 6 01:54:50 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 5 Jul 2011 22:54:50 -0700 (PDT) Subject: Does hashlib support a file mode? Message-ID: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Pythonistas: Consider this hashing code: import hashlib file = open(path) m = hashlib.md5() m.update(file.read()) digest = m.hexdigest() file.close() If the file were huge, the file.read() would allocate a big string and thrash memory. (Yes, in 2011 that's still a problem, because these files could be movies and whatnot.) So if I do the stream trick - read one byte, update one byte, in a loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit CPU. So that's the same problem; it would still be slow. So now I try this: sum = os.popen('sha256sum %r' % path).read() Those of you who like to lie awake at night thinking of new ways to flame abusers of 'eval()' may have a good vent, there. Does hashlib have a file-ready mode, to hide the streaming inside some clever DMA operations? Prematurely optimizingly y'rs -- Phlip http://bit.ly/ZeekLand From wm at localhost.localdomain Wed Jul 6 02:00:38 2011 From: wm at localhost.localdomain (Waldek M.) Date: Wed, 6 Jul 2011 08:00:38 +0200 Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1pvghkmjff37$.dlg@localhost.localdomain> Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): > Because unless you are extremely disciplined, code and the comments > describing them get out of sync. [...] True, but that gets far worse with external docs. Do you have in mind any better replacement? Br. Waldek From greg.ewing at canterbury.ac.nz Wed Jul 6 02:12:16 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 18:12:16 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> Message-ID: <97icm3Ft0eU1@mid.individual.net> rantingrick wrote: >>What he means is that On Mac, if you close "all" windows, the application is >>still running. > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. No, the windows really are closed. They no longer exist in any way. The application is still running, though, and its menu bar will appear if you bring it to the front (in MacOSX this is done by clicking on its dock icon; in classic MacOS it was done by selecting from the menu of running applications that was available in the top right corner of the screen). -- Greg From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:24:25 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:24:25 +0200 Subject: embedding: how do I redirect print output? References: <4e13217c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5dbde8-fcm.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Why do you think it [sink for use as sys.stdout] needs to be in C? As > far as I can tell, so long as it quacks like a file object (that is, > has a write method), it should work. Good point & thanks for the example fish! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From gandalf at shopzeus.com Wed Jul 6 02:25:37 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 06 Jul 2011 08:25:37 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> Message-ID: <4E13FFE1.1080303@shopzeus.com> >> Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. > > I get different results than you. > > Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. > > Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- > > Traceback (most recent call last): > File "x.py", line 46, in onPopupMenu > item = wx.MenuItem(None,-1,u"Test") > File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ > _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) > wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu I guess I'll have to write to the wxPython mailing list. Seriously, adding a simple menu to something is supposed to be platform independent, but we got four different results on four systems. :-( Thank you for trying out though. From greg.ewing at canterbury.ac.nz Wed Jul 6 02:29:03 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 18:29:03 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <72ee90d2-3cd4-4b4f-83de-f2e17d22382d@k13g2000vbv.googlegroups.com> Message-ID: <97idliF4ecU1@mid.individual.net> rantingrick wrote: > And how do you EXPLICITY quit the application? Using its "Quit" menu command. But that's Mac-specific, and not central to the discussion. On Linux and Windows, an application will usually exit when its last window is closed. Either way, there is no need for a privileged main window. -- Greg From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Jul 6 02:37:47 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 06 Jul 2011 08:37:47 +0200 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: Am 06.07.2011 07:54 schrieb Phlip: > Pythonistas: > > Consider this hashing code: > > import hashlib > file = open(path) > m = hashlib.md5() > m.update(file.read()) > digest = m.hexdigest() > file.close() > > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) > > So if I do the stream trick - read one byte, update one byte, in a > loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit > CPU. So that's the same problem; it would still be slow. Yes. That is why you should read with a reasonable block size. Not too small and not too big. def filechunks(f, size=8192): while True: s = f.read(size) if not s: break yield s # f.close() # maybe... import hashlib file = open(path) m = hashlib.md5() fc = filechunks(file) for chunk in fc: m.update(chunk) digest = m.hexdigest() file.close() So you are reading in 8 kiB chunks. Feel free to modify this - maybe use os.stat(file).st_blksize instead (which is AFAIK the recommended minimum), or a value of about 1 MiB... > So now I try this: > > sum = os.popen('sha256sum %r' % path).read() This is not as nice as the above, especially not with a path containing strange characters. What about, at least, def shellquote(*strs): return " ".join([ "'"+st.replace("'","'\\''")+"'" for st in strs ]) sum = os.popen('sha256sum %r' % shellquote(path)).read() or, even better, import subprocess sp = subprocess.Popen(['sha256sum', path'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) sp.stdin.close() # generate EOF sum = sp.stdout.read() sp.wait() ? > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? AFAIK not. Thomas From clp2 at rebertia.com Wed Jul 6 02:44:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 5 Jul 2011 23:44:28 -0700 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: On Tue, Jul 5, 2011 at 10:54 PM, Phlip wrote: > Pythonistas: > > Consider this hashing code: > > ?import hashlib > ?file = open(path) > ?m = hashlib.md5() > ?m.update(file.read()) > ?digest = m.hexdigest() > ?file.close() > > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) > > So if I do the stream trick - read one byte, update one byte, in a > loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit > CPU. So that's the same problem; it would still be slow. > > So now I try this: > > ?sum = os.popen('sha256sum %r' % path).read() > > Those of you who like to lie awake at night thinking of new ways to > flame abusers of 'eval()' may have a good vent, there. Indeed (*eyelid twitch*). That one-liner is arguably better written as: sum = subprocess.check_output(['sha256sum', path]) > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? Barring undocumented voodoo, no, it doesn't appear to. You could always read from the file in suitably large chunks instead (rather than byte-by-byte, which is indeed ridiculous); see io.DEFAULT_BUFFER_SIZE and/or the os.stat() trick referenced therein and/or the block_size attribute of hash objects. http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE http://docs.python.org/library/hashlib.html#hashlib.hash.block_size Cheers, Chris -- http://rebertia.com From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:45:44 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:45:44 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <20bd964d-a31d-4595-8ba7-c1923724a045@t7g2000vbv.googlegroups.com> Message-ID: <5lcde8-p6n.ln1@satorlaser.homedns.org> rantingrick wrote: > On Jul 5, 10:26 am, Steven D'Aprano > Since you can't do anything without a root window, I don't see the >> benefit in forcing the user to do so [create one explicitly]. > > The reason is simple. It's called order. It's called learning from day > one how the order of things exists. Widgets are part of windows, not > the other way around. Saving a few keystrokes is not acceptable if you > jumble the understanding of a new student. To understand and use > Tkinter properly you must understand the order of window->widget. > >> When they need to learn about root windows, >> they will in their own good time. > > So you would start drivers education class with road construction? Or > the history of the internal combustion engine? Who cares about > actually *driving* the car. Ahem, you are the one that suggests that in order to drive a car you should first build a road, not Steven! That said, why should I care about the choices and steps I have for creating main windows and the possibilities I get from doing this myself? A basic default main window is enough for me! Further, choice implies I can make wrong choices, too, so forcing someone to make a decision might cause errors. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Wed Jul 6 02:49:51 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 08:49:51 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mel wrote: > In wx, many of the window classes have Create methods, for filling in > various attributes in "two-step construction". I'm not sure why, because > it works so well to just supply all the details when the class is called > and an instance is constructed. Maybe there's some C++ strategy that's > being supported there. Just guessing, is it legacy, C-with-classes code rather than C++ code perhaps? Haven't looked at wx for a while. Such code typically lacks understanding of exceptions, which are the only way to signal failure from e.g. constructors. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From greg.ewing at canterbury.ac.nz Wed Jul 6 03:05:07 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 19:05:07 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <97ifp6FjfuU1@mid.individual.net> rantingrick wrote: > I was thinking more about this comment and it occurred to me that > Python does have user controlled data structures. Just because there > is no "top level syntax" like ruby does not mean these do not exists. Syntax is what it's really about, though. There's no clear dividing line, but when Guido says he's opposed to "user defined syntax" he's talking about things like Lisp macros, which let you effectively extend the grammar with new keywords and syntactic structures. Compared to that, Python's grammar is very much fixed. Anything you want to do has to be done within the existing framework of function calls, attribute references etc. If Python truly had user-defined syntax, it wouldn't have been necessary to modify the compiler to implement features such as list comprehensions and with-statements -- those features could have been implemented, with the *same syntax* or something close to it, in the base language. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 6 03:15:29 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Jul 2011 19:15:29 +1200 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <97igcjFntvU1@mid.individual.net> rantingrick wrote: > Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- > our-problems" pipe dream language. So it's just a "single-answer-to-all-our-glue-programming" pipe dream language, then? :-) -- Greg From timbovaird at gmail.com Wed Jul 6 03:39:57 2011 From: timbovaird at gmail.com (TimB) Date: Wed, 6 Jul 2011 00:39:57 -0700 (PDT) Subject: Error while downloading webpages Message-ID: Hi everyone, new to python. I'm attempting to download a large amount of webpages (about 600) to disk and for some reason a few of them fail. I'm using this in a loop where pagename and urlStr change each time: import urllib try: urllib.urlretrieve(urlStr, 'webpages/'+pagename+'.htm') except IOError: print 'Cannot open URL %s for reading' % urlStr str1 = 'error!' Out of all the webpages, it does not work for these three: http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b http://exoplanet.eu/planet.php?p1=HAT-P-27/WASP-40&p2=b http://exoplanet.eu/planet.php?p1=HAT-P-30/WASP-51&p2=b giving "Cannot open URL http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b for reading" etc. however copying and pasting the URL from the error message successfully opens in firefox it successfully downloads the 500 or so other pages such as: http://exoplanet.eu/planet.php?p1=HD+88133&p2=b I guess it has something to do with the forward slash in the names (e.g. HAT-P-30/WASP-51 compared to HD+88133 in the examples above) Is there a way I can fix this? Thanks. From timbovaird at gmail.com Wed Jul 6 03:43:14 2011 From: timbovaird at gmail.com (TimB) Date: Wed, 6 Jul 2011 00:43:14 -0700 (PDT) Subject: Error while downloading webpages References: Message-ID: <39972319-f4f5-47be-91fd-803a017c9c33@e17g2000prj.googlegroups.com> On Jul 6, 5:39?pm, TimB wrote: > Hi everyone, new to python. I'm attempting to download a large amount > of webpages (about 600) to disk and for some reason a few of them > fail. > > I'm using this in a loop where pagename and urlStr change each time: > import urllib > ? ? try: > ? ? ? ? urllib.urlretrieve(urlStr, 'webpages/'+pagename+'.htm') > ? ? except IOError: > ? ? ? ? print 'Cannot open URL %s for reading' % urlStr > ? ? ? ? str1 = 'error!' > > Out of all the webpages, it does not work for these three:http://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=bhttp://exoplanet.eu/planet.php?p1=HAT-P-27/WASP-40&p2=bhttp://exoplanet.eu/planet.php?p1=HAT-P-30/WASP-51&p2=b > giving "Cannot open URLhttp://exoplanet.eu/planet.php?p1=WASP-11/HAT-P-10&p2=b > for reading" etc. > > however copying and pasting the URL from the error message > successfully opens in firefox > > it successfully downloads the 500 or so other pages such as:http://exoplanet.eu/planet.php?p1=HD+88133&p2=b > > I guess it has something to do with the forward slash in the names > (e.g. HAT-P-30/WASP-51 compared to HD+88133 in the examples above) > > Is there a way I can fix this? Thanks. sorry, I was attempting to save the page to disk with the forward slash in the name, disreguard From ramp99 at gmail.com Wed Jul 6 03:49:36 2011 From: ramp99 at gmail.com (Rama Rao Polneni) Date: Wed, 6 Jul 2011 13:19:36 +0530 Subject: Not able to store data to dictionary because of memory limitation Message-ID: Hi All, I am facing a problem when I am storing cursor fetched(Oracle 10G) data in to a dictionary. As I don't have option to manipulate data in oracle10G, I had to stick to python to parse the data for some metrics. After storing 1.99 GB data in to the dictionary, python stopped to store the remaining data in to dictionary. Memory utilization is 26 GB/34GB. That means, still lot memory is left as unutilized. Can please share your experices/ideas to resolve this issue. Is this prople mbecasue of large memory utlization. Is there any alternate solution to resolve this issue. Like splitting the dictionaries or writing the data to hard disk instead of writing to memory. How efficiently we can use memory when we are going for dictionaries. Thanks in advacne, Rama From t at jollybox.de Wed Jul 6 04:02:19 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 06 Jul 2011 10:02:19 +0200 Subject: web browsing short cut In-Reply-To: References: Message-ID: <4E14168B.5080107@jollybox.de> On 07/06/2011 03:30 AM, Dustin Cheung wrote: > I am looking into Tkinter. But i am not sure if it will actually work. > This maybe a crazy idea but i was wondering if i can put a web browser > in the frame. I have tried to use Tkinter to resize and place the > windows to certain areas of the screen but that's not working or the way > im approaching this problem is completely wrong. I want to make a > program that will have websites displayed in specific areas of the > screen. I was planning on using the program on the big screen. So is it > possible to put the web browser inside the frame in Tkinter? What you could do, in effect, is write your own web browser, using an existing rendering engine. I do not know which rendering engines are how easily used in Tkinter code (possibly none of them). This isn't a job for (traditional, cross-platform) Python. It *may* be possible with pyWin32. It may be easier with the Windows Script Host (which apparently can support Python). I personally would use browser-side JavaScript; it's certainly possible to open a popup of a specific size in JS, not sure about specific position on-screen. Maybe you have to write an extension for Firefox or Chrome. > > > On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert > wrote: > > On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung > wrote: > > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > > and re-sizes them to display on different areas on the screen. I > looked > > around but i had no luck. Is that possible with python? if so can > someone > > point to to the right direction? Here is what I came up with so far.. > > The window positioning+resizing bit will likely require using > platform-specific APIs. Since you appear to be on Windows, the > relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32 > ). You would use it to invoke some COM API that does window > positioning+resizing. I am unable to give more details as I'm on a > Mac. > > Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature? > > Cheers, > Chris > > > > > -- > Dustin Cheung > > From rosuav at gmail.com Wed Jul 6 04:33:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 18:33:51 +1000 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 5:49 PM, Rama Rao Polneni wrote: > Hi All, > > I am facing a problem when I am storing cursor fetched(Oracle 10G) > data in to a dictionary. > As I don't have option to manipulate data in oracle10G, I had to stick > to python to parse the data for some metrics. > > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. Is the data one row from the table, or could you work with it row-by-row? ChrisA From ulrich.eckhardt at dominolaser.com Wed Jul 6 04:35:44 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jul 2011 10:35:44 +0200 Subject: Not able to store data to dictionary because of memory limitation References: Message-ID: Rama Rao Polneni wrote: > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. Question here: - Which Python? - "stopped to store" (you mean "stopped storing", btw), how does it behave? Hang? Throw exceptions? Crash right away? > Memory utilization is 26 GB/34GB. That means, still lot memory is left > as unutilized. 2GiB is typically the process limit for memory allocations on 32-bit systems. So, if you are running a 32-bit system or running a 32-bit process on a 64-bit system, you are probably hitting hard limits. With luck, you could extend this to 3GiB on a 32-bit system. > Is this proplem becasue of large memory utlization. I guess yes. > Is there any alternate solution to resolve this issue. Like splitting > the dictionaries or writing the data to hard disk instead of writing > to memory. If you have lost of equal strings, interning them might help, both in size and speed. Doing in-memory compression would be a good choice, too, like e.g. if you have string fields in the DB that can only contain very few possible values, converting them to an integer/enumeration. Otherwise, and this is a more general approach, prefer making a single sweep over the data. This means that you read a chunk of data, perform whatever operation you need on it, possibly write the results and then discard the chunk. This keeps memory requirements low. At first, it doesn't look as clean as reading the whole data in one step, calculations as a second and writing results as a third, but with such amounts of data as yours, it is the only viable step. Good luck, and I'd like to hear how you solved the issue! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rosuav at gmail.com Wed Jul 6 04:37:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 18:37:31 +1000 Subject: web browsing short cut In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 11:30 AM, Dustin Cheung wrote: > Hey, > I am looking into Tkinter. But i am not sure if it will actually work. This > maybe a crazy idea but i was wondering if i can put a web browser in the > frame. I have tried to use Tkinter to resize and place the windows to > certain areas of the screen but?that's?not working or the way im approaching > this problem is completely wrong. I want to make a program that will have > websites displayed in specific areas of the screen. I was planning on using > the program on the big screen. So is it possible to put the web browser > inside the frame in Tkinter? Thinking along a quite different line here, is it possible for you to use regular frames? Create an HTML file with: That should divide your screen four ways (if I haven't botched my HTML - ages since I've used frames). ChrisA From anddimario at gmail.com Wed Jul 6 04:44:16 2011 From: anddimario at gmail.com (AndDM) Date: Wed, 6 Jul 2011 01:44:16 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> Message-ID: <742ddcd0-37d1-4009-a82b-c12cd3b7c43f@b2g2000vbo.googlegroups.com> On Jul 5, 4:08?pm, Jean-Paul Calderone wrote: > On Jul 5, 4:52?am, Andrea Di Mario wrote: > > > Hi, I'm a new python user and I'm writing a small web service with ssl. > > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > > I've used wrap_socket, but if i try to use > > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > > urllib2.URLError: > specified for verification of other-side certificates.> > > > It works only with CERT_NONE (the default) but with this option i > > could access to the service in insicure mode. > > > Have you some suggestions for my service? > > Also specify some root certificates to use in verifying the peer's > certificate. ?Certificate verification works by proceeding from a > collection of "root" certificates which are explicitly trusted. ?These > are used to sign other certificates (which may in turn be used to sign > others, which in turn...). ?The process of certificate verification is > the process of following the signatures from the certificate in use by > the server you connect to back up the chain until you reach a root > which you have either decided to trust or not. ?If the signatures are > all valid and the root is one you trust, then you have established a > connection to a trusted entity. ?If any signature is invalid, or the > root is not one you trust, then you have not. > > The root certificates are also called the "ca certificates" or > "certificate authority certificates". ?`wrap_socket` accepts a > `ca_certs` argument. ?Seehttp://docs.python.org/library/ssl.html#ssl-certificates > for details about that argument. > > Jean-Paul Hi Jean-Paul, i thought that with self-signed certificate i shouldn't use ca_certs option. Now, i've created a ca-authority and i use this command: self.sock = ssl.wrap_socket(sock, certfile = "ca/certs/ myfriend.cert.pem", keyfile = "ca/private/myfriend.key.pem", ca_certs="/home/andrea/ca/certs/cacert.pem", cert_reqs=ssl.CERT_REQUIRED) When i use the some machine as client-server it works, but, when i use another machine as client, i've this: Traceback (most recent call last): ? File "loginsender.py", line 48, in ? ? handle = url_opener.open('https://debian.andrea.it:10700/%s+%s' % (DATA,IPIN)) ? File "/usr/lib/python2.6/urllib2.py", line 391, in open ? ? response = self._open(req, data) ? File "/usr/lib/python2.6/urllib2.py", line 409, in _open ? ? '_open', req) ? File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain ? ? result = func(*args) ? File "loginsender.py", line 33, in https_open ? ? return self.do_open(self.specialized_conn_class, req) ? File "/usr/lib/python2.6/urllib2.py", line 1145, in do_open ? ? raise URLError(err) urllib2.URLError: I see that i should create a certificate with server, client and ca autority, but i haven't clear the ca_certs option and which path i should use. Have you any suggestion? Thank. Regards. From gnarlodious at gmail.com Wed Jul 6 05:02:45 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 6 Jul 2011 02:02:45 -0700 (PDT) Subject: Extracting property getters from dir() results Message-ID: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Using introspection, is there a way to get a list of "property getters"? Does this: vars=property(getVars(), "Dump a string of variables and values") have some parsable feature that makes it different from other functions? Or would I need to use some naming scheme to parse them out? -- Gnarlie From ramp99 at gmail.com Wed Jul 6 05:05:44 2011 From: ramp99 at gmail.com (Rama Rao Polneni) Date: Wed, 6 Jul 2011 14:35:44 +0530 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: -------------------------------------------------------------------------------------------- Yes the data is from table. which is retrieved using some queries in to cx_oracel cursor. I am able to read the data row by row. One more information, I am Able to load the data in to dictionary by removing some some data from table. -Ram -------------------------------------------------------------------------------------------- > Is the data one row from the table, or could you work with it row-by-row? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -------------------------------------------------------------------------------------------- On 7/6/11, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 5:49 PM, Rama Rao Polneni wrote: >> Hi All, >> >> I am facing a problem when I am storing cursor fetched(Oracle 10G) >> data in to a dictionary. >> As I don't have option to manipulate data in oracle10G, I had to stick >> to python to parse the data for some metrics. >> >> After storing 1.99 GB data in to the dictionary, python stopped to >> store the remaining data in to dictionary. > > From lists at cheimes.de Wed Jul 6 05:35:18 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 11:35:18 +0200 Subject: Extracting property getters from dir() results In-Reply-To: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> References: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Message-ID: Am 06.07.2011 11:02, schrieb Gnarlodious: > Using introspection, is there a way to get a list of "property > getters"? > > Does this: > > vars=property(getVars(), "Dump a string of variables and values") > > have some parsable feature that makes it different from other > functions? Or would I need to use some naming scheme to parse them > out? dir() won't help you much here. The inspect module has several tools to make inspection easier. >>> import inspect >>> class Example(object): ... @property ... def method(self): ... return 1 ... >>> inspect.getmembers(Example, inspect.isdatadescriptor) [('__weakref__', ), ('method', )] inspect.getmembers() with isdatadescriptor predicate works only on classes, not on instances. >>> inspect.getmembers(Example(), inspect.isdatadescriptor) [] Property instances have the attributes fget, fset and fdel that refer to their getter, setter and delete method. >>> for name, obj in inspect.getmembers(Example, inspect.isdatadescriptor): ... if isinstance(obj, property): ... print name, obj, obj.fget ... method Christian From benjokal at gmail.com Wed Jul 6 05:44:07 2011 From: benjokal at gmail.com (Benji Benjokal) Date: Wed, 6 Jul 2011 05:44:07 -0400 Subject: Python Packaging Message-ID: Can someone show me how to package with py2exe? Every time I tried it says the file does not exist. Can you help? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From as at sci.fi Wed Jul 6 05:47:19 2011 From: as at sci.fi (Anssi Saari) Date: Wed, 06 Jul 2011 12:47:19 +0300 Subject: Does hashlib support a file mode? References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: Phlip writes: > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) I did a crc32 calculator like that and actually ran into some kind of string length limit with large files. So I switched to 4k blocks and the speed is about the same as a C implementation in the program cksfv. Well, of course crc32 is usually done with a table lookup, so it's always fast. I just picked 4k, since it's the page size in x86 systems and also a common block size for file systems. Seems to be big enough. io.DEFAULT_BUFFER_SIZE is 8k here. I suppose using that would be the proper way. From t at jollybox.de Wed Jul 6 06:48:02 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 06 Jul 2011 12:48:02 +0200 Subject: Python Packaging In-Reply-To: References: Message-ID: <4E143D62.3030103@jollybox.de> On 07/06/2011 11:44 AM, Benji Benjokal wrote: > > Can someone show me how to package with py2exe? > Every time I tried it says the file does not exist. If you show us how you're trying to do it, somebody may be able to spot your error. PS: http://www.catb.org/~esr/faqs/smart-questions.html From awilliam at whitemice.org Wed Jul 6 06:55:31 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 06 Jul 2011 06:55:31 -0400 Subject: Does hashlib support a file mode? In-Reply-To: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: <1309949732.3045.9.camel@linux-yu4c.site> On Tue, 2011-07-05 at 22:54 -0700, Phlip wrote: > Pythonistas > Consider this hashing code: > import hashlib > file = open(path) > m = hashlib.md5() > m.update(file.read()) > digest = m.hexdigest() > file.close() > If the file were huge, the file.read() would allocate a big string and > thrash memory. (Yes, in 2011 that's still a problem, because these > files could be movies and whatnot.) Yes, the simple rule is do not *ever* file.read(). No matter what the year this will never be OK. Always chunk reading a file into reasonable I/O blocks. For example I use this function to copy a stream and return a SHA512 and the output streams size: def write(self, in_handle, out_handle): m = hashlib.sha512() data = in_handle.read(4096) while True: if not data: break m.update(data) out_handle.write(data) data = in_handle.read(4096) out_handle.flush() return (m.hexdigest(), in_handle.tell()) > Does hashlib have a file-ready mode, to hide the streaming inside some > clever DMA operations? Chunk it to something close to the block size of your underlying filesystem. From exxontechnical at gmail.com Wed Jul 6 07:21:50 2011 From: exxontechnical at gmail.com (covai exxon) Date: Wed, 6 Jul 2011 04:21:50 -0700 (PDT) Subject: hiiiiiiiiiiii see this webpage Message-ID: http://123maza.com/65/papaya846/ From steve+comp.lang.python at pearwood.info Wed Jul 6 07:44:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:44:21 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> Message-ID: <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 5, 11:04?am, Corey Richardson wrote: > >> How is giving the sort method a function by which to determine the >> relative value of objects a control structure? Do you know what a control >> structure is? It's something that you use to modify control flow: >> >> if foo <= bar: >> foo += 1 >> else: >> bar += 1 > > Interesting, corey. Very interesting. However the fun is yet to come > so stay tuned... > >> That's a control structurem the "if-else". I don't know what Ruby calls a >> control structure, but that's what it is. for and while are in there too. >> When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens? > > So are you suggesting that a control structure must have at minimum > one of "for", "while", or "if"? A control structure is a structure which controls the program flow. Control structures include: * jumps (goto, gosub, comefrom, exceptions, break, continue) * loops (for, while, repeat...until) * conditional branches (if, case/switch) There may be others, although I can't think of any of hand. Jumping, looping and branching pretty much covers all the bases, I think. It excludes expressions such as ternary-if, because that doesn't control program flow, it's just an expression. A function which includes a control structure inside it is not itself a control structure, in the same way that the existence of bones inside you does not make you a bone. [...] > Yes there IS and "if" in there and IF you look closely enough you may > see two "for"'s also. So by your own definition this (naive) code > qualifies as a control structure. I see what you did there. First you put words into Cory's mouth that he did not say, they you try to criticise him based on those words -- YOUR words. No Rick, that's your definition, not Cory's. Please do not treat us as stupid. > But wait just a second Corey. My statement has nothing to do with > sort. sort is just the vehicle. My statement is that the cmp argument > to sort IS a user defined control structure (the code block to be > exact). The cmp argument to sort is not a control structure because it is not a structure and it does not control the program flow. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:44:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:44:31 +1000 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> Stefaan Himpe wrote: >> Now, I have an ulterior motive in raising this issue... I can't find the >> original article I read! My google-fu has failed me (again...). I don't >> suppose anyone can recognise it and can point me at it? > > My sarcasm detector warns me not to add a link, although perhaps it's > time for recalibration (after all, summer season started) :-) No! I was serious. I've spent *ages* trying to find the link to the article... if you know it, please share. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:45:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:45:32 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> Message-ID: <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> sal migondis wrote: > How could a belief be wrong? I believe you are a small glass of beer. Are you *actually* a small glass of beer in reality? If so, my belief is right. If you are a human being, then my belief is wrong. -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 07:46:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2011 21:46:36 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <4e124b92$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e144b1d$0$29982$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: >> Define "best for all", and try not to make it "what Rick wants". > > You want features? And remember i am talking about scripting/glue > level languages here. Something to replace Python, Ruby, Perl, > JavaScript, etc, etc not some "pie-in-the-sky", "single-answer-to-all- > our-problems" pipe dream language. > > * Intuitive syntax. Intuitive to who? Newbies? Then you get a language like Hypertalk, that experienced programmers hate. Experienced C programmers? Then you get something like Java. Forth programmers? Then you get something like Arc, that nobody except Paul Graham uses. (Not literally, no offence to anyone who likes Arc.) System administrators? They you get something like Perl. ("It's like bash scripting only better!") Mathematicians? Then you get something like Haskell. Non-programmers? Then you could get anything from Inform7, to Applescript, to Resolver's Python-in-a-spreadsheet, to Pascal, to FoxPro, to Flash, to Javascript, to Mathematica... depending on *which* non-programmers you are aiming at. > * Productivity friendly. That covers everything from Excel to Lisp, depending on who you ask. > * Complex enough to solve large problems but simple enough for simple > problems (that does include extending into C when needed) But if you are designing the "perfect language", what do you need C for? C will no longer exist, except in museums, because Rick's perfect language will be used for everything. > * Multi paradigm (problem Which is guaranteed to annoy those who believe that paradigms A, C, D and E are harmful and should be avoided... the only problem is that there is no broad agreement on which paradigm B is non-harmful. > * Promotes a culture of code readability (because people read source; > not just machines!). Define readability. Hypertalk, Python, Inform7 and Pascal are all readable, in radically different ways. >> No, Python is not a monoculture. There are the Stackless, Jython, PyPy >> and IronPython sub-cultures, all with their own needs, wants and desires. >> There are sub-cultures for embedded devices and smart phones, >> sub-cultures for those who use Python as a teaching language, for web >> development, for GUI development, and for system administration. There >> are the Numpy and Scipy sub-cultures, sub-cultures in the fields of >> linguistics and biology. > > Hmm. Just think how far ahead we would be if these folks would stop > trying to support petty differences and focus on a singular Python > language? These are not "petty differences", but real differences that are important to people who have actually work to do. A sushi chef needs a different sort of knife to a brain surgeon, both of which are different to that needed by a special forces soldier deep in enemy territory, which is different again to the sort of knife is needed by some guy working in a warehouse unpacking boxes. Different jobs need different tools. There is no perfect language because different tasks need different tools, and any compromise tool that tries to do everything will be weaker than a specialist tool. -- Steven From python.list at tim.thechases.com Wed Jul 6 07:58:45 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Jul 2011 06:58:45 -0500 Subject: Not able to store data to dictionary because of memory limitation In-Reply-To: References: Message-ID: <4E144DF5.2020208@tim.thechases.com> On 07/06/2011 02:49 AM, Rama Rao Polneni wrote: > After storing 1.99 GB data in to the dictionary, python stopped to > store the remaining data in to dictionary. > > Is there any alternate solution to resolve this issue. Like splitting > the dictionaries or writing the data to hard disk instead of writing > to memory. Without details on the specifics of what you're storing in your dictionary, you might investigate the anydbm module which would allow you to have a disk-backed dictionary, but it really only works for string->string mappings. You can use shelve/pickle to marshal other data-types into strings for use in such a mapping, but there are some odd edge-cases to be aware of (updating an instance of a class doesn't change the pickled object, so you have to intentionally re-store it after you change it; I've hit unexpected scoping issues with class-names; etc). But for the general case, it might do exactly what you need to remove the 2GB cap. -tkc From stefaan.himpe at gmail.com Wed Jul 6 08:44:45 2011 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Wed, 06 Jul 2011 14:44:45 +0200 Subject: Implicit initialization is EXCELLENT In-Reply-To: <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1NYQp.25969$Sr.25363@newsfe12.ams2> > No! I was serious. I've spent *ages* trying to find the link to the > article... if you know it, please share. Ok - I thought you were referring to some troll's rant with similar title. I'm probably way off, but were you referring to the RAII technique? http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization From rantingrick at gmail.com Wed Jul 6 09:41:52 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 06:41:52 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 6:44?am, Steven D'Aprano wrote: > A control structure is a structure which controls the program flow. Control > structures include: > > * jumps (goto, gosub, comefrom, exceptions, break, continue) > > * loops (for, while, repeat...until) > > * conditional branches (if, case/switch) ------------------------------------------- THIS CODE RESULTS IN A CONTROL STRUCTURE! --> lst.sort(lambda x,y: cmp(x[1], y[1])) ------------------------------------------- I am using a user defined spec as an argument to the cmp function. That spec then modifies the body of the compare function and creates a user defined control structure. You can argue all day that it is not a user defined control structure but no one is going to believe you. > A function which includes a control structure inside it is not itself a > control structure, Of course the FUNCTION is not a control structure (not directly). No wonder you are confused. It's the FUNCTION BODY that is the control structure. The function body that has been modified by my arguments to the cmp function. But in a way, you can say the function OWNS the code block so it is itself a control structure. Still confused? Read on... > in the same way that the existence of bones inside you > does not make you a bone. Bad analogy. See last comment. > I see what you did there. First you put words into Cory's mouth that he did > not say, they you try to criticise him based on those words -- YOUR words. I quoted Corey exactly. And why do you feel the need to answer for him? > The cmp argument to sort is not a control structure because it is not a > structure and it does not control the program flow. Again you lack simple reading and comprehension skills. It's not the argument that is the control structure itself. The argument is just the SPEC for creating a control structure. The control structure is the modified CODE BLOCK owned by the "CMP" function. The modified code block owned by the cmp function-- defined by the user through an argument spec-- controls the return value to the list sort method. USER DEFINED CONTROL STRUCTURE. Plain and simple. I don't think i can use any simpler terms to describe it. Give it up man and admit i am correct and you are wrong. From phlip2005 at gmail.com Wed Jul 6 09:47:02 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 06:47:02 -0700 (PDT) Subject: Does hashlib support a file mode? References: <952b0e40-3308-4dbc-b107-8fbe96014199@e17g2000prj.googlegroups.com> Message-ID: <72286154-f71f-4f1c-8d53-18ae3eda9ecf@q14g2000prh.googlegroups.com> wow, tx y'all! I forgot to mention that hashlib itself is not required; I could also use Brand X. But y'all agree that blocking up the file in python adds no overhead to hashing each block in C, so hashlib in a loop it is! From rantingrick at gmail.com Wed Jul 6 09:51:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 06:51:30 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: On Jul 6, 1:12?am, Gregory Ewing wrote: > rantingrick wrote: > >>What he means is that On Mac, if you close "all" windows, the application is > >>still running. > > > Then that is NOT closing windows that is only ICONIFIYING/HIDING them. > > No, the windows really are closed. They no longer exist > in any way. The application is still running, though, and > its menu bar will appear if you bring it to the front > (in MacOSX this is done by clicking on its dock icon; > in classic MacOS it was done by selecting from the menu > of running applications that was available in the top right > corner of the screen). Yes but what benefit does that gain over say, Tkinter's design (because that has been your argument). I see no benefit at all. I can destroy a GUI and still have a script run, but what's the point? If you design a GRAPHICAL user interface, then once the GRAPHICAL part is removed (window), why do need the main code to stick around? And if you do, that fact has nothing to do with Tkinter and window hierarchy. I think we've gone completely off topic here. Is this another community strawman contest? Are we mass producing these things now? From rosuav at gmail.com Wed Jul 6 09:52:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2011 23:52:40 +1000 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 11:41 PM, rantingrick wrote: > Give it up man and admit i am correct and you are wrong. > Sorry. A Lawful Good character cannot tell a lie. ChrisA From calderone.jeanpaul at gmail.com Wed Jul 6 09:53:09 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 6 Jul 2011 06:53:09 -0700 (PDT) Subject: Secure ssl connection with wrap_socket References: <898d98ba-5245-46ba-8058-987297ab3c48@s17g2000yqs.googlegroups.com> <742ddcd0-37d1-4009-a82b-c12cd3b7c43f@b2g2000vbo.googlegroups.com> Message-ID: On Jul 6, 4:44?am, AndDM wrote: > On Jul 5, 4:08?pm, Jean-Paul Calderone > wrote: > > > > > On Jul 5, 4:52?am, Andrea Di Mario wrote: > > > > Hi, I'm a new python user and I'm writing a small web service with ssl. > > > I want use a self-signed certificate like in wiki:http://docs.python.org/dev/library/ssl.html#certificates > > > I've used wrap_socket, but if i try to use > > > cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error: > > > > urllib2.URLError: > > specified for verification of other-side certificates.> > > > > It works only with CERT_NONE (the default) but with this option i > > > could access to the service in insicure mode. > > > > Have you some suggestions for my service? > > > Also specify some root certificates to use in verifying the peer's > > certificate. ?Certificate verification works by proceeding from a > > collection of "root" certificates which are explicitly trusted. ?These > > are used to sign other certificates (which may in turn be used to sign > > others, which in turn...). ?The process of certificate verification is > > the process of following the signatures from the certificate in use by > > the server you connect to back up the chain until you reach a root > > which you have either decided to trust or not. ?If the signatures are > > all valid and the root is one you trust, then you have established a > > connection to a trusted entity. ?If any signature is invalid, or the > > root is not one you trust, then you have not. > > > The root certificates are also called the "ca certificates" or > > "certificate authority certificates". ?`wrap_socket` accepts a > > `ca_certs` argument. ?Seehttp://docs.python.org/library/ssl.html#ssl-certificates > > for details about that argument. > > > Jean-Paul > > Hi Jean-Paul, i thought that with self-signed certificate i shouldn't > use ca_certs option. Now, i've created a ca-authority and i use this > command: > > ?self.sock = ssl.wrap_socket(sock, certfile = "ca/certs/ > myfriend.cert.pem", keyfile = "ca/private/myfriend.key.pem", > ca_certs="/home/andrea/ca/certs/cacert.pem", > cert_reqs=ssl.CERT_REQUIRED) > > When i use the some machine as client-server it works, but, when i use > another machine as client, i've this: > > Traceback (most recent call last): > ? File "loginsender.py", line 48, in > ? ? handle = url_opener.open('https://debian.andrea.it:10700/%s+%s'% > (DATA,IPIN)) > ? File "/usr/lib/python2.6/urllib2.py", line 391, in open > ? ? response = self._open(req, data) > ? File "/usr/lib/python2.6/urllib2.py", line 409, in _open > ? ? '_open', req) > ? File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > ? ? result = func(*args) > ? File "loginsender.py", line 33, in https_open > ? ? return self.do_open(self.specialized_conn_class, req) > ? File "/usr/lib/python2.6/urllib2.py", line 1145, in do_open > ? ? raise URLError(err) > urllib2.URLError: 0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib> > > I see that i should create a certificate with server, client and ca > autority, but i haven't clear the ca_certs option and which path i > should use. > Have you any suggestion? You need to have the CA certificate on any machine that is going to verify the certificate used on the SSL connection. The path just needs to be the path to that CA certificate on the client machine. Jean-Paul From steve+comp.lang.python at pearwood.info Wed Jul 6 10:32:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 00:32:38 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > If you design a GRAPHICAL user interface, then once the GRAPHICAL part > is removed (window), why do need the main code to stick around? Open your mind to ideas that go beyond your simple window-centric paradigm! There is more to graphical user interfaces than windows! In the Mac OS GUI, an application can have a menubar and no windows. Windows come and go as needed, but the menubar stays until the users quits the application. In the Unix/Linux world, there is a graphical application called xkill which has no menus and no windows, all it has is a mouse cursor! No, it does not run in the background: it is a foreground app. An extreme case, but telling. There is no absolute need for any windows at all, let alone for one privileged window to rule all the others. -- Steven From gnarlodious at gmail.com Wed Jul 6 10:51:05 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 6 Jul 2011 07:51:05 -0700 (PDT) Subject: Extracting property getters from dir() results References: <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> Message-ID: <0fc2a5a5-986f-4b4a-bb9a-88835e29324c@y30g2000yqb.googlegroups.com> On Jul 6, 3:35?am, Christian Heimes wrote: Thank you! Exactly what I wanted. -- Gnarlie http://Gnarlodious.com From steve+comp.lang.python at pearwood.info Wed Jul 6 10:55:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 00:55:39 +1000 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e14776c$0$29998$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 6, 6:44?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> A control structure is a structure which controls the program flow. >> Control structures include: >> >> * jumps (goto, gosub, comefrom, exceptions, break, continue) >> >> * loops (for, while, repeat...until) >> >> * conditional branches (if, case/switch) > > ------------------------------------------- > THIS CODE RESULTS IN A CONTROL STRUCTURE! > > --> lst.sort(lambda x,y: cmp(x[1], y[1])) No it doesn't. How does it change the program flow? You call the sort method, it sorts, and execution continues at the next statement. Regardless of whether you supply a cmp function or not, the program flow is identical: ENTER SORT ROUTINE PERFORM SORTING EXIT SORT ROUTINE There is no control transferred. It is a linear program flow: in, do the job, out again. Since it doesn't modify the program flow, it is not a control structure. "Perform sorting" is a black box. It could have loops, branches, unconditional exists. It could have COMEFROM statements up the wazoo, if it were implemented in a language with COMEFROM (like Intercal). None of that matters two bits: the caller cannot use sort to modify the execution sequence around it, therefore it's not a control structure. No matter how much the sort routine jumps around internally, you can't use that change program flow around it. print surely is implemented with a loop: it has to loop over a string and write it to stdout. Would you say that therefore print is a control structure: ENTER PRINT STATEMENT PERFORM PRINTING EXIT PRINT STATEMENT One entry, one exit. -- Steven From mbadoiu at gmail.com Wed Jul 6 11:04:04 2011 From: mbadoiu at gmail.com (Mihai Badoiu) Date: Wed, 6 Jul 2011 11:04:04 -0400 Subject: interactive plots Message-ID: How do I do interactive plots in python? Say I have to plot f(x) and g(x) and I want in the plot to be able to click on f and make it disappear. Any python library that does this? thanks, --mihai -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Wed Jul 6 11:10:27 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 08:10:27 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 9:32?am, Steven D'Aprano wrote: > rantingrick wrote: > > If you design a GRAPHICAL user interface, then once the GRAPHICAL part > > is removed (window), why do need the main code to stick around? > > Open your mind to ideas that go beyond your simple window-centric paradigm! Correction: Window-Centric GUI paradigm! BIG DIFFERENCE. > There is more to graphical user interfaces than windows! OMG, you mean like, widgets? Whoa! Tell me more, Tell me more! > In the Mac OS GUI, an application can have a menubar and no windows. Windows > come and go as needed, but the menubar stays until the users quits the > application. That's just window visibility (whether by hiding or destroying) under the veil of a detached UI window manager bar and has nothing to do with window hierarchy. Your half stuffed straw men are leaking like a sieve Steven. > In the Unix/Linux world, there is a graphical application called xkill which > has no menus and no windows, all it has is a mouse cursor! No, it does not > run in the background: it is a foreground app. Wow nice corner case. Can you come up with at least five of them though? You and I both know that the vast majority of GUI's require visible windows. But wait! What is a GUI WINDOW exactly? I'll tell you in the simplest terms i can muster... GUI "windows" are an abstraction and nothing more. A GUI window is nothing more than an imaginary area of the screen that can be drawn to. This area has borders that define it. No not visible borders but two dimensional spacial borders. THAT'S IT! The area could be 1x1 pixels OR the entire screen space, OR even larger! Most time you want the user to see the boundaries of this abstraction (window) space and so the GUI library draws borders that represent this boundary. Your "supposedly" windowless xkill application is not windowless at all; THE WINDOW BOUNDARIES ARE JUST NOT DRAWN! The window is the entire screen space OR IS JUST THE DESKTOP SPACE (same thing) > An extreme case, but telling. There is no absolute need for any windows at > all, let alone for one privileged window to rule all the others. Again your fear of losing "imaginary" freedoms is acting out again. And your veiled attempts to link root GUI windows and Sauron (the great antagonist of LOTH) is quite entertaining. Next you'll suggest that root windows are really just a great eye, lidless, and wreathed in flame and that i am Saruman building an army of Orc followers hell bent on destroying the freedom to believe self serving fantasies. From vvnrk.vanapalli at gmail.com Wed Jul 6 11:12:04 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 08:12:04 -0700 (PDT) Subject: trouble creating tooltips using Wx in Tk canvas Message-ID: Hi all, Hi all, I am having a trouble creating tooltips. I am trying to embed a matplotlib graph inside a TkInter canvas. After some search over the net, I found out a way to create tooltips using the WXbackend. But when I embed my matplotlib figure inside a Tk and the tooltips are not getting displayed. The error I am getting is below. Traceback (most recent call last): File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100)) # needs to be added to getover the bug with tooltip. File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", line 771, in __init__ _misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) PyNoAppError: The wx.App object must be created first! I am not able to figure out the reason. I am trying to use IDLE for running the script using python 2.7. I tried running from commandline as well but still i face the same error. Following is the piece of code I have used. I created a simple 'sin' wave using matplotlib. and a button. Added them to a TkFrame. and then binded the code using self.f.canvas.mpl_connect('motion_notify_event',_onMotion) to '_onMotion' function, where I am printing the toooltip. Can somebody please help me solving the issue. Code I have used is below. #!/usr/apps/Python/bin/python import matplotlib, sys matplotlib.use('WXAgg') matplotlib.interactive(False) import numpy as np from numpy import arange, sin, pi import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import wx import Tkinter tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' % (' '*100)) # needs to be added to getover the bug with tooltip. def alt(): print 'My Button' def _onMotion(event): print "Xvalue:",event.xdata," Yvalue:",event.ydata tip= "Xvalue:{0}, Yvalue: {1}".format(event.xdata,event.ydata) tooltip.SetTip(tip) tooltip.Enable(True) class myClass(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) #global _onMotion self.parent=parent self.buildFigure() def buildFigure(self): self.f=plt.figure() self.f = plt.figure(figsize=(5,4)) self.a = self.f.add_subplot(111) self.t = np.array([0.01,0.02,0.03,0.04,0.05,0.07,0.09,1.7,1.9,2.3,2.5,2.7,2.9]) self.s = sin(2*pi*self.t) self.a.plot(self.t,self.s) self.dataPlot = FigureCanvasTkAgg(self.f, master=self) self.f.canvas.mpl_connect('motion_notify_event',_onMotion) self.dataPlot.get_tk_widget().pack(side='top', fill='both') self.toolbar = NavigationToolbar2TkAgg( self.dataPlot, self ) self.toolbar.update() self.toolbar.pack() self.btn=Tkinter.Button(self, text='btton',command=alt) self.btn.pack(ipadx=250) def alt (self): print 9 if __name__ == "__main__": app = myClass(None) app.title('Embedding in Tk') app.mainloop() From neilc at norwich.edu Wed Jul 6 11:13:22 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Jul 2011 15:13:22 GMT Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <97jcchF8akU2@mid.individual.net> On 2011-07-06, Chris Angelico wrote: > On Wed, Jul 6, 2011 at 11:41 PM, rantingrick > wrote: >> Give it up man and admit i am correct and you are wrong. > > Sorry. A Lawful Good character cannot tell a lie. Lawful Good characters have a hard time coexisting with the Chaotic Neutrals. -- Neil Cerutti From rantingrick at gmail.com Wed Jul 6 11:33:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 08:33:46 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e14776c$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0fe80b69-c53f-4f04-84ea-e58fae5bdb79@k27g2000yqn.googlegroups.com> On Jul 6, 9:55?am, Steven D'Aprano wrote: > rantingrick wrote: > > ------------------------------------------- > > THIS CODE RESULTS IN A CONTROL STRUCTURE! > > > --> lst.sort(lambda x,y: cmp(x[1], y[1])) > > No it doesn't. > > How does it change the program flow? You call the sort method, it sorts, and > execution continues at the next statement. Regardless of whether you supply > a cmp function or not, the program flow is identical: Not identical. The sort called WITHOUT a cmp argument will sort in a predefined manner. The sort called WITH a cmp argument can modify the existing code block in a way that suits a users desired result. A USER DEFINED CONTROL STRUCTURE. Just because this realization breaks the mold of everything you hold dear about user defined control structures does not mean it is incorrect. For some reason you are religious about this subject. Could it be that you are wrong? > ENTER SORT ROUTINE > PERFORM SORTING > EXIT SORT ROUTINE True for the non-modified case. False for the modified one... ENTER SORT ROUTINE PERFORM SORTING BASED ON USER DEFINED CONTROL EXIT SORT ROUTINE > There is no control transferred. It is a linear program flow: in, do the > job, out again. Since it doesn't modify the program flow, it is not a > control structure. So you are telling me that calling cmp(itemsA[idx], itemsB[idx]) is exactly the same as cmp(itemsA[idx][-1], itemsB[idx[-1])? Please show proof of this in code. You have just witnessed the power of user defined control structures and it has rocked your little world. You believed UDCS to be evil, all the while oblivious to your own everyday usage of them. Now that's ironic. Cruel or poetic, you be the judge. > "Perform sorting" is a black box. It could have loops, branches, > unconditional exists. It could have COMEFROM statements up the wazoo, if it > were implemented in a language with COMEFROM (like Intercal). None of that > matters two bits: the caller cannot use sort to modify the execution > sequence around it, therefore it's not a control structure. No matter how > much the sort routine jumps around internally, you can't use that change > program flow around it. The "jumping"(sic) around is controlled by a user defined spec. The user is in control. The user made the definition. The cmp function just implemented it. > print surely is implemented with a loop: it has to loop over a string and > write it to stdout. Would you say that therefore print is a control > structure: > > ENTER PRINT STATEMENT > PERFORM PRINTING > EXIT PRINT STATEMENT Nope. Print only takes an argument and spits out the result to stdout.write. Print is an abstraction API for system.stdout.write, and nothing more. > One entry, one exit. As evident from all the BS you spew on a daily basis, apparently YOU have one entry and one exit! From philip at semanchuk.com Wed Jul 6 11:36:00 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 6 Jul 2011 11:36:00 -0400 Subject: wx MenuItem - icon is missing In-Reply-To: <4E13FFE1.1080303@shopzeus.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> Message-ID: <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> On Jul 6, 2011, at 2:25 AM, Laszlo Nagy wrote: > >>> Under windows, this displays the icon for the popup menu item. Under GTK it doesn't and there is no error message, no exception. >> >> I get different results than you. >> >> Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item called test with little icon of a calculator or something. >> >> Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right click I get this -- >> >> Traceback (most recent call last): >> File "x.py", line 46, in onPopupMenu >> item = wx.MenuItem(None,-1,u"Test") >> File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__ >> _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs)) >> wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): menuitem should have a menu > I guess I'll have to write to the wxPython mailing list. Seriously, adding a simple menu to something is supposed to be platform independent, but we got four different results on four systems. :-( I can understand why it's frustrating but a menu items with icons on them aren't exactly common, so you're wandering into territory that's probably not so throughly explored (nor standard across platforms). Now that I think about it, I don't know that I've ever seen one under OSX, and I don't even know if it's supported at all. Me, I would start by addressing the error in the traceback. wx doesn't seem happy with an orphan menu item; why not create a wx.Menu and assign the menu item to that? It might solve your icon problem; you never know. In defense of wxPython, we have three wx apps in our project and they contain very little platform-specific code. To be fair, we've had to rewrite some code after we found that it worked on one platform but not another, but generally we're able to find code that works on all platforms. We have only a couple of places where we were forced to resort to this kind of thing: if wx.Platform == "__WXGTK__": do X elif wx.Platform == "__WXMAC__": do Y etc. > Thank you for trying out though. You're welcome. VirtualBox helped. bye Philip From phlip2005 at gmail.com Wed Jul 6 11:59:43 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 08:59:43 -0700 (PDT) Subject: Does hashlib support a file mode? References: mailman.697.1309951505.1164.python-list@python.org Message-ID: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Tx, all!. But... > For example I use this function to copy a stream and return a SHA512 and > the output streams size: > > ? ? def write(self, in_handle, out_handle): > ? ? ? ? m = hashlib.sha512() > ? ? ? ? data = in_handle.read(4096) > ? ? ? ? while True: > ? ? ? ? ? ? if not data: > ? ? ? ? ? ? ? ? break > ? ? ? ? ? ? m.update(data) > ? ? ? ? ? ? out_handle.write(data) > ? ? ? ? ? ? data = in_handle.read(4096) > ? ? ? ? out_handle.flush() > ? ? ? ? return (m.hexdigest(), in_handle.tell()) The operation was a success but the patient died. My version of that did not return the same hex digest as the md5sum version: def file_to_hash(path, m = hashlib.md5()): with open(path, 'r') as f: s = f.read(8192) while s: m.update(s) s = f.read(8192) return m.hexdigest() You'll notice it has the same control flow as yours. That number must eventually match an iPad's internal MD5 opinion of that file, after it copies up, so I naturally cannot continue working this problem until we see which of the two numbers the iPad likes! From steve+comp.lang.python at pearwood.info Wed Jul 6 12:11:28 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 02:11:28 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: >> In the Mac OS GUI, an application can have a menubar and no windows. >> Windows come and go as needed, but the menubar stays until the users >> quits the application. > > That's just window visibility (whether by hiding or destroying) under > the veil of a detached UI window manager bar and has nothing to do > with window hierarchy. If all the windows are destroyed, and the application still is running and active, where is your window hierarchy? The Dead Window Sketch ====================== (with apologies to Monty Python) Customer enters a pet shop. Customer: 'Ello, I wish to register a complaint. Owner: We're closin' for lunch. Customer: Never mind that, my lad. I wish to complain about this GUI window what I purchased not half an hour ago from this very boutique. Owner: Oh yes, the Norwegian Blue. What's wrong with it? Customer: I'll tell you what's wrong with it, my lad. It's deleted, that's what's wrong with it! Owner: No, no, it's resting! Customer: Look, matey, I know a deleted window when I see one, and I'm looking at one right now. Owner: No no it's not deleted, it's restin'! Remarkable window, the Norwegian Blue. Beautiful widgets! Customer: The widgets don't enter into it. It's completely destroyed. Owner: Nononono, no, no! It's resting! Customer: All right then, if it's restin', I'll wake it up! (shouting at the screen) 'Ello, Mister Wally Window! I've got a lovely fresh icon for you if you show... (owner hits the screen) Owner: There, it refreshed! Customer: No, it didn't, that was you hitting the screen! Owner: I never!! Customer: Yes, you did! Owner: I never, never did anything... Customer: (yelling and hitting the screen repeatedly) 'ELLO WINDOW!!! WAKEY WAKEY! This is your notification signal!!! (takes the window out of the screen and thumps its title bar on the counter. Throws it up in the air and watches it plummet to the floor.) Customer: Now that's what I call a dead window. Owner: No, no... No, it's stunned! Customer: STUNNED?!? Owner: Yeah! You stunned it, just as it was maximising! Norwegian Blues stun easily. Customer: Now look, mate, I've definitely 'ad enough of this! That window is definitely deleted, and when I purchased it not 'alf an hour ago, you assured me that its lack of an entry in the task bar was due to it bein' tired and shagged out following a long refresh! Owner: Well, it's... probably pining for the fjords. Customer: PININ' for the FJORDS?!?!?!? What kind of talk is that? Look, why did it fall flat on its back the moment I got it home? Owner: The Norwegian Blue prefers being minimised on its back! Remarkable bird, i'nit, squire? Lovely scroll bars! Customer: Look, I took the liberty of examining that window when I got it home, and I discovered the only reason that the window was still visible in the first place was that it had been NAILED there. (pause) Owner: Well, o'course it was nailed there! If I hadn't nailed that window down, it would have nuzzled up to those pixels, bent 'em apart with its cursor, and VOOM! Feeweeweewee! Customer: "VOOM"?!? Mate, this window wouldn't "voom" if you put four million volts through it! Its bleedin' memory is reclaimed! Owner: No no! It's pining! Customer: It's not pinin'! It's purged! This window is no more! It's pointer has ceased to be! It's expired and gone to meet the memory manager! Bereft of bytes, it rests in peace! If you hadn't nailed it to the screen it'd be a Flash animation in a browser by now! It's callbacks are now 'istory! Its ref count is zero! It's called the garbage collector, its blocks have been cleared, shuffled off this mortal coil, run down the curtain and joined the bleedin' choir invisibile!! THIS IS AN EX-WINDOW!! (pause) Owner: Well, I'd better replace it, then. (he takes a quick peek behind the counter) Owner: Sorry squire, I've had a look 'round the back of the shop, and uh, we're right out of windows. Customer: I see. I see, I get the picture. Owner: I got a DOS batch file. (pause) Customer: (sweet as sugar) Pray, does it talk? Owner: Yes. Customer: Right, I'll have that one then. -- Steven From rosuav at gmail.com Wed Jul 6 12:24:37 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 02:24:37 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 7, 2011 at 1:10 AM, rantingrick wrote: > On Jul 6, 9:32?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Open your mind to ideas that go beyond your simple window-centric paradigm! > > Correction: Window-Centric GUI paradigm! BIG DIFFERENCE. > >> There is more to graphical user interfaces than windows! > > OMG, you mean like, widgets? Whoa! Tell me more, Tell me more! Okay, Window-Centric GUI Paradigm. There's still more to it than windows and widgets and mouse cursors and so on. Underneath it all is CODE. In some graphical applications, the code is relatively trivial. A desktop calculator is just there to get input graphically and give output graphically. In those, once you destroy the window, you may as well terminate the application. But in others the code drastically outweighs the windowing work. I don't have a good example handy, but I have a bad example; our (antique) accounting package has an hours-long year end process that we do at the beginning of each July, and it chugs through its database work while painting a pretty animation of a hand scribing a book. It would be far more efficient to simply close the window and proceed with the work; but the window was necessary for collecting certain parameters from the user, prior to the start of the long job. There's more to a windowed program than its window. >> In the Mac OS GUI, an application can have a menubar and no windows. Windows >> come and go as needed, but the menubar stays until the users quits the >> application. > > That's just window visibility (whether by hiding or destroying) under > the veil of a detached UI window manager bar and has nothing to do > with window hierarchy. Your half stuffed straw men are leaking like a > sieve Steven. It can be implemented with window visibility. That's not the same thing. If I want to be in Sydney tomorrow, I want to cease existing here and begin existing there. That can be implemented by burning petrol in an internal combustion engine and turning some rubber wheels. If I turn up in Sydney tomorrow, and argue vehemently that I did not drive, are you going to insist that I did, or would you accept that perhaps I took a train instead? >> In the Unix/Linux world, there is a graphical application called xkill which >> has no menus and no windows, all it has is a mouse cursor! No, it does not >> run in the background: it is a foreground app. > > Wow nice corner case. Can you come up with at least five of them > though? You and I both know that the vast majority of GUI's require > visible windows. Five corner cases. Okay. One is xkill; if I can find four more, we run out of corners and they're not corner cases any more - is that it? 1) See above. 2) Win2VNC. Doesn't actually paint a window on the screen, it just watches where the mouse goes - move the mouse off the edge of the screen, and it wraps and hides it. Very cool. 3) Firewall software with a graphical config notebook. I think ZoneAlarm actually just hides its window, but that's not strictly necessary. (My preferred firewall setup, though, has no GUI at all - iptables etc is all I need.) 4) Clipboard Converter. An old app that I wrote a while ago that, whenever you copy anything to the clipboard, runs it through a script and puts the result back on the clipboard. Handier than you might think. 5) Hotkey manager. It watches for keystrokes and replaces them with other actions. Implemented as an input hook with injection facilities. Enjoy. > But wait! What is a GUI WINDOW exactly? > > I'll tell you in the simplest terms i can muster... GUI "windows" are > an abstraction and nothing more. *Everything* in a computer is an abstraction. People are fond of saying that computers only work with 1s and 0s - that's not strictly true, those numbers represent electrical signals. And those electrical signals represent data which usually carries information. It's turtles all the way down. > A GUI window is nothing more than an > imaginary area of the screen that can be drawn to. This area has > borders that define it. No not visible borders but two dimensional > spacial borders. THAT'S IT! The area could be 1x1 pixels OR the entire > screen space, OR even larger! Leaving off the "imaginary", all you're saying is that a window is a rectangular area of screen. That's not quite true; not all windows/widgets have a painting area. A window is an object - and that object can choose to request certain resources, including a portion of its parent window's painting area if desired. (A top-level window's parent is either a Screen or a Desktop, depending on your implementation.) > Most time you want the user to see the boundaries of this abstraction > (window) space and so the GUI library draws borders that represent > this boundary. Your "supposedly" windowless xkill application is not > windowless at all; THE WINDOW BOUNDARIES ARE JUST NOT DRAWN! The > window is the entire screen space OR IS JUST THE DESKTOP SPACE (same > thing) Boundaries have nothing to do with it being a window or not. The windowless xkill does NOT HAVE a window. If it had a borderless window that covered the entire desktop, you would not be able to click on any other window, thus making xkill ... somewhat useless. >> An extreme case, but telling. There is no absolute need for any windows at >> all, let alone for one privileged window to rule all the others. > > Again your fear of losing "imaginary" freedoms is acting out again. > And your veiled attempts to link root GUI windows and Sauron (the > great antagonist of LOTH) is quite entertaining. What, the One Ring is the only entity that ever wished to rule over all of something? *boggle* I regret that I am now in the position of following an awesome post with a somewhat mediocre one. Steven, the Dead Window Sketch is awesome! ChrisA From ryan.morrone at gmail.com Wed Jul 6 12:25:38 2011 From: ryan.morrone at gmail.com (PyNewbie) Date: Wed, 6 Jul 2011 09:25:38 -0700 (PDT) Subject: Javacv / google apps Message-ID: <1191548b-ec59-4b5b-84ec-d3b146bf12cf@glegroupsg2000goo.googlegroups.com> Hi, Is it possible to use JavaCV with Google apps engine? From __peter__ at web.de Wed Jul 6 12:26:09 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jul 2011 18:26:09 +0200 Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: Phlip wrote: > Tx, all!. But... > >> For example I use this function to copy a stream and return a SHA512 and >> the output streams size: >> >> def write(self, in_handle, out_handle): >> m = hashlib.sha512() >> data = in_handle.read(4096) >> while True: >> if not data: >> break >> m.update(data) >> out_handle.write(data) >> data = in_handle.read(4096) >> out_handle.flush() >> return (m.hexdigest(), in_handle.tell()) > > The operation was a success but the patient died. > > My version of that did not return the same hex digest as the md5sum > version: > > > def file_to_hash(path, m = hashlib.md5()): > > with open(path, 'r') as f: > > s = f.read(8192) > > while s: > m.update(s) > s = f.read(8192) > > return m.hexdigest() > > You'll notice it has the same control flow as yours. > > That number must eventually match an iPad's internal MD5 opinion of > that file, after it copies up, so I naturally cannot continue working > this problem until we see which of the two numbers the iPad likes! - Open the file in binary mode. - Do the usual dance for default arguments: def file_to_hash(path, m=None): if m is None: m = hashlib.md5() From gandalf at shopzeus.com Wed Jul 6 12:26:11 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 06 Jul 2011 18:26:11 +0200 Subject: wx MenuItem - icon is missing In-Reply-To: <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> <7ED1FBA3-1A84-4A5C-A3E7-3286A03405F4@semanchuk.com> Message-ID: <4E148CA3.1010106@shopzeus.com> > I can understand why it's frustrating but a menu items with icons on them aren't exactly common, so you're wandering into territory that's probably not so throughly explored (nor standard across platforms). Now that I think about it, I don't know that I've ever seen one under OSX, and I don't even know if it's supported at all. Maybe you are right, I'm not familiar with OS X. But they are common in GTK, Qt and Windows. > Me, I would start by addressing the error in the traceback. wx doesn't seem happy with an orphan menu item; why not create a wx.Menu and assign the menu item to that? It might solve your icon problem; you never know. I did create it: menu = wx.Menu() # wx.Menu created here. item = wx.MenuItem(None,-1,u"Test") item.SetBitmap(img.GetBitmap()) menu.AppendItem(item) # Item added to menu here. > In defense of wxPython, we have three wx apps in our project and they contain very little platform-specific code. To be fair, we've had to rewrite some code after we found that it worked on one platform but not another, but generally we're able to find code that works on all platforms. We have only a couple of places where we were forced to resort to this kind of thing: > > if wx.Platform == "__WXGTK__": > do X > elif wx.Platform == "__WXMAC__": > do Y > etc. Hmmm then probably I'll have to install other OS too. :-) From ian.g.kelly at gmail.com Wed Jul 6 12:26:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 10:26:48 -0600 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt wrote: > Mel wrote: >> In wx, many of the window classes have Create methods, for filling in >> various attributes in "two-step construction". ?I'm not sure why, because >> it works so well to just supply all the details when the class is called >> and an instance is constructed. ?Maybe there's some C++ strategy that's >> being supported there. > > Just guessing, is it legacy, C-with-classes code rather than C++ code > perhaps? Haven't looked at wx for a while. Such code typically lacks > understanding of exceptions, which are the only way to signal failure from > e.g. constructors. No, wx is C++ through and through. For the why of it, see: http://wiki.wxpython.org/TwoStageCreation The "More Details" section is particularly illuminating. From bahamutzero8825 at gmail.com Wed Jul 6 12:28:35 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 11:28:35 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E148D33.8030306@gmail.com> On 2011.07.06 11:11 AM, Steven D'Aprano wrote: > The Dead Window Sketch > ====================== As much as I hate it when people feed trolls, that was pretty funny. From mwilson at the-wire.com Wed Jul 6 12:36:33 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 06 Jul 2011 12:36:33 -0400 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt > wrote: >> Mel wrote: >>> In wx, many of the window classes have Create methods, for filling in >>> various attributes in "two-step construction". I'm not sure why, >>> because it works so well to just supply all the details when the class >>> is called and an instance is constructed. Maybe there's some C++ >>> strategy that's being supported there. >> >> Just guessing, is it legacy, C-with-classes code rather than C++ code >> perhaps? Haven't looked at wx for a while. Such code typically lacks >> understanding of exceptions, which are the only way to signal failure >> from e.g. constructors. > > No, wx is C++ through and through. For the why of it, see: > > http://wiki.wxpython.org/TwoStageCreation > > The "More Details" section is particularly illuminating. Yes, it is. Many thanks. From phlip2005 at gmail.com Wed Jul 6 12:49:10 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 09:49:10 -0700 (PDT) Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: > - Open the file in binary mode. I had tried open(path, 'rb') and it didn't change the "wrong" number. And I added --binary to my evil md5sum version, and it didn't change the "right" number! Gods bless those legacy hacks that will never die, huh? But I'm using Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that might explain why "binary mode" is a no-op. > - Do the usual dance for default arguments: > ? ? def file_to_hash(path, m=None): > ? ? ? ? if m is None: > ? ? ? ? ? ? m = hashlib.md5() Not sure why if that's what the defaulter does? I did indeed get an MD5-style string of what casually appeared to be the right length, so that implies the defaulter is not to blame... From tlikonen at iki.fi Wed Jul 6 12:55:53 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 06 Jul 2011 19:55:53 +0300 Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <97d8spFg2nU1@mid.individual.net> <22a13bda-899d-4765-a03c-f8a36efaf905@34g2000yqr.googlegroups.com> <4e144a96$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrfv9wme.fsf@mithlond.arda> * 2011-07-06T06:41:52-07:00 * wrote: > I am using a user defined spec as an argument to the cmp function. > That spec then modifies the body of the compare function and creates a > user defined control structure. You can argue all day that it is not a > user defined control structure but no one is going to believe you. I won't argue all day, I'll just show you an example of a user defined control structure. This is like the standard (DOTIMES (VAR COUNT) BODY) macro expect that it executes BODY forms first forwards and then backwards. The iterator variable VAR goes first up from 0 and then down to 0. (defmacro ping-pong-iterator ((var count &optional result) &body body) `(progn (loop for ,var from 0 below ,count do (progn , at body)) (loop for ,var from (1- ,count) downto 0 do (progn ,@(reverse body)) finally (return ,result)))) CL-USER> (ping-pong-iterator (i 3 "ready") (format t "form 1: ~A~%" i) (format t "form 2: ~A~%" i) (format t "form 3: ~A~%" i) (format t "~%")) form 1: 0 form 2: 0 form 3: 0 form 1: 1 form 2: 1 form 3: 1 form 1: 2 form 2: 2 form 3: 2 form 3: 2 form 2: 2 form 1: 2 form 3: 1 form 2: 1 form 1: 1 form 3: 0 form 2: 0 form 1: 0 => "ready" From wm at localhost.localdomain Wed Jul 6 12:56:05 2011 From: wm at localhost.localdomain (Waldek M.) Date: Wed, 6 Jul 2011 18:56:05 +0200 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1a9lv7u7bfrdj$.dlg@localhost.localdomain> Dnia Wed, 6 Jul 2011 08:10:27 -0700 (PDT), rantingrick napisa?(a): >> In the Unix/Linux world, there is a graphical application called xkill which >> has no menus and no windows, all it has is a mouse cursor! No, it does not >> run in the background: it is a foreground app. > > Wow nice corner case. Can you come up with at least five of them > though? You and I both know that the vast majority of GUI's require > visible windows. - 90% of MS DOS games; should I list them here? ;-) - M$ Windows taskbar-only applications - Linux apps using framebuffer but not X One could argue that the second and the third case are - in one way or another - using windows. But not the first case, and I don't think you'd call them GUI-less. Br. Waldek From ian.g.kelly at gmail.com Wed Jul 6 12:59:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 10:59:52 -0600 Subject: interactive plots In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: > How do I do interactive plots in python? ?Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. ?Any > python library that does this? Matplotlib can be integrated with either wxPython or PyQt to create GUI applications with interactive plots. From __peter__ at web.de Wed Jul 6 13:06:13 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jul 2011 19:06:13 +0200 Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: Phlip wrote: >> - Open the file in binary mode. > > I had tried open(path, 'rb') and it didn't change the "wrong" number. > > And I added --binary to my evil md5sum version, and it didn't change > the "right" number! > > Gods bless those legacy hacks that will never die, huh? But I'm using > Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that > might explain why "binary mode" is a no-op. Indeed. That part was a defensive measure mostly meant to make your function Windows-proof. >> - Do the usual dance for default arguments: >> def file_to_hash(path, m=None): >> if m is None: >> m = hashlib.md5() > > Not sure why if that's what the defaulter does? I did indeed get an > MD5-style string of what casually appeared to be the right length, so > that implies the defaulter is not to blame... The first call will give you the correct checksum, the second: not. As the default md5 instance remembers the state from the previous function call you'll get the checksum of both files combined. From python.list at tim.thechases.com Wed Jul 6 13:37:39 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Jul 2011 12:37:39 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E149D63.3090108@tim.thechases.com> On 07/06/2011 11:24 AM, Chris Angelico wrote: > On Thu, Jul 7, 2011 at 1:10 AM, rantingrick wrote: >> Wow nice corner case. Can you come up with at least five of them >> though? You and I both know that the vast majority of GUI's require >> visible windows. > > Five corner cases. Okay. One is xkill; if I can find four more, we run > out of corners and they're not corner cases any more - is that it? > > 1) See above. > 2) Win2VNC. Doesn't actually paint a window on the screen, it just > watches where the mouse goes - move the mouse off the edge of the > screen, and it wraps and hides it. Very cool. > 3) Firewall software with a graphical config notebook. I think > ZoneAlarm actually just hides its window, but that's not strictly > necessary. (My preferred firewall setup, though, has no GUI at all - > iptables etc is all I need.) > 4) Clipboard Converter. An old app that I wrote a while ago that, > whenever you copy anything to the clipboard, runs it through a script > and puts the result back on the clipboard. Handier than you might > think. > 5) Hotkey manager. It watches for keystrokes and replaces them with > other actions. Implemented as an input hook with injection facilities. 6) possibly xneko (just mouse-cursor amusements) 7) screen-shot/print-screen software (several such as "scrot" don't have an actual window, just a process that interacts with the other windows) 8) AutoHotkey and other keystroke-monitors (or mouse-gesture-monitors) to expand text, send key-sequences, launch programs, reconfigure windows, signal changes in display-configuration, etc 9) other clipboard utilities such as xclip or multi-clipboard functionality 10) DPMI screen-savers (that only listen for key/mouse activity and send a blank-screen signal to the monitor after a given period of inactivity) I think there are sufficiently many edge cases this formerly-square room is starting to look round... > I regret that I am now in the position of following an awesome post > with a somewhat mediocre one. Steven, the Dead Window Sketch is > awesome! agreed :) -tkc From phlip2005 at gmail.com Wed Jul 6 13:38:10 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 10:38:10 -0700 (PDT) Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: > >> def file_to_hash(path, m=None): > >> if m is None: > >> m = hashlib.md5() > The first call will give you the correct checksum, the second: not. As the > default md5 instance remembers the state from the previous function call > you'll get the checksum of both files combined. Ouch. That was it. Python sucks. m = md5() looks like an initial assignment, not a special magic storage mode. Principle of least surprise fail, and principle of most helpful default behavior fail. From steve+comp.lang.python at pearwood.info Wed Jul 6 13:41:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 03:41:45 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e149e5a$0$29996$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > On 2011.07.06 11:11 AM, Steven D'Aprano wrote: >> The Dead Window Sketch >> ====================== > As much as I hate it when people feed trolls, that was pretty funny. Thanks. Re the troll-feeding, every few months I get a strange seizure in my brain that compels me to interact with rantingrick and try to treat him seriously. It never ends well, he always ends up back in my killfile. Call it the triumph of hope over experience. -- Steven From rosuav at gmail.com Wed Jul 6 13:46:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 03:46:28 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <4E149D63.3090108@tim.thechases.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4E149D63.3090108@tim.thechases.com> Message-ID: Five more good entries (though I think #8 and #9 are mostly covered already). But hey, we have at least an octagon to work in. On Thu, Jul 7, 2011 at 3:37 AM, Tim Chase wrote: > I think there are sufficiently many edge cases this formerly-square room is > starting to look round... The room is starting to look round? Eek, it might see us! *flees* ChrisA From nospam at torek.net Wed Jul 6 13:54:07 2011 From: nospam at torek.net (Chris Torek) Date: 6 Jul 2011 17:54:07 GMT Subject: Does hashlib support a file mode? References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: >> - Do the usual dance for default arguments: >> def file_to_hash(path, m=None): >> if m is None: >> m = hashlib.md5() [instead of def file_to_hash(path, m = hashlib.md5()): ] In article Phlip wrote: >Not sure why if that's what the defaulter does? For the same reason that: def spam(somelist, so_far = []): for i in somelist: if has_eggs(i): so_far.append(i) return munch(so_far) is probably wrong. Most beginners appear to expect this to take a list of "things that pass my has_eggs test", add more things to that list, and return whatever munch(adjusted_list) returns ... which it does. But then they *also* expect: result1_on_clean_list = spam(list1) result2_on_clean_list = spam(list2) result3_on_partly_filled_list = spam(list3, prefilled3) to run with a "clean" so_far list for *each* of the first two calls ... but it does not; the first call starts with a clean list, and the second one starts with "so_far" containing all the results accumulated from list1. (The third call, of course, starts with the prefilled3 list and adjusts that list.) >I did indeed get an MD5-style string of what casually appeared >to be the right length, so that implies the defaulter is not to >blame... In this case, if you do: print('big1:', file_to_hash('big1')) print('big2:', file_to_hash('big2')) you will get two md5sum values for your two files, but the md5sum value for big2 will not be the equivalent of "md5sum big2" but rather that of "cat big1 big2 | md5sum". The reason is that you are re-using the md5-sum-so-far on the second call (for file 'big2'), so you have the accumulated sum from file 'big1', which you then update via the contents of 'big2'. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From howe.steven at gmail.com Wed Jul 6 13:57:54 2011 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 06 Jul 2011 10:57:54 -0700 Subject: interactive plots In-Reply-To: References: Message-ID: <4E14A222.8000504@gmail.com> On 07/06/2011 09:59 AM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: >> How do I do interactive plots in python? Say I have to plot f(x) and g(x) >> and I want in the plot to be able to click on f and make it disappear. Any >> python library that does this? > Matplotlib can be integrated with either wxPython or PyQt to create > GUI applications with interactive plots. PyGTK interface too. From rantingrick at gmail.com Wed Jul 6 14:19:17 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 6 Jul 2011 11:19:17 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> On Jul 6, 11:11?am, Steven D'Aprano wrote: > The Dead Window Sketch > ====================== > > [snip] ########################## The Roman Stawman Sketch ########################## [cmp.lang.python]: (The trolls are gathered and a righteous man speaks.) GRACCHUS: For your guidance TrollCaesar, the Senate has prepared a series of protocols to address the many problems in the community, beginning with basic understanding of USER DEFINED CONTROL STRUCTURES, which is already propagated wildly throughout the community and people are suffering gravely from a misunderstanding. So if TrollCaesar? (Obviously bored, Commodus is spinning his sword on its tip on the marble floor. He interrupts.) COMMODUS: Shhh. Don?t you see Gracchus? That?s the very problem, isn?t it? You've spent all your time at study, at books, learning and programming. All the while my self aggrandizing has been forgotten by the people. (He rises and brings his sword to rest across his shoulders. He begins to pace.) GRACCHUS: But comp.lang.python is the people, Sire, chosen from among the people, a place to "speak" for the people. COMMODUS: I doubt if many people know as much as you do Gracchus, or have such splendid code bases, Gaius. I think I understand my own people. GRACCHUS: Then perhaps TrollCaesar would be so kind as to teach us, out of his own extensive experience about the nature of USER DEFINED CONTROL STRUCTURES. (Laughter is heard from the other group members.) COMMODUS: I call it lies. The people are my children and I their father. I shall hold them to my bosom and embrace them tightly with lies and propaganda. GRACCHUS(interrupting): Have you ever embraced someone dying of exceptions, Sire? (Commodus stops pacing and turns to face Gracchus bringing his sword down from his shoulder.) COMMODUS: No, but if you interrupt me again, I assure you, that you shall! [INT. PALACE ? COMMODUS CHAMBERS]: (He is struggling to clear his conscience. Lucilla assists him.) COMMODUS: Who would deign to lecture me? LUCILLA: Commodus, the community has its uses. COMMODUS: What uses? All they do is talk. It should be just you and me, and Guido. LUCILLA: Don?t even think it. There has always been a community. COMMODUS: The community has changed. It takes an emperor to rule an empire. LUCILLA: Of course, but leave the people their (She hesitates, searching for the right word.) COMMODUS: Illusions? LUCILLA: Traditions. COMMODUS: My war against the righteous, they said it themselves, it achieved nothing. But the minions loved me! LUCILLA: Minions always love victories. COMMODUS: Why? They didn?t see all the work that went into stuffing those straw-men. LUCILLA: They care about the entertainment. COMMODUS: The Entertainment? Well what is that? LUCILLA: It?s a way to waste time, entertainment. Entertainment is a vision. COMMODUS: Exactly! A vision. Do you not see, Lucilla? I will give the people a vision, a false vision and they will love me for it. And they?ll soon forget the tedious sermonizing of a few honest group members. (He extends his hand to her and without hesitation, she accepts it. Commodus raises her hand to his lips and kisses it.) COMMODUS: I will give the people the greatest false vision of their lives... Strawmen! Legions of them! (A hand reaches out and opens a mail reader. It is Usenet. And a thread called the "Dead Window Sketch". The splendor of his false victory.) [EXT. Rome ? MARKET]: (Gaius approaches Gracchus at an outdoor caf? (starbucks). Gaius is waving a leaflet advertising ?Comp.lang.python.Gladiators_Violante.?) GAIUS: Straw-men. 150 days of Straw-men! GRACCHUS: He?s cleverer than I thought. GAIUS: Clever? The whole of cmp.lang.python would be laughing at him if they weren't so afraid of his forked tongue. GRACCHUS: Fear and wonder. A powerful combination. GAIUS: You really think the people will be seduced by that? GRACCHUS: I think he knows what comp.lang.python is. Comp.lang.python is the mob. He will conjure comedy for them and they will be distracted. He will take away their freedom to think with half stuffed straw-men, and still they will roar. The beating heart of comp.lang.python is not the halls of righteousness; it is the den of minions. He will give them tripe, and they will love him for it. From ian.g.kelly at gmail.com Wed Jul 6 14:32:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 12:32:59 -0600 Subject: trouble creating tooltips using Wx in Tk canvas In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth wrote: > Hi all, > Hi all, > > I am having a trouble creating tooltips. I am trying to embed a > matplotlib graph inside ?a TkInter canvas. After some search over the > net, I found out a way to create tooltips using the WXbackend. > But when I embed my matplotlib figure inside a Tk and ?the tooltips > are not getting displayed. That's pretty much what I would expect, since wxPython and Tkinter are completely different GUI libraries. Trying to use them together is a bit like trying to call a .NET function from Java -- maybe possible, but it's going to take a lot of work. > The error I am getting is below. > > Traceback (most recent call last): > ?File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in > > ? ?tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' > % (' '*100)) # needs to be added to getover the bug with tooltip. > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", > line 771, in __init__ > ? ?_misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) > PyNoAppError: The wx.App object must be created first! > > I am not able to figure out the reason. As it says, you haven't created the wx.App object necessary for pretty much all wxPython code. You could create one, but your tooltip still would not work correctly because you would be running the Tkinter event loop rather than the wxPython event loop. If you want to use the wxToolTip widget, then you should write your program to use wxPython only. Alternatively, googling for "tkinter tooltip" turns up a couple of recipes; you could try one of those. Cheers, Ian From bahamutzero8825 at gmail.com Wed Jul 6 14:36:25 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 13:36:25 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> Message-ID: <4E14AB29.30408@gmail.com> On 2011.07.06 01:19 PM, rantingrick wrote: > ########################## > The Roman Stawman Sketch > ########################## Nice try, but you have to use a Monty Python sketch (and you have to spell correctly :-P ). From bahamutzero8825 at gmail.com Wed Jul 6 14:42:12 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 13:42:12 -0500 Subject: Does hashlib support a file mode? In-Reply-To: References: <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> Message-ID: <4E14AC84.1090303@gmail.com> On 2011.07.06 12:38 PM, Phlip wrote: > Python sucks. m = md5() looks like an initial assignment, not a > special magic storage mode. Principle of least surprise fail, and > principle of most helpful default behavior fail. func() = whatever the function returns func = the function object itself (in Python, everything's an object) Maybe you have Python confused with another language (I don't know what exactly you mean by initial assignment). Typically one does not need more than one name for a function/method. When a function/method is defined, it gets created as a function object and occupies the namespace in which it's defined. From phlip2005 at gmail.com Wed Jul 6 15:07:56 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 12:07:56 -0700 (PDT) Subject: Does hashlib support a file mode? References: mailman.715.1309977744.1164.python-list@python.org Message-ID: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> On Jul 6, 11:42?am, Andrew Berg wrote: > On 2011.07.06 12:38 PM, Phlip wrote:> Python sucks. m = md5() looks like an initial assignment, not a > > special magic storage mode. Principle of least surprise fail, and > > principle of most helpful default behavior fail. > > func() = whatever the function returns > func = the function object itself (in Python, everything's an object) > > Maybe you have Python confused with another language (I don't know what > exactly you mean by initial assignment). Typically one does not need > more than one name for a function/method. When a function/method is > defined, it gets created as a function object and occupies the namespace > in which it's defined. If I call m = md5() twice, I expect two objects. I am now aware that Python bends the definition of "call" based on where the line occurs. Principle of least surprise. From ian.g.kelly at gmail.com Wed Jul 6 15:15:50 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 13:15:50 -0600 Subject: Implicit initialization is EVIL! In-Reply-To: <4E14AB29.30408@gmail.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: > On 2011.07.06 01:19 PM, rantingrick wrote: >> ########################## >> ?The Roman Stawman Sketch >> ########################## > Nice try, but you have to use a Monty Python sketch (and you have to > spell correctly :-P ). Seriously. The source he borrowed from is the movie Gladiator, which isn't even a comedy. From debatem1 at gmail.com Wed Jul 6 15:15:54 2011 From: debatem1 at gmail.com (geremy condra) Date: Wed, 6 Jul 2011 15:15:54 -0400 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 3:07 PM, Phlip wrote: > On Jul 6, 11:42?am, Andrew Berg wrote: >> On 2011.07.06 12:38 PM, Phlip wrote:> Python sucks. m = md5() looks like an initial assignment, not a >> > special magic storage mode. Principle of least surprise fail, and >> > principle of most helpful default behavior fail. >> >> func() = whatever the function returns >> func = the function object itself (in Python, everything's an object) >> >> Maybe you have Python confused with another language (I don't know what >> exactly you mean by initial assignment). Typically one does not need >> more than one name for a function/method. When a function/method is >> defined, it gets created as a function object and occupies the namespace >> in which it's defined. > > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Python doesn't do anything to the definition of call. If you call hashlib.md5() twice, you get two objects: >>> import hashlib >>> m1 = hashlib.md5() >>> m2 = hashlib.md5() >>> id(m1) 139724897544712 >>> id(m2) 139724897544880 Geremy Condra From noway at nohow.com Wed Jul 6 15:30:18 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 15:30:18 -0400 Subject: Large number multiplication Message-ID: I was looking through the python source and noticed that long multiplication is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n log n). I was wondering if there was a reason the Karatsuba method was chosen over the FFT convolution method? -- Bill From python at mrabarnett.plus.com Wed Jul 6 15:34:28 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jul 2011 20:34:28 +0100 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: <4E14B8C4.6010107@mrabarnett.plus.com> On 06/07/2011 20:15, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: >> On 2011.07.06 01:19 PM, rantingrick wrote: >>> ########################## >>> The Roman Stawman Sketch >>> ########################## >> Nice try, but you have to use a Monty Python sketch (and you have to >> spell correctly :-P ). > > Seriously. The source he borrowed from is the movie Gladiator, which > isn't even a comedy. If it was from "Life of Brian", then it would be OK: What has Guido ever done for us...? :-) From vvnrk.vanapalli at gmail.com Wed Jul 6 15:35:59 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 12:35:59 -0700 (PDT) Subject: trouble creating tooltips using Wx in Tk canvas References: Message-ID: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> On Jul 6, 1:32?pm, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth wrote: > > Hi all, > > Hi all, > > > I am having a trouble creating tooltips. I am trying to embed a > > matplotlib graph inside ?a TkInter canvas. After some search over the > > net, I found out a way to create tooltips using the WXbackend. > > But when I embed my matplotlib figure inside a Tk and ?the tooltips > > are not getting displayed. > > That's pretty much what I would expect, since wxPython and Tkinter are > completely different GUI libraries. ?Trying to use them together is a > bit like trying to call a .NET function from Java -- maybe possible, > but it's going to take a lot of work. > > > The error I am getting is below. > > > Traceback (most recent call last): > > ?File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in > > > > ? ?tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' > > % (' '*100)) # needs to be added to getover the bug with tooltip. > > ?File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", > > line 771, in __init__ > > ? ?_misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs)) > > PyNoAppError: The wx.App object must be created first! > > > I am not able to figure out the reason. > > As it says, you haven't created the wx.App object necessary for pretty > much all wxPython code. ?You could create one, but your tooltip still > would not work correctly because you would be running the Tkinter > event loop rather than the wxPython event loop. ?If you want to use > the wxToolTip widget, then you should write your program to use > wxPython only. ?Alternatively, googling for "tkinter tooltip" turns up > a couple of recipes; you could try one of those. > > Cheers, > Ian Thank you Ian for your insights to me on this. I will migrate to wxPython to achieve the functionality. From bahamutzero8825 at gmail.com Wed Jul 6 15:42:30 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jul 2011 14:42:30 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: mailman.715.1309977744.1164.python-list@python.org <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <4E14BAA6.6070207@gmail.com> On 2011.07.06 02:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. You get two objects because you make the function run again. Of course, the first one is garbage collected if it doesn't have another reference. >>> m1 = hashlib.md5() >>> m2 = hashlib.md5() >>> m1 is m2 False Are you assuming Python acts like another language or is there something confusing in the docs or something else? From mwilson at the-wire.com Wed Jul 6 15:43:36 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 06 Jul 2011 15:43:36 -0400 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Actually, in def file_to_hash(path, m = hashlib.md5()): hashlib.md5 *is* called once; that is when the def statement is executed. Later on, when file_to_hash gets called, the value of m is either used as is, as the default parameter, or is replaced for the duration of the call by another object supplied by the caller. Mel. From ian.g.kelly at gmail.com Wed Jul 6 15:48:36 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 13:48:36 -0600 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: On Wed, Jul 6, 2011 at 1:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. There is no definition-bending. The code: """ def file_to_hash(path, m = hashlib.md5()): # do stuff... file_to_hash(path1) file_to_hash(path2) """ does not call hashlib.md5 twice. It calls it *once*, at the time the file_to_hash function is defined. The returned object is stored on the function object, and that same object is passed into file_to_hash as a default value each time the function is called. See: http://docs.python.org/reference/compound_stmts.html#function From ian.g.kelly at gmail.com Wed Jul 6 16:02:04 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 14:02:04 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: > I was looking through the python source and noticed that long multiplication > is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n > log n). ?I was wondering if there was a reason the Karatsuba method was > chosen over the FFT convolution method? According to Wikipedia: """ In practice the Sch?nhage?Strassen algorithm starts to outperform older methods such as Karatsuba and Toom?Cook multiplication for numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). """ I think most Python users are probably not working with numbers that large, and if they are, they are probably using specialized numerical libraries anyway, so there would be little benefit in implementing it in core. From lists at cheimes.de Wed Jul 6 16:05:52 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 22:05:52 +0200 Subject: Large number multiplication In-Reply-To: References: Message-ID: Am 06.07.2011 21:30, schrieb Billy Mays: > I was looking through the python source and noticed that long > multiplication is done using the Karatsuba method (O(~n^1.5)) rather > than using FFTs O(~n log n). I was wondering if there was a reason the > Karatsuba method was chosen over the FFT convolution method? The Karatsuba algorithm uses just addition, subtraction and multiplication, so you don't need to resort to floats and have no rounding errors. On the other hand FFT are based on e, complex numbers or trigonometric functions (=floats), which mean you'll get rounding errors. We don't want rounding errors for large long multiplication. Christian From noway at nohow.com Wed Jul 6 16:15:06 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 16:15:06 -0400 Subject: Large number multiplication References: Message-ID: On 07/06/2011 04:05 PM, Christian Heimes wrote: > Am 06.07.2011 21:30, schrieb Billy Mays: >> I was looking through the python source and noticed that long >> multiplication is done using the Karatsuba method (O(~n^1.5)) rather >> than using FFTs O(~n log n). I was wondering if there was a reason the >> Karatsuba method was chosen over the FFT convolution method? > > The Karatsuba algorithm uses just addition, subtraction and > multiplication, so you don't need to resort to floats and have no > rounding errors. On the other hand FFT are based on e, complex numbers > or trigonometric functions (=floats), which mean you'll get rounding errors. > > We don't want rounding errors for large long multiplication. > > Christian > I believe it is possible to do FFTs without significant rounding error. I know that the GIMPS's Prime95 does very large multiplications using FFTs (I don't know if they use the integer based or double based version). I also know they have guards to prevent rounding errors so I don't think it would be impossible to implement. -- Bill From hobson42 at gmail.com Wed Jul 6 16:19:41 2011 From: hobson42 at gmail.com (Ian) Date: Wed, 06 Jul 2011 21:19:41 +0100 Subject: web browsing short cut In-Reply-To: References: Message-ID: <4E14C35D.80007@gmail.com> On 03/07/2011 02:21, Dustin Cheung wrote: > Hey guys, > > I am new to python. I want to make a shortcut that opens my websites > and re-sizes them to display on different areas on the screen. I > looked around but i had no luck. Is that possible with python? if so > can someone point to to the right direction? Here is what I came up > with so far.. > > I suggest you create a dummy page on your disk with an onload event that uses javascript to open, size and load all the windows you want. Then create a short cut to the dummy page. Regards Ian From noway at nohow.com Wed Jul 6 16:21:03 2011 From: noway at nohow.com (Billy Mays) Date: Wed, 06 Jul 2011 16:21:03 -0400 Subject: Large number multiplication References: Message-ID: On 07/06/2011 04:02 PM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: >> I was looking through the python source and noticed that long multiplication >> is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n >> log n). I was wondering if there was a reason the Karatsuba method was >> chosen over the FFT convolution method? > > According to Wikipedia: > > """ > In practice the Sch?nhage?Strassen algorithm starts to outperform > older methods such as Karatsuba and Toom?Cook multiplication for > numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). > """ > > I think most Python users are probably not working with numbers that > large, and if they are, they are probably using specialized numerical > libraries anyway, so there would be little benefit in implementing it > in core. You are right that not many people would gain significant use of it. The reason I ask is because convolution has a better (best ?) complexity class than the current multiplication algorithm. I do like the idea of minimizing reliance on external libraries, but only if the changes would be useful to all the regular users of python. I was more interested in finding previous discussion (if any) on why Karatsuba was chosen, not so much as trying to alter the current multiplication implementation. Side note: Are Numpy/Scipy the libraries you are referring to? -- Bill From ethan at stoneleaf.us Wed Jul 6 16:24:31 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 06 Jul 2011 13:24:31 -0700 Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: mailman.715.1309977744.1164.python-list@python.org <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <4E14C47F.3020601@stoneleaf.us> Phlip wrote: >> On 2011.07.06 12:38 PM, Phlip wrote: >>> Python sucks. m = md5() looks like an initial assignment, not a >>> special magic storage mode. Principle of least surprise fail, and >>> principle of most helpful default behavior fail. >>> > > If I call m = md5() twice, I expect two objects. You didn't call md5 twice -- you called it once when you defined the function. Phlips naive code: --- def file_to_hash(path, m = hashlib.md5()): \---------------/ happens once, when def line is executed If you want separate md5 objects, don't create just one when you create the function, create one inside the function: def file_to_hash(path, m = None): if m is None: m = hashlib.md5() You should try the Principle of Learning the Language. ~Ethan~ From pavlovevidence at gmail.com Wed Jul 6 16:25:37 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 6 Jul 2011 13:25:37 -0700 (PDT) Subject: Does hashlib support a file mode? In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> On Wednesday, July 6, 2011 12:07:56 PM UTC-7, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. Phlip: We already know about this violation of the least surprise principle; most of us acknowledge it as small blip in an otherwise straightforward and clean language. (Incidentally, fixing it would create different surprises, but probably much less common ones.) We've helped you with your problem, but you risk alienating those who helped you when you badmouth the whole language on account of this one thing, and you might not get such prompt help next time. So try to be nice. You are wrong about Python bending the definition of "call", though. Surprising though it be, the Python language is very explicit that the default arguments are executed only once, when creating the function, *not* when calling it. Carl Banks From ian.g.kelly at gmail.com Wed Jul 6 16:37:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Jul 2011 14:37:23 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Wed, Jul 6, 2011 at 2:21 PM, Billy Mays wrote: > Side note: Are Numpy/Scipy the libraries you are referring to? I was thinking more of gmpy or mpmath, but I'm not personally well acquainted with any of them. From lists at cheimes.de Wed Jul 6 16:43:04 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jul 2011 22:43:04 +0200 Subject: Large number multiplication In-Reply-To: References: Message-ID: Am 06.07.2011 22:15, schrieb Billy Mays: > I believe it is possible to do FFTs without significant rounding error. > I know that the GIMPS's Prime95 does very large multiplications using > FFTs (I don't know if they use the integer based or double based > version). I also know they have guards to prevent rounding errors so I > don't think it would be impossible to implement. It might work for medium large longs but how about really large longs like 5 * 1,000**10,000? I'm not familiar with FFT based multiplication but I guess that very large numbers are going to introduce rounding errors if floating points are involved. Python used to run on platforms without an FPU and floats. These days Python might still run on platforms with just an emulated FPU. Unless there is a way to implement FFT without floating point ops, an emulated or missing FPU makes FFT slower than Karatsuba. There might be one but I haven't learned a way in my numerics classes. Christian From phlip2005 at gmail.com Wed Jul 6 17:07:47 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 6 Jul 2011 14:07:47 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> Message-ID: <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> On Jul 6, 1:25?pm, Carl Banks wrote: > We already know about this violation of the least surprise principle; most of us acknowledge it as small blip in an otherwise straightforward and clean language. Here's the production code we're going with - thanks again all: def file_to_hash(path, hash_type=hashlib.md5): """ Per: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ea1c46f77ac1738c """ hash = hash_type() with open(path, 'rb') as f: while True: s = f.read(8192) # CONSIDER: io.DEFAULT_BUFFER_SIZE if not s: break hash.update(s) return hash.hexdigest() Note the fix also avoids comparing to None, which, as usual, is also icky and less typesafe! (And don't get me started about the extra lines needed to avoid THIS atrocity! while s = f.read(8192): hash.update(s) ;) From jeremy at jeremysanders.net Wed Jul 6 17:25:56 2011 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Wed, 06 Jul 2011 22:25:56 +0100 Subject: interactive plots References: Message-ID: Mihai Badoiu wrote: > How do I do interactive plots in python? Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. > Any python library that does this? You could try veusz, which is a python module and plotting program combined. You can also embed it in a PyQt program. Jeremy From almar.klein at gmail.com Wed Jul 6 18:00:06 2011 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 7 Jul 2011 00:00:06 +0200 Subject: interactive plots In-Reply-To: References: Message-ID: On 6 July 2011 17:04, Mihai Badoiu wrote: > How do I do interactive plots in python? Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear. Any > python library that does this? Visvis is a plotting toolkit that has good support for interactive use and picking: http://code.google.com/p/visvis/ I'll even give you an example: import visvis as vv # Create to lines, increase line width (lw) for easier clicking f = vv.plot([1,2,3,2], lc='r', lw=3) g = vv.plot([2,1,4,3], lc='b', lw=3) # Create callback function def deleteLine(event): event.owner.Destroy() # Enable picking and set callback for fg in [f, g]: fg.hitTest = True fg.eventMouseDown.Bind(deleteLine) Regards, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From almar.klein at gmail.com Wed Jul 6 18:03:19 2011 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 7 Jul 2011 00:03:19 +0200 Subject: interactive plots In-Reply-To: References: Message-ID: On 7 July 2011 00:00, Almar Klein wrote: > > > On 6 July 2011 17:04, Mihai Badoiu wrote: > >> How do I do interactive plots in python? Say I have to plot f(x) and g(x) >> and I want in the plot to be able to click on f and make it disappear. Any >> python library that does this? > > > Visvis is a plotting toolkit that has good support for interactive use and > picking: http://code.google.com/p/visvis/ > > I'll even give you an example: > > import visvis as vv > > > # Create to lines, increase line width (lw) for easier clicking > > f = vv.plot([1,2,3,2], lc='r', lw=3) > > g = vv.plot([2,1,4,3], lc='b', lw=3) > > > # Create callback function > > def deleteLine(event): > > event.owner.Destroy() > > # Enable picking and set callback > > for fg in [f, g]: > > fg.hitTest = True > > fg.eventMouseDown.Bind(deleteLine) > Except that the indentation got mangled when I pasted the code in. Sorry about that. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From vvnrk.vanapalli at gmail.com Wed Jul 6 18:05:48 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:05:48 -0700 (PDT) Subject: show() in pylab doesn't work if used twice Message-ID: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Hi all, I have been using python for just over a month now. I am writing a program to plot some graph using the show() twice in the same program. The code snippet is shown below. I am trying to plot a simple x vs y using ax.plot() then I get a figure displayed. I close the figure displayed and then the execution proceeds. Now If i try to call show second time with the updated values of x and y, the second figure does not appear on my desktop. but the second call to show() appears to work as the code also printed 'passed the second show' as well Can someone help me figure out what the problem here is.why is the second figure not coming up on the desktop. I am using python 2.7 . from pylab import * import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the first show()' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show()' From vvnrk.vanapalli at gmail.com Wed Jul 6 18:42:26 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:42:26 -0700 (PDT) Subject: multiple call to show not working in matplotlib Message-ID: <3a3d960b-b0f2-4d15-a0bd-1644e18fc106@s17g2000yqs.googlegroups.com> Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' Thanks Ravikanth From vvnrk.vanapalli at gmail.com Wed Jul 6 18:49:02 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 15:49:02 -0700 (PDT) Subject: multiple calls to show doesnot work for matplotlib Message-ID: Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' Thanks Ravikanth From mrunalu1 at gmail.com Wed Jul 6 19:10:44 2011 From: mrunalu1 at gmail.com (mru) Date: Wed, 6 Jul 2011 16:10:44 -0700 (PDT) Subject: multiple call to show not working in matplotlib Message-ID: Hi, I am facing some problem. I have made multiple calls to show() function in a sinlge program. as below. Before the first call I plotted x vs y . then i called show. execution halted until i closed the window. Once I closed the window, execution again progressed and even passed second show(), but the dispaly did not appear. Can anyone please suggest me how to go about solving this issue. from pylab import * from matplotlib import pyplot as p import scipy import pylab as pl import matplotlib.pyplot as plt fig=pl.figure() ax=fig.add_subplot(111) x=arange(10) y=x*2 ax.plot(x,y) show() print 'passed the border' x=arange(10) y=sin(x) ax.plot(x,y) show() print 'passed the second show' From steve+comp.lang.python at pearwood.info Wed Jul 6 19:15:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:15:29 +1000 Subject: multiple calls to show doesnot work for matplotlib References: Message-ID: <4e14ec92$0$29990$c3e8da3$5496439d@news.astraweb.com> Ravikanth wrote: > Hi, > > I am facing some problem. Yes, we heard you the first two times, there's no need to keep repeating the question over and over again. There is no Service Level Agreement for guaranteed response times for free advice over the Internet. Be patient, and hopefully somebody with an answer to your question will respond once they have read the question. Wait AT LEAST a day before reposting the question. In the meantime, you might like to Read the Fine Manual, which explains everything you need to know about using show(). http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show Does that answer your question? -- Steven From steve+comp.lang.python at pearwood.info Wed Jul 6 19:16:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:16:35 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> Message-ID: <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: > Note the fix also avoids comparing to None, which, as usual, is also > icky and less typesafe! "Typesafe"? Are you trying to make a joke? -- Steven From dustin299 at gmail.com Wed Jul 6 19:16:45 2011 From: dustin299 at gmail.com (Dustin Cheung) Date: Wed, 6 Jul 2011 16:16:45 -0700 Subject: web browsing short cut In-Reply-To: <4E14C35D.80007@gmail.com> References: <4E14C35D.80007@gmail.com> Message-ID: Okay thanks for the help guys, ill keep you guys posted. On Wed, Jul 6, 2011 at 1:19 PM, Ian wrote: > On 03/07/2011 02:21, Dustin Cheung wrote: > >> Hey guys, >> >> I am new to python. I want to make a shortcut that opens my websites and >> re-sizes them to display on different areas on the screen. I looked around >> but i had no luck. Is that possible with python? if so can someone point to >> to the right direction? Here is what I came up with so far.. >> >> >> I suggest you create a dummy page on your disk with an onload event that > uses javascript to open, size and load all the windows you want. > > Then create a short cut to the dummy page. > > Regards > > Ian > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Dustin Cheung -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Jul 6 19:26:15 2011 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 06 Jul 2011 18:26:15 -0500 Subject: show() in pylab doesn't work if used twice In-Reply-To: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> References: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Message-ID: On 7/6/11 5:05 PM, Ravikanth wrote: > Hi all, > > I have been using python for just over a month now. > I am writing a program to plot some graph using the show() twice in > the same program. The code snippet is shown below. Please use the matplotlib-users list for matplotlib questions. By the way, four versions of your message made it to this list. I'm sure the repetition was an honest mistake, but there may be things you can do to prevent it in the future. https://lists.sourceforge.net/lists/listinfo/matplotlib-users To answer your question, you are probably using an older version of matplotlib than 1.0.0. The ability to use show() more than once was only added in 1.0.0: http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show -- 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 vvnrk.vanapalli at gmail.com Wed Jul 6 19:31:33 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 16:31:33 -0700 (PDT) Subject: multiple calls to show doesnot work for matplotlib References: <4e14ec92$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f19a626-7d8b-4266-8c0a-8b63c64bd6ae@em7g2000vbb.googlegroups.com> On Jul 6, 6:15?pm, Steven D'Aprano wrote: > Ravikanth wrote: > > Hi, > > > I am facing some problem. > > Yes, we heard you the first two times, there's no need to keep repeating the > question over and over again. > > There is no Service Level Agreement for guaranteed response times for free > advice over the Internet. Be patient, and hopefully somebody with an answer > to your question will respond once they have read the question. Wait AT > LEAST a day before reposting the question. > > In the meantime, you might like to Read the Fine Manual, which explains > everything you need to know about using show(). > > http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show > > Does that answer your question? > > -- > Steven Hi Steven, I do understand that posting several times causes trouble. I did not see my post appear on the groups over in the groups site even after like 15 mints after posting. I thought I was posting it incorrectly. Thank you for your link. I will look through it. Regards, Ravikanth From steve+comp.lang.python at pearwood.info Wed Jul 6 19:40:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 09:40:44 +1000 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> <4e144aa0$0$29982$c3e8da3$5496439d@news.astraweb.com> <1NYQp.25969$Sr.25363@newsfe12.ams2> Message-ID: <4e14f27e$0$29971$c3e8da3$5496439d@news.astraweb.com> Stefaan Himpe wrote: > >> No! I was serious. I've spent *ages* trying to find the link to the >> article... if you know it, please share. > > Ok - I thought you were referring to some troll's rant with similar > title. I'm probably way off, but were you referring to the RAII technique? > > http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization Thanks Stefaan, but although it *sounds* like it should be from the title, that's not the idea I'm talking about. Despite the name, RAII is more about destructor/finalizer methods than initialisation. The blog post I'm looking for is not about finalizers, but about API design: don't make the caller give an explicit second activation call if you don't need to. -- Steven From nobody at nowhere.com Wed Jul 6 20:22:05 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:22:05 +0100 Subject: How do twisted and multiprocessing.Process create zombies? References: Message-ID: On Tue, 05 Jul 2011 14:52:49 -0700, bitcycle wrote: > In python, using twisted loopingcall, multiprocessing.Process, and > multiprocessing.Queue; is it possible to create a zombie process. And, if > so, then how? A zombie is a process which has terminated but hasn't been wait()ed on (aka "reaped") by its parent. Most libraries which create child processes make some effort to reap them. E.g. the subprocess module keeps a list of "orphaned" processes (those for which the Popen object was deleted while the underlying process was still alive), and polls the list periodically (specifically, whenever a new Popen object is created). From nobody at nowhere.com Wed Jul 6 20:25:31 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:25:31 +0100 Subject: Should ctypes handle mis-matching structure return ABI between mingw and MSVC? References: Message-ID: On Wed, 06 Jul 2011 11:12:47 +0800, Just Fill Bugs wrote: > According the Bug 36834 of gcc, there is a mis-matching between mingw and > MSVC when a struct was returned by value from a C function. > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834 > > Should ctypes handle this situation automatically somehow? I would expect this to be the responsibility of libffi rather than ctypes. From vvnrk.vanapalli at gmail.com Wed Jul 6 20:29:02 2011 From: vvnrk.vanapalli at gmail.com (Ravikanth) Date: Wed, 6 Jul 2011 17:29:02 -0700 (PDT) Subject: show() in pylab doesn't work if used twice References: <580fff12-3ae1-4c64-97ca-3ca6eec8c144@gc3g2000vbb.googlegroups.com> Message-ID: On Jul 6, 6:26?pm, Robert Kern wrote: > On 7/6/11 5:05 PM, Ravikanth wrote: > > > Hi all, > > > I have been using python for just over a month now. > > I am writing a program to plot some graph using the ?show() twice in > > the same program. The code snippet is shown below. > > Please use the matplotlib-users list for matplotlib questions. By the way, four > versions of your message made it to this list. I'm sure the repetition was an > honest mistake, but there may be things you can do to prevent it in the future. > > ? ?https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > To answer your question, you are probably using an older version of matplotlib > than 1.0.0. The ability to use show() more than once was only added in 1.0.0: > > ? ?http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show > > -- > 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 Hi Robert, Thank you for the link. I did not see my post posted onto the groups after i sent my query, which usually does happen in a few minutes. So I thought i posted it wrongly and reposted it. My apologies for inconvenience. I'll make sure this does not repeat. Regards, Ravikanth From nobody at nowhere.com Wed Jul 6 20:33:06 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 07 Jul 2011 01:33:06 +0100 Subject: Large number multiplication References: Message-ID: On Wed, 06 Jul 2011 22:05:52 +0200, Christian Heimes wrote: > On the other hand FFT are based on e, complex numbers or > trigonometric functions (=floats), which mean you'll get rounding errors. It's possible to perform a DFT over any field. Schoenhage-Strassen uses a DFT over a finite field (integers modulo N); it doesn't use floats. From kw at codebykevin.com Wed Jul 6 21:04:34 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 06 Jul 2011 21:04:34 -0400 Subject: trouble creating tooltips using Wx in Tk canvas In-Reply-To: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> References: <93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com> Message-ID: <8709b$4e150668$4275d90a$21028@FUSE.NET> On 7/6/11 3:35 PM, Ravikanth wrote: >> As it says, you haven't created the wx.App object necessary for pretty >> much all wxPython code. You could create one, but your tooltip still >> would not work correctly because you would be running the Tkinter >> event loop rather than the wxPython event loop. If you want to use >> the wxToolTip widget, then you should write your program to use >> wxPython only. Alternatively, googling for "tkinter tooltip" turns up >> a couple of recipes; you could try one of those. >> >> Cheers, >> Ian > > Thank you Ian for your insights to me on this. > I will migrate to wxPython to achieve the functionality. Tooltips are trivial to create in Tkinter: http://tkinter.unpythonic.net/wiki/ToolTip --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rosuav at gmail.com Thu Jul 7 00:55:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2011 14:55:45 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <4e147207$0$29979$c3e8da3$5496439d@news.astraweb.com> <4e148932$0$29981$c3e8da3$5496439d@news.astraweb.com> <433cd778-ac93-435b-a7da-ff17ada29a64@n5g2000yqh.googlegroups.com> <4E14AB29.30408@gmail.com> Message-ID: On Thu, Jul 7, 2011 at 5:15 AM, Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: >> On 2011.07.06 01:19 PM, rantingrick wrote: >>> ########################## >>> ?The Roman Stawman Sketch >>> ########################## >> Nice try, but you have to use a Monty Python sketch (and you have to >> spell correctly :-P ). > > Seriously. ?The source he borrowed from is the movie Gladiator, which > isn't even a comedy. Thanks, I was wondering where it was from. Unfortunately parodies tend to lose a lot if the reader doesn't know the original (although there are exceptions to that). ChrisA From ben+python at benfinney.id.au Thu Jul 7 01:10:56 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Jul 2011 15:10:56 +1000 Subject: The end to all language wars and the great unity API to come! References: <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4E137BC5.2080401@gmail.com> Message-ID: <87r562iskf.fsf@benfinney.id.au> Dennis Lee Bieber writes: > On Tue, 05 Jul 2011 16:01:57 -0500, Andrew Berg > declaimed the following in > gmane.comp.python.general: > > > On 2011.07.05 01:14 PM, sal migondis wrote: > > > How could a belief be wrong? > > Beliefs aren't subjective. One's taste in music, for example, is > > largely subjective and can't be right or wrong, but a belief (which > > has to do with facts) certainly can be. > > Pardon???? By ?has to do with facts?, I understand Andrew to be saying that a belief is *about* facts. That is, a belief is the position that a factual claim is true. > Most "beliefs" that I've encountered do their best to ignore any > facts that contradict the belief. You seem to be ignoring beliefs that are not usually held dogmatically: that the sun will rise tomorrow, that the newspaper article one is reading is likely true, that one's lunch is not poison, etc. These are distinct from so-called ?beliefs? that are really opinions: that my daughter is the loveliest in the world, that wasabi is horrible, etc. > "Facts" imply testable evidence, hypotheses, eventual theorems... I'd say facts are claims about reality which have been independently verified to be true. Beliefs that are about facts are thereby correct or incorrect. -- \ ?Only the educated are free.? ?Epictetus, _Discourses_ | `\ | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Thu Jul 7 01:34:23 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Jul 2011 17:34:23 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> Message-ID: <97kur2FlkhU1@mid.individual.net> rantingrick wrote: > Yes but what benefit does that gain over say, Tkinter's design > (because that has been your argument). Like I said, it's a tangential issue. The important thing is that it's okay for an app to stay alive until its *last* top level window is closed. There doesn't have to be a special "main" window that kills the whole app when you close it. However, I think what the original complaint was really about is that when you create a non-toplevel widget in Tkinter you have to specify its parent (and if you don't, it assumes you want it to be a child of the main window). You can't create the widget first and specify its parent later. This is another API flaw that is seen distressingly often in GUI libraries. It's a nuisance, because it means you can't write code that creates a widget hierarchy bottom-up. For example, in PyGUI you can write things like dialog_contents = Column([ Label("Caution: Your underpants are on fire."), Row([Button("OK"), Button("Cancel")]) ]) There's no way you could write Row and Column functions for Tkinter that work like that -- they would have to take parent widgets as arguments, and you wouldn't be able to nest the calls. -- Greg From greg.ewing at canterbury.ac.nz Thu Jul 7 01:37:55 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Jul 2011 17:37:55 +1200 Subject: wx MenuItem - icon is missing In-Reply-To: References: <4E12C505.3020300@shopzeus.com> <8B072395-5E0C-49C7-BBC4-38BAD25D0C05@semanchuk.com> <4E1366D5.6030208@shopzeus.com> <4E13FFE1.1080303@shopzeus.com> Message-ID: <97kv1mFmrkU1@mid.individual.net> Philip Semanchuk wrote: > I can understand why it's frustrating but a menu items with icons on them > aren't exactly common... Now that I think about it, I > don't know that I've ever seen one under OSX, and I don't even know if it's > supported at all. It's supported -- I've got FruitMenu running at the moment and it makes fairly heavy use of them. I agree that they don't seem to be used much anywhere else these days, though. -- Greg From ulrich.eckhardt at dominolaser.com Thu Jul 7 03:12:06 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 07 Jul 2011 09:12:06 +0200 Subject: Implicit initialization is EXCELLENT References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt > wrote: >> Mel wrote: >>> In wx, many of the window classes have Create methods, for filling in >>> various attributes in "two-step construction". [...] >> >> Just guessing, is it legacy, C-with-classes code rather than C++ code >> perhaps? Haven't looked at wx for a while. Such code typically lacks >> understanding of exceptions, which are the only way to signal failure >> from e.g. constructors. > > No, wx is C++ through and through. No namespaces. No templates but macros. No exceptions. No C++. Sorry, I beg to differ. BTW, they say themselves that they tolerate but not use exceptions, so they actually need two-stage construction if construction can fail, and for exactly the guessed legacy reasons. > http://wiki.wxpython.org/TwoStageCreation A C++ object is not a window, it is rather a proxy for managing the window. As such, it can be attached or detached from the underlying window, just like a std::fstream, so in this light it makes sense actually. Thanks for the link! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From cousinstanley at gmail.com Thu Jul 7 03:21:34 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 7 Jul 2011 07:21:34 +0000 (UTC) Subject: web browsing short cut References: Message-ID: Chris Angelico wrote: > > > > > > > > > > > > That should divide your screen four ways > ( if I haven't botched my HTML > - ages since I've used frames ). html !botched .... :-) An example of your frameset code http://csphx.net/fourpy.htm -- Stanley C. Kitching Human Being Phoenix, Arizona From kvaradhan3 at gmail.com Thu Jul 7 04:08:30 2011 From: kvaradhan3 at gmail.com (Kannan Varadhan) Date: Thu, 7 Jul 2011 01:08:30 -0700 (PDT) Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) Message-ID: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Hi Folks, Here is something I don't fully understand. 1 def DefaultTracer(fmt, *args): 2 fmt = 'in DefaultTracer ' + fmt 3 print(fmt % args) 4 pass 5 def myTracer(fmt, *args): 6 fmt = 'in myTracer ' + fmt 7 print(fmt % args) 8 9 class MyClass: 10 ClassDefaultTracer = DefaultTracer 11 def __init__(self): 12 self.InstanceTracer = MyClass.ClassDefaultTracer 13 def trace(self, fmt, *args): 14 self.InstanceTracer(fmt, *args) 15 16 17 DefaultTracer("Testing %s", 'at first') 18 myTracer("Testing %s", 'at first') 19 20 MyClass().trace('Using ClassDefaultTracer') 21 22 # override ClassDefaultTracer for all new instances 23 MyClass.ClassDefaultTracer = myTracer 24 MyClass().trace('Using Overridden ClassDefaultTracer') I want ClassDefaultTracer to store a reference to DefaultTracer and be used by instances of MyClass. Why does line20 give me the following error: $ python foo.py in DefaultTracer Testing at first in myTracer Testing at first Traceback (most recent call last): File "foo.py", line 20, in MyClass().trace('Using ClassDefaultTracer') File "foo.py", line 14, in trace self.InstanceTracer(fmt, *args) TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) Alternately, how can I achieve what I want, i.e. a class-wide default used by all instances created off it, but itself be changeable, so that once changed, the changed default would be used by subsequent newer instances of that class. Thanks, Kannan From ulrich.eckhardt at dominolaser.com Thu Jul 7 04:30:09 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 07 Jul 2011 10:30:09 +0200 Subject: Large number multiplication References: Message-ID: Billy Mays wrote: > On 07/06/2011 04:02 PM, Ian Kelly wrote: >> According to Wikipedia: >> >> """ >> In practice the Sch?nhage?Strassen algorithm starts to outperform >> older methods such as Karatsuba and Toom?Cook multiplication for >> numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). >> """ >> >> I think most Python users are probably not working with numbers that >> large, and if they are, they are probably using specialized numerical >> libraries anyway, so there would be little benefit in implementing it >> in core. > > You are right that not many people would gain significant use of it. Even worse, most people would actually pay for its use, because they don't use numbers large enough to merit the Sch?nhage?Strassen algorithm. > The reason I ask is because convolution has a better (best ?) complexity > class than the current multiplication algorithm. The "asymptotic complexity" of algorithms (I guess that's what you mean) is concerned with large up to infinite n elements in operations. The claim there always excludes any number of elements below n_0, where the complexity might be different, even though that is usually not repeatedly mentioned. In other words, lower complexity does not mean that something runs faster, only that for large enough n it runs faster. If you never realistically reach that limit, you can't reap those benefits. That said, I'm sure that the developers would accept a patch that switches to a different algorithm if the numbers get large enough. I believe it already doesn't use Karatsuba for small numbers that fit into registers, too. > I was more interested in finding previous discussion (if any) on why > Karatsuba was chosen, not so much as trying to alter the current > multiplication implementation. I would hope that such design decisions are documented in code or at least referenced from there. Otherwise the code is impossible to understand and argue about. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From washakie at gmail.com Thu Jul 7 04:59:35 2011 From: washakie at gmail.com (John [H2O]) Date: Thu, 7 Jul 2011 01:59:35 -0700 (PDT) Subject: more advanced learning resources (code structure, fundamentals) Message-ID: <32011481.post@talk.nabble.com> Hello, I've been programming in Python for a few years now. I have read most the typical learning resources, such as 'Dive Into Python', 'A Byte of Python', etc. In general I feel I have a good overview of the language. However, as I advanced toward trying to create more OO styled programs, I feel I am lacking some background on basic concepts. I have read 'Coding' and 'Beautiful Code', and while these provide good information on how to style and think about code, they haven't help me design classes, think about where and when to use inheritance, decorators, etc. The point is, most examples stop at demonstrating a single class, or show a trivial decorator example. What I am after is something that will help me design a program from scratch. What are the key points to the classes? Is it okay to reference or pass classes to instantiate a class? When would I want to use a decorator? How to decide which should be a static method, and if I need them at all? I know a lot of this would come from experience of working in a team, but unfortunately, I'm mostly running solo. I am starting to look more and more at source code too, which I find helpful, but the styles of programming vary significantly. Perhaps someone could say which modules have nice 'exemplary' code worth learning from? So, if someone has a good book or online reference, please point me to it. Other ideas too are most certainly welcome! Best, john -- View this message in context: http://old.nabble.com/more-advanced-learning-resources-%28code-structure%2C-fundamentals%29-tp32011481p32011481.html Sent from the Python - python-list mailing list archive at Nabble.com. From __peter__ at web.de Thu Jul 7 05:04:15 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 11:04:15 +0200 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: Kannan Varadhan wrote: > Here is something I don't fully understand. > > 1 def DefaultTracer(fmt, *args): > 2 fmt = 'in DefaultTracer ' + fmt > 3 print(fmt % args) > 4 pass > 5 def myTracer(fmt, *args): > 6 fmt = 'in myTracer ' + fmt > 7 print(fmt % args) > 8 > 9 class MyClass: > 10 ClassDefaultTracer = DefaultTracer > 11 def __init__(self): > 12 self.InstanceTracer = MyClass.ClassDefaultTracer > 13 def trace(self, fmt, *args): > 14 self.InstanceTracer(fmt, *args) > 15 > 16 > 17 DefaultTracer("Testing %s", 'at first') > 18 myTracer("Testing %s", 'at first') > 19 > 20 MyClass().trace('Using ClassDefaultTracer') > 21 > 22 # override ClassDefaultTracer for all new instances > 23 MyClass.ClassDefaultTracer = myTracer > 24 MyClass().trace('Using Overridden ClassDefaultTracer') > > I want ClassDefaultTracer to store a reference to DefaultTracer and be > used by instances of MyClass. Why does line20 give me the following > error: > > $ python foo.py > in DefaultTracer Testing at first > in myTracer Testing at first > Traceback (most recent call last): > File "foo.py", line 20, in > MyClass().trace('Using ClassDefaultTracer') > File "foo.py", line 14, in trace > self.InstanceTracer(fmt, *args) > TypeError: unbound method DefaultTracer() must be called with MyClass > instance as first argument (got str instance instead) Functions written in Python are also "descriptors", they have a __get__() method. The seemingly harmless whatever = MyClass.ClassDefaultTracer therefore results in something like whatever = MyClass.__dict__["ClassDefaultTracer"].__get__(None, MyClass) internally, and whatever becomes an "unbound method", essentially the DefaultTracer function wrapped in a check that its first argument is a MyClass instance. The simplest workaround is probably to spell out the dictionary access whatever = MyClass.__dict__["ClassDefaultTracer"] If you want inheritance to work properly you need something more invoved, perhaps (untested) f = self.ClassDefaultTracer try: f = f.im_func except AttributeError: pass self.InstanceTracer = f or you wrap the callable in a descriptor: >>> def DefaultTracer(*args): print args ... >>> class D(object): ... def __init__(self, f): ... self.f = f ... def __get__(self, *args): ... return self.f ... >>> class MyClass(object): ... old = DefaultTracer ... new = D(DefaultTracer) ... >>> MyClass.old >>> MyClass.new >>> m = MyClass() >>> m.old > >>> m.new Not pretty, but in Python 3 the problem is gone... > Alternately, how can I achieve what I want, i.e. a class-wide default > used by all instances created off it, but > itself be changeable, so that once changed, the changed default would > be used by subsequent newer instances of that class. From a24061 at ducksburg.com Thu Jul 7 05:47:50 2011 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 07 Jul 2011 10:47:50 +0100 Subject: bash: testing whether anyone is or has recently been logged in? References: Message-ID: <6vbge8x0pa.ln2@news.ducksburg.com> On 2011-04-20, Bill Marcum wrote: > On 2011-04-20, Adam Funk wrote: >> I'd appreciate any suggestions for testing (preferably from a bash >> script, although perl or python would be OK too) whether anyone is >> currently logged in, and whether anyone has been logged in during the >> past $N minutes. >> >> (The idea is to use this in a cron script that only does its job when >> the machine is not "in live use".) >> > A script could parse the output of "who", "w" or "last", and the stored > output from previous commands. [adding comp.lang.python] Here's what I came up with in python. If you call it with no arguments or with 0 as the argument, it gives a 0 exit code if no-one is logged in. If you call it with a non-zero argument N, it gives a 0 exit code if no-one has been logged in in the past N minutes. I welcome suggestions, corrections, &c. #v+ #!/usr/bin/python # -*- coding: utf-8 -*- import subprocess, re from dateutil.parser import * from sys import stdout, stderr, argv from datetime import datetime, timedelta from optparse import OptionParser oparser = OptionParser(usage="usage: %prog [options] [N]") oparser.add_option("-v", dest="verbose", default=False, action="store_true", help="Verbose output") (options, args) = oparser.parse_args() query = 0 try: if len(args) > 0: query = int(args[0]) except ValueError: stderr.write('Invalid argument %s\n' % argv[1]) exit(-1) if (options.verbose): stdout.write('query %i\n' % query) last_proc = subprocess.Popen(args=['last'], stdout=subprocess.PIPE) last_out = last_proc.stdout.read().split('\n') still_logged = re.compile(r'still logged in') line_pattern = re.compile(r'^\S+\s+\S+\s+\S+\s+(\S+\s+\S+\s+\S+) ..:.. - (..:..)\s+.*$') timestamps = []; minutes = 1 for line in last_out: if line.startswith('reboot'): pass elif still_logged.search(line): minutes = 0 if (options.verbose): stdout.write('still logged in\n') break else: matcher = line_pattern.match(line) # user term host Tue Apr 26 13:49 - 14:52 (01:02) if matcher: date_string = matcher.group(1) + ' ' + matcher.group(2) timestamp = parse(date_string) stdout.write('d> ' + date_string + ' --> ' + str(timestamp) + '\n') timestamps.append(timestamp) if len(timestamps) > 0: latest = max(timestamps) stderr.write(str(latest) + '\n') now = datetime.now() delta = now - latest minutes = delta.days * 24 * 60 + delta.seconds / 60 diff_value = query + 1 - minutes exit_value = max (0, diff_value) if (options.verbose): stdout.write('min %i\n' % minutes) stdout.write('diff %i\n' % diff_value) stdout.write('exit %i\n' % exit_value) exit(exit_value) #v- -- I worry that 10 or 15 years from now, [my daughter] will come to me and say 'Daddy, where were you when they took freedom of the press away from the Internet?' [Mike Godwin] http://www.eff.org/ From prakash.stack at gmail.com Thu Jul 7 05:58:25 2011 From: prakash.stack at gmail.com (prakash jp) Date: Thu, 7 Jul 2011 15:28:25 +0530 Subject: find max and min values from a column of a csv file Message-ID: Hi All , Could any one help to get max and min values from a specified column of a csv file. The* csv file is large* and hence the below code did go bad. *Alternate methods would be highly appreciated ** minimum.py*: import csv filename = "testLog_4.csv" f = open(filename) def col_min(mincname): with open(filename, 'rb') as f: reader = csv.reader(f, delimiter=",") #print reader #print mincname col_index = next(reader).index(mincname) #print col_index least = min(rec[col_index] for rec in reader) print least col_min(str("Server Latency")) col_min(str("Client Latency")) f.close() *maximum.py:* import csv filename = "testLog_4.csv" f = open(filename) def col_max(maxcname): with open(filename, 'rb') as f: reader = csv.reader(f, delimiter=",") #print reader #print cname col_index = next(reader).index(maxcname) #print col_index highest = max(rec[col_index] for rec in reader) print highest col_max(str("Server Latency")) col_max(str("Client Latency")) f.close() Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From washakie at gmail.com Thu Jul 7 06:38:04 2011 From: washakie at gmail.com (John [H2O]) Date: Thu, 7 Jul 2011 03:38:04 -0700 (PDT) Subject: find max and min values from a column of a csv file In-Reply-To: References: Message-ID: <32012126.post@talk.nabble.com> I think you would benefit from reading the data into a numpy array first, then using numpy min, max functions. prakash jp wrote: > > Hi All , > > Could any one help to get max and min values from a specified column of a > csv file. The* csv file is large* and hence the below code did go bad. > *Alternate > methods would be highly appreciated > ** > minimum.py*: > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_min(mincname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print mincname > col_index = next(reader).index(mincname) > #print col_index > least = min(rec[col_index] for rec in reader) > print least > > col_min(str("Server Latency")) > col_min(str("Client Latency")) > f.close() > > *maximum.py:* > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_max(maxcname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print cname > col_index = next(reader).index(maxcname) > #print col_index > highest = max(rec[col_index] for rec in reader) > print highest > > col_max(str("Server Latency")) > col_max(str("Client Latency")) > f.close() > > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/find-max-and-min-values-from-a-column-of-a-csv-file-tp32011861p32012126.html Sent from the Python - python-list mailing list archive at Nabble.com. From mwilson at the-wire.com Thu Jul 7 07:04:40 2011 From: mwilson at the-wire.com (Mel) Date: Thu, 07 Jul 2011 07:04:40 -0400 Subject: more advanced learning resources (code structure, fundamentals) References: Message-ID: John [H2O] wrote: [ ... ] > What are the key points to the classes? Is it okay to reference or pass > classes to instantiate a class? Yes. The standard library does this in BaseHTTPServer (via its parent SocketServer.) Maybe looks abstruse at the outset, but it's the natural way to assign a fresh message handler to a new input message. Docs are via the Python Global Module Index, source is in some directory like /usr/lib/python2.6/SocketServer.py , .../BaseHTTPServer.py , etc. Mel. From as at sci.fi Thu Jul 7 07:29:38 2011 From: as at sci.fi (Anssi Saari) Date: Thu, 07 Jul 2011 14:29:38 +0300 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: Mel writes: > def file_to_hash(path, m = hashlib.md5()): > > hashlib.md5 *is* called once; that is when the def statement is executed. Very interesting, I certainly wasn't clear on this. So after that def, the created hashlib object is in the module's scope and can be accessed via file_to_hash.__defaults__[0]. From dmitrey15 at gmail.com Thu Jul 7 08:08:56 2011 From: dmitrey15 at gmail.com (dmitrey) Date: Thu, 7 Jul 2011 05:08:56 -0700 (PDT) Subject: blist question Message-ID: hi all, I feel lack of native Python lists operations (e.g. taking N greatest elements with the involved key function and O(n) speed) and occasionally found blist http://pypi.python.org/pypi/blist/ Its entry says it is better than Python list. Did anyone ensure? Will it ever be merged into Python source code? D. From paul.nospam at rudin.co.uk Thu Jul 7 08:13:22 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 07 Jul 2011 13:13:22 +0100 Subject: Does hashlib support a file mode? References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> Message-ID: <87aacq70gt.fsf@no-fixed-abode.cable.virginmedia.net> Anssi Saari writes: > Mel writes: > >> def file_to_hash(path, m = hashlib.md5()): >> >> hashlib.md5 *is* called once; that is when the def statement is executed. > > Very interesting, I certainly wasn't clear on this. So after that def, > the created hashlib object is in the module's scope and can be > accessed via file_to_hash.__defaults__[0]. This also why you have to be a bit careful if you use e.g. [] or {} as a default argument - if you then modify these things within the function you might not end up with what you expect - it's the same list or dictionary each time the function is called. So to avoid that kind of thing you end up with code like: def foo(bar=None): if bar is None: bar = [] ... From __peter__ at web.de Thu Jul 7 08:33:25 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 14:33:25 +0200 Subject: find max and min values from a column of a csv file References: Message-ID: prakash jp wrote: > Could any one help to get max and min values from a specified column of a > csv file. The* csv file is large* and hence the below code did go bad. > *Alternate > methods would be highly appreciated > ** > minimum.py*: > import csv > filename = "testLog_4.csv" > f = open(filename) > def col_min(mincname): > with open(filename, 'rb') as f: > reader = csv.reader(f, delimiter=",") > #print reader > #print mincname > col_index = next(reader).index(mincname) > #print col_index > least = min(rec[col_index] for rec in reader) > print least > > col_min(str("Server Latency")) > col_min(str("Client Latency")) > f.close() I don't see a way to make this much faster as it is probably already i/o- bound. You can try and calculate all four extrema at once, so you have to iterate over the file only once: $ cat csv_minmax_chunked.py #!/usr/bin/env python import csv import locale from itertools import islice def make_key(index, type): def key(row): return type(row[index]) return key class Aggregator(object): def __init__(self, name, index, type, key=None): self.name = name self.index = index self.type = type or float self.getvalue = make_key(index, type) self.key = {"key": key} if key is not None else {} def __repr__(self): return "{0}(name={1}, index={2}, type={3}".format( type(self).__name__, self.name, self.index, self.type) def __str__(self): try: return "%s: %s...%s" % (self.name, self.min, self.max) except AttributeError: return "%s: (no values)" % self.name def update(self, rows): values = map(self.getvalue, rows) chunkmin = min(values, **self.key) chunkmax = max(values, **self.key) try: curmin = self.min curmax = self.max except AttributeError: self.min = chunkmin self.max = chunkmax else: self.min = min(curmin, chunkmin, **self.key) self.max = max(curmax, chunkmax, **self.key) def identity(s): return s convert = { "float": (float,), "int": (int,), "text": (lambda s: s, locale.strxfrm), "": (identity,) } def main(): locale.setlocale(locale.LC_ALL, "") import argparse parser = argparse.ArgumentParser() parser.add_argument("csvfile") parser.add_argument("columns", nargs="+") parser.add_argument("--chunksize", "-s", type=int, default=2**12) args = parser.parse_args() ntpairs = (column.partition(":")[::2] for column in args.columns) with open(args.csvfile, "rb") as instream: rows = csv.reader(instream) header = dict((name, index) for index, name in enumerate(next(rows))) aggregators = [ Aggregator( "{0}({1})".format(name, type or "str"), header[name], *convert[type]) for name, type in ntpairs] chunksize = args.chunksize while True: chunk = list(islice(rows, chunksize)) if not chunk: break for agg in aggregators: agg.update(chunk) for agg in aggregators: print agg if __name__ == "__main__": main() $ head sample.csv alpha,beta,gamma,delta 69,-454,460960,ELIJAH 92,796,278885,SUFFICIENCY 42,895,934523,PIONEERED 88,-213,360633,reassert 63,-518,327010,mcmahon 84,604,540764,deprecatory 83,117,621832,VEGETARIANISM'S 61,411,844243,tan 29,-147,982043,plushest $ ./csv_minmax_chunked.py sample.csv alpha:int beta:int beta gamma:float delta delta:text alpha(int): 0...99 beta(int): -1000...999 beta(str): -1...999 gamma(float): 0.0...999997.0 delta(str): AALIYAH...?tudes delta(text): a...ZYUGANOV'S From steve+comp.lang.python at pearwood.info Thu Jul 7 08:36:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 07 Jul 2011 22:36:33 +1000 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: <4e15a853$0$29982$c3e8da3$5496439d@news.astraweb.com> Kannan Varadhan wrote: > Hi Folks, > > Here is something I don't fully understand. > > 1 def DefaultTracer(fmt, *args): > 2 fmt = 'in DefaultTracer ' + fmt > 3 print(fmt % args) > 4 pass > 5 def myTracer(fmt, *args): > 6 fmt = 'in myTracer ' + fmt > 7 print(fmt % args) Please don't post code with line numbers. That makes it difficult to copy and paste your function into an interactive session, so that we can run it and see what it does. [...] > I want ClassDefaultTracer to store a reference to DefaultTracer and be > used by instances of MyClass. Why does line20 give me the following > error: > > $ python foo.py > in DefaultTracer Testing at first > in myTracer Testing at first > Traceback (most recent call last): > File "foo.py", line 20, in > MyClass().trace('Using ClassDefaultTracer') > File "foo.py", line 14, in trace > self.InstanceTracer(fmt, *args) > TypeError: unbound method DefaultTracer() must be called with MyClass > instance as first argument (got str instance instead) Unfortunately you've run into a side-effect of one of the very few "Do What I Mean" aspects of Python: under many circumstances, storing a function in a class automatically turns it into a method. This is almost always what you want, but not this time. Here's a simple example: >>> def function(s): ... print s ... >>> class C(object): ... func = function ... print func, type(func) ... >>> print C.func, type(C.func) How to interpret this: The class block is an executable statement which is executed at runtime. During that execution, "print func" is called, and it sees func is an actual function object. After the block finishes executing, a class object (also called a type) is created. This is where the DWIM behaviour happens: function attributes are automatically turned into methods. That's normally what you want, but in this case, it gives you the surprising result: >>> C.func("hello world") Traceback (most recent call last): File "", line 1, in TypeError: unbound method function() must be called with C instance as first argument (got str instance instead) Instead of calling it from the class C, you can call it from an instance: >>> c = C() >>> c.func("hello world") Traceback (most recent call last): File "", line 1, in TypeError: function() takes exactly 1 argument (2 given) Two arguments? What? Where's the second argument??? But wait: *bound* methods automatically get the instance as their first argument. (When you define a method in the class, you write a function with "self" as the first argument.) A bound method is one that is called from an instance, not the class, and it gets the instance as first argument automatically: instance.method(args) # a bound method is translated by Python into: theclass = type(instance) theclass.method(instance, args) # an unbound method So if we do this, the method works: >>> c.func() # bound methods get the instance as first argument <__main__.C object at 0xb7f8fb6c> There are a couple of solutions to avoid this. One is to live with it: def function(self, s): # Define this as if it were a method. print s class C(object): func = function Now you can call: instance = C() # unbound method, you are responsible for supplying "self" C.func(instance, arg) # bound method, Python supplies "self" instance.func(arg) but of course now you can't call function(arg) from outside the class. Another solution is to use a staticmethod: def function(s): print s class C(object): func = staticmethod(function) A third is to disguise the function: class C(object): func = (function,) # In a tuple and then call C.func[0](arg) but that's hideous. Don't do that. Fourthly, the DWIM magic only happens when you store a function in the *class*, not if you do it in the instance: class C(object): def __init__(self): self.func = function but now you can't call C.func because it doesn't exist, you have to initialise an instance first. > Alternately, how can I achieve what I want, i.e. a class-wide default > used by all instances created off it, but > itself be changeable, so that once changed, the changed default would > be used by subsequent newer instances of that class. class C(object): default = staticmethod(function) def __init__(self): self.func = type(self).default ought to do it. -- Steven From paul.nospam at rudin.co.uk Thu Jul 7 08:38:04 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 07 Jul 2011 13:38:04 +0100 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> <4e15a853$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8762ne6zbn.fsf@no-fixed-abode.cable.virginmedia.net> Steven D'Aprano writes: > Please don't post code with line numbers. That makes it difficult to copy > and paste your function into an interactive session, so that we can run it > and see what it does. C-x r d From bahamutzero8825 at gmail.com Thu Jul 7 08:50:08 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 07:50:08 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E15AB80.50906@gmail.com> On 2011.07.06 06:16 PM, Steven D'Aprano wrote: > Phlip wrote: > > > Note the fix also avoids comparing to None, which, as usual, is also > > icky and less typesafe! > > "Typesafe"? Are you trying to make a joke? Maybe he has a duck phobia. Maybe he denies the existence of ducks. Maybe he doesn't like the sound of ducks. Maybe he just weighs the same as a duck. In any case, duck tolerance is necessary to use Python effectively. On a side note, it turns out there's no word for the fear of ducks. The closest phobia is anatidaephobia, which is the fear of being /watched/ by a duck. From __peter__ at web.de Thu Jul 7 08:50:33 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2011 14:50:33 +0200 Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: Peter Otten wrote: > or you wrap the callable in a descriptor: > >>>> def DefaultTracer(*args): print args > ... >>>> class D(object): > ... def __init__(self, f): > ... self.f = f > ... def __get__(self, *args): > ... return self.f > ... After skimming over Steven's post: use staticmethod. No idea why I didn't think of that myself. From phlip2005 at gmail.com Thu Jul 7 09:11:19 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 06:11:19 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> > On 2011.07.06 06:16 PM, Steven D'Aprano wrote:> Phlip wrote: > > > > Note the fix also avoids comparing to None, which, as usual, is also > > > icky and less typesafe! > > > "Typesafe"? Are you trying to make a joke? No, I was pointing out that passing a type is more ... typesafe. From bahamutzero8825 at gmail.com Thu Jul 7 09:24:58 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 08:24:58 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> Message-ID: <4E15B3AA.4030106@gmail.com> On 2011.07.07 08:11 AM, Phlip wrote: > No, I was pointing out that passing a type is more ... typesafe. None is a type. >>> None.__class__ From phlip2005 at gmail.com Thu Jul 7 09:39:54 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 06:39:54 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> Message-ID: <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> On Jul 7, 6:24?am, Andrew Berg wrote: > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that passing a type is more ... typesafe. > > None is a type. I never said it wasn't. From bahamutzero8825 at gmail.com Thu Jul 7 09:58:48 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 08:58:48 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> Message-ID: <4E15BB98.2040804@gmail.com> On 2011.07.07 08:39 AM, Phlip wrote: > On Jul 7, 6:24 am, Andrew Berg wrote: > > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that passing a type is more ... typesafe. > > > > None is a type. > > I never said it wasn't. You are talking about this code, right? def file_to_hash(path, m=None): if m is None: m = hashlib.md5() What's not a type? The is operator compares types (m's value isn't the only thing compared here; even an separate instance of the exact same type would make it return False), and m can't be undefined. From invalid at invalid.invalid Thu Jul 7 10:18:32 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 7 Jul 2011 14:18:32 +0000 (UTC) Subject: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> <1pvghkmjff37$.dlg@localhost.localdomain> Message-ID: On 2011-07-06, Waldek M. wrote: > Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): >> Because unless you are extremely disciplined, code and the comments >> describing them get out of sync. [...] > True, but that gets far worse with external docs. Do you have in mind > any better replacement? You write code that's easy to read, and you provide the language with introspection capabilities that allow you do do things like write a program that will list the symbols exported by a module. -- Grant Edwards grant.b.edwards Yow! Now that I have my at "APPLE", I comprehend COST gmail.com ACCOUNTING!! From python at bdurham.com Thu Jul 7 10:20:02 2011 From: python at bdurham.com (python at bdurham.com) Date: Thu, 07 Jul 2011 10:20:02 -0400 Subject: Tips/lessons learned for writing a Python powered DSL? Message-ID: <1310048402.8528.2149215773@webmail.messagingengine.com> Looking for tips and lessons learned (advice on what to do and not do) for writing a Python based DSL. Googling python dsl yields some wonderful content which I've just started to read. If there are specific articles or 3rd party libraries that you used to implement a DSL, I would appreciate hearing about them. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwoolcoc at gmail.com Thu Jul 7 10:40:39 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Thu, 7 Jul 2011 10:40:39 -0400 Subject: Tips/lessons learned for writing a Python powered DSL? In-Reply-To: <1310048402.8528.2149215773@webmail.messagingengine.com> References: <1310048402.8528.2149215773@webmail.messagingengine.com> Message-ID: For me, diving into the data model really helped me grasp some of the metaprogramming capabilities that python has, which is helping me as I am implementing my own DSL in python. http://docs.python.org/reference/datamodel.html On Thu, Jul 7, 2011 at 10:20 AM, wrote: > Looking for tips and lessons learned (advice on what to do and not do) for > writing a Python based DSL. > > Googling python dsl yields some wonderful content which I've just started > to read. If there are specific articles or 3rd party libraries that you used > to implement a DSL, I would appreciate hearing about them. > > Thank you, > Malcolm > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- --- Paul Woolcock -------------- next part -------------- An HTML attachment was scrubbed... URL: From toyze.rocha at gmail.com Thu Jul 7 11:21:12 2011 From: toyze.rocha at gmail.com (=?ISO-8859-1?Q?Ant=F3nio_Rocha?=) Date: Thu, 7 Jul 2011 16:21:12 +0100 Subject: Question- Getting Windows 64bits information Python 32bits Message-ID: Greetings I'm running Python (32b) in Windows7 (at 64bits) and I would like to know how can I check if my machine is a 32b or 64b in Python. Is it possible? I saw a few examples (like platform) but they only provide information about Python not the machine. Thanks Toze -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Thu Jul 7 11:46:56 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 10:46:56 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: References: Message-ID: <4E15D4F0.5040408@gmail.com> On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: > I'm running Python (32b) in Windows7 (at 64bits) and I would like to > know how can I check if my machine is a 32b or 64b in Python. Is it > possible? I saw a few examples (like platform) but they only provide > information about Python not the machine. os.environ['processor_architecture'] os.environ is a dictionary of system environment variables. That exact key probably only exists on Windows, but I'm there is a similar key on other platforms. From ian.g.kelly at gmail.com Thu Jul 7 11:49:10 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:49:10 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt wrote: > Even worse, most people would actually pay for its use, because they don't > use numbers large enough to merit the Sch?nhage?Strassen algorithm. As it stands, Karatsuba is only used for numbers greater than a specific threshold. Adding Sch?nhage?Strassen would just mean adding another threshold, below which Karatsuba would still be used. So at worst it would just add another comparison or two for numbers within the Karatsuba range. From ian.g.kelly at gmail.com Thu Jul 7 11:50:34 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:50:34 -0600 Subject: Large number multiplication In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 9:49 AM, Ian Kelly wrote: > On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt > wrote: >> Even worse, most people would actually pay for its use, because they don't >> use numbers large enough to merit the Sch?nhage?Strassen algorithm. > > As it stands, Karatsuba is only used for numbers greater than a > specific threshold. ?Adding Sch?nhage?Strassen would just mean adding > another threshold, below which Karatsuba would still be used. ?So at > worst it would just add another comparison or two for numbers within > the Karatsuba range. And I just realized that you said as much yourself further down in your message. My apologies for the needless lecturing. From ian.g.kelly at gmail.com Thu Jul 7 11:58:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jul 2011 09:58:47 -0600 Subject: Implicit initialization is EXCELLENT In-Reply-To: References: <4e132d0f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 7, 2011 at 1:12 AM, Ulrich Eckhardt wrote: >>> Just guessing, is it legacy, C-with-classes code rather than C++ code >>> perhaps? Haven't looked at wx for a while. Such code typically lacks >>> understanding of exceptions, which are the only way to signal failure >>> from e.g. constructors. >> >> No, wx is C++ through and through. > > No namespaces. No templates but macros. No exceptions. No C++. > > Sorry, I beg to differ. BTW, they say themselves that they tolerate but not > use exceptions, so they actually need two-stage construction if construction > can fail, and for exactly the guessed legacy reasons. Ah, I think I misunderstood your meaning. By "C-with-classes" I thought you were referring to the practice of OOP in C, and my response was to the effect that building wx requires a C++ compiler, not just a C compiler. From nabble.com at bodrato.it Thu Jul 7 12:00:08 2011 From: nabble.com at bodrato.it (Parerga) Date: Thu, 7 Jul 2011 09:00:08 -0700 (PDT) Subject: Large number multiplication In-Reply-To: References: Message-ID: <32014454.post@talk.nabble.com> Hi, Billy Mays wrote: > >> On 07/06/2011 04:02 PM, Ian Kelly wrote: >> > On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: >> >> I was looking through the python source and noticed that long >> multiplication >> >> is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs >> O(~n >> >> log n). I was wondering if there was a reason the Karatsuba method >> was >> >> chosen over the FFT convolution method? > >> The reason I ask is because convolution has a better (best ?) complexity > Better complexity, yes. This means "smaller execution time for LARGE ENOUGH operands" Billy Mays wrote: > >> I was more interested in finding previous discussion (if any) on why >> Karatsuba was chosen, not so much as trying to alter the current >> multiplication implementation. > I'm not a python developer, but I worked on multiplication algorithms for GMP [ http://gmplib.org/ ], and I can guess the answer: - Karatsuba is (by far) simpler to implement, - FFT-based multiplication is (by far) slower than Karatsuba for numbers that are not huge. I try to attach a small graph http://old.nabble.com/file/p32014454/karaVSfft.pdf karaVSfft.pdf , with timings for multiplications of n-bits operands (with GMP, on my very old laptop) with Toom(2,2) (it's Karatsuba!) and the FFT-based computation. The first is faster than the latter up to 10000 bits (GMP uses some Toom for that size, to get the result even faster). Regards, Marco -- http://bodrato.it/software/toom.html -- View this message in context: http://old.nabble.com/Large-number-multiplication-tp32007815p32014454.html Sent from the Python - python-list mailing list archive at Nabble.com. From phil at brassy.net Thu Jul 7 12:33:16 2011 From: phil at brassy.net (Philip Reynolds) Date: Thu, 7 Jul 2011 17:33:16 +0100 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: <4E15D4F0.5040408@gmail.com> References: <4E15D4F0.5040408@gmail.com> Message-ID: <20110707163315.GA14053@brassy.net> On Thu, 07 Jul 2011, Andrew Berg wrote: > On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: > > I'm running Python (32b) in Windows7 (at 64bits) and I would like to > > know how can I check if my machine is a 32b or 64b in Python. Is it > > possible? I saw a few examples (like platform) but they only provide > > information about Python not the machine. > os.environ['processor_architecture'] > > os.environ is a dictionary of system environment variables. That exact > key probably only exists on Windows, but I'm there is a similar key on > other platforms. $ python -c 'import platform; print platform.architecture()' ('64bit', 'ELF') http://docs.python.org/library/platform.html Phil. From robert.kern at gmail.com Thu Jul 7 12:43:55 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 07 Jul 2011 11:43:55 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: <20110707163315.GA14053@brassy.net> References: <4E15D4F0.5040408@gmail.com> <20110707163315.GA14053@brassy.net> Message-ID: On 7/7/11 11:33 AM, Philip Reynolds wrote: > On Thu, 07 Jul 2011, Andrew Berg wrote: > >> On 2011.07.07 10:21 AM, Ant?nio Rocha wrote: >>> I'm running Python (32b) in Windows7 (at 64bits) and I would like to >>> know how can I check if my machine is a 32b or 64b in Python. Is it >>> possible? I saw a few examples (like platform) but they only provide >>> information about Python not the machine. >> os.environ['processor_architecture'] >> >> os.environ is a dictionary of system environment variables. That exact >> key probably only exists on Windows, but I'm there is a similar key on >> other platforms. > > $ python -c 'import platform; print platform.architecture()' > ('64bit', 'ELF') > > http://docs.python.org/library/platform.html This is not what the OP is looking for. The OP wants to know what the CPU and OS are capable of, not what the Python executable is compiled for. platform.architecture() gives the latter. -- 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 stutzbach at google.com Thu Jul 7 13:03:25 2011 From: stutzbach at google.com (Daniel Stutzbach) Date: Thu, 7 Jul 2011 10:03:25 -0700 Subject: blist question In-Reply-To: References: Message-ID: On Thu, Jul 7, 2011 at 5:08 AM, dmitrey wrote: > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) and > occasionally found blist > http://pypi.python.org/pypi/blist/ > > Its entry says it is better than Python list. Did anyone ensure? > It has better performance for many operations. I made a very detailed performance comparison here (against Python 3.1): http://stutzbachenterprises.com/performance-blist Undoubtedly, you can find sequences of operations where Python's built-in list type has better performance by a constant factor. Python's built-in list type is more memory-efficient for small lists (blist's memory usage for small lists could be improved to be similar, but I haven't gotten around to making the necessary changes.) > Will it ever be merged into Python source code? > Seems unlikely. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Thu Jul 7 13:15:20 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Thu, 7 Jul 2011 12:15:20 -0500 Subject: Question- Getting Windows 64bits information Python 32bits In-Reply-To: References: Message-ID: 2011/7/7 Ant?nio Rocha > Greetings > > I'm running Python (32b) in Windows7 (at 64bits) and I would like to know > how can I check if my machine is a 32b or 64b in Python. Is it possible? I > saw a few examples (like platform) but they only provide information about > Python not the machine. > Thanks > Toze > Running CPython compiled for 32-bit on a Windows 7 64-bit machine gives the following: >>> platform.architecture() ('32bit', 'WindowsPE') >>> platform.machine() 'AMD64' This didn't used to be the case - it was corrected in http://bugs.python.org/issue7860 so you may need to upgrade to get accurate information if you have an older Python installed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.schoon at gmail.com Thu Jul 7 13:22:56 2011 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 7 Jul 2011 17:22:56 GMT Subject: Programming tips :-) Message-ID: <97m8bgFqq4U1@mid.individual.net> I just found the following url in my archives at work and thought you might enjoy it: http://thc.org/root/phun/unmaintain.html /Martin From peterirbizon at gmail.com Thu Jul 7 13:24:04 2011 From: peterirbizon at gmail.com (miamia) Date: Thu, 7 Jul 2011 10:24:04 -0700 (PDT) Subject: module problem on windows 64bit References: <55f1238e-2613-4767-9c5f-ae4b6e56d1c2@d1g2000yqm.googlegroups.com> Message-ID: <682c2d6e-4564-4451-ae77-84638aa4d6c9@q17g2000vby.googlegroups.com> On Jul 5, 5:05?pm, Thomas Jollans wrote: > On 06/27/2011 06:59 PM, miamia wrote: > > > Hello, > > > on 32-bit windows everything works ok but on 64-bit win I am getting > > this error: > > Traceback (most recent call last): > > ? File "app.py", line 1040, in do_this_now > > ? File "kinterbasdb\__init__.pyc", line 119, in > > ? File "kinterbasdb\_kinterbasdb.pyc", line 12, in > > ? File "kinterbasdb\_kinterbasdb.pyc", line 10, in __load > > ImportError: DLL load failed: This application has failed to start > > because the application configuration is incorrect. Reinstalling the > > application may fix this problem. > > > How to get it work on 64bit windows as well? many thanks > > A process can only link to a shared library compiled for the same > architecture as the process. In layman's terms: A 32-bit DLL won't work > with a 64-bit program. It looks like this package is attempting to load > a 32-bit DLL. That's not going to work. Either procure a 64-bit version > of the DLL, or use a 32-bit version of Python. hello, it looks lite I solved it with files msvcp80.dll, Microsoft.VC80.CRT.manifest. I forgot to extract these files from firebird embedded pachage to my app folder. now it seems to be ok on both systems 32 and 64bit (so It wasn't 64bit issue as I thought). thank you From miki.tebeka at gmail.com Thu Jul 7 13:27:30 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 7 Jul 2011 10:27:30 -0700 (PDT) Subject: blist question In-Reply-To: Message-ID: Have you looked at http://docs.python.org/library/collections.html#collections.deque ? From rantingrick at gmail.com Thu Jul 7 13:29:58 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 7 Jul 2011 10:29:58 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> Message-ID: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> On Jul 7, 12:34?am, Gregory Ewing wrote: > rantingrick wrote: > > Yes but what benefit does that gain over say, Tkinter's design > > (because that has been your argument). > > Like I said, it's a tangential issue. Agreed. > The important thing is that it's okay for an app to stay > alive until its *last* top level window is closed. So your argument is: """ A window hierarchy is bad because if your application requires a user to open a gazillion windows (read as: designed poorly) --each representing completely different transactions-- and if you close the original window all the "other" windows will close too. Boo :(""" continuing... > There > doesn't have to be a special "main" window that kills the > whole app when you close it. So you prefer to close a gazillion windows one by one? If so, why not just code the GUI correctly from the start; by creating separate transactions? Thereby reducing the number of windows a user must juggle? FYI: You know the user complexity of a GUI increases exponentially by the number of windows present. > However, I think what the original complaint was really > about is that when you create a non-toplevel widget in Tkinter > you have to specify its parent (and if you don't, it assumes > you want it to be a child of the main window). Thats was MY complaint yes. On the grounds that widgets require windows NOT windows require widgets. This fact will confuse folks. > You can't > create the widget first and specify its parent later. > > This is another API flaw that is seen distressingly often > in GUI libraries. It's a nuisance, because it means you can't > write code that creates a widget hierarchy bottom-up. Actually you can! Stay tuned for enlightenment! > For > example, in PyGUI you can write things like > ? ?dialog_contents = Column([ > ? ? ?Label("Caution: Your underpants are on fire."), > ? ? ?Row([Button("OK"), Button("Cancel")]) > ? ?]) > > There's no way you could write Row and Column functions for > Tkinter that work like that -- they would have to take parent > widgets as arguments, and you wouldn't be able to nest the > calls. WRONG! A function or class structure can handle this just fine. And lends itself nicely to GUI programming. ## START CODE ## import Tkinter as tk class DumbDialog(tk.Toplevel): def __init__(self, master, **kw): w=tk.Label(master, text="Caution: Your underpants are on fire.") w.pack() w=tk.Button(master, text="OK").pack() w=tk.Button(master, text="Cancel").pack() print 'start script' root = tk.Tk() d = DumbDialog(root) root.mainloop() print 'continue script' root = tk.Tk() d = DumbDialog(root) root.mainloop() print 'end script' ## END CODE ## *school bell rings* From casevh at gmail.com Thu Jul 7 13:46:35 2011 From: casevh at gmail.com (casevh) Date: Thu, 7 Jul 2011 10:46:35 -0700 (PDT) Subject: Large number multiplication References: Message-ID: On Jul 7, 1:30?am, Ulrich Eckhardt wrote: > Billy Mays wrote: > > On 07/06/2011 04:02 PM, Ian Kelly wrote: > >> According to Wikipedia: > > >> """ > >> In practice the Sch?nhage?Strassen algorithm starts to outperform > >> older methods such as Karatsuba and Toom?Cook multiplication for > >> numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits). > >> """ > > >> I think most Python users are probably not working with numbers that > >> large, and if they are, they are probably using specialized numerical > >> libraries anyway, so there would be little benefit in implementing it > >> in core. > > > You are right that not many people would gain significant use of it. > > Even worse, most people would actually pay for its use, because they don't > use numbers large enough to merit the Sch?nhage?Strassen algorithm. > > > The reason I ask is because convolution has a better (best ?) complexity > > class than the current multiplication algorithm. > > The "asymptotic complexity" of algorithms (I guess that's what you mean) is > concerned with large up to infinite n elements in operations. The claim > there always excludes any number of elements below n_0, where the complexity > might be different, even though that is usually not repeatedly mentioned. In > other words, lower complexity does not mean that something runs faster, only > that for large enough n it runs faster. If you never realistically reach > that limit, you can't reap those benefits. > > That said, I'm sure that the developers would accept a patch that switches > to a different algorithm if the numbers get large enough. I believe it > already doesn't use Karatsuba for small numbers that fit into registers, > too. > > > I was more interested in finding previous discussion (if any) on why > > Karatsuba was chosen, not so much as trying to alter the current > > multiplication implementation. > > I would hope that such design decisions are documented in code or at least > referenced from there. Otherwise the code is impossible to understand and > argue about. > > Cheers! > > Uli > > -- > Domino Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932- Hide quoted text - > > - Show quoted text - A quick search on the Python issue tracker (bugs.python.org) yields the following issues: http://bugs.python.org/issue560379 http://bugs.python.org/issue4258 The issues also refer to discussion threads on the python-dev mailing list. casevh From postslot at gmail.com Thu Jul 7 14:18:08 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 11:18:08 -0700 (PDT) Subject: i get different answers based on run platform Message-ID: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> I have this simple palindrome program that yields different results depending on whether I run it from Windows or from IDLE. The answer is correct off IDLE, but why is this the case? Here's the code: def reverse(text): return text[::-1] def is_palindrome(text): return text==reverse(text) while True: something=input('enter text:') print(something) print(something[::-1]) if (is_palindrome(something)): print("yes, it is a palindrome") break else: print("no, it is not a palindrome") continue print ('done') Thanks for your help. From widebandwidth at gmail.com Thu Jul 7 14:18:18 2011 From: widebandwidth at gmail.com (high bandwidth) Date: Thu, 7 Jul 2011 14:18:18 -0400 Subject: making socket.getaddrinfo use cached dns In-Reply-To: References: Message-ID: I use cached dns lookups with pdnsd on my ubuntu machine to speed up web access as regular lookups can take 15-30 seconds. However, python's mechanize and urllib etc use socket.getaddrinfo, which seems not to be using dns cacheing or taking a long time because of ipv6 lookups. In either case, I subsequent access to the same site to be fast and not require lengthy calls to getaddrinfo. How can I get python to correctly use cached dns lookups and ipv4 only (at least in those cases where it is appropriate). As mentioned here: http://stackoverflow.com/questions/2014534/force-python-mechanize-urllib2-to-only-use-a-requests/2035686#2035686 It seems that many python libraries are hardcoded to look for both ipv6 and ipv4. Since ipv6 lookups are extremely slow at least for some users, perhaps the devs should carry over these optional arguments to higher level libraries like mechanize, urllib, httplib etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jul 7 14:24:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2011 04:24:12 +1000 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: On Fri, Jul 8, 2011 at 3:29 AM, rantingrick wrote: > So your argument is: > ? ?""" A window hierarchy is bad because if your application requires > a user to open a gazillion windows (read as: designed poorly) --each > representing completely different transactions-- and if you close the > original window all the "other" windows will close too. Boo :(""" Why should opening multiple windows AUTOMATICALLY equate to poor design? > So you prefer to close a gazillion windows one by one? If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. By "separate transactions" do you mean that the user can simultaneously perform multiple actions? Because that's best done with multiple separate interfaces - such as, multiple windows. Or do you really mean "sequential transactions"? That would not in any way be good design. >> For >> example, in PyGUI you can write things like > >> ? ?dialog_contents = Column([ >> ? ? ?Label("Caution: Your underpants are on fire."), >> ? ? ?Row([Button("OK"), Button("Cancel")]) >> ? ?]) >> > WRONG! A function or class structure can handle this just fine. And > lends itself nicely to GUI programming. You have to break your code into two pieces. Here's an alternative way of laying out a dialog, this taken from Pike-GTK2: mainwindow->add(GTK2.Vbox(0,0)->add(GTK2.HbuttonBox()->add(button("E_xit",window_destroy)->set_use_underline(1))->add(button("Set",setprops))->set_layout(GTK2.BUTTONBOX_SPREAD)))->show_all(); This program uses utility functions such as: //Helper function to create a button and give it an event. Useful because signal_connect doesn't return self. GTK2.Button button(mixed content,function clickevent,mixed|void arg) { GTK2.Button ret=GTK2.Button(content); ret->signal_connect("clicked",clickevent,arg); return ret; } I make no apologies for the braces in the code :) The 'button' function creates a button and assigns it an event. At this stage, the button has no parent; it won't be drawn anywhere. The GTK2.Button object is returned, and then added. It's added to the HbuttonBox which is then added to the Vbox which is only then added to the main window; although the code would work just fine if done in the other order. It's important here that objects are simply objects - they don't have to be built in a tree structure; and the window's layout is entirely in the one place, I don't have to put half of it into the window's constructor. ChrisA From rosuav at gmail.com Thu Jul 7 14:26:37 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2011 04:26:37 +1000 Subject: making socket.getaddrinfo use cached dns In-Reply-To: References: Message-ID: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth wrote: > I use cached dns lookups with pdnsd on my ubuntu machine to speed up web > access as regular lookups can take 15-30 seconds. However, python's > mechanize and urllib etc use socket.getaddrinfo, which seems not to be using > dns cacheing or taking a long time because of ipv6 lookups. In either case, > I subsequent access to the same site to be fast and not require lengthy > calls to getaddrinfo. How can I get python to correctly use cached dns > lookups and ipv4 only (at least in those cases where it is appropriate). One solution would be to do your own DNS lookups and then pass urllib an IP address. Is pdnsd set up to be your computer's primary resolver? (Is /etc/resolv.conf pointing to localhost?) If not, that might help. I've generally done my DNS caching using BIND, so I can't help with pdnsd specifically. ChrisA From bahamutzero8825 at gmail.com Thu Jul 7 14:36:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 13:36:55 -0500 Subject: Programming tips :-) In-Reply-To: <97m8bgFqq4U1@mid.individual.net> References: <97m8bgFqq4U1@mid.individual.net> Message-ID: <4E15FCC7.3020501@gmail.com> On 2011.07.07 12:22 PM, Martin Sch??n wrote: > I just found the following url in my archives at work and > thought you might enjoy it: > http://thc.org/root/phun/unmaintain.html That's awesome. > If a maintenance programmer can't quote entire Monty Python movies > from memory, he or she has *no* business being a programmer. :-D From gordon at panix.com Thu Jul 7 14:37:54 2011 From: gordon at panix.com (John Gordon) Date: Thu, 7 Jul 2011 18:37:54 +0000 (UTC) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: In <842fce9d-1b3f-434a-b748-a6dc4828c385 at h12g2000pro.googlegroups.com> linda writes: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: Your code contains debugging statements that print the value of the normal string and the reversed string. What do those statements print when you run your program under Windows? That should go a long way towards telling you what the problem is. (Perhaps Windows leaves a linefeed character hanging at the end of the input line, which upsets the palindromic balance?) By the way, I could not make your program work as you provided it; I had to replace input() with raw_input(). Does it really work for you this way? -- 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 bahamutzero8825 at gmail.com Thu Jul 7 14:42:04 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 13:42:04 -0500 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <4E15FDFC.3080506@gmail.com> On 2011.07.07 12:29 PM, rantingrick wrote: > So you prefer to close a gazillion windows one by one? If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. :-D Are you paid to troll? I must say, your technique of presenting semi-logical, but completely wrong arguments is admirable. Truly the work of a professional. From python at mrabarnett.plus.com Thu Jul 7 14:54:47 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 07 Jul 2011 19:54:47 +0100 Subject: i get different answers based on run platform In-Reply-To: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1600F7.5030107@mrabarnett.plus.com> On 07/07/2011 19:18, linda wrote: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: > > def reverse(text): > return text[::-1] > def is_palindrome(text): > return text==reverse(text) > while True: > something=input('enter text:') > print(something) > print(something[::-1]) > if (is_palindrome(something)): > print("yes, it is a palindrome") > break > else: > print("no, it is not a palindrome") > continue > print ('done') > > Thanks for your help. > Try printing ascii(something) too. There's a known bug in Python 3.2 where it leaves a training '\r', if that's what you're using (http://bugs.python.org/issue12435), fixed in Python 3.2.1. From ethan at stoneleaf.us Thu Jul 7 14:58:22 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 11:58:22 -0700 Subject: i get different answers based on run platform In-Reply-To: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1601CE.3070100@stoneleaf.us> linda wrote: > I have this simple palindrome program that yields different results > depending on whether I run it from Windows or from IDLE. The answer > is correct off IDLE, but why is this the case? Here's the code: > > def reverse(text): > return text[::-1] > def is_palindrome(text): > return text==reverse(text) > while True: > something=input('enter text:') try changing this to: something = input('enter text:').rstrip('\n') > print(something) > print(something[::-1]) > if (is_palindrome(something)): > print("yes, it is a palindrome") > break > else: > print("no, it is not a palindrome") > continue > print ('done') From python at mrabarnett.plus.com Thu Jul 7 14:59:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 07 Jul 2011 19:59:05 +0100 Subject: i get different answers based on run platform In-Reply-To: References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1601F9.6070506@mrabarnett.plus.com> On 07/07/2011 19:37, John Gordon wrote: > In<842fce9d-1b3f-434a-b748-a6dc4828c385 at h12g2000pro.googlegroups.com> linda writes: > >> I have this simple palindrome program that yields different results >> depending on whether I run it from Windows or from IDLE. The answer >> is correct off IDLE, but why is this the case? Here's the code: > > Your code contains debugging statements that print the value of the normal > string and the reversed string. What do those statements print when you > run your program under Windows? That should go a long way towards telling > you what the problem is. > > (Perhaps Windows leaves a linefeed character hanging at the end of the > input line, which upsets the palindromic balance?) > > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? > It's Python 3. Python 2's raw_input() has been renamed input() in Python 3 and Python 2's input() was never in Python 3 because it uses eval on the string, which usually undesirable. From ethan at stoneleaf.us Thu Jul 7 15:11:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 12:11:52 -0700 Subject: i get different answers based on run platform In-Reply-To: References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <4E1604F8.3020000@stoneleaf.us> John Gordon wrote: > By the way, I could not make your program work as you provided it; I had > to replace input() with raw_input(). Does it really work for you this way? input() is the 3.x name for raw_input() ~Ethan~ From yorick.brunet at gmail.com Thu Jul 7 15:34:39 2011 From: yorick.brunet at gmail.com (yorick) Date: Thu, 7 Jul 2011 12:34:39 -0700 (PDT) Subject: Serial & reset of the device Message-ID: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Hello, I'm trying to access a hardware board of my company through a serial connection using a Python script and the pyserial module. I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). The board to which I'm trying to connect works correctly with serial as some other guys did some TCL scripts to manage it. My problem is that every time I open a new connection, the device is reset. I'd like to not have the device reset. The code is the following : handler = serial.Serial(port=self.portname, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stHello, I'm trying to access a hardware board of my company through a serial connection using a Python script and the pyserial module. I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). The board to which I'm trying to connect works correctly with serial as some other guys did some TCL scripts to manage it. My problem is that every time I open a new connection, the device is reset. I'd like to not have the device reset. The code is the following : handler = serial.Serial(port=self.portname, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=False) # here the device is reset ... handler.close() I found the following post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274205532 but I haven't tested it yet as I don't like the idea to change files managed by the system (and it is for Windows). Is there any possibility to not reset the device when opening the connection ? Thanks, Yorickopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=False) # here the device is reset ... handler.close() I found the following post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274205532 but I haven't tested it yet as I don't like the idea to change files managed by the system (and it is for Windows). Is there any possibility to not reset the device when opening the connection ? Thanks, Yorick From mrkwjc at gmail.com Thu Jul 7 16:08:37 2011 From: mrkwjc at gmail.com (ichi) Date: Thu, 7 Jul 2011 13:08:37 -0700 (PDT) Subject: multiprocessing.Manager().Namespace() and data copying Message-ID: Hi! I'm trying to share data between processes using multiprocessing.Manager and? creating shared Namespace. I have the following code: from multiprocessing import Manager from scipy import rand x = rand(5000, 5000) m = Manager() n = m.Namespace() n.x = x?? It seems that at n.x = x data is serialized and copied. It seems it is also? serialized and copied at x = n.x. Is there a way to omit this to have really? shared objects with Namespace? I need read only objects (not necessarily? arrays)... From AimeeG at sgainc.com Thu Jul 7 16:48:17 2011 From: AimeeG at sgainc.com (Aimee Gerzofsky) Date: Thu, 7 Jul 2011 16:48:17 -0400 Subject: FULL TIME PYTHON DEVELOPER OPPORTUNITY IN CHICAGO, IL Message-ID: <817109B09119D849A3B8FCFBBEAAA8E15294DA8A@sga3.sga.local> Python Developer Major financial clients is seeking a Python Developer for a full time position in Chicago, IL. The candidate will be a mid level developer responsible for contributing to all phases of the SDLC including analysis, design, development, QA, UAT, and tier-2 production support. The deliverables include real-time rules engines, real-time processing engines, real-time dashboards, and scheduled end of day reporting processes built on our cross-asset strategic trading and processing platform. Responsibilities: Required: * 5+ years Object Oriented Programming experience * 3+ years Python programming * Experience with Microsoft WPF UI programming a plus * 2+ years XML experience * Experience with SQL databases * Experience with NoSQL databases a plus * Working knowledge of Unix/Linux * Agile development life-cycle experience Preferred: * Financial experience a plus * Knowledge of Dodd-Frank regulations a huge plus * Knowledge of derivative products Contact me: aimee at sgainc.com if you or someone you know is interested. Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From postslot at gmail.com Thu Jul 7 17:09:11 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 14:09:11 -0700 (PDT) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> Message-ID: <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> I tried something = input('enter text:').rstrip('\n') as suggested but the problem persists. BTW, the intermediate print commands agree and so are not an issue. The disagreement is in IDLE correctly identifying palindromes and Windows not. I do suspect it may be a trailing '\r' issue. Is there an easy fix or shall I wait for the new Python versions to be released? Thanks for helping. From postslot at gmail.com Thu Jul 7 17:37:14 2011 From: postslot at gmail.com (linda) Date: Thu, 7 Jul 2011 14:37:14 -0700 (PDT) Subject: i get different answers based on run platform References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> Message-ID: On Jul 7, 2:42?pm, Ethan Furman wrote: > linda wrote: > > I tried something = input('enter text:').rstrip('\n') as suggested but > > the problem persists. ?BTW, the intermediate print commands agree and > > so are not an issue. ?The disagreement is in IDLE correctly > > identifying palindromes and Windows not. ?I do suspect it may be a > > trailing '\r' issue. ?Is there an easy fix or shall I wait for the new > > Python versions to be released? ?Thanks for helping. > > My apologies -- change the '\n' to '\r' and that will hopefully do the > trick. > > ~Ethan~ Thanks Ethan--that did work :) From ethan at stoneleaf.us Thu Jul 7 17:42:45 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 07 Jul 2011 14:42:45 -0700 Subject: i get different answers based on run platform In-Reply-To: <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> References: <842fce9d-1b3f-434a-b748-a6dc4828c385@h12g2000pro.googlegroups.com> <88cc310e-9436-4381-bd13-bc8816c7f5e4@v11g2000prn.googlegroups.com> Message-ID: <4E162855.4000605@stoneleaf.us> linda wrote: > I tried something = input('enter text:').rstrip('\n') as suggested but > the problem persists. BTW, the intermediate print commands agree and > so are not an issue. The disagreement is in IDLE correctly > identifying palindromes and Windows not. I do suspect it may be a > trailing '\r' issue. Is there an easy fix or shall I wait for the new > Python versions to be released? Thanks for helping. My apologies -- change the '\n' to '\r' and that will hopefully do the trick. ~Ethan~ From python at rcn.com Thu Jul 7 18:46:16 2011 From: python at rcn.com (Raymond Hettinger) Date: Thu, 7 Jul 2011 15:46:16 -0700 (PDT) Subject: blist question References: Message-ID: On Jul 7, 5:08?am, dmitrey wrote: > hi all, > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) Take a look at heapq.nlargest()... > and > occasionally found blisthttp://pypi.python.org/pypi/blist/ > Its entry says it is better than Python list. It should say: better in some respects and worse in others Do you honestly think that python's list implementation as a simple array of pointers can be beaten in every category of performance? > Did anyone ensure? > Will it ever be merged into Python source code? It was rejected as a replacement for the existing list implementation. There is some chance it will get accepted into the collections module someday. Raymond From clp2 at rebertia.com Thu Jul 7 20:36:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 7 Jul 2011 17:36:27 -0700 Subject: Testing if a global is defined in a module In-Reply-To: References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <4e124916$0$29970$c3e8da3$5496439d@news.astraweb.com> <4e124db1$0$29973$c3e8da3$5496439d@news.astraweb.com> <20110705000131.GN1971@johnsons-web.com> <4e134b99$0$29993$c3e8da3$5496439d@news.astraweb.com> <1pvghkmjff37$.dlg@localhost.localdomain> Message-ID: On Thu, Jul 7, 2011 at 7:18 AM, Grant Edwards wrote: > On 2011-07-06, Waldek M. wrote: >> Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): > >>> Because unless you are extremely disciplined, code and the comments >>> describing them get out of sync. [...] > >> True, but that gets far worse with external docs. Do you have in mind >> any better replacement? > > You write code that's easy to read Reminded me of this excellent presentation: "Uncomment Your Code" https://docs.google.com/present/view?id=ah82mvnssv5d_162dbgx78gw Cheers, Chris From steve+comp.lang.python at pearwood.info Thu Jul 7 21:25:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 11:25:14 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 7, 12:34?am, Gregory Ewing wrote: >> The important thing is that it's okay for an app to stay >> alive until its *last* top level window is closed. I partially disagree with Greg on this. This is not the only model: on the Apple Mac, or any system with a similar GUI design, the application can survive having the last window closed. There are other application types that don't need any window at all. So while it is common for closing the last window to exit the application, it is not a necessary requirement. >> There >> doesn't have to be a special "main" window that kills the >> whole app when you close it. > > So you prefer to close a gazillion windows one by one? Nonsense. Greg says nothing of the sort. Avoiding the anti-pattern "close a gazillion windows one by one" is why you have an application-wide Quit or Exit command, as opposed to a Close command which applies only to the current window. > If so, why not > just code the GUI correctly from the start; by creating separate > transactions? Thereby reducing the number of windows a user must > juggle? FYI: You know the user complexity of a GUI increases > exponentially by the number of windows present. Don't assume that there is a one-to-one relationship between transactions (documents?) and windows. The relationship is actually many-to-many: windows can contain tabbed or notepad interfaces, or can be split into multiple panes, or both. Panes and tabs can be split into independent windows, or rejoined into one main window. E.g. I can have six Firefox windows open, each one with many different websites open in separate tabs. I have Close Tab, Close Window and Exit Firefox commands. In Konquorer, not only can I have multiple windows and multiple tabs, but I can split each tab into two or more panes, and display two views of the same document in the same tab, or two different documents in the one tab. This is especially useful when using it as a file manager. In older versions of Word (and possibly current, although I haven't tested it) you can open files multiple times. Each time opens in a new window, representing a new view of the one file. Edits in one window update all the others. This can be useful for, e.g. making edits to page 3 while simultaneously viewing page 303. An alternate UI for to split the one window into two panes, and scroll them independently. So a single file may have one or two panes, in one or more windows. So, you can have multiple documents in multiple windows, and there is no 1:1 relationship between them. -- Steven From steve+comp.lang.python at pearwood.info Thu Jul 7 21:46:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 11:46:12 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> Message-ID: <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > On 2011.07.07 08:39 AM, Phlip wrote: >> On Jul 7, 6:24 am, Andrew Berg wrote: >> > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that >> > passing a type is more ... typesafe. >> > >> > None is a type. >> >> I never said it wasn't. Unfortunately, it isn't. None is not a type, it is an instance. >>> isinstance(None, type) # is None a type? False >>> isinstance(None, type(None)) # is None an instance of None's type? True So None is not itself a type, although it *has* a type: >>> type(None) >>> isinstance(type(None), type) # is NoneType itself a type? True > You are talking about this code, right? > > def file_to_hash(path, m=None): > if m is None: > m = hashlib.md5() > > What's not a type? The is operator compares types (m's value isn't the > only thing compared here; even an separate instance of the exact same > type would make it return False), and m can't be undefined. The is operator does not compare types, it compares instances for identity. There is no need for is to ever care about the type of the arguments -- that's just a waste of time, since a fast identity (memory location) test is sufficient. This is why I initially thought that Phlip was joking when he suggested that "m is None" could be type-unsafe. It doesn't matter what type m has, "m is " will always be perfectly safe. -- Steven From greg.ewing at canterbury.ac.nz Thu Jul 7 21:58:42 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Jul 2011 13:58:42 +1200 Subject: Implicit initialization is EVIL! In-Reply-To: <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> Message-ID: <97n6ilFpbkU1@mid.individual.net> rantingrick wrote: > So you prefer to close a gazillion windows one by one? If I want to close all the windows, I can use the application's "Quit" or "Exit" command, or whatever the platform calls it. (Note that if there is a separate instance of the application for each window -- as was suggested earlier -- then you don't have that option, and you have to close them one by one anyway.) >>There's no way you could write Row and Column functions for >>Tkinter that work like that -- they would have to take parent >>widgets as arguments, and you wouldn't be able to nest the >>calls. > > WRONG! A function or class structure can handle this just fine. > > class DumbDialog(tk.Toplevel): > def __init__(self, master, **kw): > w=tk.Label(master, text="Caution: Your underpants are on > fire.") > w.pack() > w=tk.Button(master, text="OK").pack() > w=tk.Button(master, text="Cancel").pack() Which is *exactly* what I said you would have to do in Tkinter! Each widget creation requires a separate statement, with the parent passed in at each step. This is nowhere near as convenient as the nested function call style. -- Greg From bahamutzero8825 at gmail.com Thu Jul 7 22:32:59 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Jul 2011 21:32:59 -0500 Subject: Does hashlib support a file mode? In-Reply-To: <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E166C5B.8030100@gmail.com> On 2011.07.07 08:46 PM, Steven D'Aprano wrote: > None is not a type, it is an instance. > > >>> isinstance(None, type) # is None a type? > False > >>> isinstance(None, type(None)) # is None an instance of None's type? > True > > So None is not itself a type, although it *has* a type: > > >>> type(None) > > >>> isinstance(type(None), type) # is NoneType itself a type? > True I worded that poorly. None is (AFAIK) the only instance of NoneType, but I should've clarified the difference. > The is operator does not compare types, it compares instances for identity. > There is no need for is to ever care about the type of the arguments -- > that's just a waste of time, since a fast identity (memory location) test > is sufficient. "Compare" was the wrong word. I figured the interpreter doesn't explicitly compare types, but obviously identical instances are going to be of the same type. From phlip2005 at gmail.com Thu Jul 7 22:44:12 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 19:44:12 -0700 (PDT) Subject: Programming tips :-) References: <97m8bgFqq4U1@mid.individual.net> Message-ID: <5b0c982a-5b4c-4136-ba6f-e6223b713f99@s2g2000vbw.googlegroups.com> On Jul 7, 11:36?am, Andrew Berg wrote: > On 2011.07.07 12:22 PM, Martin Sch??n wrote:> I just found the following url in my archives at work and > > thought you might enjoy it: > >http://thc.org/root/phun/unmaintain.html > > That's awesome. That's "How To Write Unmaintainable Code" - a venerable classic. Compare these: http://c2.com/cgi/wiki?HowToPissOffYourPair http://c2.com/cgi/wiki?HelpSourceForgeSuck From phlip2005 at gmail.com Thu Jul 7 23:26:56 2011 From: phlip2005 at gmail.com (Phlip) Date: Thu, 7 Jul 2011 20:26:56 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> > I worded that poorly. None is (AFAIK) the only instance of NoneType, but > I should've clarified the difference.> The is operator does not compare types, it compares instances for identity. None is typesafe, because it's strongly typed. However, what's even MORE X-safe (for various values of X) is a method that takes LESS for its arguments. That's why I switched from passing an object to passing a type, because the more restrictive argument type is more typesafe. However, the MOST X-safe version so far simply passes a string, and uses hashlib the way it designs to be used: def file_to_hash(path, hash_type): hash = hashlib.new(hash_type) with open(path, 'rb') as f: while True: s = f.read(8192) if not s: break hash.update(s) return hash.hexdigest() From drsalists at gmail.com Fri Jul 8 00:22:58 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 7 Jul 2011 21:22:58 -0700 Subject: Serial & reset of the device In-Reply-To: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Message-ID: On Thu, Jul 7, 2011 at 12:34 PM, yorick wrote: > Hello, > > I'm trying to access a hardware board of my company through a serial > connection using a Python script and the pyserial module. > > I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- > serial with version 2.5.2, > http://pyserial.sourceforge.net/pyserial_api.html). > > The board to which I'm trying to connect works correctly with serial > as some other guys did some TCL scripts to manage it. > My problem is that every time I open a new connection, the device is > reset. I'd like to not have the device reset. A few suggestions: 1) You could try strace'ing the TCL, and then strace'ing the Python, and comparing - especially if you're comfortable with low-level I/O in C, but not only. Hunt for the open() call to the relevant device file, and other system calls near it. Even if you aren't that cozy with C, you could try putting the strace results on a website or ftp server, and posting links to them here. 2) Check and double check and triple check your line discipline parameters: bits per second, parity, word size, start/stop bits. 3) It's also possible the cable is bad (or merely inappropriate), especially if the TCL is accessing such a device over a different cable. There is no "one true serial (RS-232) cable standard" - RS-232 is a rather large collection of ways of doing communications, and they are frequently not compatible with one another. 4) One of the more likely causes of a reset of a device that is accessed serially, is sending it a break signal. There are official ways of sending a break, and accidental ways. Sometimes the two boil down to the same thing behind the scenes, but look very different in the code. A break signal is a longish sequence of unframed 0 bits (IE, with no start/stop bits separating one byte from another). An accidental way of sending a break, is to set your bits per second too low, and then sending a 0 byte - because those 8 0 bits at the too-low speed will look like a long series of unframed 0's from the perspective of the reader process that's running at the correct speed. So I guess the gist of point #4 (this point), is "make sure your bps is set correctly" and "check the device doc to see if a break signal causes a reset" 5) If the protocol layered over the serial communication is ASCII-based, you could try connecting to the device using something like minicom, to make sure the device is behaving as expected. If the device is speaking a binary protocol, this is unlikely to help much HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From eaglebalti at gmail.com Fri Jul 8 01:08:50 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Thu, 7 Jul 2011 22:08:50 -0700 (PDT) Subject: Hello Sweet Friends. Message-ID: <78af194e-3b51-49c4-ac4d-b238e01fa140@h17g2000yqn.googlegroups.com> I bring you a source of entertaintment.Just visit the following link and know about Bollywood actresses www.bollywoodactresseshotpictures.blogspot.com From nobody at nowhere.com Fri Jul 8 02:18:35 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 08 Jul 2011 07:18:35 +0100 Subject: making socket.getaddrinfo use cached dns References: Message-ID: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth wrote: >> I use cached dns lookups with pdnsd on my ubuntu machine to speed up >> web access as regular lookups can take 15-30 seconds. However, python's >> mechanize and urllib etc use socket.getaddrinfo, which seems not to be >> using dns cacheing or taking a long time because of ipv6 lookups. In >> either case, I subsequent access to the same site to be fast and not >> require lengthy calls to getaddrinfo. How can I get python to correctly >> use cached dns lookups and ipv4 only (at least in those cases where it >> is appropriate). To only query IPv4 addresses, pass socket.AF_INET as the third argument (family) to socket.getaddrinfo(). The default is AF_UNSPEC (= 0), which will return both IPv4 and IPv6 addresses. From mdickinson at enthought.com Fri Jul 8 03:31:10 2011 From: mdickinson at enthought.com (Mark Dickinson) Date: Fri, 8 Jul 2011 00:31:10 -0700 (PDT) Subject: Large number multiplication References: Message-ID: On Jul 7, 9:30?am, Ulrich Eckhardt wrote: > That said, I'm sure that the developers would accept a patch that switches > to a different algorithm if the numbers get large enough. I believe it > already doesn't use Karatsuba for small numbers that fit into registers, > too. I'm far from sure that such a patch would be accepted. :-) Indeed, Tim Peters has been heard to mention that if he were to do it all again, he probably wouldn't even have implemented Karatsuba [1]. Asymptotically fast integer multiplication is a specialist need that's already available in 3rd-party Python libraries (gmpy). IMO, it's not appropriate to include it in a general-purpose programming language, and the burden of maintaining such code would outweigh the benefits. One thing that has been considered in the past is making it possible to use GMP directly for Python's implementation of long integers; see Victor Stinner's efforts in this direction [2]. Licensing concerns, and the fact that Python's implementation is faster for small integers, ended up killing this issue. [1] http://mail.python.org/pipermail/python-dev/2008-November/083355.html [2] http://bugs.python.org/issue1814 -- Mark From steve+comp.lang.python at pearwood.info Fri Jul 8 03:42:47 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2011 17:42:47 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> Message-ID: <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but >> I should've clarified the difference.> The is operator does not compare >> types, it compares instances for identity. > > None is typesafe, because it's strongly typed. Everything in Python is strongly typed. Why single out None? Python has strongly-typed objects, dynamically typed variables, and a philosophy of preferring duck-typing over explicit type checks when possible. > However, what's even MORE X-safe (for various values of X) is a method > that takes LESS for its arguments. That's why I switched from passing > an object to passing a type, because the more restrictive argument > type is more typesafe. It seems to me that you are defeating duck-typing, and needlessly restricting what the user can pass, for dubious or no benefit. I still don't understand what problems you think you are avoiding with this tactic. > However, the MOST X-safe version so far simply passes a string, and > uses hashlib the way it designs to be used: > > def file_to_hash(path, hash_type): > hash = hashlib.new(hash_type) > with open(path, 'rb') as f: > while True: > s = f.read(8192) > if not s: break > hash.update(s) > return hash.hexdigest() There is no advantage to this that I can see. It limits the caller to using only hashes in hashlib. If the caller wants to provide her own hashing algorithm, your function will not support it. A more reasonable polymorphic version might be: def file_to_hash(path, hash='md5', blocksize=8192): # FIXME is md5 a sensible default hash? if isinstance(hash, str): # Allow the user to specify the hash by name. hash = hashlib.new(hash) else: # Otherwise hash must be an object that implements the # hashlib interface, i.e. a callable that returns an # object with appropriate update and hexdigest methods. hash = hash() with open(path, 'rb') as f: while True: s = f.read(blocksize) if not s: break hash.update(s) return hash.hexdigest() -- Steven From timr at probo.com Fri Jul 8 03:45:22 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 08 Jul 2011 00:45:22 -0700 Subject: Serial & reset of the device References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> Message-ID: <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> yorick wrote: > >I'm trying to access a hardware board of my company through a serial >connection using a Python script and the pyserial module. > >I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python- >serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html). > >The board to which I'm trying to connect works correctly with serial >as some other guys did some TCL scripts to manage it. >My problem is that every time I open a new connection, the device is >reset. I'd like to not have the device reset. I'm not sure what that means. The RS-232 standard does not have the concept of "reset". What is it that triggers a device reset? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bpajith at gmail.com Fri Jul 8 04:41:34 2011 From: bpajith at gmail.com (Ajith Kumar) Date: Fri, 8 Jul 2011 14:11:34 +0530 Subject: Python for science experiments Message-ID: Hello, Just posting a link of a project using Python for doing science experiments. with regards ajith -- Dr. Ajith Kumar B.P. Scientist SG Inter-University Accelerator Centre Aruna Asaf Ali Marg New Delhi 110067 www.iuac.res.in Ph: (off) 91 11 26893955 (Ext.230) (res)91 11 26897867 (mob) 91 9868150852 -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.net.no Fri Jul 8 07:29:44 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 08 Jul 2011 19:29:44 +0800 Subject: Finding duplicated photo Message-ID: Hello, I came across the problem that Gwenview moves the photo from the camera memory by renaming them, but later I forgot which where moved. Then I tought about a small script in python, but I stumbled upon my ignorance on the way to do that. PIL can find similar pictures. I was thinking to reduce the foto into gray scale and resize them to same size, what algorithm should take place? Is PIL able to compare 2 images? -- goto /dev/null From noway at nohow.com Fri Jul 8 08:37:58 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 08:37:58 -0400 Subject: Finding duplicated photo References: Message-ID: On 07/08/2011 07:29 AM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > I recently wrote a program after reading an article ( http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html ) using the DCT method he proposes. It worked surprisingly well even with just the 64bit hash it produces. -- Bill From python.list at tim.thechases.com Fri Jul 8 08:58:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 08 Jul 2011 07:58:13 -0500 Subject: Serial & reset of the device In-Reply-To: <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> Message-ID: <4E16FEE5.5050807@tim.thechases.com> On 07/08/2011 02:45 AM, Tim Roberts wrote: > yorick wrote: >> I'm trying to access a hardware board of my company through a serial >> connection using a Python script and the pyserial module. >> >> The board to which I'm trying to connect works correctly with serial >> as some other guys did some TCL scripts to manage it. >> My problem is that every time I open a new connection, the device is >> reset. I'd like to not have the device reset. > > I'm not sure what that means. The RS-232 standard does not have the > concept of "reset". What is it that triggers a device reset? While not a "reset" per-se, it might be triggered by the RTS/CTS, DSR/DTR, or carrier-detect pins depending on the configuration. Without the code and with minimal pySerial experience, I don't know whether opening a serial-port in pySerial automatically lights up one of those aux. lines and unsignals it when the connection is closed. If the device expects a "power on" signal on one of those pins, I'd start by looking to see if pySerial's .close() drops the signal on those pins and if it offers a way to keep the signal high while releasing the port. Otherwise, you may have to open once, do all your work and only close the port when you're done (and the device can be reset) -tkc From phlip2005 at gmail.com Fri Jul 8 09:03:54 2011 From: phlip2005 at gmail.com (Phlip) Date: Fri, 8 Jul 2011 06:03:54 -0700 (PDT) Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0c552105-dd13-40d4-8265-d06097adda18@d22g2000yqn.googlegroups.com> On Jul 8, 12:42?am, Steven D'Aprano wrote: > Phlip wrote: > >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but > >> I should've clarified the difference.> The is operator does not compare > >> types, it compares instances for identity. > > > None is typesafe, because it's strongly typed. > > Everything in Python is strongly typed. Why single out None? You do understand these cheap shots are bad for conversations, right? I didn't single out None. When did you stop raping your mother? From invalid at invalid.invalid Fri Jul 8 09:56:12 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 8 Jul 2011 13:56:12 +0000 (UTC) Subject: Serial & reset of the device References: <36bbf415-4dc0-461b-b945-1d0b70430b57@x41g2000yqd.googlegroups.com> <7add17lockutv6nf4u66cq004k56qd6099@4ax.com> Message-ID: On 2011-07-08, Tim Chase wrote: > On 07/08/2011 02:45 AM, Tim Roberts wrote: >> yorick wrote: >>> I'm trying to access a hardware board of my company through a serial >>> connection using a Python script and the pyserial module. >>> >>> The board to which I'm trying to connect works correctly with serial >>> as some other guys did some TCL scripts to manage it. My problem is >>> that every time I open a new connection, the device is reset. I'd >>> like to not have the device reset. >> >> I'm not sure what that means. The RS-232 standard does not have the >> concept of "reset". What is it that triggers a device reset? > > While not a "reset" per-se, it might be triggered by the RTS/CTS, > DSR/DTR, or carrier-detect pins depending on the configuration. > Without the code and with minimal pySerial experience, I don't > know whether opening a serial-port in pySerial automatically > lights up one of those aux. lines and unsignals it when the > connection is closed. On Unix, the serial port device driver generally turns DTR and RTS off when a port is closed and turns them on when it's opened. I don't know what Windows does. A quick glance through the pyserial sources shows that it turns on DTR and RTS when a port is opened, and does nothing with them when a port is closed. If you need RTS/DTR to stay in a known state, then open the port, set them to the state you want them, and keep the port open. -- Grant Edwards grant.b.edwards Yow! Remember, in 2039, at MOUSSE & PASTA will gmail.com be available ONLY by prescription!! From nobody at nowhere.net.no Fri Jul 8 10:14:54 2011 From: nobody at nowhere.net.no (TheSaint) Date: Fri, 08 Jul 2011 22:14:54 +0800 Subject: Finding duplicated photo References: Message-ID: Billy Mays wrote: > It worked surprisingly well even > with just the 64bit hash it produces. > I'd say that comparing 2 images reduced upto 32x32 bit seems too little to find if one of the 2 portrait has a smile referred to the other. I think it's about that mine and your suggestion are similar, but I'd like to scale pictures not less than 256x256 pixel. Also to take a wider case which the comparison involve a rotated image. -- goto /dev/null From noway at nohow.com Fri Jul 8 10:32:13 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 10:32:13 -0400 Subject: Finding duplicated photo References: Message-ID: On 07/08/2011 10:14 AM, TheSaint wrote: > Billy Mays wrote: > >> It worked surprisingly well even >> with just the 64bit hash it produces. >> > I'd say that comparing 2 images reduced upto 32x32 bit seems too little to > find if one of the 2 portrait has a smile referred to the other. > I think it's about that mine and your suggestion are similar, but I'd like > to scale pictures not less than 256x256 pixel. > Also to take a wider case which the comparison involve a rotated image. > Originally I thought the same thing. It turns out that doing a DCT on an image typically moves the more important data to the top left corner of the output. This means that most of the other data in the output an be thrown away since most of it doesn't significantly affect the image. The 32x32 is an arbitrary size, you can make it any square block that you want. Rotation is harder to find. You can always take a brute force approach by simply rotating the image a couple of times and try running the algorithm on each of the rotated pics. Image matching is a difficult problem. -- Bill From widebandwidth at gmail.com Fri Jul 8 10:40:34 2011 From: widebandwidth at gmail.com (high bandwidth) Date: Fri, 8 Jul 2011 10:40:34 -0400 Subject: making socket.getaddrinfo use cached dns Message-ID: my /etc/resolv.conf says: # Dynamic resolv.conf(5) file for glibc resolver(3) generated by > resolvconf(8) > # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN > nameserver 127.0.0.1 > search Dynex > But getaddrinfo still takes a lot of time for repeated queries. After installing BIND9 and starting it, getaddrinfo is almost instantaneous for repeated queries. Thanks! *Chris Angelico* rosuav at gmail.com wrote: On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth > wrote: >* I use cached dns lookups with pdnsd on my ubuntu machine to speed up web*>* access as regular lookups can take 15-30 seconds. However, python's*>* mechanize and urllib etc use socket.getaddrinfo, which seems not to be using*>* dns cacheing or taking a long time because of ipv6 lookups. In either case,*>* I subsequent access to the same site to be fast and not require lengthy*>* calls to getaddrinfo. How can I get python to correctly use cached dns*>* lookups and ipv4 only (at least in those cases where it is appropriate).* One solution would be to do your own DNS lookups and then pass urllib an IP address. Is pdnsd set up to be your computer's primary resolver? (Is /etc/resolv.conf pointing to localhost?) If not, that might help. I've generally done my DNS caching using BIND, so I can't help with pdnsd specifically. ChrisA -------------- next part -------------- An HTML attachment was scrubbed... URL: From mapere.ali at gmail.com Fri Jul 8 10:45:51 2011 From: mapere.ali at gmail.com (Mapere Ali) Date: Fri, 8 Jul 2011 16:45:51 +0200 Subject: Python-list Digest, Vol 94, Issue 52 In-Reply-To: References: Message-ID: Hi, I need help with a python script to monitor my wireless router internet usage using a Mac address and then backup the report files on the server. i would also like to create login access on the website to have users checkout their bandwidth usage...Please help anyone I'm a newbie in Python.. Regards mapere I'v On 7/8/11, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > From t at jollybox.de Fri Jul 8 11:13:10 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 08 Jul 2011 17:13:10 +0200 Subject: Python-list Digest, Vol 94, Issue 52 In-Reply-To: References: Message-ID: <4E171E86.4090806@jollybox.de> On 07/08/2011 04:45 PM, Mapere Ali wrote: > Hi, > > I need help with a python script to monitor my wireless router > internet usage using a Mac address and then backup the report files on > the server. i would also like to create login access on the website to > have users checkout their bandwidth usage...Please help anyone > I'm a newbie in Python.. Try doing it yourself. Give it your best shot, one step at a time. Depending on how new you are to Python, you might want to go through a tutorial before embarking on your own project. The Python documentation (this will be very useful) is here: http://doc.python.org/ When you get stuck, come back here, show us what you've done and what the problem is, and we can help you with your (specific) problem. Also, if you ask questions here, you'll want to be able to respond to individual answers, so please subscribe to the actual list, not the digest. Have fun Thomas > > Regards > mapere > > I'v > On 7/8/11, python-list-request at python.org > wrote: >> Send Python-list mailing list submissions to >> python-list at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.python.org/mailman/listinfo/python-list >> or, via email, send a message with subject or body 'help' to >> python-list-request at python.org >> >> You can reach the person managing the list at >> python-list-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Python-list digest..." >> From t at jollybox.de Fri Jul 8 11:16:57 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 08 Jul 2011 17:16:57 +0200 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: <4E171F69.3090709@jollybox.de> On 07/08/2011 01:29 PM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > If Gwenview simply moves/renames the images, is it not enough to compare the actual files, byte by byte? From drsalists at gmail.com Fri Jul 8 11:29:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jul 2011 08:29:13 -0700 Subject: Finding duplicated photo In-Reply-To: <4E171F69.3090709@jollybox.de> References: <4E171F69.3090709@jollybox.de> Message-ID: On Fri, Jul 8, 2011 at 8:16 AM, Thomas Jollans wrote: > On 07/08/2011 01:29 PM, TheSaint wrote: > > Hello, > > > > I came across the problem that Gwenview moves the photo from the camera > > memory by renaming them, but later I forgot which where moved. > > Then I tought about a small script in python, but I stumbled upon my > > ignorance on the way to do that. > > > > PIL can find similar pictures. I was thinking to reduce the foto into > gray > > scale and resize them to same size, what algorithm should take place? > > Is PIL able to compare 2 images? > > > > If Gwenview simply moves/renames the images, is it not enough to compare > the actual files, byte by byte? > This'll detect duplicates pretty fast; it often doesn't even need to read a whole file once, while not sacrificing accuracy: http://stromberg.dnsalias.org/~dstromberg/equivalence-classes.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Jul 8 12:13:43 2011 From: davea at ieee.org (Dave Angel) Date: Fri, 08 Jul 2011 12:13:43 -0400 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: <4E172CB7.7060007@ieee.org> On 01/-10/-28163 02:59 PM, TheSaint wrote: > Hello, > > I came across the problem that Gwenview moves the photo from the camera > memory by renaming them, but later I forgot which where moved. > Then I tought about a small script in python, but I stumbled upon my > ignorance on the way to do that. > > PIL can find similar pictures. I was thinking to reduce the foto into gray > scale and resize them to same size, what algorithm should take place? > Is PIL able to compare 2 images? > If your real problem is identifying a renamed file amongst thousands of others, why not just compare the metadata? it'll be much faster. For example, if you only have one camera, the timestamp stored in the EXIF data would be pretty close, Some cameras also store their "shutter release number" in the metadata, which would be even better. One concern is whether Glenview or any other of your utilities discard the metadata. That would be a big mistake. Also, if Gwenview has no other features you're counting on, perhaps you should write your own "move the files from camera to computer" utility. that's what I did, and it renames and reorganises the files as it does, according to my conventions, not someone else's. One reason for the renaming is that my cameras only use 4 digit numbers, and these recycle every 10000 images. DaveA From sharanya9030 at gmail.com Fri Jul 8 12:21:52 2011 From: sharanya9030 at gmail.com (sharu) Date: Fri, 8 Jul 2011 09:21:52 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <144abcea-1553-4002-9516-9bd7b3577cd7@w4g2000yqm.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From rantingrick at gmail.com Fri Jul 8 13:30:20 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 8 Jul 2011 10:30:20 -0700 (PDT) Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <77ae91c9-b170-402a-81cf-264af825858a@e21g2000vbz.googlegroups.com> On Jul 7, 8:25?pm, Steven D'Aprano wrote: > rantingrick wrote: > > On Jul 7, 12:34?am, Gregory Ewing wrote: > >> The important thing is that it's okay for an app to stay > >> alive until its *last* top level window is closed. > > I partially disagree with Greg on this. This is not the only model: on the > Apple Mac, or any system with a similar GUI design, the application can > survive having the last window closed. There are other application types > that don't need any window at all. Yeah they call those "command line" programs. > So while it is common for closing the > last window to exit the application, it is not a necessary requirement. If a "root-window-hierarchy" type GUI needs to close any or all windows (or allow the user to do so) it can do this quite well. It's called logic (in programming circles). But the GUI by default exposes an interface to the user: * Close all windows by clicking the X of the ROOT window. * Close any window by clicking the X of THAT window. However, if (as you argue) you need the program to continue AFTER the root is closed well then, i have wonderful news for you... THAT CAN BE DONE!. You just create some logic to handle it. This is very simple ideas Steven. I am talking about CS 101 here. Do you need a tutor? > >> There > >> doesn't have to be a special "main" window that kills the > >> whole app when you close it. > > > So you prefer to close a gazillion windows one by one? > > Nonsense. Greg says nothing of the sort. > > Avoiding the anti-pattern "close a gazillion windows one by one" is why you > have an application-wide Quit or Exit command, as opposed to a Close > command which applies only to the current window. CRIKEY! That's what the ROOT window does you blankity-blank! Are you just arguing for the sake of arguing? Just because Apple removed the root-window's "window-management user-interface" (psst: that's the three buttons at the top of the root window (Minimize|Maximize|Close)) and nailed them on the desktop does not change anything. You are comparing a half dozen eggs and six eggs and then claiming them to be somehow different. There is no comparison! If i remove the steering wheel from a car and hook up some "remote- controlled" gearbox to the front wheel linkage how does that modification change anything about how the CAR itself interfaces with the road? I just simply moved around some of the interface elements from a user point of view. Someone is still driving the car; albeit from a remote location. They can go left, they can go right. And you claim that this "remote-window management user-interface" has some magical benefit over the "window-management user-interface". There is no benefit that is applicable to this argument. The only benefit in my version is driver safety, however safety is non applicable to this thread. And i would argue that as the safety of a driver increases the safety of the general public decreases due to the driver being "once removed" from the danger zone. Not that "safety" is applicable either. > > If so, why not > > just code the GUI correctly from the start; by creating separate > > transactions? Thereby reducing the number of windows a user must > > juggle? FYI: You know the user complexity of a GUI increases > > exponentially by the number of windows present. > > Don't assume that there is a one-to-one relationship between transactions > (documents?) and windows. The relationship is actually many-to-many: > windows can contain tabbed or notepad interfaces, or can be split into > multiple panes, or both. Panes and tabs can be split into independent > windows, or rejoined into one main window. Of course, and that is exactly why i suggested using a tabbed widget to an earlier confused GUI designer. > E.g. I can have six Firefox windows open, each one with many different > websites open in separate tabs. I have Close Tab, Close Window and Exit > Firefox commands. Yes. Firefox itself is the "root" window. Each tab is a transaction. What is your point? Proving yourself incorrect? > In Konquorer, not only can I have multiple windows and multiple tabs, but I > can split each tab into two or more panes, and display two views of the > same document in the same tab, or two different documents in the one tab. > This is especially useful when using it as a file manager. Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. > In older versions of Word (and possibly current, although I haven't tested > it) you can open files multiple times. Each time opens in a new window, > representing a new view of the one file. Edits in one window update all the > others. This can be useful for, e.g. making edits to page 3 while > simultaneously viewing page 303. An alternate UI for to split the one > window into two panes, and scroll them independently. So a single file may > have one or two panes, in one or more windows. [repeated from above] Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. > So, you can have multiple documents in multiple windows, and there is no 1:1 > relationship between them. [repeated from above] Yes and what has that got to do with "root window hierarchies"? Nothing! Do you even know which side your arguing for anymore? If you are trying to support my argument you are doing a good job of it. Thanks. Keep up the good work. I would argue to say that i am one of the most informed users in this group when it comes to GUI API design, GUI interface design, and GUI implementation via code. The fact that some of you wish to challenge me is quite amusing. Just admit you are wrong already. Geez! How many straw-men and David Copperfeild style misdirections are you willing to conjure in your feeble attempts to discredit me with tripe. From sridharr at activestate.com Fri Jul 8 13:32:28 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:32:28 -0700 Subject: ANN: ActivePython 2.7.2.5 is now available Message-ID: <7A37DA3F-DF69-415C-91F4-266A344E54CA@activestate.com> ActiveState is pleased to announce ActivePython 2.7.2.5, a complete, ready-to-install binary distribution of Python 2.7. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.7.2.5 ================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.7.2 (`release notes `__) - Security upgrade to openssl-0.9.8r - [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16 - Upgrade to pythonselect 1.3 which supports Windows - Upgrade to PyPM 1.3.4: - [Windows] `Bug #89474 `_: automatically expand %APPDATA%\Python\Scripts - Bug #90382: --no-ignore option to fail immediately for missing packages - Upgraded the following packages: - Distribute-0.6.19 - pip-1.0.1 - virtualenv-1.6.1 Noteworthy Changes & Bug Fixes ------------------------------ - PyPM: - Upgrade to six 1.0.0 - Bug #89540: `uninstall` command now properly removes symlinks - Bug #89648: shebang fixer skips symlinks - Include SQLAlchemy in the private area (pypm/external/{2,3}/sqlalchemy) What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From sridharr at activestate.com Fri Jul 8 13:36:07 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:36:07 -0700 Subject: ANN: ActivePython 2.6.7.20 is now available Message-ID: <9A72BB58-735D-4201-B978-168128268382@activestate.com> ActiveState is pleased to announce ActivePython 2.6.7.20, a complete, ready-to-install binary distribution of Python 2.6. http://www.activestate.com/activepython/downloads What's New in ActivePythonEE-2.6.7.20 ===================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.6.7 (`release notes `__) - Upgrade to pythonselect 1.3 which supports Windows - Upgrade to PyPM 1.3.4: - [Windows] `Bug #89474 `_: automatically expand %APPDATA%\Python\Scripts - Bug #90382: --no-ignore option to fail immediately for missing packages - Upgraded the following packages: - Distribute-0.6.19 - pip-1.0.1 - virtualenv-1.6.1 Noteworthy Changes & Bug Fixes ------------------------------ - PyPM: - Upgrade to six 1.0.0 - Bug #89540: `uninstall` command now properly removes symlinks - Bug #89648: shebang fixer skips symlinks What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From sridharr at activestate.com Fri Jul 8 13:39:34 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 8 Jul 2011 10:39:34 -0700 Subject: ANN: ActivePython 2.5.6.10 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.5.6.10, a complete, ready-to-install binary distribution of Python 2.5. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.5.6.10 =================================== New Features & Upgrades ----------------------- - Upgrade to Python 2.5.6 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - [Windows] Installer upgrade: automatically uninstall previous versions - Bug #87783 - [Linux] Include Tcl/Tk development files (`#40`_) - [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16 - Security upgrade to openssl-0.9.8r Noteworthy Changes & Bug Fixes ------------------------------ - [MacOSX] Fix uninstall on Snow Leopard (10.6) - Bug #87600: create a `idleX.Y` script on unix - [Windows] Renamed "python25.exe" to "python2.5.exe" (Unix like) - [Windows] Include "python2.exe" What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install numpy [...] C:\>python >>> import numpy.linalg >>> See this page for full details: http://docs.activestate.com/activepython/2.5/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.5/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From salmig99 at gmail.com Fri Jul 8 15:05:03 2011 From: salmig99 at gmail.com (sal migondis) Date: Fri, 8 Jul 2011 12:05:03 -0700 (PDT) Subject: The end to all language wars and the great unity API to come! References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 6, 7:45?am, Steven D'Aprano wrote: > sal migondis wrote: > > How could a belief be wrong? > I believe... Shifting from 'belief' to 'believe', the latter having a considerably wider semantic scope. After that, anything goes.. naturally. > you are a small glass of beer. Are you *actually* a small glass of > beer in reality? If so, my belief is right. If you are a human being, then > my belief is wrong. Are you a lawyer..? Sal. From ian.g.kelly at gmail.com Fri Jul 8 15:21:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jul 2011 13:21:00 -0600 Subject: The end to all language wars and the great unity API to come! In-Reply-To: References: <1bf8cf87-b173-470a-a05e-a65616c988a0@d22g2000yqn.googlegroups.com> <41f31477-48ee-4a8a-ab2d-87073a918996@r18g2000vbs.googlegroups.com> <6dd92755-c8e9-47ef-aa08-ffffbc3d1893@5g2000yqb.googlegroups.com> <97a7q6FtqcU1@mid.individual.net> <6a9373cd-4b27-447a-8be4-db74effde338@g16g2000yqg.googlegroups.com> <61329ec7-da3e-49fe-bf25-3c179dc8cd2c@j14g2000prn.googlegroups.com> <05c559ee-983d-414b-a499-5e675e6592c7@5g2000yqb.googlegroups.com> <8430f2a6-bbfb-489c-8f6b-81bd4a12c261@r18g2000vbs.googlegroups.com> <4e144add$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 8, 2011 at 1:05 PM, sal migondis wrote: >> I believe... > > Shifting from 'belief' to 'believe', the latter having a considerably > wider semantic scope. Wider how? Would you care to give an example of something that is believed but is not a belief? From g.rodola at gmail.com Fri Jul 8 15:22:31 2011 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 8 Jul 2011 21:22:31 +0200 Subject: ANN: psutil 0.3.0 released Message-ID: Hi folks, I'm pleased to announce the 0.3.0 release of psutil: http://code.google.com/p/psutil === Major enhancements === * disk usage * mounted disk partitions * system per-cpu percentage utilization and times * per-process terminal * physical and virtual memory usage including percentage === New features by example === >>> import psutil >>> >>> for x in range(3): ... psutil.cpu_percent(percpu=True) ... [4.0, 34.2] [7.0, 8.5] [1.2, 9.0] >>> >>> psutil.phymem_usage() usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6) >>> psutil.virtmem_usage() usage(total=2097147904, used=4096, free=2097143808, percent=0.0) >>> >>> psutil.get_partitions() [partition(device='/dev/sda3', mountpoint='/', fstype='ext4'), partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')] >>> >>> psutil.disk_usage('/') usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) >>> >>> >>> psutil.Process(os.getpid()).terminal '/dev/pts/0' >>> Also, a new examples directory showing some examples usages: http://code.google.com/p/psutil/source/browse/#svn%2Ftrunk%2Fexamples For a complete list of features and bug fixes see: http://psutil.googlecode.com/svn/trunk/HISTORY === Links === * Home page: http://code.google.com/p/psutil * Source tarball: http://psutil.googlecode.com/files/psutil-0.3.0.tar.gz * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance. --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From bahamutzero8825 at gmail.com Fri Jul 8 16:18:37 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 08 Jul 2011 15:18:37 -0500 Subject: String concatenation vs. string formatting Message-ID: <4E17661D.6020307@gmail.com> Is it bad practice to use this > logger.error(self.preset_file + ' could not be stored - ' + > sys.exc_info()[1]) Instead of this? > logger.error('{file} could not be stored - > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) Other than the case where a variable isn't a string (format() converts variables to strings, automatically, right?) and when a variable is used a bunch of times, concatenation is fine, but somehow, it seems wrong. Sorry if this seems a bit silly, but I'm a novice when it comes to design. Plus, there's not really supposed to be "more than one way to do it" in Python. From gordon at panix.com Fri Jul 8 16:23:52 2011 From: gordon at panix.com (John Gordon) Date: Fri, 8 Jul 2011 20:23:52 +0000 (UTC) Subject: String concatenation vs. string formatting References: Message-ID: In Andrew Berg writes: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. Concatenation feels ugly/clunky to me. I prefer this usage: logger.error('%s could not be stored - %s' % \ (self.preset_file, sys.exc_info()[1])) -- 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 noway at nohow.com Fri Jul 8 16:57:09 2011 From: noway at nohow.com (Billy Mays) Date: Fri, 08 Jul 2011 16:57:09 -0400 Subject: String concatenation vs. string formatting References: Message-ID: On 07/08/2011 04:18 PM, Andrew Berg wrote: > Is it bad practice to use this >> logger.error(self.preset_file + ' could not be stored - ' + >> sys.exc_info()[1]) > Instead of this? >> logger.error('{file} could not be stored - >> {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. If it means anything, I think concatenation is faster. __TIMES__ a() - 0.09s b() - 0.09s c() - 54.80s d() - 5.50s Code is below: def a(v): out = "" for i in xrange(1000000): out += v return len(out) def b(v): out = "" for i in xrange(100000): out += v+v+v+v+v+v+v+v+v+v return len(out) def c(v): out = "" for i in xrange(1000000): out = "%s%s" % (out, v) return len(out) def d(v): out = "" for i in xrange(100000): out = "%s%s%s%s%s%s%s%s%s%s%s" % (out,v,v,v,v,v,v,v,v,v,v) return len(out) print "a", a('xxxxxxxxxx') print "b", b('xxxxxxxxxx') print "c", c('xxxxxxxxxx') print "d", d('xxxxxxxxxx') import profile profile.run("a('xxxxxxxxxx')") profile.run("b('xxxxxxxxxx')") profile.run("c('xxxxxxxxxx')") profile.run("d('xxxxxxxxxx')") From benjamin.kaplan at case.edu Fri Jul 8 17:23:08 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 8 Jul 2011 14:23:08 -0700 Subject: String concatenation vs. string formatting In-Reply-To: <4E17661D.6020307@gmail.com> References: <4E17661D.6020307@gmail.com> Message-ID: On Fri, Jul 8, 2011 at 1:18 PM, Andrew Berg wrote: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. > String formatting is the One Right Way here. It's fine to use string concatenation for a few things, but the operation is O(n^2) because each concat occurs one at a time: Python allocates space for a string the size of the first 2 things, copies the contents over. Then allocate a string the size of that string plus the third string and copy the contents over. It can get pretty slow if you're building a really big string With string formatting, Python creates a single string large enough to copy all the formatting arguements in and then copies the contents over once. Also, string formatting (especially using the new syntax like you are) is much clearer because there's less noise (the quotes all over the place and the plusses) and it's better for dealing with internationalization if you need to do that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Jul 8 17:38:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jul 2011 15:38:18 -0600 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> Message-ID: On Fri, Jul 8, 2011 at 3:23 PM, Benjamin Kaplan wrote: > String formatting is the One Right Way here.?It's fine to use string > concatenation for a few things, but?the operation is O(n^2) because each > concat occurs?one at a time: Python allocates space for a string the size of > the first 2 things, copies the contents over. Then?allocate a string the > size of that string plus the third string and copy the contents over. It can > get pretty slow if you're building a really big string?With string > formatting, Python?creates a single string large enough to copy all?the > formatting arguements in and then copies?the contents over once. This argument doesn't really fly, because a string formatting operation is typically used as an alternative for a constant number of concatenations, not O(n) concatenations. As such, either approach would be O(n) for a single instance. In the case that you do need to do O(n) concatenations, it is usually best to use a StringIO object, or to build a list and then call str.join. > Also, string formatting (especially using the new syntax like you are) is > much clearer because there's less noise (the quotes all over the place and > the plusses) and?it's better for dealing with internationalization if you > need to do that. This is the real reason to prefer string formatting over concatenation. It's also much less clutter to be able to use the %s placeholder rather than having to call str() on everything. From ben+python at benfinney.id.au Fri Jul 8 18:50:03 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 08:50:03 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <87box4ie04.fsf@benfinney.id.au> John Gordon writes: > I prefer this usage: > > logger.error('%s could not be stored - %s' % \ > (self.preset_file, sys.exc_info()[1])) That can be improved by learning two things: * The backslash-linebreak is ugly and fragile, and almost never needed, since Python knows to continue a statement if any bracketing syntax (parens, brackets, braces, triple quotes, etc.) is still open. So you can continue a statement over multiple lines by introducing some bracketing syntax at an appropriate place. In this case, you don't even need to add any bracketing syntax, since the function parens are still open. * The ?%? string formatting operator is superseded in current Python versions by the more flexible ?format? method of string objects. So: logger.error( '{0} could not be stored - {1}'.format( (self.preset_file, sys.exc_info()[1])) I usually prefer to use named placeholders instead of positional, but this duplicates your original. -- \ ?We have clumsy, sputtering, inefficient brains?. It is a | `\ *struggle* to be rational and objective, and failures are not | _o__) evidence for an alternative reality.? ?Paul Z. Myers, 2010-10-14 | Ben Finney From ben+python at benfinney.id.au Fri Jul 8 18:59:53 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 08:59:53 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <877h7sidjq.fsf@benfinney.id.au> Andrew Berg writes: > Is it bad practice to use this > > logger.error(self.preset_file + ' could not be stored - ' + > > sys.exc_info()[1]) This is not necessarily bad practice, but there are not many points in its favour. It's inflexible and makes the eventual formatting harder to discern. > Instead of this? > > logger.error('{file} could not be stored - > > {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) With the caveat that the formatting of that line should be using PEP 8 indentation for clarity: logger.error( '{file} could not be stored - {error}'.format( file=self.preset_file, error=sys.exc_info()[1])) > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) If you don't specify a conversion in the placeholder, it will default to ?str?, yes. > and when a variable is used a bunch of times, concatenation is fine, I don't see any argument for concatenation there; using a variable a bunch of times works just fine with the ?format? method. > but somehow, it seems wrong. Sorry if this seems a bit silly, but I'm > a novice when it comes to design. Plus, there's not really supposed to > be "more than one way to do it" in Python. There is often more than one way to do it. The Zen of Python is explicit that there should be one obvious way to do it (and preferably only one). The ?OOW? in ?TOOWTDI? is not ?only one way?, but ?one obvious way?. The presence of multiple ways to format strings (the ?%? operator, the ?format? method) is for backward compatibility with code written before the current recommended ?format? method. Backward compatibility is a common reason for more than one way to do it in Python. It's just preferable that all but one of them should be non-obvious :-) -- \ ?The whole area of [treating source code as intellectual | `\ property] is almost assuring a customer that you are not going | _o__) to do any innovation in the future.? ?Gary Barnett | Ben Finney From drsalists at gmail.com Fri Jul 8 19:02:25 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jul 2011 16:02:25 -0700 Subject: String concatenation vs. string formatting In-Reply-To: <87box4ie04.fsf@benfinney.id.au> References: <87box4ie04.fsf@benfinney.id.au> Message-ID: On Fri, Jul 8, 2011 at 3:50 PM, Ben Finney wrote: > * The ?%? string formatting operator is superseded in current Python > versions by the more flexible ?format? method of string objects. > AFAIK, % formatting is the only kind of formatting that works portably across all of CPythons 2.5, 2.6, 2.7, 3.0, 3.1, 3.2; Pypy and Jython. So I'm still writing new code using %. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Jul 8 19:15:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Jul 2011 09:15:41 +1000 Subject: String concatenation vs. string formatting References: <87box4ie04.fsf@benfinney.id.au> Message-ID: <8739igicte.fsf@benfinney.id.au> Ben Finney writes: > logger.error( > '{0} could not be stored - {1}'.format( > (self.preset_file, sys.exc_info()[1])) > > I usually prefer to use named placeholders instead of positional, but > this duplicates your original. Ah, I see that the OP *did* use named placeholders. So, even better: logger.error( '{file} could not be stored - {error}'.format( file=self.preset_file, error=sys.exc_info()[1])) -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From bahamutzero8825 at gmail.com Fri Jul 8 19:29:40 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 08 Jul 2011 18:29:40 -0500 Subject: String concatenation vs. string formatting In-Reply-To: <877h7sidjq.fsf@benfinney.id.au> References: <877h7sidjq.fsf@benfinney.id.au> Message-ID: <4E1792E4.9030809@gmail.com> On 2011.07.08 05:59 PM, Ben Finney wrote: > With the caveat that the formatting of that line should be using PEP 8 > indentation for clarity: PEP 8 isn't bad, but I don't agree with everything in it. Certain lines look good in chunks, some don't, at least to me. It's quite likely I'm going to be writing 98%, if not more, of this project's code, so what looks good to me matters more than a standard (as long as the code works). Obviously, if I need to work in a team, then things change. > > and when a variable is used a bunch of times, concatenation is fine, I prefaced that sentence with "Other than the case", as in "except for the following case(s)". > There is often more than one way to do it. The Zen of Python is explicit > that there should be one obvious way to do it (and preferably only one). I meant in contrast to the idea of intentionally having multiple ways to do something, all with roughly equal merit. On 2011.07.08 04:38 PM, Ian Kelly wrote: > Also, string formatting (especially using the new syntax like you are) > is much clearer because there's less noise (the quotes all over the > place and the plusses) I don't find it that much clearer unless there are a lot of chunks. > and it's better for dealing with internationalization if you need to > do that. I hadn't thought of that. That's probably the best reason to use string formatting. Thanks, everyone. From mark at curphey.com Fri Jul 8 19:41:48 2011 From: mark at curphey.com (mark curphey) Date: Fri, 8 Jul 2011 16:41:48 -0700 Subject: CI and BDD with Python Message-ID: Moving to Python from Ruby, first time poster. Anyone any opinions (non-religious) on investing time in Lettuce (www.lettuce.it) or Freshen (https://github.com/rlisagor/freshen#readme) for their BDD ? And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? Cheers! Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From joey.zh.cn at gmail.com Fri Jul 8 20:14:29 2011 From: joey.zh.cn at gmail.com (Joey) Date: Fri, 8 Jul 2011 17:14:29 -0700 (PDT) Subject: meaning of numpy.fft coefficients Message-ID: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> the list generated by numpy is of form [ a+bi, c+di, ...] could anybody tell me the meaning of the coefficients a and b? I am very confused about fourier transform! information provided by numpy reference says Ak = Sum of a[m] * exp{-2*pi * i * m * k / n} for m from 0 to n-1 Which part is a and which part is b and what is the meaning of each part? Thx in adv. From kb1pkl at aim.com Fri Jul 8 20:52:23 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Fri, 08 Jul 2011 20:52:23 -0400 Subject: meaning of numpy.fft coefficients In-Reply-To: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> References: <71bf5cd6-624e-495c-9a04-dae212a62927@j15g2000yqf.googlegroups.com> Message-ID: <1310172576-sup-7317@dalek> Excerpts from Joey's message of Fri Jul 08 20:14:29 -0400 2011: > the list generated by numpy is of form [ a+bi, c+di, ...] > > could anybody tell me the meaning of the coefficients a and b? I am > very confused about fourier transform! > a+bi is a typical complex number. a is the real part, b is the imaginary. Python uses j, >>> 4+5j (4+5j) http://en.wikipedia.org/wiki/Complex_number http://docs.python.org/library/stdtypes.html#typesnumeric -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From thorsten at thorstenkampe.de Sat Jul 9 00:23:42 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 9 Jul 2011 06:23:42 +0200 Subject: String concatenation vs. string formatting References: Message-ID: * John Gordon (Fri, 8 Jul 2011 20:23:52 +0000 (UTC)) > I prefer this usage: > > logger.error('%s could not be stored - %s' % \ > (self.preset_file, sys.exc_info()[1])) The syntax for formatting logging messages according to the documentation is: Logger.error(msg, *args) NOT Logger.error(msg % (*args)) Thorsten From stefan_ml at behnel.de Sat Jul 9 00:36:36 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 09 Jul 2011 06:36:36 +0200 Subject: CI and BDD with Python In-Reply-To: References: Message-ID: mark curphey, 09.07.2011 01:41: > And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? I warmly recommend Jenkins (i.e. Hudson) for anything CI. It gives you tons of plugins and configuration options together with full information awareness about your build status and dependencies through a nice web interface. The only reason to go native here is that it may become simpler to set up Python build and test jobs. But given that it's usually just a couple of shell commands that you write once, you'd miss more from the interface than what you gain from a quicker job setup. Stefan From steve+comp.lang.python at pearwood.info Sat Jul 9 00:41:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 14:41:45 +1000 Subject: Implicit initialization is EVIL! References: <97dc7iF9eiU1@mid.individual.net> <78624344-9696-42c9-9ed8-9454c55c1d9f@g12g2000yqd.googlegroups.com> <97ga0jFq2lU1@mid.individual.net> <4e131ef7$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e133509$0$12858$426a74cc@news.free.fr> <999dd05c-cae5-4c86-8ee7-6e1d6116d2ed@gh5g2000vbb.googlegroups.com> <97icm3Ft0eU1@mid.individual.net> <97kur2FlkhU1@mid.individual.net> <371088c4-b0c1-4cdb-bd50-357c695b9c47@j25g2000vbr.googlegroups.com> <4e165c7b$0$29987$c3e8da3$5496439d@news.astraweb.com> <77ae91c9-b170-402a-81cf-264af825858a@e21g2000vbz.googlegroups.com> Message-ID: <4e17dc09$0$29966$c3e8da3$5496439d@news.astraweb.com> rantingrick wrote: > On Jul 7, 8:25?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> rantingrick wrote: >> > On Jul 7, 12:34?am, Gregory Ewing wrote: >> >> The important thing is that it's okay for an app to stay >> >> alive until its *last* top level window is closed. >> >> I partially disagree with Greg on this. This is not the only model: on >> the Apple Mac, or any system with a similar GUI design, the application >> can survive having the last window closed. There are other application >> types that don't need any window at all. > > Yeah they call those "command line" programs. Only idiots who don't understand that Graphical User Interface does not equal Window. I'm done with this conversation. Welcome to Killfile City, population rantingrick. See you in a few months. Try to have grown up by then. -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 00:44:48 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 14:44:48 +1000 Subject: Does hashlib support a file mode? References: <0c058f60-3fd7-4b67-85a2-0658b2bb1887@glegroupsg2000goo.googlegroups.com> <9e976158-94c7-4e8b-8aa8-f0daa644b06d@fv14g2000vbb.googlegroups.com> <4e14ecd4$0$29965$c3e8da3$5496439d@news.astraweb.com> <0cd66788-5603-421e-82fb-fa3ac089711c@u42g2000yqm.googlegroups.com> <6218f9fc-2155-4f31-aa07-fe2caadac190@y30g2000yqb.googlegroups.com> <4e166165$0$29983$c3e8da3$5496439d@news.astraweb.com> <06e6fd07-6630-41eb-9dc9-a9bf5f7524cb@p31g2000vbs.googlegroups.com> <4e16b4f8$0$29983$c3e8da3$5496439d@news.astraweb.com> <0c552105-dd13-40d4-8265-d06097adda18@d22g2000yqn.googlegroups.com> Message-ID: <4e17dcc0$0$29966$c3e8da3$5496439d@news.astraweb.com> Phlip wrote: > On Jul 8, 12:42?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Phlip wrote: >> >> I worded that poorly. None is (AFAIK) the only instance of NoneType, >> >> but I should've clarified the difference.> The is operator does not >> >> compare types, it compares instances for identity. >> >> > None is typesafe, because it's strongly typed. >> >> Everything in Python is strongly typed. Why single out None? > > You do understand these cheap shots are bad for conversations, right? > > I didn't single out None. Phlip, I'm not an idiot, please don't pee on my leg and tell me it's raining. In the very sentence you quote above, you clearly and obviously single out None: "None is typesafe, because it's strongly typed." Yes, None is strongly typed -- like everything else in Python. I don't understand what point you are trying to make. Earlier you claimed that identity testing for None is type-unsafe (or at least *less* type-safe, whatever that means): "Note the fix also avoids comparing to None, which, as usual, is also icky and less typesafe!" then you say None is type-safe -- if there is a coherent message in your posts, it is too cryptic for me. > When did you stop raping your mother? What makes you think I've stopped? -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 01:12:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 15:12:39 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e17e348$0$29993$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > Is it bad practice to use this >> logger.error(self.preset_file + ' could not be stored - ' + >> sys.exc_info()[1]) > Instead of this? >> logger.error('{file} could not be stored - >> {error}'.format(file=self.preset_file, error=sys.exc_info()[1])) > > > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) Not exactly, but more or less. format() has type codes, just like % string interpolation: >>> '{0:d}'.format(1) '1' >>> '{0:d}'.format(None) Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code 'd' for object of type 'str' >>> '%d' % 1 '1' >>> '%d' % None Traceback (most recent call last): File "", line 1, in TypeError: %d format: a number is required, not NoneType If you don't give a type code, format converts any object to string (if possible). > and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. I don't like long chains of string concatenation, but short chains seem okay to me. One or two plus signs seems fine to my eyes, three at the most. Any more than that, I'd look at replacing it with % interpolation, the str.join() idiom, the string.Template class, or str.format. That's five ways of building strings. Of course, *repeated* string concatenation risks being slow -- not just a little slow, but potentially MASSIVELY slow, hundreds or thousands of times slower that alternatives. Fortunately recent versions of CPython tend to avoid this (which makes it all the more mysterious when the slow-down does strike), but other Pythons like Jython and IronPython may not. So it's best to limit string concatenation to one or two strings. And finally, if you're concatenating string literals, you can use implicit concatenation (*six* ways): >>> s = ("hello " ... "world" ... "!") >>> s 'hello world!' > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. On the contrary -- there are many different examples of "more than one way to do it". The claim that Python has "only one way" to do things comes from the Perl community, and is wrong. It is true that Python doesn't deliberately add multiple ways of doing things just for the sake of being different, or because they're cool, although of course that's a subjective judgement. (Some people think that functional programming idioms such as map and filter fall into that category, wrongly in my opinion.) In any case, it's clear that Python supports many ways of doing "the same thing", not all of which are exactly equivalent: # e.g. copy a list blist = list(alist) blist = alist[:] blist[:] = alist # assumes blist already exists blist = copy.copy(alist) blist = copy.deepcopy(alist) blist = []; blist.extend(alist) blist = [x for x in alist] # don't do this Hardly "only one way" :) -- Steven From steve+comp.lang.python at pearwood.info Sat Jul 9 01:30:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2011 15:30:55 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > If it means anything, I think concatenation is faster. You are measuring the speed of an implementation-specific optimization. You'll likely get *very* different results with Jython or IronPython, or old versions of CPython, or even if you use instance attributes instead of local variables. It also doesn't generalise: only appends are optimized, not prepends. Worse, the optimization can be defeated by accidents of your operating system's memory management, so code that runs snappily and fast on one machine will run SLLLOOOOOOWWWWWWWWWWWWWWWLY on another. This is not a hypothetical risk. People have been burned by this in real life: http://www.gossamer-threads.com/lists/python/dev/771948 If you're interested in learning about the optimization: http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt -- Steven From ian.g.kelly at gmail.com Sat Jul 9 02:04:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Jul 2011 00:04:41 -0600 Subject: String concatenation vs. string formatting In-Reply-To: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 8, 2011 at 11:30 PM, Steven D'Aprano wrote: > Billy Mays wrote: > >> If it means anything, I think concatenation is faster. > > You are measuring the speed of an implementation-specific optimization. > You'll likely get *very* different results with Jython or IronPython, or > old versions of CPython, or even if you use instance attributes instead of > local variables. > > It also doesn't generalise: only appends are optimized, not prepends. Indeed: $ python -m timeit -s "v = 'x' * 10; out = ''" "out = out + v" 1000000 loops, best of 3: 6.59 usec per loop $ python -m timeit -s "v = 'x' * 10; out = ''" "out = v + out" 100000 loops, best of 3: 268 usec per loop Good to know. I had no idea such an optimization existed. Cheers, Ian From rosuav at gmail.com Sat Jul 9 02:16:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jul 2011 16:16:55 +1000 Subject: String concatenation vs. string formatting In-Reply-To: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 3:30 PM, Steven D'Aprano wrote: > It also doesn't generalise: only appends are optimized, not prepends. > > If you're interested in learning about the optimization: > > http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt >From that page: "Also, this is only for plain (byte) strings, not for Unicode strings; as of Python 2.4.2, Unicode string concatenation remains un-optimized." Has the same optimization been implemented for Unicode? The page doesn't mention Python 3 at all, and I would guess that the realloc optimization would work fine for both types of string. ChrisA From ian.g.kelly at gmail.com Sat Jul 9 02:29:38 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 9 Jul 2011 00:29:38 -0600 Subject: String concatenation vs. string formatting In-Reply-To: References: <4e17e790$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 12:16 AM, Chris Angelico wrote: > Has the same optimization been implemented for Unicode? The page > doesn't mention Python 3 at all, and I would guess that the realloc > optimization would work fine for both types of string. Seems to be implemented for strs in 3.2, but not unicode in 2.7. From k.sahithi2862 at gmail.com Sat Jul 9 03:58:03 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 9 Jul 2011 00:58:03 -0700 (PDT) Subject: NEW HOT PHOTOS Message-ID: <594c3f69-2061-4ad4-b8b3-f5015e232e75@x12g2000yql.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From vinay_sajip at yahoo.co.uk Sat Jul 9 07:06:37 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 9 Jul 2011 11:06:37 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > Other than the case where a variable isn't a string (format() converts > variables to strings, automatically, right?) and when a variable is used > a bunch of times, concatenation is fine, but somehow, it seems wrong. > Sorry if this seems a bit silly, but I'm a novice when it comes to > design. Plus, there's not really supposed to be "more than one way to do > it" in Python. In a logging context at least, using the form like logger.debug("formatting message with %s", "arguments") rather than logger.debug("formatting message with %s" % "arguments") means that the formatting is deferred by logging until it is actually needed. If the message never gets output because of the logging configuration in use, then the formatting is never done. This optimisation won't matter in most cases, but it will in some scenarios. By the way, logging primarily uses %-formatting instead of the newer {}-formatting, because it pre-dates {}-formatting. In more recent versions of Python, all of Python's three formatting styles are supported - see http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html Also by the way - Python doesn't say there shouldn't be more than one way to do things - just that there should be one *obvious* way (from the Zen of Python). Regards, Vinay Sajip From babedoudi at yahoo.fr Sat Jul 9 08:55:37 2011 From: babedoudi at yahoo.fr (=?ISO-8859-1?Q?R=E9mi?=) Date: Sat, 09 Jul 2011 14:55:37 +0200 Subject: HTTP Proxy : receive call on local socket takes a lot of time Message-ID: <4e184fca$0$18114$426a74cc@news.free.fr> Hi all, I am currently working on a HTTP Proxy. For maximum flexibility, I am implementing the proxy at a low level : I am using the SocketServer library. The server itself is very simple: class MyTCPServer(SocketServer.TCPServer): allow_reuse_address = 1 and the handler looks like: class MyTCPHandler(SocketServer.BaseRequestHandler): def handle(self): # Prints ip and port print "\n#### " + str(self.client_address) + " ####" requestParser = HTTPRequestParser() while True: # Get packet data = self.request.recv(4096) if data == '': break # Parse request packet if requestParser.got_new_chunk(data): break someStuff = "" self.request.send(someStuff) This is working fine, but I have a small performance issue. The proxy is targeted by Firefox. Sometimes the first receive call on the input socket takes a lot of time (up to 20s sometimes), which should not be as this is a communication of two local sockets. This is occurring maybe every 30 requests or so. When looking at the logs I noticed that this weird behavior happens when the client port is not contiguous to the previous ones. For example, handling the fourth request takes a lot of time: #### ('127.0.0.1', 49704) #### #### ('127.0.0.1', 49705) #### #### ('127.0.0.1', 49706) #### #### ('127.0.0.1', 49674) #### Do you have any idea what the problem could be ? I tried to manually close self.request request, but I still have the problem. Is it related to "allow_reuse_address = 1" ? Thanks for your help ! R?mi From jessrobe at gmail.com Sat Jul 9 14:24:30 2011 From: jessrobe at gmail.com (Jesse R) Date: Sat, 9 Jul 2011 11:24:30 -0700 (PDT) Subject: ctypes: point to buffer in structure Message-ID: Hey I've been trying to convert this to run through ctypes and i'm having a hard time typedef struct _SYSTEM_PROCESS_ID_INFORMATION { HANDLE ProcessId; UNICODE_STRING ImageName; } SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, *PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; to class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): _fields_ = [('pid', ctypes.c_ulong), ('imageName', ctypes.c_wchar_p)] processNameBuffer = ctypes.create_unicode_buffer(0x100) pidInfo = SYSTEM_PROCESS_ID_INFORMATION(pid, ctypes.byref(processNameBuffer)) status = ntdll.NtQuerySystemInformation(0x58, ctypes.byref(pidInfo), ctypes.sizeof(pidInfo), None) does anyone know how to get this working? From thinke365 at gmail.com Sat Jul 9 16:45:30 2011 From: thinke365 at gmail.com (smith jack) Date: Sun, 10 Jul 2011 04:45:30 +0800 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? Message-ID: from threading import Thread def calc(start, end): total = 0; for i in range(start, end + 1): total += i; print '----------------------result:', total return total t = Thread(target=calc, args=(1,100)) t.start() I have run this program for many times,and the result is always 5050, if there is any concurrency problem, the result should not be 5050, which is never met, anyhow I mean this program should get the wrong answer at some times, but this never happens, why? can concurrency without synchronize mechanism always get the right answer? any special case in python programming? From alex.kapps at web.de Sat Jul 9 17:17:29 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 09 Jul 2011 23:17:29 +0200 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? In-Reply-To: References: Message-ID: <4E18C569.10400@web.de> On 09.07.2011 22:45, smith jack wrote: > from threading import Thread > > def calc(start, end): > total = 0; > for i in range(start, end + 1): > total += i; > print '----------------------result:', total > return total > > t = Thread(target=calc, args=(1,100)) > t.start() > > I have run this program for many times,and the result is always 5050, > if there is any concurrency problem, the result should not be 5050, > which is never met, anyhow > I mean this program should get the wrong answer at some times, but > this never happens, why? > can concurrency without synchronize mechanism always get the right answer? > any special case in python programming? Why do you think, that there's a concurrency problem? All variables are local to the calc() function and all calc() invocations run in an own thread. No thread tries to access any shared data, so why should there be a concurrency problem? Concurrency is an issue, when two or more threads/processes try to access the same data, but in your program everything is local to the calc() function. From ericsnowcurrently at gmail.com Sat Jul 9 17:28:58 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 15:28:58 -0600 Subject: What makes functions special? Message-ID: A tracker issue [1] recently got me thinking about what makes functions special. The discussion there was regarding the distinction between compile time (generation of .pyc files for modules and execution of code blocks), [function] definition time, and [function] execution time. Definition time actually happens during compile time, but it has its own label to mark the contrast with execution time. So why do functions get this special treatment? Functions are a special case in Python for providing a more optimized execution of a code block in pure Python code. And how is that? When the function is defined, a code object is generated for the function body along with a few "static" details that will be used during execution. No other objects have code objects. No other objects in Python have this special optimization. Maybe I am missing something, or maybe it is super obvious, but isn't this a critical point? Is it just a CPython implementation detail that code objects should provide an optimization, or is it a specification of the language? From the docs, the code objects in of function objects are the latter, but the optimization expectation is not clearly indicated. Are there other motivations behind code objects that I am missing? Am I wrong about the optimization expectation? Thoughts? -eric [1] http://bugs.python.org/issue12374 From bahamutzero8825 at gmail.com Sat Jul 9 18:02:32 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 17:02:32 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> Message-ID: <4E18CFF8.1060908@gmail.com> On 2011.07.09 06:06 AM, Vinay Sajip wrote: > In a logging context at least, using the form like > > logger.debug("formatting message with %s", "arguments") > > rather than > > logger.debug("formatting message with %s" % "arguments") How would I do that with the newer formatting? I've tried: > logger.info('Binary preset file {file} successfully stored.', {file : > queue[0].preset_file}) (global name 'file' not defined) and > logger.info('Binary preset file {file} successfully stored.', > file=queue[0].preset_file) (unexpected keyword 'file') > By the way, logging primarily uses %-formatting instead of the newer > {}-formatting, because it pre-dates {}-formatting. In more recent versions of > Python, all of Python's three formatting styles are supported - see I've noticed. :-) > log_formatter = logging.Formatter('{asctime} - __main__ - {funcName} - > line {lineno} - {levelname} - {message}', style='{') From ben+python at benfinney.id.au Sat Jul 9 18:41:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 08:41:27 +1000 Subject: What makes functions special? References: Message-ID: <87sjqfgjqg.fsf@benfinney.id.au> Eric Snow writes: > A tracker issue [1] recently got me thinking about what makes > functions special. As you describe, functions are special for your scenario because a function definition needs to result in executable code as an object. > Definition time actually happens during compile time, but it has its > own label to mark the contrast with execution time. So why do > functions get this special treatment? You answer this question. > No other objects have code objects. No other objects in Python have > this special optimization. Yes. The two facts are directly related. > Maybe I am missing something, or maybe it is super obvious, but isn't > this a critical point? What is the crisis (?a stark change from one state to another?) that you're referring to by ?a critical point?? Yes, functions are different and are treated differently. What's your question? > From the docs, the code objects in of function objects are the latter, > but the optimization expectation is not clearly indicated. Are there > other motivations behind code objects that I am missing? Am I wrong > about the optimization expectation? What optimisation expectation? > Thoughts? I think yours need to be expressed more explicitly; I'm not seeing the issue that concerns you. -- \ ?The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.? ?Bill Gates, 1995-10-23 | _o__) | Ben Finney From ericsnowcurrently at gmail.com Sat Jul 9 19:16:19 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 17:16:19 -0600 Subject: What makes functions special? In-Reply-To: <87sjqfgjqg.fsf@benfinney.id.au> References: <87sjqfgjqg.fsf@benfinney.id.au> Message-ID: On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: > Eric Snow writes: > >> A tracker issue [1] recently got me thinking about what makes >> functions special. > > As you describe, functions are special for your scenario because a > function definition needs to result in executable code as an object. > >> Definition time actually happens during compile time, but it has its >> own label to mark the contrast with execution time. So why do >> functions get this special treatment? > > You answer this question. > >> No other objects have code objects. No other objects in Python have >> this special optimization. > > Yes. The two facts are directly related. > >> Maybe I am missing something, or maybe it is super obvious, but isn't >> this a critical point? > > What is the crisis (?a stark change from one state to another?) that > you're referring to by ?a critical point?? > > Yes, functions are different and are treated differently. What's your > question? > >> From the docs, the code objects in of function objects are the latter, >> but the optimization expectation is not clearly indicated. Are there >> other motivations behind code objects that I am missing? Am I wrong >> about the optimization expectation? > > What optimisation expectation? > >> Thoughts? > > I think yours need to be expressed more explicitly; I'm not seeing the > issue that concerns you. > My point is that functions are special in Python because they provide a built in optimization via the special execution of code objects. I would like to know if it is really that big a deal, and if the optimized execution of code objects is a CPython implementation detail or a specification of the language. -eric > -- > ?\ ? ? ? ??The reason we come up with new versions is not to fix bugs. | > ?`\ ? ? ? ? ? ? ? ? ? ? It's absolutely not.? ?Bill Gates, 1995-10-23 | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat Jul 9 20:21:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Jul 2011 17:21:28 -0700 Subject: What makes functions special? In-Reply-To: References: Message-ID: On 7/9/2011 2:28 PM, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Not true. For main modules, execution of each statement immediately follows compilation, but not for other modules, where compilation and caching of code objects may happen years before the function object is created. > Functions are a special case in Python for providing a more optimized > execution of a code block in pure Python code. And how is that? When > the function is defined, a code object is generated for the function > body along with a few "static" details that will be used during > execution. No other objects have code objects. No other objects in > Python have this special optimization. A .pyc file is a serialized code object for a module. As for the rest, I am not sure what you are asking. Terry Reedy From johnjsal at gmail.com Sat Jul 9 20:26:50 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 9 Jul 2011 17:26:50 -0700 (PDT) Subject: How can I make a program automatically run once per day? Message-ID: I have a script that does some stuff that I want to run every day for maybe a week, or a month. So far I've been good about running it every night, but is there some way (using Python, of course) that I can make it automatically run at a set time each night? From ben+python at benfinney.id.au Sat Jul 9 20:38:28 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 10:38:28 +1000 Subject: What makes functions special? References: <87sjqfgjqg.fsf@benfinney.id.au> Message-ID: <87mxgngebf.fsf@benfinney.id.au> Eric Snow writes: > On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: > > Eric Snow writes: > >> No other objects have code objects. No other objects in Python have > >> this special optimization. > > > > Yes. The two facts are directly related. [?] > > Yes, functions are different and are treated differently. What's > > your question? > > My point is that functions are special in Python because they provide > a built in optimization via the special execution of code objects. Functions are special because they define a code object. > I would like to know if it is really that big a deal Is *what* really that big a deal? Perhaps this could be clearer if you'd describe what it is that surprises you, and how you'd expect it to be different. > and if the optimized execution of code objects is a CPython > implementation detail or a specification of the language. I don't know that it's a specification. But functions result in code objects, and other statements don't; I am not seeing why treating them differently is surprising. -- \ ?I see little commercial potential for the Internet for at | `\ least ten years.? ?Bill Gates, 1994 | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Jul 9 20:40:17 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 10:40:17 +1000 Subject: How can I make a program automatically run once per day? References: Message-ID: <87iprbge8e.fsf@benfinney.id.au> John Salerno writes: > is there some way (using Python, of course) that I can make it > automatically run at a set time each night? You need to use whatever facilities your operating system has for scheduled events. That's unrelated to the language you use for implementing the program. On a Unix-like system (e.g. GNU+Linux), you could create a ?cron? job entry. -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From bahamutzero8825 at gmail.com Sat Jul 9 20:49:14 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 19:49:14 -0500 Subject: How can I make a program automatically run once per day? In-Reply-To: References: Message-ID: <4E18F70A.2010309@gmail.com> On 2011.07.09 07:26 PM, John Salerno wrote: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? I would use the OS to worry about scheduling (cron/Windows Task Scheduler/whatever), but in Python, you could probably use a while True loop, time.sleep() (to specify how often to check the time) and a datetime.time or datetime.now object (e.g. datetime.now().hour). From alex.kapps at web.de Sat Jul 9 21:00:57 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 10 Jul 2011 03:00:57 +0200 Subject: How can I make a program automatically run once per day? In-Reply-To: References: Message-ID: <4E18F9C9.8090006@web.de> On 10.07.2011 02:26, John Salerno wrote: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? Use your operating system's facilities to run timed jobs. Unix/Linux: Cron jobs Windows: Scheduled Tasks Mac: don't know, but probably Cron too From ericsnowcurrently at gmail.com Sat Jul 9 21:10:55 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 19:10:55 -0600 Subject: What makes functions special? In-Reply-To: References: Message-ID: On Sat, Jul 9, 2011 at 6:21 PM, Terry Reedy wrote: > On 7/9/2011 2:28 PM, Eric Snow wrote: >> >> A tracker issue [1] recently got me thinking about what makes >> functions special. ?The discussion there was regarding the distinction >> between compile time (generation of .pyc files for modules and >> execution of code blocks), [function] definition time, and [function] >> execution time. ?Definition time actually happens during compile time, > > Not true. For main modules, execution of each statement immediately follows > compilation, but not for other modules, where compilation and caching of > code objects may happen years before the function object is created. > So for non-main modules the function definition happens during module compilation, and for all other code blocks (__main__, exec, etc.) it happens during execution of the code block? >> Functions are a special case in Python for providing a more optimized >> execution of a code block in pure Python code. ?And how is that? ?When >> the function is defined, a code object is generated for the function >> body along with a few "static" details that will be used during >> execution. ?No other objects have code objects. ?No other objects in >> Python have this special optimization. > > A .pyc file is a serialized code object for a module. > I hadn't thought of it like that. Nice insight. In that case, do [non-main] module definition and execution time have the same logical separation as function phases do? > As for the rest, I am not sure what you are asking. > Yeah, I have a real knack for communicating. :) Mostly I am just trying to put together more pieces of the Python puzzle. In this case I was trying to find out if the optimized execution of code objects for functions is a part of the language or just an implementation detail. -eric > Terry Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > From ericsnowcurrently at gmail.com Sat Jul 9 21:28:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 19:28:02 -0600 Subject: What makes functions special? In-Reply-To: <87mxgngebf.fsf@benfinney.id.au> References: <87sjqfgjqg.fsf@benfinney.id.au> <87mxgngebf.fsf@benfinney.id.au> Message-ID: On Sat, Jul 9, 2011 at 6:38 PM, Ben Finney wrote: > Eric Snow writes: > >> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney wrote: >> > Eric Snow writes: >> >> No other objects have code objects. No other objects in Python have >> >> this special optimization. >> > >> > Yes. The two facts are directly related. > [?] > >> > Yes, functions are different and are treated differently. What's >> > your question? >> >> My point is that functions are special in Python because they provide >> a built in optimization via the special execution of code objects. > > Functions are special because they define a code object. > Right. But the point is that the code objects (in CPython at least) allow a special execution of the function body. What does that special execution give us? I am guessing a sufficient performance increase. Is there anything else? And do other Python implementations do anything special with code objects? I am not questioning why it was done a certain way, but rather trying to understand how Python works. >> I would like to know if it is really that big a deal > > Is *what* really that big a deal? > > Perhaps this could be clearer if you'd describe what it is that > surprises you, and how you'd expect it to be different. > I don't have any unexpected failure that I ran into or anything like that. I am just trying to learn more about the ins and outs of Python and that tracker issue got me thinking. And I know that there are plenty of people on this list that know a lot more about Python than I do. :) So I thought I would ask (in my own obscure way) if I was understanding the definition/execution model correctly. Sorry for any confusion. -eric >> and if the optimized execution of code objects is a CPython >> implementation detail or a specification of the language. > > I don't know that it's a specification. But functions result in code > objects, and other statements don't; I am not seeing why treating them > differently is surprising. > > -- > ?\ ? ? ? ? ??I see little commercial potential for the Internet for at | > ?`\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? least ten years.? ?Bill Gates, 1994 | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > From bruce at whealton.info Sat Jul 9 21:32:00 2011 From: bruce at whealton.info (Bruce Whealton) Date: Sat, 9 Jul 2011 21:32:00 -0400 Subject: Newbie help - Programming the Semantic Web with Python Message-ID: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Hello, So, I got this book on Programming the Semantic Web about the same time I started learning Python. The code seems to be developed for python 2.7 and not 3, I believe. The code is here: http://semprog.com/content/the-book/ I tried to run simpletriple.py from inside eclipse with PYDEV. The first thing it has a problem with is this line: def add(self, (sub, pred, obj)): I think the problem is with the parentheses before the sub. I removed those and that seemed to fix that error or make it go away. I don?t remember how I figured that out, It should be on the Errata page for sure. Then it has a problem with this line: print list(g.triples((None, None, None))) If I was using python 3, it would require () around the thing that is going to be printed, right? Maybe python 2.7 doesn?t like this line for the same reason. The book suggests that from IDLE, I can just use >>>from simplegraph import SimpleGraph That means it is going to look for a file named simplegraph.py but where will it be looking? I guess I would have to have it in the same folder as the python interpreter or one of the PATH directories, right? Thanks, Bruce ++++++++++++++++++++++++++++++++++++++++++++++++++ Bruce Whealton, Owner Future Wave Designs FOAF: http://whealton.info/BruceWhealtonJr/foaf.rdf Vcard: http://whealton.info/BruceWhealtonJr/brucewhealtonvcard.html Web Design and Development http://FutureWaveDesigns.com http://futurewavedesigns.com/wordpress/ Web Technology wiki: http://futurewavedesigns.com/w/ ++++++++++++++++++++++++++++++++++++++++++++++++++ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: wlEmoticon-smile[1].png Type: image/png Size: 1041 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Sat Jul 9 21:34:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2011 11:34:50 +1000 Subject: What makes functions special? References: Message-ID: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > Mostly I am just > trying to put together more pieces of the Python puzzle. In this case > I was trying to find out if the optimized execution of code objects > for functions is a part of the language or just an implementation > detail. You keep using that phrase, "optimized execution of code objects for functions", but I have no idea what that means. The best I can think of is that you are thinking along these lines... "Suppose we have the source code to a function: def spam(n): return "SPAM"*n To execute this, Python currently compiles the function into a code block, and then when you call spam(n) elsewhere, Python executes the already compiled code block. Suppose instead an implementation of Python did not pre-compile the function. Each time you called spam(n), the implementation would have to locate the source code and interpret it on the spot. Would that be allowed?" If that's your question, then I would call that a Python interpreter using c.1960 technology (as opposed to a byte-code compiler, which all the main implementations currently are). If that were the *only* difference, then I see no reason why it wouldn't be allowed as an implementation of Python. A horribly slow implementation, but still an implementation. However, I doubt that would be the only difference. Given such a simple-minded Python interpreter, it would be hard to provide expected Python language features such as compiled code objects, closures, etc. You would have to fake them somehow. Provided you could fake them sufficiently well, then the lack of a byte-code compiler is just a quality of implementation issue. If that's *not* your question, them I'm stumped. -- Steven From cs at zip.com.au Sat Jul 9 21:58:59 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 10 Jul 2011 11:58:59 +1000 Subject: How can I make a program automatically run once per day? In-Reply-To: <4E18F9C9.8090006@web.de> References: <4E18F9C9.8090006@web.de> Message-ID: <20110710015859.GA26678@cskk.homeip.net> On 10Jul2011 03:00, Alexander Kapps wrote: | On 10.07.2011 02:26, John Salerno wrote: | >I have a script that does some stuff that I want to run every day for | >maybe a week, or a month. So far I've been good about running it every | >night, but is there some way (using Python, of course) that I can make | >it automatically run at a set time each night? | | Use your operating system's facilities to run timed jobs. | | Unix/Linux: Cron jobs | Windows: Scheduled Tasks | Mac: don't know, but probably Cron too Yep. Macs are UNIX, BSD derived. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ USENET: Post to exotic, distant machines. Meet exciting, unusual people. And flame them. - Dan Sorenson, z1dan at exnet.iastate.edu, DoD #1066 From johnjsal at gmail.com Sat Jul 9 22:01:27 2011 From: johnjsal at gmail.com (John Salerno) Date: Sat, 9 Jul 2011 19:01:27 -0700 (PDT) Subject: How can I make a program automatically run once per day? References: Message-ID: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Thanks everyone! I probably should have said something like "Python, if possible and efficient, otherwise any other method" ! :) I'll look into the Task Scheduler. Thanks again! From phlip2005 at gmail.com Sat Jul 9 22:05:25 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 19:05:25 -0700 (PDT) Subject: CI and BDD with Python References: Message-ID: On Jul 8, 9:36?pm, Stefan Behnel wrote: > mark curphey, 09.07.2011 01:41: > > > And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? I'm kind'a partial to Morelia for BDD. Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted opinion. "BDD" means "your customer gives you requirements as sentences, and you make them into executable statements." That's what Cucumber does, which Morelia learns from. And BDD and CI are orthogonal. BDD should be part of a complete TDD test suite, and your CI tool should run that. I still like CruiseControl.rb - even though it has bugs when it sees too many git integrations. Hudson had way too many features, and CCrb mildly presumes you know how to operate its .cruise/projects folder manually! From rosuav at gmail.com Sat Jul 9 22:10:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2011 12:10:31 +1000 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton wrote: problem with is this line: > ??? def add(self, (sub, pred, obj)): > I think the problem is with the parentheses before the sub.? I removed those and that seemed to fix that error or make it go away.? I don?t remember how I figured that out, ? It should be on the Errata page for sure. > Then it has a problem with this line: > ??? print list(g.triples((None, None, None))) > If I was using python 3, it would require () around the thing that is going to be printed, right?? Maybe python 2.7 doesn?t like this line for the same reason. > The issue there is with tuple unpacking. To match the older syntax, don't touch the call, but change the definition thus: def add(self, args): (sub, pred, obj)=args Or, of course, simply list the arguments directly, rather than in a tuple; but that requires changing every call (if it's a small program that may not be a problem). You're right about needing parentheses around the print() call; in Python 2 it's a statement, but in Python 3, print is a function like any other. Regarding the module search path, this may help: http://docs.python.org/dev/tutorial/modules.html#the-module-search-path Chris Angelico From ericsnowcurrently at gmail.com Sat Jul 9 22:33:10 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 9 Jul 2011 20:33:10 -0600 Subject: What makes functions special? In-Reply-To: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2011 at 7:34 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> Mostly I am just >> trying to put together more pieces of the Python puzzle. ?In this case >> I was trying to find out if the optimized execution of code objects >> for functions is a part of the language or just an implementation >> detail. > > You keep using that phrase, "optimized execution of code objects for > functions", but I have no idea what that means. > > The best I can think of is that you are thinking along these lines... > > "Suppose we have the source code to a function: > > def spam(n): > ? ?return "SPAM"*n > > To execute this, Python currently compiles the function into a code block, > and then when you call spam(n) elsewhere, Python executes the already > compiled code block. > Yeah, that's pretty much it. Is that all there is to it? I was saying optimized, but I guess there isn't much special optimization going on then. Thanks for taking the time. -eric > Suppose instead an implementation of Python did not pre-compile the > function. Each time you called spam(n), the implementation would have to > locate the source code and interpret it on the spot. Would that be > allowed?" > > If that's your question, then I would call that a Python interpreter using > c.1960 technology (as opposed to a byte-code compiler, which all the main > implementations currently are). > > If that were the *only* difference, then I see no reason why it wouldn't be > allowed as an implementation of Python. A horribly slow implementation, but > still an implementation. > > However, I doubt that would be the only difference. Given such a > simple-minded Python interpreter, it would be hard to provide expected > Python language features such as compiled code objects, closures, etc. You > would have to fake them somehow. Provided you could fake them sufficiently > well, then the lack of a byte-code compiler is just a quality of > implementation issue. > > If that's *not* your question, them I'm stumped. > > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From mark at curphey.com Sat Jul 9 22:39:06 2011 From: mark at curphey.com (mark curphey) Date: Sat, 9 Jul 2011 19:39:06 -0700 Subject: CI and BDD with Python In-Reply-To: References: Message-ID: Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) over the last few days and Lettuce appears to be the most "actively" maintained and closest to a cucumber-like implementation IMHO. I have decided to adopt it for now. I played with a few CI servers but Jenkins (Hudson) is tough to beat IMHO but I am sure this is just my personal preference. Anyways thanks for the help. Cheers, Mark On Jul 9, 2011, at 7:05 PM, Phlip wrote: > On Jul 8, 9:36 pm, Stefan Behnel wrote: >> mark curphey, 09.07.2011 01:41: >> >>> And for CI having been using Hudson for a while, any real advantages in a Python / Django world for adopting something native like Trac and one of the CI plugins like Bitten? > > I'm kind'a partial to Morelia for BDD. > > Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted > opinion. "BDD" means "your customer gives you requirements as > sentences, and you make them into executable statements." That's what > Cucumber does, which Morelia learns from. > > And BDD and CI are orthogonal. BDD should be part of a complete TDD > test suite, and your CI tool should run that. > > I still like CruiseControl.rb - even though it has bugs when it sees > too many git integrations. Hudson had way too many features, and CCrb > mildly presumes you know how to operate its .cruise/projects folder > manually! > -- > http://mail.python.org/mailman/listinfo/python-list From bahamutzero8825 at gmail.com Sat Jul 9 22:44:47 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 21:44:47 -0500 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: <4E19121F.4010203@gmail.com> On 2011.07.09 08:32 PM, Bruce Whealton wrote: > Hello, > So, I got this book on Programming the Semantic Web about > the same time I started learning Python. The code seems to be > developed for python 2.7 and not 3, I believe. If you're going to learn Python 3, I suggest learning from a book that deals with Python 3 (if there's not an updated text for the area you're dealing with, go with something that teaches the basics). Once you have the basics down and you know the common differences, then it will be much easier to learn from a text that's based on Python 2 (you'll stumble a whole lot less when trying to learn from such texts). You'll also find some things in Python 3 that have been added to recent versions of Python 2 that the text may not cover (e.g., the old % string formatting syntax vs. the new format() string method). > If I was using python 3, it would require () around the thing that is > going to be printed, right? That's not really the right way to think of the print() function. The print statement has some very arbitrary syntax that could cause unexpected behavior if simply put in the print() function. The print function has parameters for optional behavior rather than odd syntax. In the simplest cases, print and print() are extremely similar, but print() has a bunch of functionality that is either difficult/annoying to decipher (for humans, not the interpreter) or simply doesn't exist in print. From pavlovevidence at gmail.com Sat Jul 9 22:47:08 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 9 Jul 2011 19:47:08 -0700 (PDT) Subject: What makes functions special? In-Reply-To: Message-ID: <4e9d97d9-2804-488c-8939-8221bf9a9328@glegroupsg2000goo.googlegroups.com> On Saturday, July 9, 2011 2:28:58 PM UTC-7, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Nope. Compile time and definition time are always distinct. > but it has its own label to mark the contrast with execution time. So > why do functions get this special treatment? They don't really. [snip] > Am I wrong about the optimization expectation? As best as I can tell, you are asking (in a very opaque way) why the Python compiler even bothers to create code objects, rather than just to create a function object outright, because it doesn't (you think) do that for any other kind of object. Two answers (one general, one specific): 1. You're looking for a pattern where it doesn't make any sense for there to be one. The simple truth of the matter is different syntaxes do different things, and there isn't anything more to it. A lambda expression or def statement does one thing; a different syntax, such as an integer constant, does another thing. Neither one is treated "specially"; they're just different. Consider another example: tuple syntax versus list syntax. Python will often build the tuple at compile time, but it never builds a list at compile time. Neither one is "special"; it's just that tuple syntax does one thing, list syntax does a different thing. 2. Now that we've dispensed with the idea that Python is treating functions specially, let's answer your specific question. It's not special, but still, why the code object? The reason, simply, is that code objects are used for more than just functions. Code objects are also used in modules, and in eval and exec statements, and there's one for each statement at the command line. Code objects are also used directly by the interpreter when executing byte code. A function object is only one of several "interfaces" to a code object. A minor reason is that code objects are constant (in fact, any object that is built at compile time must be a constant). However, function objects are mutable. I hope that helps clear things up. Carl Banks From pavlovevidence at gmail.com Sat Jul 9 22:47:08 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 9 Jul 2011 19:47:08 -0700 (PDT) Subject: What makes functions special? In-Reply-To: Message-ID: <4e9d97d9-2804-488c-8939-8221bf9a9328@glegroupsg2000goo.googlegroups.com> On Saturday, July 9, 2011 2:28:58 PM UTC-7, Eric Snow wrote: > A tracker issue [1] recently got me thinking about what makes > functions special. The discussion there was regarding the distinction > between compile time (generation of .pyc files for modules and > execution of code blocks), [function] definition time, and [function] > execution time. Definition time actually happens during compile time, Nope. Compile time and definition time are always distinct. > but it has its own label to mark the contrast with execution time. So > why do functions get this special treatment? They don't really. [snip] > Am I wrong about the optimization expectation? As best as I can tell, you are asking (in a very opaque way) why the Python compiler even bothers to create code objects, rather than just to create a function object outright, because it doesn't (you think) do that for any other kind of object. Two answers (one general, one specific): 1. You're looking for a pattern where it doesn't make any sense for there to be one. The simple truth of the matter is different syntaxes do different things, and there isn't anything more to it. A lambda expression or def statement does one thing; a different syntax, such as an integer constant, does another thing. Neither one is treated "specially"; they're just different. Consider another example: tuple syntax versus list syntax. Python will often build the tuple at compile time, but it never builds a list at compile time. Neither one is "special"; it's just that tuple syntax does one thing, list syntax does a different thing. 2. Now that we've dispensed with the idea that Python is treating functions specially, let's answer your specific question. It's not special, but still, why the code object? The reason, simply, is that code objects are used for more than just functions. Code objects are also used in modules, and in eval and exec statements, and there's one for each statement at the command line. Code objects are also used directly by the interpreter when executing byte code. A function object is only one of several "interfaces" to a code object. A minor reason is that code objects are constant (in fact, any object that is built at compile time must be a constant). However, function objects are mutable. I hope that helps clear things up. Carl Banks From phlip2005 at gmail.com Sat Jul 9 23:03:13 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 20:03:13 -0700 (PDT) Subject: CI and BDD with Python References: Message-ID: On Jul 9, 7:39?pm, mark curphey wrote: > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) Morelia is "undermaintained" because it's finished. It attaches to any pre-existing TestCase-style test runner, hence there's nothing to maintain! Packages like Lettuce rebuild the entire TestCase back-end just to change the front end. That forces its maintainer to then do the Red Queen thing, and constantly compete with all other test runners just to stay in place. Props for the effort, though..! From bahamutzero8825 at gmail.com Sat Jul 9 23:23:32 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 22:23:32 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E191B34.8090100@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote: > "file" is a built-in (related to "open"). It is? What is it? >>> type(file) Traceback (most recent call last): File "", line 1, in NameError: name 'file' is not defined I don't see it in the docs as a built-in function, constant or type. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGRszAAoJEPiOA0Bgp4/LAG4H/23ZZZWTEVUWDtFb28JtVKnq oIQG3aKGxHTUrvUgZqRge6KbpYhDtZFNXcknPmC6rXjVFTBb6Ag5eOCVbEq1Nu5t Ahonxy9Mr+a5URe+E4oeLvjp0ascLs2NuGxY35QFGm16jRehZ5egCnhvpMOaa1lp q+VbKWIms2xNw4eyYVfGhfGNvBJ0RXDqHfHKjPwA+oDuUNpFeTRGLrBx9T4qazw5 2+P6fmz6Y8oV3Tu9PQe8L7qksV/NrLe4rG8+sxhlpfzqTGisfKbIsYodo1uUgcdc 723hnkxz1Nh3VmUrB+JTYwYz1mD0ndHMJpkNc4JGBEoxp2lSMk1LE+1+tAlA7b4= =Gd/f -----END PGP SIGNATURE----- From benjamin.kaplan at case.edu Sat Jul 9 23:36:58 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 9 Jul 2011 20:36:58 -0700 Subject: How can I make a program automatically run once per day? In-Reply-To: <20110710015859.GA26678@cskk.homeip.net> References: <4E18F9C9.8090006@web.de> <20110710015859.GA26678@cskk.homeip.net> Message-ID: On Sat, Jul 9, 2011 at 6:58 PM, Cameron Simpson wrote: > On 10Jul2011 03:00, Alexander Kapps wrote: > | On 10.07.2011 02:26, John Salerno wrote: > | >I have a script that does some stuff that I want to run every day for > | >maybe a week, or a month. So far I've been good about running it every > | >night, but is there some way (using Python, of course) that I can make > | >it automatically run at a set time each night? > | > | Use your operating system's facilities to run timed jobs. > | > | Unix/Linux: Cron jobs > | Windows: Scheduled Tasks > | Mac: don't know, but probably Cron too > > Yep. Macs are UNIX, BSD derived. > Macs have Cron, but Apple's trying to switch away from it. They wrote their own framework to replace the various process-launching programs called launchd. It uses a pretty simple XML config file to launch programs either at startup (replacing init) or on an schedule (replacing cron). -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Jul 9 23:38:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 13:38:54 +1000 Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: Message-ID: <871uxyhkj5.fsf_-_@benfinney.id.au> Phlip writes: > On Jul 9, 7:39?pm, mark curphey wrote: > > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) > > Morelia is "undermaintained" because it's finished. It attaches to any > pre-existing TestCase-style test runner, hence there's nothing to > maintain! It looks good! But it's not yet in Debian :-( I've filed bug report #633411 to call for an interested Python programmer to package it for Debian. -- \ ?That's the essence of science: Ask an impertinent question, | `\ and you're on the way to the pertinent answer.? ?Jacob | _o__) Boronowski, _The Ascent of Man_, 1976 | Ben Finney From bahamutzero8825 at gmail.com Sun Jul 10 00:04:53 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 23:04:53 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E1924E5.8040500@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote: > "file" is a built-in (related to "open"). Also: > Traceback (most recent call last): File > "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 178, in > save_preset() File > "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 169, in > save_preset logger.info('Binary preset file {barf} successfully > stored.', barf=queue[0].preset_file) File > "C:\Python32\lib\logging\__init__.py", line 1229, in info > self._log(INFO, msg, args, **kwargs) TypeError: _log() got an > unexpected keyword argument 'barf' Is barf built-in as well? - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGSTlAAoJEPiOA0Bgp4/LfbgH/0yo5BegsXcqu3ZTyn3Src+k RJBwnIZNBOpaUS2oogiD8eILF5JonCvztKn6rPuB8uhMWzOKl+jTwf5Y4y2Y+kJ7 37v3d41Bar1vAPQ42vKSqYkQ+p1ZHG5VMjkTFH76g8Q1a82oUMTNucqIXu84an2K 8sZA223ZZqzKa7VTzxr59TNX+4EnUIoBBZGH8LATAp9ILa0cNj/TJm7UOQmRAWzC He2zkhrAERbKm9w0BR/Y9JidJ5BlgdkqY7/yNbaYucAm8aI5xgHYvqt7SrSnSFu8 3X7HBxWz2Kinanvlpb5zZEnBmESrR+PujZqS89Bo/uznipkmgZNdXYPyhO/Rbzk= =QkWp -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 00:53:34 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Jul 2011 23:53:34 -0500 Subject: String concatenation vs. string formatting In-Reply-To: <4E1924E5.8040500@gmail.com> References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1924E5.8040500@gmail.com> Message-ID: <4E19304E.1040607@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.09 11:04 PM, Andrew Berg wrote: > > Is barf built-in as well? > That came off more hostile than I wanted, so I'll rephrase it: I doubt it has anything to do with built-ins, since it fails on a variable name that obviously does not reference a built-in. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGTBOAAoJEPiOA0Bgp4/LbkcH/2GdaIXnTRbfs4/aZInlf2sJ CK3rxb5OVY2Xz8rWVyHSd5tLRcCV8+R8+Mvv0/Ho6ckZjVi3xi6LHvoVFnhUP5Iv wayXHIJEjrN2oU5DJCSBbKGdtxjAMg48UUe6c2d4UUnV05bFX31SnHfI6Jq13uhs RpLSS3vELl/XDrcNGzMpOP1z8NYt7KpwHWoAWwN2wSZ8SQnyJFcFqbapWxA165Lp btDz1ufJ0nO/td+28y8FELoAkDtwrSBHCPqokbURA6zXy7KmVeGH9nVRO08Lz5ez qRII3lTBzeI9E2X/CUMOwrfLiWYDYYvh6VWBJZifBe5B4PQe/ksVe586A1LHetM= =5Xeo -----END PGP SIGNATURE----- From phlip2005 at gmail.com Sun Jul 10 01:10:46 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 22:10:46 -0700 (PDT) Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: <871uxyhkj5.fsf_-_@benfinney.id.au> Message-ID: <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> On Jul 9, 8:38?pm, Ben Finney wrote: > Phlip writes: > > On Jul 9, 7:39?pm, mark curphey wrote: > > > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) > > > Morelia is "undermaintained" because it's finished. It attaches to any > > pre-existing TestCase-style test runner, hence there's nothing to > > maintain! > > It looks good! But it's not yet in Debian :-( Tx - I never added anything to a distro before! But..! 'sudo pip install morelia' just worked for me, on Ubuntu. I don't think a python-morelia aptitude package would add any value. Such test rigs shall never have any embedded C code or other shenanigans. If I needed to think of a feature to add, it would be P notation in the regular expressions, to then enforce the names of the matching arguments. But this is fluff; real programmers can do without it. If I worked closer to the center of the BDD thought leadership I'd know what else to add... From phlip2005 at gmail.com Sun Jul 10 01:11:26 2011 From: phlip2005 at gmail.com (Phlip) Date: Sat, 9 Jul 2011 22:11:26 -0700 (PDT) Subject: Morelia for BDD in Python (was: CI and BDD with Python) References: <871uxyhkj5.fsf_-_@benfinney.id.au> Message-ID: <0922c0f1-1c3e-49fa-87d0-92d43b96f7bf@17g2000prr.googlegroups.com> > -- > ?\ ? ? ? ??That's the essence of science: Ask an impertinent question, | > ? `\ ? ? ? ? ? ?and you're on the way to the pertinent answer.? ?Jacob | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ?Boronowski, _The Ascent of Man_, 1976 | > Ben Finney That nose keeps reminding me of the start of one of the Pirates of the Caribbean movies... From ben+python at benfinney.id.au Sun Jul 10 01:21:30 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Jul 2011 15:21:30 +1000 Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> Message-ID: <87wrfqg17p.fsf@benfinney.id.au> Phlip writes: > 'sudo pip install morelia' just worked for me, on Ubuntu. The problem with ?pip? is that it's a parallel package installation that ignores the available package management system on the OS. That's not a fault of ?pip? or Setuptools or PyPI or the rest; but it's a higher maintenance burden for the user than getting a package from the same system that provides all the rest of their packages on the computer. On operating systems with poor package management, Python's distutils and PyPI etc. are better than nothing. But on an OS like Debian with good package management already for free software, it's a step backward to rely on external dependencies from a disjoint package system. > I don't think a python-morelia aptitude package would add any value. I think it would add great value, since without it I'm unlikely to bother using Morelia in any project. The maintenance burden is too high to keep adding dependencies that come from a distinct dependency system outside my OS. -- \ ?Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff.? ?Jack Handey | _o__) | Ben Finney From bahamutzero8825 at gmail.com Sun Jul 10 02:15:52 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 01:15:52 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E191B34.8090100@gmail.com> Message-ID: <4E194398.4040802@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 12:55 AM, Dennis Lee Bieber wrote: > Maybe it's been removed, but from the help file for my installation help(file) returns a NameError in 3.2. It shows up as a built-in function in the 2.7 docs, but not in the py3k docs. It's not mentioned in any of the "what's new" sections of the docs for any version since 2.2, though. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGUOYAAoJEPiOA0Bgp4/LS+oH/iirBETfcYYYtr3kaR/0JPMT iz4eEwCvReiXGdNE/AsIfB7aUCwlNPP+KBr3fq9e8N+a8OvM8pwGcDbYGJd92zxI atujVPZqYFWt8EfJEJBoqEmuofbnNlVdqzDaYFmrxQfXFxv2gl7wyEY1QH/udLt4 oL+zzNLgxMYGWp85Xrf/MLqqWOkp1Yk56m90oyU+DhzGnP15r/1jiQQ7/U6dydkc ZgJ09W7mZ7svOq4+pVG+rOk3UFQKEe3E1XO5nEreRp9KGwWp+qYE9XUCzxv40/Y2 WKUN3G5MJ1GvkdfeeNcf4a08mTNe1wtVJQdtUyBQzZ23eTxN0PqNZXwSkg2OIIg= =9nbT -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 02:45:15 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 01:45:15 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: Message-ID: <4E194A7B.30804@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 How should I go about switching from concatenation to string formatting for this? avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + dn_filter + fpsout_filter + trim_filter + info_filter) I can think of a few ways, but none of them are pretty. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGUp7AAoJEPiOA0Bgp4/L3koIAMntYStREGjww6yKGKE/xI0W ecAg2BHdqBxTFsPT6NMrSRyrNbdfnWRQcRi/0Z+Hhbwqp4qsz5hDFgsoVPkT5gyj 6q0TeJqaSE+Uoj5g2BofqVlWydyQ7fW34KaANbj7V71/UqXXgb+fl8TYvVRJbg0A KlfytOO0HBrDW8f6dzGZuxLxCb3EONt7buIUV3Pa7b9jQZNTTiOKktLtWAteMMiC CHivQhqzB8/cNVddpyk5LaMEDzJ9yz8a83fjuK8F5E/wrYk22t6Fad6PKgDEivaj hAiE5HMeUw+gQ7xFhJGkK31/KyHRqAaFR4mUh16u9GHMTaGPobk8NEj81LwCbvg= =g3kL -----END PGP SIGNATURE----- From stefan_ml at behnel.de Sun Jul 10 02:52:34 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 10 Jul 2011 08:52:34 +0200 Subject: Morelia for BDD in Python In-Reply-To: <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> Message-ID: Phlip, 10.07.2011 07:10: > On Jul 9, 8:38 pm, Ben Finney wrote: >> Phlip writes: >>> On Jul 9, 7:39 pm, mark curphey wrote: >> >>>> Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce....) >> >>> Morelia is "undermaintained" because it's finished. It attaches to any >>> pre-existing TestCase-style test runner, hence there's nothing to >>> maintain! >> >> It looks good! But it's not yet in Debian :-( > > Tx - I never added anything to a distro before! But..! > > 'sudo pip install morelia' just worked for me, on Ubuntu. I don't > think a python-morelia aptitude package would add any value. There's no "pip uninstall", though. Stefan From tjreedy at udel.edu Sun Jul 10 03:04:20 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jul 2011 00:04:20 -0700 Subject: What makes functions special? In-Reply-To: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7/9/2011 6:34 PM, Steven D'Aprano wrote: > Suppose instead an implementation of Python did not pre-compile the > function. Each time you called spam(n), the implementatio n would have to > locate the source code and interpret it on the spot. Would that be > allowed?" > > If that's your question, then I would call that a Python interpreter using > c.1960 technology (as opposed to a byte-code compiler, which all the main > implementations currently are). > > If that were the *only* difference, then I see no reason why it wouldn't be > allowed as an implementation of Python. A horribly slow implementation, but > still an implementation. while and for loops would also be terribly slow if their bodies were not compiled but were reinterpreted at the source code level for each loop. Having to reinterpred the compiled byte code for each loop does make them slower than compiled to native code C. Same as for functions. From vinay_sajip at yahoo.co.uk Sun Jul 10 03:23:12 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 10 Jul 2011 07:23:12 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > How would I do that with the newer formatting? I've tried: There are examples in the blog post I linked to earlier: http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun Jul 10 03:50:50 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 02:50:50 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> Message-ID: <4E1959DA.80600@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 02:23 AM, Vinay Sajip wrote: > There are examples in the blog post I linked to earlier: It seems that would require logutils. I'm trying to keep dependencies to a minimum in my project, but I'll take a look at logutils and see if there's anything else I could use. Thanks. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGVnZAAoJEPiOA0Bgp4/LvLoH/3DL2mf7UcI/JVrrYfRmh2gb oofQzskbFrIp74U9w+8Qdxu2dmgctIk7q0S+y6jKVbc1tk1SfqQS+wAIP058ckak SDq0AoVrTSYEee+cuAvMiGHZCom2Y49mzdbXEHOOLDYZi8y3KojOJEAm0PWMdpN6 1dIpojozNOZU3V4j91E5UXV4APe8ixXrjlWNwhxqiTITrMenCG6O0LfxVvnHedTl gKvpC2Sfr2ql1+Xo7Nl6Z5jbMjFb0m8DmYaPXpS7QU6KXHOD7L6wt9+iG4H2F146 aYXukjkTXu9nwtn2s6EVn2QUyImlfzxtpd+UrpfAb0mMwItdInTKOrCwAAHSHl0= =/VOv -----END PGP SIGNATURE----- From rafadurancastaneda at gmail.com Sun Jul 10 04:49:44 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 10 Jul 2011 10:49:44 +0200 Subject: How can I make a program automatically run once per day? In-Reply-To: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Message-ID: <4E1967A8.5010006@gmail.com> On 10/07/11 04:01, John Salerno wrote: > Thanks everyone! I probably should have said something like "Python, > if possible and efficient, otherwise any other method" ! :) > > I'll look into the Task Scheduler. Thanks again! You may use Celery http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html From vinay_sajip at yahoo.co.uk Sun Jul 10 05:47:08 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 10 Jul 2011 09:47:08 +0000 (UTC) Subject: String concatenation vs. string formatting References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1959DA.80600@gmail.com> Message-ID: Andrew Berg gmail.com> writes: > On 2011.07.10 02:23 AM, Vinay Sajip wrote: > > There are examples in the blog post I linked to earlier: > It seems that would require logutils. I'm trying to keep dependencies to > a minimum in my project, but I'll take a look at logutils and see if > there's anything else I could use. Thanks. You don't need logutils, just the BraceMessage class - which is shown in the blog post (around 10 lines). Feel free to use it with copy and paste :-) Regards, Vinay Sajip From bahamutzero8825 at gmail.com Sun Jul 10 06:10:02 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 05:10:02 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: <4E17661D.6020307@gmail.com> <4E18CFF8.1060908@gmail.com> <4E1959DA.80600@gmail.com> Message-ID: <4E197A7A.9040000@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 04:47 AM, Vinay Sajip wrote: > You don't need logutils, just the BraceMessage class - which is > shown in the blog post (around 10 lines). Feel free to use it with > copy and paste :-) I didn't realize that was the actual class when I first read it. Thanks. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGXp6AAoJEPiOA0Bgp4/LHhgH/2lLFrRPep9rBsmSVSc794YM w2A/e8KMTuChITTSa90WOsjqfIAkS1cvP7JWEJZ1QUqtZJMAWLhlZBaG8QuZRR2b OGBia15fzMEfHcWkNfLZ9fbZvSVZNH71YSA7bEbz5MYy+iBUcbmHI8KmQiJN1kI3 Be4uXH+l09iJBqgQKsfARzNcVxtauKylfla4/0aIWoumX6ioP+l6C+M/2iq+mYG5 w+NX1AWH2f85UT5Wlt3FcyNMP6PZHFZg+hojS4p+NVZChl7KMlJihWPSRxZNWhGp 0qf/qh9y4d1M2Kfo1C3DTDdpdL+tWWanlJ3ghXSF096/ylmytxivZ17utl3U5vA= =RQGa -----END PGP SIGNATURE----- From paul.nospam at rudin.co.uk Sun Jul 10 06:21:40 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 10 Jul 2011 11:21:40 +0100 Subject: How can I make a program automatically run once per day? References: Message-ID: <87r55y4erv.fsf@no-fixed-abode.cable.virginmedia.net> John Salerno writes: > I have a script that does some stuff that I want to run every day for > maybe a week, or a month. So far I've been good about running it every > night, but is there some way (using Python, of course) that I can make > it automatically run at a set time each night? Well - you can make a long lived python process that puts itself to sleep for 24 hours and then wakes up and does stuff, but the normal approach to this kind of thing is to use cron. On windows there's also some kind of scheduler. From kevin.misc.10 at gmail.com Sun Jul 10 09:20:52 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Sun, 10 Jul 2011 21:20:52 +0800 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: On Fri, Jul 8, 2011 at 8:37 PM, Billy Mays wrote: > > > I recently wrote a program after reading an article ( > http://www.hackerfactor.com/**blog/index.php?/archives/432-** > Looks-Like-It.html) using the DCT method he proposes. It worked surprisingly well even with > just the 64bit hash it produces. > > The link you provided was so great. It mentioned an implementation of the hash algorithm in Python though invalid, so I spent some time writing my own version. It works really fine and kind of solved the problem of finding duplicated pictures to delete I recently came across. Thanks Billy! ps. If anyone's interested, pleas checkout the source code in the attachment and welcome any advise. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pic_seeker.py Type: application/octet-stream Size: 3992 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Sun Jul 10 09:42:48 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2011 23:42:48 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e19ac59$0$29977$c3e8da3$5496439d@news.astraweb.com> Andrew Berg wrote: > How should I go about switching from concatenation to string formatting > for this? > > avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + > dn_filter + fpsout_filter + trim_filter + info_filter) > > I can think of a few ways, but none of them are pretty. fields = (demux_filter, field_filter, fpsin_filter, i2pfilter, dn_filter, fpsout_filter, trim_filter, info_filter) avs.write("%s"*len(fields) % fields) works for me. -- Steven From lanyjie at yahoo.com Sun Jul 10 10:21:43 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sun, 10 Jul 2011 07:21:43 -0700 (PDT) Subject: anonymous function with multiple statements Message-ID: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> Hi all, I wonder if Python provides a way to define anonymous functions containing multiple statements? With lambda form, we can only define a function of a single expression. In Javascript, it is possible to define a full-fledged anonymous functions, which suggests it is useful to have it. In Python, it might be like this: #============== def test( fn, K ): return sum(fn(i) for i in range(K))/K test( def (i): #indent from start of this line, not from 'def' from math import sin #the last statement ends with a ',' or ')'. return sin(i)+i*i;, 100) #';' to mark end of statement #another way: test( def (i): #indent from start of this line, not from 'def' from math import sin return sin(i)+i*i , 100) #freely place ',' anywhere #=============== Any thoughts? Yingjie From roy at panix.com Sun Jul 10 10:33:08 2011 From: roy at panix.com (Roy Smith) Date: Sun, 10 Jul 2011 10:33:08 -0400 Subject: String concatenation vs. string formatting References: Message-ID: In article , Andrew Berg wrote: > How should I go about switching from concatenation to string formatting > for this? > > avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter + > dn_filter + fpsout_filter + trim_filter + info_filter) > > I can think of a few ways, but none of them are pretty. The canonical way to do that would be something like fields = [demux_filter, field_filter, fpsin_filter, i2pfilter, dn_filter, fpsout_filter, trim_filter, info_filter] avs.write(''.join(fields)) From nobody at nowhere.net.no Sun Jul 10 10:50:11 2011 From: nobody at nowhere.net.no (TheSaint) Date: Sun, 10 Jul 2011 22:50:11 +0800 Subject: why the following python program does not face any concurrency problems without synchronize mechanism? References: Message-ID: smith jack wrote: > have run this program for many times,and the result is always 5050 You might not need to make it in a multiprocess environment Try it in the python (3) shell >>> tot= 0 >>> for k in range(1,100): ... tot += k ... print(tot) ... And watch the risults. -- goto /dev/null From phlip2005 at gmail.com Sun Jul 10 11:00:25 2011 From: phlip2005 at gmail.com (Phlip) Date: Sun, 10 Jul 2011 08:00:25 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: <303c5739-89ae-48ba-9680-c0218b33d66e@p29g2000pre.googlegroups.com> > I think it would add great value, since without it I'm unlikely to > bother using Morelia in any project. The maintenance burden is too high > to keep adding dependencies that come from a distinct dependency system > outside my OS. pip freeze! Specifically, we already added pip freeze and virtualenv support to our project's fab file... > There's no "pip uninstall", though. I can see that would matter to projects you would want to uninstall, but not Morelia... From tjreedy at udel.edu Sun Jul 10 11:20:34 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jul 2011 08:20:34 -0700 Subject: anonymous function with multiple statements In-Reply-To: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> References: <1310307703.11933.YahooMailRC@web121515.mail.ne1.yahoo.com> Message-ID: On 7/10/2011 7:21 AM, Yingjie Lan wrote: > I wonder if Python provides a way to define anonymous functions containing > multiple statements? No, intentionally not. Forget this idea. Multiple functions named '' are inferior for representation purposes, like in error tracebacks, to those with individual names. Just use def statements. Terry J. Reedy From phlip2005 at gmail.com Sun Jul 10 11:29:09 2011 From: phlip2005 at gmail.com (Phlip) Date: Sun, 10 Jul 2011 08:29:09 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> <303c5739-89ae-48ba-9680-c0218b33d66e@p29g2000pre.googlegroups.com> Message-ID: Two of my feature requests for Morelia: - integrate with the test runner (nose etc.) to provide one dot . per passing step - insert a long multi-line abstract string (typically XML) with inside [[CDATA-style escaping tags - the ability to stub a step as - the ability to pass a | delimited | table into a step as an argument containing an array, instead of unrolling the table into multiple calls to one step - a rapid conversion to an HTML report, with folding blocks, as an instant project documentation. Lack of the second option is why we _didn't_ use M for the BDD test runner on our latest project. (The onsite customer is an XML-freak, AND the lead architect until I can manage to retire him upstairs!;) But if I could put those four in, then write a disposable script that converted our XML "project definition" file back into Morelia-Cucumber- Gherkin notation, I'd have Morelia back in our project! From rantingrick at gmail.com Sun Jul 10 13:15:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 10:15:07 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> Message-ID: On Jul 4, 3:43?am, Gregory Ewing wrote: > rantingrick wrote: > > what concerns me is the fact that virtual methods in derived > > classes just blend in to the crowd. > > I think we really need some > > sort of visual cue in the form of forced syntactical notation (just > > like the special method underscores). > > If you're suggesting that it should be impossible to override > a method unless it is specially marked somehow in the base > class, I think that would be a bad idea. Sorry i did explain properly... No NOT marked in the BASE class but marked in the DERIVED class! My concerns are from a readability standpoint. Here's a naive example... class Top(object): def __init__(self): pass def m1(self): """overide""" return True def m2(self): print 'm2' def Derived(Top): def __init__(self): Top.__init__(self) def m1(self): return False My argument is this... """If class "Derived" exists in another module the reader has no idea which methods where clobbered and which were not WITHOUT being intimate with the entire code base.""" I suggest we solve this dilemma by forcing a syntax "tag" when declaring clobbering virtual functions. And if someone forgets to include the tag python would throw an exception. This has the effect of making the code MUCH easier to follow by the human readers. And it put NO constraints on the API. Also it has the added effect of warning unsuspecting programmers of name clashes that would otherwise not produce an error. > One of the principles behind the design of Eiffel is that > classes should *always* be open to modification in any way > by a subclass. The reason is that the author of a class > library can't anticipate all the ways people might want to > use it. Consequently Eiffel has no equivalent of C++'s > "private" declaration -- everything is at most "protected". > It also has no equivalent of Java's "final". Exactly! We should never put limits on what methods CAN be virtual. However, we CAN enforce a syntax that removes ambiguity from the equation. From rosuav at gmail.com Sun Jul 10 13:30:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 03:30:12 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: References: <97dcpqFdndU1@mid.individual.net> Message-ID: On Mon, Jul 11, 2011 at 3:15 AM, rantingrick wrote: > ?I suggest we solve this dilemma by forcing a syntax "tag" when > declaring clobbering virtual functions. Python has other dilemmas, too. I suggest we adopt the same solution. For instance, every statement should begin with a marker, so that we know it isn't a comment; every variable name should be adorned, so that we know it's not a keyword like 'if'; and every decimal integer should begin with "0d" so that we know it isn't hex. Plus, we should get rid of binary operators with their messy precedence tables; everything should become function calls. $assign($x,$add(0d5,0d7)) # assigns 12 (decimal) to x This would make Python far less ambiguous. We should proceed with this right away. ChrisA From tim at johnsons-web.com Sun Jul 10 13:41:21 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 09:41:21 -0800 Subject: Function docstring as a local variable Message-ID: <20110710174121.GB12935@johnsons-web.com> Consider the following: ## code def test(): """This is my docstring""" print(??) ## can I print the docstring above? ## /code It possible for a function to print it's own docstring? thanks (pointers to docs could be sufficient) -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From rantingrick at gmail.com Sun Jul 10 13:44:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 10:44:30 -0700 (PDT) Subject: Function docstring as a local variable References: Message-ID: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> On Jul 10, 12:41?pm, Tim Johnson wrote: > It possible for a function to print it's own docstring? def f(): """docstring""" print "docstring" any questions? From rustompmody at gmail.com Sun Jul 10 13:45:01 2011 From: rustompmody at gmail.com (rusi) Date: Sun, 10 Jul 2011 10:45:01 -0700 (PDT) Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: On Jul 10, 10:21?am, Ben Finney wrote: > Phlip writes: > > 'sudo pip install morelia' just worked for me, on Ubuntu. > > The problem with ?pip? is that it's a parallel package installation that > ignores the available package management system on the OS. > > That's not a fault of ?pip? or Setuptools or PyPI or the rest; but it's > a higher maintenance burden for the user than getting a package from the > same system that provides all the rest of their packages on the > computer. > > On operating systems with poor package management, Python's distutils > and PyPI etc. are better than nothing. But on an OS like Debian with > good package management already for free software, it's a step backward > to rely on external dependencies from a disjoint package system. Just curious: Do you manage to stay within debian packages and have all the python packages you want/need at the versions that are most convenient? For myself, until recently my debian testing did not even give python2.7. From bahamutzero8825 at gmail.com Sun Jul 10 13:47:17 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 12:47:17 -0500 Subject: Function docstring as a local variable In-Reply-To: <20110710174121.GB12935@johnsons-web.com> References: <20110710174121.GB12935@johnsons-web.com> Message-ID: <4E19E5A5.5020905@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 12:41 PM, Tim Johnson wrote: > It possible for a function to print it's own docstring? >>> def test(): ... """Hi there.""" ... print(test.__doc__) ... >>> test() Hi there. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGeWlAAoJEPiOA0Bgp4/LT1EIAM32NS/RdZ9y6IlAkpEYkYeP qGf2A/+8eZHrSYtCWYWwpfusa9guYaQsDvq31sFHnI3VPria7mUeB6HoyqP1sO3B 5D0lpBK0/u3rWNL9FHeWeb+Cc6CLXBB7531VAR1pzfUVb1mw3LPww16klNMkr5Gd 9Qob710lKIW+om8rEF+L5o/DOFSTN7oodTsNpdj8zhHVnPVpV/gtL7iQR82C0KPq UuukVkCuhvYyWoJMz1qDZjKU1bI2T064TC8IeOQLdOVMnQLhTJdgsHD4nNVszixN EU9eemscW0cABF2MgUPnuJLytUJHcxtEC4aj3Cue0oLhMyVN57yNIBaf1Pm6M7E= =tCFP -----END PGP SIGNATURE----- From rosuav at gmail.com Sun Jul 10 14:11:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 04:11:14 +1000 Subject: Function docstring as a local variable In-Reply-To: <4E19E5A5.5020905@gmail.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: On Mon, Jul 11, 2011 at 3:47 AM, Andrew Berg wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: RIPEMD160 > > On 2011.07.10 12:41 PM, Tim Johnson wrote: >> It possible for a function to print it's own docstring? >>>> def test(): > ... ? ? """Hi there.""" > ... ? ? print(test.__doc__) That's assuming that it knows its own name, and that that name hasn't been rebound. Is there a way for a function to find its own self? >>> def findself(): """Find myself. Ooh look, there I am!""" import sys try: 1/0 except: traceback=sys.exc_info()[2] # Now I'm not sure what to do with traceback. # traceback.tb_frame.f_code.co_name is the function name ("findself"). # Is there a way to get the function object? I'm kinda half-way there, but I've never worked with traceback objects. Someone will know, I'm sure! ChrisA ChrisA From bruce at whealton.info Sun Jul 10 15:28:40 2011 From: bruce at whealton.info (Bruce Whealton) Date: Sun, 10 Jul 2011 15:28:40 -0400 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <4E19121F.4010203@gmail.com> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> <4E19121F.4010203@gmail.com> Message-ID: <5DF6A565818746A89E82DC7D3375C181@BrucePC> Thanks for the tips. I actually had done some studies with Python, mainly Python 3, back about 6 months ago and over a period of a few months. I didn't write a great deal of programs though, at the time. I got away from it in a while and I didn't want to go back to step one of being like a total beginner. There are so many things I try to keep up with as a Web Developer and coder and trying to expand my skills. Unfortunately, I don't do well with picking a focus. I remember reading through this long reference manual, called "Learning Python," while I was on a flight and over a trip. That was without a computer, so I was just reading, which is not the way to learn programming, obviously. I feel the many concepts will come back to me fast. I have another text, called "Beginning Python: From Novice to Professional" which covers Python 3. This is a bit more practical in orientation. I'm debating whether to jump to the chapters dealing with the web and see what I can do or starting from the beginning. I did look into some online training, tutorials, or the like. The Programming the Semantic Web book uses Python but all the code is included. So, while it won't be a way to learn python, I hope I can get the code to run correctly. In that text, they must be using Python 2.7 because I see print statements and not the print function call. If you know of any good resources for finding python applications on the web, this might be a good way to learn. I don't know if I should look for Python applications, or if I'll have more luck looking for Python Libraries. Thanks, Bruce -----Original Message----- From: Andrew Berg Sent: Saturday, July 09, 2011 10:44 PM To: comp.lang.python Subject: Re: Newbie help - Programming the Semantic Web with Python On 2011.07.09 08:32 PM, Bruce Whealton wrote: > Hello, > So, I got this book on Programming the Semantic Web about > the same time I started learning Python. The code seems to be > developed for python 2.7 and not 3, I believe. If you're going to learn Python 3, I suggest learning from a book that deals with Python 3 (if there's not an updated text for the area you're dealing with, go with something that teaches the basics). Once you have the basics down and you know the common differences, then it will be much easier to learn from a text that's based on Python 2 (you'll stumble a whole lot less when trying to learn from such texts). You'll also find some things in Python 3 that have been added to recent versions of Python 2 that the text may not cover (e.g., the old % string formatting syntax vs. the new format() string method). > If I was using python 3, it would require () around the thing that is > going to be printed, right? That's not really the right way to think of the print() function. The print statement has some very arbitrary syntax that could cause unexpected behavior if simply put in the print() function. The print function has parameters for optional behavior rather than odd syntax. In the simplest cases, print and print() are extremely similar, but print() has a bunch of functionality that is either difficult/annoying to decipher (for humans, not the interpreter) or simply doesn't exist in print. -- http://mail.python.org/mailman/listinfo/python-list From tim at johnsons-web.com Sun Jul 10 16:34:36 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 12:34:36 -0800 Subject: Function docstring as a local variable In-Reply-To: <4E19E5A5.5020905@gmail.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: <20110710203436.GC12935@johnsons-web.com> * Andrew Berg [110710 09:59]: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: RIPEMD160 > > On 2011.07.10 12:41 PM, Tim Johnson wrote: > > It possible for a function to print it's own docstring? > >>> def test(): > ... """Hi there.""" > ... print(test.__doc__) Holy Moly. Of course! thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From tyler at tysdomain.com Sun Jul 10 16:59:29 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 10 Jul 2011 14:59:29 -0600 Subject: parsing packets Message-ID: <4E1A12B1.8060205@tysdomain.com> Hello all: I'm working on a server that will need to parse packets sent from a client, and construct it's own packets. The setup is something like this: the first two bytes is the type of the packet. So, lets say we have a packet set to connect. There are two types of connect packet: a auth packet and a connect packet. The connect packet then has two bytes with the type, another byte that notes that it is a connect packet, and 4 bytes that contains the version of the client. The auth packet has the two bytes that tells what packet it is, one byte denoting that it is an auth packet, then the username, a NULL character, and a password and a NULL character. With all of this said, I'm kind of curious how I would 1) parse out something like this (I am using twisted, so it'll just be passed to my Receive function), and how I get the length of the packet with multiple NULL values. I'm also looking to build a packet and send it back out, is there something that will allow me to designate two bytes, set individual bits, then put it altogether in a packet to be sent out? -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 My programs don't have bugs; they're randomly added features! From chardster at gmail.com Sun Jul 10 17:16:05 2011 From: chardster at gmail.com (Richard Thomas) Date: Sun, 10 Jul 2011 14:16:05 -0700 (PDT) Subject: Function docstring as a local variable References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> Message-ID: > >>> def findself(): > > ? ? ? ? """Find myself. Ooh look, there I am!""" > ? ? ? ? import sys > ? ? ? ? try: > ? ? ? ? ? ? ? ? 1/0 > ? ? ? ? except: > ? ? ? ? ? ? ? ? traceback=sys.exc_info()[2] > ? ? ? ? # Now I'm not sure what to do with traceback. > ? ? ? ? # traceback.tb_frame.f_code.co_name is the function name ("findself"). > ? ? ? ? # Is there a way to get the function object? I'm pretty sure there isn't. I've tried a number of times before to find it but failed. Fundamentally frame objects don't need to know about functions. Functions are just one way of wrapping code objects but sometimes code objects come in modules. You can use sys._getframe() to get the current frame instead of the traceback. Richard From debatem1 at gmail.com Sun Jul 10 17:34:10 2011 From: debatem1 at gmail.com (geremy condra) Date: Sun, 10 Jul 2011 17:34:10 -0400 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > The setup is something like this: the first two bytes is the type of the > packet. > So, lets say we have a packet set to connect. There are two types of connect > packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that notes > that it is a connect packet, and 4 bytes that contains the version of the > client. > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, and > a password and a NULL character. > > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), and how I get the length of the packet with multiple NULL > values. I'm also looking to build a packet and send it back out, is there > something that will allow me to designate two bytes, set individual bits, > then put it altogether in a packet to be sent out? Just use the struct module[0] to do your packing for you. There's not enough info in your description to write it out for you, but it sounds like it should do everything you need. Geremy Condra [0]: http://docs.python.org/library/struct.html From bahamutzero8825 at gmail.com Sun Jul 10 17:45:57 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 16:45:57 -0500 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: <5DF6A565818746A89E82DC7D3375C181@BrucePC> References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> <4E19121F.4010203@gmail.com> <5DF6A565818746A89E82DC7D3375C181@BrucePC> Message-ID: <4E1A1D95.1040702@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 02:28 PM, Bruce Whealton wrote: > If you know of any good resources for finding python applications on > the web, this might be a good way to learn. I don't know if I > should look for Python applications, or if I'll have more luck > looking for Python Libraries. Tutorials and simple code examples are the best way to learn (walk before you run). If you tried to study the standard libraries (or any but the simplest libraries on PyPI), you'd get lost. Studying the standard libraries would probably be a good way to learn good design once you have a great command of the language. Of course, actually doing a project to solve a real problem is probably the best way to learn once you have the basics down (I'm learning a lot doing my first Python project). - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGh2VAAoJEPiOA0Bgp4/LIjoIAOaAnLWpPwRvwZm2VxhnA5CY dNEJvEU4DyCvqKBOQ5Eh0NKgK7M81+sibgqsIqKLzIdUdK9io7zVQ+mYfS0h40TO WzYOTX54Tx1d9w9K2/UWNAz+csWJ06TSsHDDVmhQ1JdHAhWz9EM4RzSt96RtdHsc 1dh/UtWTpn6Fm+9o2nIJ/471ZwtxAjOENprrC8SGchRT9mxlNvOyWe9+N3xr/g6l qqGHHqSfazQU1wqbEbyvQxB0CsJ5kVVm764c0a1tkiVcGT6o+e93zB1tm0Di4KNe gbDXVHtfo5jQIKCs8utt0a+m4IMzuU182MLz05ngWIQxIbhHW/zBNfw2pMxRxBA= =RFgH -----END PGP SIGNATURE----- From ben+python at benfinney.id.au Sun Jul 10 17:57:21 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 07:57:21 +1000 Subject: Morelia for BDD in Python References: <871uxyhkj5.fsf_-_@benfinney.id.au> <91740322-7b3f-452f-aba6-8c37aaea71b2@j9g2000prj.googlegroups.com> <87wrfqg17p.fsf@benfinney.id.au> Message-ID: <87hb6tg5oe.fsf@benfinney.id.au> rusi writes: > Just curious: Do you manage to stay within debian packages and have > all the python packages you want/need at the versions that are most > convenient? When that's not the case, I consider it not a status quo to live with, but a problem to be addressed. -- \ ?I cannot conceive that anybody will require multiplications at | `\ the rate of 40,000 or even 4,000 per hour ?? ?F. H. Wales, 1936 | _o__) | Ben Finney From egriffith92 at gmail.com Sun Jul 10 18:06:37 2011 From: egriffith92 at gmail.com (Eric) Date: Sun, 10 Jul 2011 18:06:37 -0400 Subject: A beginning programmer Message-ID: Greetings everyone; Fresh High School graduate here with a passion for problem solving. My last 2 years of HS I took programming courses (actually fairly good ones; yay for good tech departments) that showed me QuickBasic VisualBasic C++ Java (in that order) A friend of mine often talked about how nice Python was and being an xkcd fan, i saw Python come up alot in the jokes. Python's awesome; I see limitless possibilities in a very easy to understand and use language that as xkcd put it "Programmings fun again!" My problem is this though... I don't know what to do with this new found knowledge of these languages. I'm a linux user so availability of development tools is haaaaaaardly a problem. But I just don't know what to do with it, I don't have any problems that need to be solved and unfortunately I'm not familar enough with the languages (except maybe c++) to help out the big projects like KDE / Gnome. I realize this is the python mailing list and that I brought up some non-python languages but I'm sure my situation is hardly new for those looking to get into programming but having no idea of where to begin. Any feedback is much appreciated! -Eric- From python at bdurham.com Sun Jul 10 18:13:29 2011 From: python at bdurham.com (python at bdurham.com) Date: Sun, 10 Jul 2011 18:13:29 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <20110710174121.GB12935@johnsons-web.com><4E19E5A5.5020905@gmail.com> Message-ID: <1310336009.20776.2150240761@webmail.messagingengine.com> I'm not sure how a function can get a generic handle to itself, but if you're willing to hardcode the function name, then this technique works: def test(): """This is my doc string""" print test.__doc__ test() Outputs: This is my doc string Malcolm From t at jollybox.de Sun Jul 10 18:22:38 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 00:22:38 +0200 Subject: A beginning programmer In-Reply-To: References: Message-ID: <4E1A262E.5040108@jollybox.de> On 07/11/2011 12:06 AM, Eric wrote: > My problem is this though... I don't know what to do with this new > found knowledge of these languages. I'm a linux user so availability > of development tools is haaaaaaardly a problem. But I just don't know > what to do with it, I don't have any problems that need to be solved > and unfortunately I'm not familar enough with the languages (except > maybe c++) to help out the big projects like KDE / Gnome. Open source bug trackers are a great source of problems. Take an open source program you like, ideally one with a sizeable and active user base, written in a programming language you're comfortable with, check out an open bug, and try solving it. This will * Get you reading other people's code. You can learn a lot from this * Provide a challenge * Do good CPython itself is a great project to have a go at. I don't know how familiar you are with C (as opposed to C++), but a large part of the code is written in Python, there's loads of activity on the bug tracker, and, in my experience, the community is very happy to help along new people contributing their first patch. Cheers, Thomas From bahamutzero8825 at gmail.com Sun Jul 10 18:24:46 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 17:24:46 -0500 Subject: A beginning programmer In-Reply-To: References: Message-ID: <4E1A26AE.4090401@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 05:06 PM, Eric wrote: > But I just don't know what to do with it You and I are quite different. I don't enjoy programming much, but Python is a great tool to accomplish a few goals that I have. > I don't have any problems that need to be solved and unfortunately > I'm not familar enough with the languages (except maybe c++) to help > out the big projects like KDE / Gnome. The KDE for Windows project is really struggling. You could help there with your C++ skills. > I realize this is the python mailing list and that I brought up some > non-python languages but I'm sure my situation is hardly new for > those looking to get into programming but having no idea of where to > begin. I could use some help on my project, but two inexperienced coders are going to be slower than one. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGiatAAoJEPiOA0Bgp4/LqxkH/1fbq+m0uyQDAV38mJq861HC a4r3XZAka5BbGqIF753LRMzPdd31RpTiv+AUWtF7/AUVE+b0UsHaBDvyVvSBRcw9 XGwXUOy9WWtpeGS5CaKyJumMJStzzhCGetKeX+86F7RB6XgiBOCAFuaH4NRCpkYb 4y+Kg+0FqzYJk/lW9J/ZsoqyIbloet7zDC1EkrmwsfsodoTqL/NqRW4MY0u9PzU3 HTg2hBshj8EGe1wLG1DHxR7q/T88GuQZq7f6dYjwLmyljzs21cIj+Dn2d7nhbPpi KwszNCpENbn4fssUh+xca71kd4S2zWEkxz0gLkVPdsuVffWKkLgrY8flnqVuXQk= =NFjK -----END PGP SIGNATURE----- From cjw at ncf.ca Sun Jul 10 18:28:15 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 10 Jul 2011 18:28:15 -0400 Subject: Function docstring as a local variable In-Reply-To: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: On 10-Jul-11 13:44 PM, rantingrick wrote: > On Jul 10, 12:41 pm, Tim Johnson wrote: >> It possible for a function to print it's own docstring? > > def f(): > """docstring""" > print "docstring" > > any questions? Try: def f(): ds= """docstring""" print ds > Colin W. From roy at panix.com Sun Jul 10 18:41:51 2011 From: roy at panix.com (Roy Smith) Date: Sun, 10 Jul 2011 18:41:51 -0400 Subject: Function docstring as a local variable References: <20110710174121.GB12935@johnsons-web.com> Message-ID: In article , python at bdurham.com wrote: > I'm not sure how a function can get a generic handle to itself, but if > you're willing to hardcode the function name, then this technique works: > > def test(): > """This is my doc string""" > print test.__doc__ > > test() > > Outputs: > > This is my doc string > > Malcolm I'm sure there has to be a cleaner way that this, but one possible way for a function to find its name is to catch an exception and look at the traceback: --------------------------------------- #!/usr/bin/env python import sys import traceback def foo(): "The Larch" try: raise Exception except Exception, ex: _, _, tb = sys.exc_info() stacks = traceback.extract_tb(tb) file_name, line_number, function_name, text = stacks[0] print "I am %s", function_name print "My docstring is", eval(function_name).__doc__ foo() -------------------------------------- This works, but yuck. From t at jollybox.de Sun Jul 10 18:42:16 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 00:42:16 +0200 Subject: A beginning programmer In-Reply-To: <4E1A262E.5040108@jollybox.de> References: <4E1A262E.5040108@jollybox.de> Message-ID: <4E1A2AC8.2070604@jollybox.de> On 07/11/2011 12:22 AM, Thomas Jollans wrote: > On 07/11/2011 12:06 AM, Eric wrote: >> My problem is this though... I don't know what to do with this new >> found knowledge of these languages. I'm a linux user so availability >> of development tools is haaaaaaardly a problem. But I just don't know >> what to do with it, I don't have any problems that need to be solved >> and unfortunately I'm not familar enough with the languages (except >> maybe c++) to help out the big projects like KDE / Gnome. > > Open source bug trackers are a great source of problems. Take an open > source program you like, ideally one with a sizeable and active user > base, written in a programming language you're comfortable with, check > out an open bug, and try solving it. This will > * Get you reading other people's code. You can learn a lot from this > * Provide a challenge > * Do good Do note: Maybe you won't be able to create quality patches at first. But you'll familiarize yourself with the language (and project) in time, and if you follow a bug on a bug tracker, you can, when somebody else has fixed it, study their patch as well. It's like a puzzle ;-) As Andrew pointed out, KDE is written in C++. So you might want to check that out. > > CPython itself is a great project to have a go at. I don't know how > familiar you are with C (as opposed to C++), but a large part of the > code is written in Python, there's loads of activity on the bug tracker, > and, in my experience, the community is very happy to help along new > people contributing their first patch. > > Cheers, > Thomas From steve+comp.lang.python at pearwood.info Sun Jul 10 18:48:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2011 08:48:29 +1000 Subject: String concatenation vs. string formatting References: Message-ID: <4e1a2c3e$0$29966$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > The canonical way to do that would be something like > > fields = [demux_filter, > field_filter, > fpsin_filter, > i2pfilter, > dn_filter, > fpsout_filter, > trim_filter, > info_filter] > avs.write(''.join(fields)) I can't believe I didn't think of that. I must be getting sick. (The sore throat, stuffy nose and puffy eyes may also be a sign.) Yes, ''.join() is far to be preferred over my solution using "%s". -- Steven From tim at johnsons-web.com Sun Jul 10 18:50:18 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 14:50:18 -0800 Subject: Function docstring as a local variable In-Reply-To: <1310336009.20776.2150240761@webmail.messagingengine.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> <1310336009.20776.2150240761@webmail.messagingengine.com> Message-ID: <20110710225018.GD12935@johnsons-web.com> * python at bdurham.com [110710 14:17]: > I'm not sure how a function can get a generic handle to itself, but if > you're willing to hardcode the function name, then this technique works: > > def test(): > """This is my doc string""" > print test.__doc__ > > test() Works for me. Works for the application I'm after. thanks Here's a related question: I can get the docstring for an imported module: >>> import tmpl as foo >>> print(foo.__doc__) Python templating features Author - tim at akwebsoft dot com ## Is it possible to get the module docstring ## from the module itself? Thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From ikljaic at gmail.com Sun Jul 10 18:50:31 2011 From: ikljaic at gmail.com (Ivan Kljaic) Date: Sun, 10 Jul 2011 15:50:31 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python Message-ID: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Ok Guys. I know that most of us have been expiriencing the need for a nice Gui builder tool for RAD and most of us have been googling for it a lot of times. But seriously. Why is the not even one single RAD tool for Python. I mean what happened to boa constructor that it stopped developing. I simply do not see any reasons why there isn't anything. Please help me understand it. Any insights? From pavlovevidence at gmail.com Sun Jul 10 18:59:02 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 10 Jul 2011 15:59:02 -0700 (PDT) Subject: Function docstring as a local variable In-Reply-To: Message-ID: On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > Here's a related question: > I can get the docstring for an imported module: > >>> import tmpl as foo > >>> print(foo.__doc__) > Python templating features > > Author - tim at akwebsoft dot com > > ## Is it possible to get the module docstring > ## from the module itself? print __doc__ Carl Banks From kb1pkl at aim.com Sun Jul 10 19:00:11 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:00:11 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <1310338587-sup-7938@dalek> Excerpts from Colin J. Williams's message of Sun Jul 10 18:28:15 -0400 2011: > Try: > > def f(): > ds= """docstring""" > print ds That doesn't actually make a docstring, though. It makes a string object and points the name ds at it. Do you know what a docstring is? def foo(): """I am a docstring""" pass def bar(): ds = "I am not a docstring!" def baz(): "I am a docstring too!" pass def qux(): 'And even me! Quote type don't matter (besides style)' pass -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From kb1pkl at aim.com Sun Jul 10 19:03:47 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:03:47 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310338946-sup-2322@dalek> Excerpts from Ivan Kljaic's message of Sun Jul 10 18:50:31 -0400 2011: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? What is RAD? If you're just looking for a GUI builder there's Glade for gtk, wxGlade for wxWidgets, QtCreator (And something new for their newer system, don't remember the name), etc. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From kb1pkl at aim.com Sun Jul 10 19:06:27 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 19:06:27 -0400 Subject: Function docstring as a local variable In-Reply-To: References: Message-ID: <1310339164-sup-5162@dalek> Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > print __doc__ > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def foo(): ... "Docstring" ... print __doc__ ... >>> foo() None >>> What does yours do? -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From python.list at tim.thechases.com Sun Jul 10 19:14:53 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 10 Jul 2011 18:14:53 -0500 Subject: Function docstring as a local variable In-Reply-To: <20110710225018.GD12935@johnsons-web.com> References: <20110710174121.GB12935@johnsons-web.com> <4E19E5A5.5020905@gmail.com> <1310336009.20776.2150240761@webmail.messagingengine.com> <20110710225018.GD12935@johnsons-web.com> Message-ID: <4E1A326D.3050107@tim.thechases.com> On 07/10/2011 05:50 PM, Tim Johnson wrote: > * python at bdurham.com [110710 14:17]: >> def test(): >> """This is my doc string""" >> print test.__doc__ >> test() > > Works for me. Works for the application I'm after. thanks > Here's a related question: > ## Is it possible to get the module docstring > ## from the module itself? You're gonna kick yourself :) print __doc__ -tkc From bahamutzero8825 at gmail.com Sun Jul 10 19:24:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 18:24:33 -0500 Subject: String concatenation vs. string formatting In-Reply-To: References: Message-ID: <4E1A34B1.5010205@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 09:33 AM, Roy Smith wrote: > The canonical way to do that would be something like > > fields = [demux_filter, field_filter, fpsin_filter, i2pfilter, > dn_filter, fpsout_filter, trim_filter, info_filter] > avs.write(''.join(fields)) That would look really awful (IMO) if the strings weren't intended to be on separate lines (I use embedded newlines instead of joining them with newlines in order to prevent blank lines whenever a certain filter isn't used). In this particular case, they are, so even though it uses a lot of whitespace, it does match the layout of its output. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGjSxAAoJEPiOA0Bgp4/LHzcH+gKeSCkbdEh8jg2UV0vICJdS Fea95/vqCbZkjQxSuW8L73CpoACiv4XQ6hoxyIUq7maf+W89rGMVmLsPWYXtmif9 FV6WM3kSpg4hoC1cbqGW5g1bnpMnSPlznm74mKtdGhF+3zEtlm9+j8m53362YQHc 0Y9D+4KAeee5QUT/NII5QBRvSG2rAuv5+sayMNayix0pCJLEGrRLp/7LJOyhvJLN eDdywE+svfcQAi4iGAylrmvDfgf6pBgysyY/pv2YD9IpdpYL5mkVqLi+ADZdZBOb M4uxBReowgC/RaWxB+qEvfg5AxWmfg4uCtAl48Z/Jv/uYR9d9jeHAlbuV2xPfnk= =wRB5 -----END PGP SIGNATURE----- From bahamutzero8825 at gmail.com Sun Jul 10 19:27:53 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jul 2011 18:27:53 -0500 Subject: Function docstring as a local variable In-Reply-To: <1310339164-sup-5162@dalek> References: <1310339164-sup-5162@dalek> Message-ID: <4E1A3579.2050500@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.10 06:06 PM, Corey Richardson wrote: > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) [GCC 4.4.5] on > linux2 Type "help", "copyright", "credits" or "license" for more > information. >>>> def foo(): > ... "Docstring" ... print __doc__ ... >>>> foo() > None I get the same result with Python 3.2. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOGjV5AAoJEPiOA0Bgp4/LF2YH/jaEjS6sFuwekVG0cKyjnx/z 8j28OHB9mklXg6oEMSsypU5dVPst2a6fmEHm+sXPYgQHZ9tk0oun+xxmdldNyV8h knfFVgMC5ww1Q7gLkPWzY8me3k4YcokYGhsuwXEGBvPby4M4ZC5uyetKTzVWp+uH sO11DPBaaXzGj7E7wu+HbfWsvPxw9h9jfJ7ihjhHNSUiL3MkGEqlxK8Pw2o3cw1e sCY7XWm1x8qClJLrwwxnB7pfuOfNJ6aS3xLd8FFs4hRp1J9W+z4on91XZooa5kT+ UEfkrzppOjw1UNA1etxIGmJQ+/qrKSGg5Nmc4jHXNfwIZCECHuWxEqaL5e0WdHU= =5gdS -----END PGP SIGNATURE----- From mhrivnak at hrivnak.org Sun Jul 10 19:33:38 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Sun, 10 Jul 2011 19:33:38 -0400 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: In order to find the end of the packet, include a field that is the packet length. This is what IP packets do to find the end of their header. http://en.wikipedia.org/wiki/IPv4#Header And the TCP header (see "data offset") does the same: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure Of course in both cases they are specifying the header length, not including a data payload. However, it sounds like you might not have a payload, so your entire packet might consist of header-like data. Michael On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > The setup is something like this: the first two bytes is the type of the > packet. > So, lets say we have a packet set to connect. There are two types of connect > packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that notes > that it is a connect packet, and 4 bytes that contains the version of the > client. > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, and > a password and a NULL character. > > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), and how I get the length of the packet with multiple NULL > values. I'm also looking to build a packet and send it back out, is there > something that will allow me to designate two bytes, set individual bits, > then put it altogether in a packet to be sent out? > > -- > > Take care, > Ty > my website: > http://tds-solutions.net > my blog: > http://tds-solutions.net/blog > skype: st8amnd127 > My programs don't have bugs; they're randomly added features! > > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Sun Jul 10 19:48:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 09:48:46 +1000 Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <87d3hhg0ip.fsf@benfinney.id.au> "Colin J. Williams" writes: > On 10-Jul-11 13:44 PM, rantingrick wrote: > > On Jul 10, 12:41 pm, Tim Johnson wrote: > >> It possible for a function to print it's own docstring? > > > > def f(): > > """docstring""" > > print "docstring" > > Try: > > def f(): > ds= """docstring""" > print ds The OP wants the function to print its own docstring, which your example does not do. You've defined a function with an empty docstring. >>> def foo(): ... ds = "The Larch" ... print ds ... >>> foo.__doc__ >>> -- \ ?Firmness in decision is often merely a form of stupidity. It | `\ indicates an inability to think the same thing out twice.? | _o__) ?Henry L. Mencken | Ben Finney From cmpython at gmail.com Sun Jul 10 19:49:51 2011 From: cmpython at gmail.com (CM) Date: Sun, 10 Jul 2011 16:49:51 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Jul 10, 6:50?pm, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? Just because Boa Constructor stopped (or lengthily paused?) development doesn't mean it doesn't exist. It does, and (at least on Windows), it is, IMO, really good. So why don't you use it? Che From tim at johnsons-web.com Sun Jul 10 20:00:54 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 16:00:54 -0800 Subject: Function docstring as a local variable In-Reply-To: References: Message-ID: <20110711000054.GF12935@johnsons-web.com> * Carl Banks [110710 15:18]: > On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > Here's a related question: > > I can get the docstring for an imported module: > > >>> import tmpl as foo > > >>> print(foo.__doc__) > > Python templating features > > > > Author - tim at akwebsoft dot com > > > > ## Is it possible to get the module docstring > > ## from the module itself? > > > print __doc__ Thanks Carl. Where is general documentation on the subject of variables beginning with 2 underscores? I'm presuming the key phrase is 'builtin variables'. I'm searching too ... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From clp2 at rebertia.com Sun Jul 10 20:09:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 10 Jul 2011 17:09:27 -0700 Subject: Function docstring as a local variable In-Reply-To: <20110711000054.GF12935@johnsons-web.com> References: <20110711000054.GF12935@johnsons-web.com> Message-ID: On Sun, Jul 10, 2011 at 5:00 PM, Tim Johnson wrote: > * Carl Banks [110710 15:18]: >> On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: >> > ?## Is it possible to get the module docstring >> > ?## from the module itself? >> >> print __doc__ > ?Thanks Carl. > > ?Where is general documentation on the subject of variables > ?beginning with 2 underscores? > > ?I'm presuming the key phrase is 'builtin variables'. I'm searching > ?too ... I've never heard that phrase used to describe __doc__ or its friends. Look in the "underscore" section of the documentation index: http://docs.python.org/genindex-_.html Cheers, Chris From clp2 at rebertia.com Sun Jul 10 20:16:23 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 10 Jul 2011 17:16:23 -0700 Subject: Function docstring as a local variable In-Reply-To: <1310339164-sup-5162@dalek> References: <1310339164-sup-5162@dalek> Message-ID: On Sun, Jul 10, 2011 at 4:06 PM, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: >> print __doc__ >> > > Python 2.7.1 (r271:86832, Jul ?8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def foo(): > ... ? ? "Docstring" > ... ? ? print __doc__ > ... >>>> foo() > None >>>> > > > What does yours do? The question Carl's code was in answer to was, slightly paraphrased: "Is it possible to get a *module*'s docstring from within the module itself?" The question had nothing to do with *function* docstrings. The interactive interpreter environment also isn't quite a true module, so you can't give it a docstring or really test the relevant feature there. Try this instead: $ cat test.py """I am the docstring of the `test` module!""" print("This module's docstring is:", __doc__) $ python test.py This module's docstring is: I am the docstring of the `test` module! $ Cheers, Chris -- http://rebertia.com From tim at johnsons-web.com Sun Jul 10 20:21:59 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 10 Jul 2011 16:21:59 -0800 Subject: Function docstring as a local variable In-Reply-To: References: <20110711000054.GF12935@johnsons-web.com> Message-ID: <20110711002159.GG12935@johnsons-web.com> * Chris Rebert [110710 16:14]: > > > > ?Where is general documentation on the subject of variables > > ?beginning with 2 underscores? > > I've never heard that phrase used to describe __doc__ or its friends. :) That why I wasn't satified with my search results. > Look in the "underscore" section of the documentation index: > http://docs.python.org/genindex-_.html And that is what I was looking for. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From kb1pkl at aim.com Sun Jul 10 20:26:02 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sun, 10 Jul 2011 20:26:02 -0400 Subject: Function docstring as a local variable In-Reply-To: References: <1310339164-sup-5162@dalek> Message-ID: <1310343648-sup-869@dalek> Excerpts from Chris Rebert's message of Sun Jul 10 20:16:23 -0400 2011: > The question Carl's code was in answer to was, slightly paraphrased: > "Is it possible to get a *module*'s docstring from within the module > itself?" > The question had nothing to do with *function* docstrings. > Ah. My bad, thank you for clarifying. -- Corey Richardson "Those who deny freedom to others, deserve it not for themselves" -- Abraham Lincoln -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From mhrivnak at hrivnak.org Sun Jul 10 20:31:49 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Sun, 10 Jul 2011 20:31:49 -0400 Subject: Virtual functions are virtually invisible! In-Reply-To: References: <97dcpqFdndU1@mid.individual.net> Message-ID: It sounds to me like you need a better IDE, better documentation, and/or better code to work on and use. I don't understand why it's difficult to look at a derived class as see what methods are overridden. If you are working on the code, it is quite obvious what methods exist in the base class. If you're not willing to get an intimate understanding of how the base class works, you probably shouldn't be working on the subclass. If the base class is difficult to understand, it's probably poorly written and/or poorly documented. Neither of these problems should be solved by adding complexity to the language. Referencing the Zen of Python: "If the implementation is hard to explain, it's a bad idea." If you are just using a library but not developing it, why does it matter what methods are overridden? As long as class "Derived" behaves the way it is documented, who cares how it got that way or what is going on behind the scenes? If you need to read the code to figure out how it works, then it's just poorly documented. Django is a great example, because it is very well documented. Most users have little idea of what base classes are involved and what features are overridden, because it doesn't matter when you are just using the library. When you need to write your own subclass of a django class, then it might matter, and you should see my first paragraph. And in terms of "non-starters", any "Pythonista" who isn't willing to adhere to the style guide and document their code wouldn't work on my team for very long, if at all. There is just no excuse for that. Michael On Sun, Jul 10, 2011 at 1:15 PM, rantingrick wrote: > On Jul 4, 3:43?am, Gregory Ewing wrote: >> rantingrick wrote: >> > what concerns me is the fact that virtual methods in derived >> > classes just blend in to the crowd. >> > I think we really need some >> > sort of visual cue in the form of forced syntactical notation (just >> > like the special method underscores). >> >> If you're suggesting that it should be impossible to override >> a method unless it is specially marked somehow in the base >> class, I think that would be a bad idea. > > Sorry i did explain properly... No NOT marked in the BASE class but > marked in the DERIVED class! My concerns are from a readability > standpoint. Here's a naive example... > > class Top(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def m1(self): > ? ? ? ?"""overide""" > ? ? ? ?return True > ? ?def m2(self): > ? ? ? ?print 'm2' > > > def Derived(Top): > ? ?def __init__(self): > ? ? ? ?Top.__init__(self) > ? ?def m1(self): > ? ? ? ?return False > > My argument is this... > > ? """If class "Derived" exists in another module the reader has no > idea which methods where clobbered and which were not WITHOUT being > intimate with the entire code base.""" > > ?I suggest we solve this dilemma by forcing a syntax "tag" when > declaring clobbering virtual functions. And if someone forgets to > include the tag python would throw an exception. This has the effect > of making the code MUCH easier to follow by the human readers. And it > put NO constraints on the API. Also it has the added effect of warning > unsuspecting programmers of name clashes that would otherwise not > produce an error. > >> One of the principles behind the design of Eiffel is that >> classes should *always* be open to modification in any way >> by a subclass. The reason is that the author of a class >> library can't anticipate all the ways people might want to >> use it. Consequently Eiffel has no equivalent of C++'s >> "private" declaration -- everything is at most "protected". >> It also has no equivalent of Java's "final". > > Exactly! We should never put limits on what methods CAN be virtual. > However, we CAN enforce a syntax that removes ambiguity from the > equation. > -- > http://mail.python.org/mailman/listinfo/python-list > From awilliam at whitemice.org Sun Jul 10 20:42:11 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sun, 10 Jul 2011 20:42:11 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310344932.3072.6.camel@linux-yu4c.site> On Sun, 2011-07-10 at 15:50 -0700, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? I've pondered this myself, for a long time - since I could use RAD to build very nice applications using Borland's OWL on Windows For Workgroups.... it is sad. But Open Source land is simply too fragmented. There are too many database bindings [and RAD requires something like an ORM (think SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list goes on and on]. Nothing can muster the gravity required to bring a quality RAD tool into existence. I also suspect - seeing some of the articles that float across the FLOSS-o-sphere mentioning "RAD" - that many Open Source developers have never had the pleasure [yes, it is a pleasure] of using a professional RAD tool. From benjamin.kaplan at case.edu Sun Jul 10 20:42:16 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 10 Jul 2011 17:42:16 -0700 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 10, 2011 at 3:50 PM, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? > -- > Because RAD tools are for GUI toolkits, not for languages. If you're using GTK, Glade works fine. Same with QT and QTDesigner. If you're using WPF with IronPython, there's plenty of tools out there for you to use. And Boa Constructor isn't the only RAD tool for wx- you can also use wxGlade, which can output code in several languages in addition to XRC files (an XML file you can load into wx from any language) > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Sun Jul 10 20:43:53 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sun, 10 Jul 2011 20:43:53 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <1310345034.3072.8.camel@linux-yu4c.site> >Because RAD tools are for GUI toolkits, not for languages. If you're >using GTK, Glade works fine. Same with QT and QTDesigner. If you're >using WPF with IronPython, t These [Glade, etc...] are *NOT* RAD tools. They are GUI designers. A RAD tool provides a GUI designer that can be bound to a backend [typically an SQL database]. RAD = GUI + ORM. From papillion at gmail.com Sun Jul 10 20:51:57 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 19:51:57 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: As someone who was a Visual Studio user for many years, I felt much the same way you do when I made the jump to Python on Linux last year. But then I discovered Glade and am quite satisfied. Glades UI design paradigm is a little different than that of VS but it's not so hard that you couldn't learn it in a week. It's very usable, pretty easy to learn, and doesn't cost you a penny. If you've not already, I recommend you check out Glade. I think it's probably what you're looking for. Anthony On 7/10/11, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Anthony Papillion Advanced Data Concepts Get real about your software/web development and IT Services Phone: (918) 919-4624 Does your business need to reduce its phone bill? I can help! Email me and ask me how! From steve+comp.lang.python at pearwood.info Sun Jul 10 21:54:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2011 11:54:32 +1000 Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: <4e1a57df$0$29987$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Jul 2011 09:00 am Corey Richardson wrote: > Excerpts from Colin J. Williams's message of Sun Jul 10 18:28:15 -0400 > 2011: >> Try: >> >> def f(): >> ds= """docstring""" >> print ds > > That doesn't actually make a docstring, though. It makes a string object > and points the name ds at it. Do you know what a docstring is? Colin might not be aware of why docstrings are useful, and arbitrary local variables ds="""docstring""" are not. def f1(): """This is my documentation string. Imagine this has actual useful information. """ def f2(): dc = """This is my documentation string. Imagine this has actual useful information. """ Now, at the interactive interpreter, call: help(f1) help(f2) -- Steven From drsalists at gmail.com Sun Jul 10 22:02:57 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 10 Jul 2011 19:02:57 -0700 Subject: Backshift mailing list create - opensource, deduplicating, compressing backups in Python Message-ID: I've created a google mailing list for the discussion of the backup program I've been working on, "backshift". You can find it at: backshift at googlegroups.com And I'd be pleased if you were to choose to join, if you're interested in the subject of Python and Backups. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amannijhawan at gmail.com Sun Jul 10 22:08:45 2011 From: amannijhawan at gmail.com (Aman Nijhawan) Date: Sun, 10 Jul 2011 19:08:45 -0700 Subject: parsing packets Message-ID: Are you sending binary data if so you can use the struct module to pack, unpack and interpret binary data http://docs.python.org/library/struct.html , You will have to design the header scheme yourself you can either embed length in the packets or try to use a carefully selected delimiter character . Thanks Aman On Sun, Jul 10, 2011 at 5:31 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: parsing packets (Michael Hrivnak) > 2. Re: Wgy isn't there a good RAD Gui tool fo python (CM) > 3. Re: Function docstring as a local variable (Ben Finney) > 4. Re: Function docstring as a local variable (Tim Johnson) > 5. Re: Function docstring as a local variable (Chris Rebert) > 6. Re: Function docstring as a local variable (Chris Rebert) > 7. Re: Function docstring as a local variable (Tim Johnson) > 8. Re: Function docstring as a local variable (Corey Richardson) > 9. Re: Virtual functions are virtually invisible! (Michael Hrivnak) > > > ---------- Forwarded message ---------- > From: Michael Hrivnak > To: tyler at tysdomain.com > Date: Sun, 10 Jul 2011 19:33:38 -0400 > Subject: Re: parsing packets > In order to find the end of the packet, include a field that is the > packet length. This is what IP packets do to find the end of their > header. > > http://en.wikipedia.org/wiki/IPv4#Header > > And the TCP header (see "data offset") does the same: > > > http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure > > Of course in both cases they are specifying the header length, not > including a data payload. However, it sounds like you might not have > a payload, so your entire packet might consist of header-like data. > > Michael > > > On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler > wrote: > > Hello all: > > I'm working on a server that will need to parse packets sent from a > client, > > and construct it's own packets. > > The setup is something like this: the first two bytes is the type of the > > packet. > > So, lets say we have a packet set to connect. There are two types of > connect > > packet: a auth packet and a connect packet. > > The connect packet then has two bytes with the type, another byte that > notes > > that it is a connect packet, and 4 bytes that contains the version of the > > client. > > The auth packet has the two bytes that tells what packet it is, one byte > > denoting that it is an auth packet, then the username, a NULL character, > and > > a password and a NULL character. > > > > With all of this said, I'm kind of curious how I would 1) parse out > > something like this (I am using twisted, so it'll just be passed to my > > Receive function), and how I get the length of the packet with multiple > NULL > > values. I'm also looking to build a packet and send it back out, is there > > something that will allow me to designate two bytes, set individual bits, > > then put it altogether in a packet to be sent out? > > > > -- > > > > Take care, > > Ty > > my website: > > http://tds-solutions.net > > my blog: > > http://tds-solutions.net/blog > > skype: st8amnd127 > > My programs don't have bugs; they're randomly added features! > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > ---------- Forwarded message ---------- > From: CM > To: python-list at python.org > Date: Sun, 10 Jul 2011 16:49:51 -0700 (PDT) > Subject: Re: Wgy isn't there a good RAD Gui tool fo python > On Jul 10, 6:50 pm, Ivan Kljaic wrote: > > Ok Guys. I know that most of us have been expiriencing the need for a > > nice Gui builder tool for RAD and most of us have been googling for it > > a lot of times. But seriously. Why is the not even one single RAD tool > > for Python. I mean what happened to boa constructor that it stopped > > developing. I simply do not see any reasons why there isn't anything. > > Please help me understand it. Any insights? > > Just because Boa Constructor stopped (or lengthily paused?) > development > doesn't mean it doesn't exist. It does, and (at least on Windows), it > is, IMO, really good. So why don't you use it? > > Che > > > > > ---------- Forwarded message ---------- > From: Ben Finney > To: python-list at python.org > Date: Mon, 11 Jul 2011 09:48:46 +1000 > Subject: Re: Function docstring as a local variable > "Colin J. Williams" writes: > > > On 10-Jul-11 13:44 PM, rantingrick wrote: > > > On Jul 10, 12:41 pm, Tim Johnson wrote: > > >> It possible for a function to print it's own docstring? > > > > > > def f(): > > > """docstring""" > > > print "docstring" > > > > Try: > > > > def f(): > > ds= """docstring""" > > print ds > > The OP wants the function to print its own docstring, which your example > does not do. You've defined a function with an empty docstring. > > >>> def foo(): > ... ds = "The Larch" > ... print ds > ... > >>> foo.__doc__ > >>> > > -- > \ ?Firmness in decision is often merely a form of stupidity. It | > `\ indicates an inability to think the same thing out twice.? | > _o__) ?Henry L. Mencken | > Ben Finney > > > > ---------- Forwarded message ---------- > From: Tim Johnson > To: python-list at python.org > Date: Sun, 10 Jul 2011 16:00:54 -0800 > Subject: Re: Function docstring as a local variable > * Carl Banks [110710 15:18]: > > On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > > Here's a related question: > > > I can get the docstring for an imported module: > > > >>> import tmpl as foo > > > >>> print(foo.__doc__) > > > Python templating features > > > > > > Author - tim at akwebsoft dot com > > > > > > ## Is it possible to get the module docstring > > > ## from the module itself? > > > > > > print __doc__ > Thanks Carl. > > Where is general documentation on the subject of variables > beginning with 2 underscores? > > I'm presuming the key phrase is 'builtin variables'. I'm searching > too ... > > -- > Tim > tim at johnsons-web dot com or akwebsoft dot com > http://www.akwebsoft.com > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Tim Johnson > Date: Sun, 10 Jul 2011 17:09:27 -0700 > Subject: Re: Function docstring as a local variable > On Sun, Jul 10, 2011 at 5:00 PM, Tim Johnson wrote: > > * Carl Banks [110710 15:18]: > >> On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: > > >> > ## Is it possible to get the module docstring > >> > ## from the module itself? > >> > >> print __doc__ > > Thanks Carl. > > > > Where is general documentation on the subject of variables > > beginning with 2 underscores? > > > > I'm presuming the key phrase is 'builtin variables'. I'm searching > > too ... > > I've never heard that phrase used to describe __doc__ or its friends. > > Look in the "underscore" section of the documentation index: > http://docs.python.org/genindex-_.html > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: Corey Richardson > Date: Sun, 10 Jul 2011 17:16:23 -0700 > Subject: Re: Function docstring as a local variable > On Sun, Jul 10, 2011 at 4:06 PM, Corey Richardson wrote: > > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > >> print __doc__ > >> > > > > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) > > [GCC 4.4.5] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> def foo(): > > ... "Docstring" > > ... print __doc__ > > ... > >>>> foo() > > None > >>>> > > > > > > What does yours do? > > The question Carl's code was in answer to was, slightly paraphrased: > "Is it possible to get a *module*'s docstring from within the module > itself?" > The question had nothing to do with *function* docstrings. > > The interactive interpreter environment also isn't quite a true > module, so you can't give it a docstring or really test the relevant > feature there. Try this instead: > $ cat test.py > """I am the docstring of the `test` module!""" > > print("This module's docstring is:", __doc__) > $ python test.py > This module's docstring is: I am the docstring of the `test` module! > $ > > Cheers, > Chris > -- > http://rebertia.com > > > > ---------- Forwarded message ---------- > From: Tim Johnson > To: Python ML > Date: Sun, 10 Jul 2011 16:21:59 -0800 > Subject: Re: Function docstring as a local variable > * Chris Rebert [110710 16:14]: > > > > > > Where is general documentation on the subject of variables > > > beginning with 2 underscores? > > > > I've never heard that phrase used to describe __doc__ or its friends. > :) That why I wasn't satified with my search results. > > Look in the "underscore" section of the documentation index: > > http://docs.python.org/genindex-_.html > And that is what I was looking for. > thanks > -- > Tim > tim at johnsons-web dot com or akwebsoft dot com > http://www.akwebsoft.com > > > > ---------- Forwarded message ---------- > From: Corey Richardson > To: python-list > Date: Sun, 10 Jul 2011 20:26:02 -0400 > Subject: Re: Function docstring as a local variable > Excerpts from Chris Rebert's message of Sun Jul 10 20:16:23 -0400 2011: > > The question Carl's code was in answer to was, slightly paraphrased: > > "Is it possible to get a *module*'s docstring from within the module > > itself?" > > The question had nothing to do with *function* docstrings. > > > > Ah. My bad, thank you for clarifying. > -- > Corey Richardson > "Those who deny freedom to others, deserve it not for themselves" > -- Abraham Lincoln > > > ---------- Forwarded message ---------- > From: Michael Hrivnak > To: rantingrick > Date: Sun, 10 Jul 2011 20:31:49 -0400 > Subject: Re: Virtual functions are virtually invisible! > It sounds to me like you need a better IDE, better documentation, > and/or better code to work on and use. I don't understand why it's > difficult to look at a derived class as see what methods are > overridden. If you are working on the code, it is quite obvious what > methods exist in the base class. If you're not willing to get an > intimate understanding of how the base class works, you probably > shouldn't be working on the subclass. If the base class is difficult > to understand, it's probably poorly written and/or poorly documented. > Neither of these problems should be solved by adding complexity to the > language. Referencing the Zen of Python: "If the implementation is > hard to explain, it's a bad idea." > > If you are just using a library but not developing it, why does it > matter what methods are overridden? As long as class "Derived" > behaves the way it is documented, who cares how it got that way or > what is going on behind the scenes? If you need to read the code to > figure out how it works, then it's just poorly documented. > > Django is a great example, because it is very well documented. Most > users have little idea of what base classes are involved and what > features are overridden, because it doesn't matter when you are just > using the library. When you need to write your own subclass of a > django class, then it might matter, and you should see my first > paragraph. > > And in terms of "non-starters", any "Pythonista" who isn't willing to > adhere to the style guide and document their code wouldn't work on my > team for very long, if at all. There is just no excuse for that. > > Michael > > On Sun, Jul 10, 2011 at 1:15 PM, rantingrick > wrote: > > On Jul 4, 3:43 am, Gregory Ewing wrote: > >> rantingrick wrote: > >> > what concerns me is the fact that virtual methods in derived > >> > classes just blend in to the crowd. > >> > I think we really need some > >> > sort of visual cue in the form of forced syntactical notation (just > >> > like the special method underscores). > >> > >> If you're suggesting that it should be impossible to override > >> a method unless it is specially marked somehow in the base > >> class, I think that would be a bad idea. > > > > Sorry i did explain properly... No NOT marked in the BASE class but > > marked in the DERIVED class! My concerns are from a readability > > standpoint. Here's a naive example... > > > > class Top(object): > > def __init__(self): > > pass > > def m1(self): > > """overide""" > > return True > > def m2(self): > > print 'm2' > > > > > > def Derived(Top): > > def __init__(self): > > Top.__init__(self) > > def m1(self): > > return False > > > > My argument is this... > > > > """If class "Derived" exists in another module the reader has no > > idea which methods where clobbered and which were not WITHOUT being > > intimate with the entire code base.""" > > > > I suggest we solve this dilemma by forcing a syntax "tag" when > > declaring clobbering virtual functions. And if someone forgets to > > include the tag python would throw an exception. This has the effect > > of making the code MUCH easier to follow by the human readers. And it > > put NO constraints on the API. Also it has the added effect of warning > > unsuspecting programmers of name clashes that would otherwise not > > produce an error. > > > >> One of the principles behind the design of Eiffel is that > >> classes should *always* be open to modification in any way > >> by a subclass. The reason is that the author of a class > >> library can't anticipate all the ways people might want to > >> use it. Consequently Eiffel has no equivalent of C++'s > >> "private" declaration -- everything is at most "protected". > >> It also has no equivalent of Java's "final". > > > > Exactly! We should never put limits on what methods CAN be virtual. > > However, we CAN enforce a syntax that removes ambiguity from the > > equation. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Aman Nijhawan -------------- next part -------------- An HTML attachment was scrubbed... URL: From kvaradhan3 at gmail.com Sun Jul 10 22:13:33 2011 From: kvaradhan3 at gmail.com (Kannan Varadhan) Date: Sun, 10 Jul 2011 19:13:33 -0700 (PDT) Subject: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead) References: <38cc43c2-7f4d-4b30-9260-cc439fc7000a@a10g2000vbz.googlegroups.com> Message-ID: <2be5417f-6b4c-4296-bcb0-e01961701a79@h38g2000pro.googlegroups.com> Thanks folks, Tried all of these, and went with staticmethod(). Was cleanest solution, > After skimming over Steven's post: use staticmethod. > No idea why I didn't think of that myself. Kannan From papillion at gmail.com Sun Jul 10 22:14:10 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 21:14:10 -0500 Subject: How to get or set the text of a textfield? Message-ID: Hi Everyone, So I've built a UI with Glade and have loaded it using the standard Python code. In my UI, I have a textfield called txtUsername. How do I get and set the text in this field from my Python code? Thanks! Anthony -- Anthony Papillion Advanced Data Concepts Get real about your software/web development and IT Services Phone: (918) 919-4624 Does your business need to reduce its phone bill? I can help! Email me and ask me how! From rantingrick at gmail.com Sun Jul 10 22:35:05 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 10 Jul 2011 19:35:05 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> Message-ID: <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> On Jul 10, 7:31?pm, Michael Hrivnak wrote: > It sounds to me like you need a better IDE, better documentation, > and/or better code to work on and use. Yes the last two points are relevant here. However whilst IDE choice belongs to the user, documentation and code are in the hands of the developer; who's own selfish needs often outweigh that of the user AND community as a whole. >?I don't understand why it's > difficult to look at a derived class as see what methods are > overridden. Well in my simple example it is VERY easy, WHY? Here are a few reasons why the clobbered methods are easy to spot (in both the base and derived classes)... * Both exists within the same view frame. No need to flip back and forth between two windows. * Both have only one method. The complexity increases exponentially by the number of methods AND the length of their respective code blocks! * "Derived.m1" has a syntactical mark. You can clearly see which method has been clobbered WITHOUT even bothering to look at the base class. The only time you SHOULD have to look at the base class is to see what mandates the virtual method may impose. Does it require a Boolean return? An Integer? A Float? A List? Does it modify an object? Etc, etc? > ?If you are working on the code, it is quite obvious what > methods exist in the base class. Let me correct your statement... IF you have an intimate understanding of the base. Heck what if the base is derived also? These things are NOT strictly single level you know. > ?If you're not willing to get an > intimate understanding of how the base class works, you probably > shouldn't be working on the subclass. ? Not true, many times you don't need an intimate understanding of the base to wield a derived class. That's when the syntactical markers come in handy. > If the base class is difficult > to understand, it's probably poorly written and/or poorly documented. > Neither of these problems should be solved by adding complexity to the > language. How is adding syntactical markers to an otherwise obfuscation of virtual method clobbering going to confuse anyone? I would say the opposite is true. Python has used the forced convention "double- leading-and-trailing-underscores" to mark special methods since it's beginning. One reason for this convention is prevent name clashes HOWEVER the most important reason (i would argue) is for readability of source code. When Guido implemented this convention it was one of his greatest gifts to Python and the world (only to be outdone by forced indention!). >?Referencing the Zen of Python: "If the implementation is > hard to explain, it's a bad idea." What if the code is "difficult" to read? Does "readability count" ring a bell? > If you are just using a library but not developing it, why does it > matter what methods are overridden? ?As long as class "Derived" > behaves the way it is documented, who cares how it got that way or > what is going on behind the scenes? ?If you need to read the code to > figure out how it works, then it's just poorly documented. Yes. It is obviously poorly documented. And all the writer would have to do is put a little doc string there saying "clobbered virtual method here". HOWEVER, do you know how many folks bother to ACTUALLY do that? Huh? Do ya? None! Exactly. > Django is a great example, because it is very well documented. ?Most > users have little idea of what base classes are involved and what > features are overridden, because it doesn't matter when you are just > using the library. ?When you need to write your own subclass of a > django class, then it might matter, and you should see my first > paragraph. When a method has been clobbered any reader of such code NEEDS to know about it. WHY, well because usually clobbered methods have "magic" going on being the scenes. Sometimes many layers of "magic". > And in terms of "non-starters", any "Pythonista" who isn't willing to > adhere to the style guide and document their code wouldn't work on my > team for very long, if at all. ?There is just no excuse for that. I agree. However as we are all aware many "great Pythonistas" refuse to follow the style guide (*cough* freg! :). The only way to correct this problem is via a forced syntactical marker placed by the derived class's writer. Just like with "__IDENTIFIER__" READABILITY COUNTS! From jialiuonlineshoe02 at 163.com Sun Jul 10 23:28:41 2011 From: jialiuonlineshoe02 at 163.com (amy) Date: Sun, 10 Jul 2011 20:28:41 -0700 (PDT) Subject: paypal wholesale all brand(UGGBOOTS, SHOES, CLOTHES, HANDBAG, WATCH, JEANS, JERSEY, T-SHIRT, SHIRTS, HOODY, EYEGLASS, CAP, SHAWL, WALLT) and so on. Message-ID: <5cfc664b-557c-47d5-a39c-424df921f867@t38g2000prj.googlegroups.com> paypal payment wholesale all brand shoes(NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,UGG BOOTS,D&G,DIOR )and so on. paypal payment wholesale all brand clothing(T- SHIRT,JEANS,JERSEY,HOODIES,JACKETS,HARDY,SWEATER,SHIRTS )and so on . http://www.24hour-buy.com paypal payment all brand watch(ROLEX,OMEGA,CHANEL,LV,CARTIER,IWC,GUCCI,RADO )and so on. http://www.24hour-buy.com paypal payment all brand handbag(LV,GUCCI,CHANEL,PRADA,POLO,COACH,FENDI,CHLOE,BUBERRY,JUICY) and so on. paypal payment brand CAP,SHAWL,BELT,WALLET,UNDER WEAR)and so on. More detail land,address: http://www.24hour-buy.com From gordon at panix.com Sun Jul 10 23:44:44 2011 From: gordon at panix.com (John Gordon) Date: Mon, 11 Jul 2011 03:44:44 +0000 (UTC) Subject: How to get or set the text of a textfield? References: Message-ID: In Anthony Papillion writes: > So I've built a UI with Glade and have loaded it using the standard > Python code. In my UI, I have a textfield called txtUsername. How do I > get and set the text in this field from my Python code? I don't know anything about Glade, so I can't answer your question definitively. However, as a general rule, you can use the dir() builtin function to see what methods are defined by an object. So, assuming you have access to an interactive shell within your Glade environment, you can do this: dir(txtUsername) and it will print a list of methods that are defined by that object. Hopefully one of them will be called something helpful like set_text() or set_property(). Once you know the method name, you might try a Google search to determine the exact usage and arguments. -- 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 wuwei23 at gmail.com Mon Jul 11 00:05:47 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 10 Jul 2011 21:05:47 -0700 (PDT) Subject: Function docstring as a local variable References: <64b5198e-5cc7-4790-898e-7f1abb199230@y24g2000yqb.googlegroups.com> Message-ID: On Jul 11, 9:00?am, Corey Richardson wrote: > def qux(): > ? ? 'And even me! Quote type don't matter (besides style)' Well, style and the presence of the string literal notation in the quoted text :) From papillion at gmail.com Mon Jul 11 00:09:27 2011 From: papillion at gmail.com (Anthony Papillion) Date: Sun, 10 Jul 2011 23:09:27 -0500 Subject: How to get or set the text of a textfield? - SOLVED In-Reply-To: References: Message-ID: <4E1A7777.8040101@gmail.com> > I don't know anything about Glade, so I can't answer your question > definitively. However, as a general rule, you can use the dir() builtin > function to see what methods are defined by an object. Hi John, Thanks for the input and it looks like it's pretty simple. Basically, I can access the properties of objects like: self.objectname.property_or_method() So, to solve my question, I'd just use: self.txtUsername.set_text('Whatever I want') or enteredText = self.txtUsername.get_text() Pretty simple and this actually solves ALL of my Glade problems. I'm excited. Thanks for the direction! Anthony From wuwei23 at gmail.com Mon Jul 11 00:14:11 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 10 Jul 2011 21:14:11 -0700 (PDT) Subject: Function docstring as a local variable References: Message-ID: <44de56f6-8ded-488f-a2bb-5b0f19582ef5@e20g2000prf.googlegroups.com> On Jul 11, 9:06?am, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > > > print __doc__ > > Python 2.7.1 (r271:86832, Jul ?8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> def foo(): > > ... ? ? "Docstring" > ... ? ? print __doc__ > ... > > >>> foo() > None > > What does yours do? Is foo() declared in a module with a docstring? Because that's what Carl was talking about. test_module.py: '''module docstring''' def foo(): print __doc__ Works for me. From mhrivnak at hrivnak.org Mon Jul 11 00:45:45 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Mon, 11 Jul 2011 00:45:45 -0400 Subject: Virtual functions are virtually invisible! In-Reply-To: <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> Message-ID: I can't believe you're saying that you will create a sub-class without taking the time to understand the base class. Seriously? That right there is why you are seeing method overrides that aren't documented. How can you document something you don't understand? Furthermore, how can you have any confidence in your subclass if you don't understand what its base class is doing? Do you write unit tests? How do you know what to test if you don't understand the code you are subclassing? Suggesting that no developers document their methods? Incredible. Clobbered methods have "magic"? Multi-layered "magic"? Perhaps when you take the time to 1) document the base class and 2) understand that base class before subclassing it, that "magic" will start to look like reasonable and logical processes. Professional developers document their code. They take the time to understand the code they are working on. If you don't want to do those things, that's your business, and I'm sure you can find other people who also don't do those things. But I really don't think you'll have much success changing the language to accommodate your refusal to follow the most basic best practices. Best of luck, Michael On Sun, Jul 10, 2011 at 10:35 PM, rantingrick wrote: > On Jul 10, 7:31?pm, Michael Hrivnak wrote: >> It sounds to me like you need a better IDE, better documentation, >> and/or better code to work on and use. > > Yes the last two points are relevant here. However whilst IDE choice > belongs to the user, documentation and code are in the hands of the > developer; who's own selfish needs often outweigh that of the user AND > community as a whole. > >>?I don't understand why it's >> difficult to look at a derived class as see what methods are >> overridden. > > Well in my simple example it is VERY easy, WHY? Here are a few reasons > why the clobbered methods are easy to spot (in both the base and > derived classes)... > > ?* Both exists within the same view frame. No need to flip back and > forth between two windows. > ?* Both have only one method. The complexity increases exponentially > by the number of methods AND the length of their respective code > blocks! > ?* "Derived.m1" has a syntactical mark. You can clearly see which > method has been clobbered WITHOUT even bothering to look at the base > class. > > The only time you SHOULD have to look at the base class is to see what > mandates the virtual method may impose. Does it require a Boolean > return? An Integer? A Float? A List? Does it modify an object? Etc, > etc? > >> ?If you are working on the code, it is quite obvious what >> methods exist in the base class. > > Let me correct your statement... IF you have an intimate understanding > of the base. Heck what if the base is derived also? These things are > NOT strictly single level you know. > >> ?If you're not willing to get an >> intimate understanding of how the base class works, you probably >> shouldn't be working on the subclass. > > Not true, many times you don't need an intimate understanding of the > base to wield a derived class. That's when the syntactical markers > come in handy. > >> If the base class is difficult >> to understand, it's probably poorly written and/or poorly documented. >> Neither of these problems should be solved by adding complexity to the >> language. > > How is adding syntactical markers to an otherwise obfuscation of > virtual method clobbering going to confuse anyone? I would say the > opposite is true. Python has used the forced convention "double- > leading-and-trailing-underscores" to mark special methods since it's > beginning. One reason for this convention is prevent name clashes > HOWEVER the most important reason (i would argue) is for readability > of source code. When Guido implemented this convention it was one of > his greatest gifts to Python and the world (only to be outdone by > forced indention!). > >>?Referencing the Zen of Python: "If the implementation is >> hard to explain, it's a bad idea." > > What if the code is "difficult" to read? Does "readability count" ring > a bell? > >> If you are just using a library but not developing it, why does it >> matter what methods are overridden? ?As long as class "Derived" >> behaves the way it is documented, who cares how it got that way or >> what is going on behind the scenes? ?If you need to read the code to >> figure out how it works, then it's just poorly documented. > > Yes. It is obviously poorly documented. And all the writer would have > to do is put a little doc string there saying "clobbered virtual > method here". HOWEVER, do you know how many folks bother to ACTUALLY > do that? Huh? Do ya? None! Exactly. > >> Django is a great example, because it is very well documented. ?Most >> users have little idea of what base classes are involved and what >> features are overridden, because it doesn't matter when you are just >> using the library. ?When you need to write your own subclass of a >> django class, then it might matter, and you should see my first >> paragraph. > > When a method has been clobbered any reader of such code NEEDS to know > about it. WHY, well because usually clobbered methods have "magic" > going on being the scenes. Sometimes many layers of "magic". > >> And in terms of "non-starters", any "Pythonista" who isn't willing to >> adhere to the style guide and document their code wouldn't work on my >> team for very long, if at all. ?There is just no excuse for that. > > I agree. However as we are all aware many "great Pythonistas" refuse > to follow the style guide (*cough* freg! :). The only way to correct > this problem is via a forced syntactical marker placed by the derived > class's writer. Just like with "__IDENTIFIER__" > > READABILITY COUNTS! > -- > http://mail.python.org/mailman/listinfo/python-list > From wm at localhost.localdomain Mon Jul 11 01:03:10 2011 From: wm at localhost.localdomain (Waldek M.) Date: Mon, 11 Jul 2011 07:03:10 +0200 Subject: How to get or set the text of a textfield? References: Message-ID: Dnia Sun, 10 Jul 2011 21:14:10 -0500, Anthony Papillion napisa?(a): > > So I've built a UI with Glade and have loaded it using the standard > Python code. In my UI, I have a textfield called txtUsername. How do I > get and set the text in this field from my Python code? http://developer.gnome.org/pygtk/stable/ http://www.learningpython.com/2006/05/07/creating-a-gui-using-pygtk-and-glade/ Br. Waldek From timr at probo.com Mon Jul 11 01:12:31 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 10 Jul 2011 22:12:31 -0700 Subject: ctypes: point to buffer in structure References: Message-ID: Jesse R wrote: > >Hey I've been trying to convert this to run through ctypes and i'm >having a hard time > >typedef struct _SYSTEM_PROCESS_ID_INFORMATION >{ > HANDLE ProcessId; > UNICODE_STRING ImageName; >} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, >*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; > >to > >class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): > _fields_ = [('pid', ctypes.c_ulong), > ('imageName', ctypes.c_wchar_p)] >... >does anyone know how to get this working? UNICODE_STRING is not just a pointer to wide characters. It is itself a structure: typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; So, I think you want fields of ctypes.c_ulong, ctypes.c_ushort, ctypes.c_ushort, and ctypes.c_wchar_p. MaximumLength gives the allocated size of the buffer. Length gives the length of the string currently held in the buffer. It can be less than the maximum length, and the buffer does NOT necessarily contain a zero-terminator. UNICODE_STRING and ANSI_STRING are used in kernel programming to avoid the potential ambiguities of counted strings. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From shilparani9030 at gmail.com Mon Jul 11 01:13:46 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Sun, 10 Jul 2011 22:13:46 -0700 (PDT) Subject: south actress hot photos and videos Message-ID: <4fa16485-0b74-4209-887e-462954f92941@y13g2000prb.googlegroups.com> v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From georg at python.org Mon Jul 11 01:23:32 2011 From: georg at python.org (Georg Brandl) Date: Mon, 11 Jul 2011 07:23:32 +0200 Subject: [RELEASED] Python 3.2.1 Message-ID: <4E1A88D4.5070704@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the final release of Python 3.2.1. Python 3.2.1 is the first bugfix release for Python 3.2, fixing over 120 bugs and regressions in Python 3.2. For an extensive list of changes and features in the 3.2 line, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2.1 visit: http://www.python.org/download/releases/3.2.1/ This is a final release: Please report any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEARECAAYFAk4aiNMACgkQN9GcIYhpnLDofwCglfgDQ1/B/TxxwfqtDxK13ksz micAn0CVWmNNaYE2a6z0N7+Dz+hCZSj1 =7Mia -----END PGP SIGNATURE----- From kracethekingmaker at gmail.com Mon Jul 11 01:23:54 2011 From: kracethekingmaker at gmail.com (kracekumar ramaraju) Date: Sun, 10 Jul 2011 22:23:54 -0700 (PDT) Subject: python xauth Message-ID: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> I am looking to use xauth in python?It is for my command line process,I would like to have few examples and resources. From papillion at gmail.com Mon Jul 11 02:42:30 2011 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 11 Jul 2011 01:42:30 -0500 Subject: OK, I lied, I do have another question... Message-ID: <4E1A9B56.6080608@gmail.com> Hi Everyone, So I've used Glade to build a simple UI and I'm loading it with gtkBuilder. The UI loads fine but, for some reason, none of my signals are being connected. For example, in Glade, I said when the button called btnExit was clicked, execute the btnExit_clicked method. Then, in my App() class definition, I defined btnExit_clicked(self, widget) and simply added the gtk.main_quit() statement (to exit). But when I start my app, I am told that the btnExit_clicked() method isn't defined. This happens for every single signal I define. I'm assuming I'm simply putting something in the wrong place so can anyone have a look at this and tell me what that might be? It looks almost identical to examples I've seen on the net. Thanks! CODE: class App: def __init__(self): builder = gtk.Builder() builder.add_from_file('bcbackup.ui') builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : btnExit_clicked}) self.window = builder.get_object("winMain") self.window.show() def btnSaveInformation_clicked(self, widget): pass def btnExit_clicked(self, widget): gtk.main_quit() if __name__ == "__main__": myApp = App() gtk.main() END CODE From cousinstanley at gmail.com Mon Jul 11 02:48:26 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 11 Jul 2011 06:48:26 +0000 (UTC) Subject: python xauth References: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> Message-ID: kracekumar ramaraju wrote: > I am looking to use xauth in python ? > > It is for my command line process, > I would like to have few examples > and resources. A simple example .... >>> import subprocess as SP >>> >>> proc = [ 'xauth' , 'list' , ':0' ] >>> >>> pipe = SP.Popen( proc , stdout = SP.PIPE ) >>> >>> data = pipe.stdout.readline() >>> >>> print '\n' , data em1dsq/unix:0 MIT-MAGIC-COOKIE-1 10a533afab15a57c8704a16d1dc5bb12 -- Stanley C. Kitching Human Being Phoenix, Arizona From ian.g.kelly at gmail.com Mon Jul 11 02:57:01 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 00:57:01 -0600 Subject: python xauth In-Reply-To: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> References: <3da05ccc-30b4-42b1-a233-c9d56bd536ec@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, Jul 10, 2011 at 11:23 PM, kracekumar ramaraju wrote: > I am looking to use xauth in python?It is for my command line process,I would like to have few examples and resources. First, by "xauth" do you mean the X11 authorization scheme, or the "extended authentication" (xauth.org) scheme? The name is unfortunately overloaded. Second, have you tried googling for "python xauth"? Cheers, Ian From rosuav at gmail.com Mon Jul 11 04:09:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2011 18:09:52 +1000 Subject: A beginning programmer In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 8:06 AM, Eric wrote: > But I just don't know what > to do with it, I don't have any problems that need to be solved... There are always more problems to be solved than people willing to solve them! It's just a matter of finding ones you're interested in. Several people have recommended looking at bugtrackers and such. Another good source of programming tasks is automation - look for any task that you or someone else does repeatedly, and write a script that does it. That can range from a half-dozen lines of shell script up to full-on commercial-grade packages (if you think about it, an accounting system is nothing more than reports automation). Learn as many languages as you can. Develop the skill of picking up a new language and mastering it; obscure languages have just as interesting problems as do mainstream ones, and being able to learn Pike might suddenly come in handy when you find yourself invited to code on somebody's MUD some day! Chris Angelico Currently striving to be the Mr Melas of programming languages From awilliam at whitemice.org Mon Jul 11 06:24:53 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 11 Jul 2011 06:24:53 -0400 Subject: How to get or set the text of a textfield? In-Reply-To: References: Message-ID: <1310379894.3072.17.camel@linux-yu4c.site> On Mon, 2011-07-11 at 03:44 +0000, John Gordon wrote: > In Anthony Papillion writes: > > So I've built a UI with Glade and have loaded it using the standard > > Python code. In my UI, I have a textfield called txtUsername. How do I > > get and set the text in this field from my Python code? field.get_text() field.set_text(value) > and it will print a list of methods that are defined by that object. > Hopefully one of them will be called something helpful like set_text() > or set_property(). Once you know the method name, you might try a Google > search to determine the exact usage and arguments. -1 -1 -1 Do not "google" [search the Internet] for solutions to pyGtk problems. That is just a confusing waste of time. Use the *excellent* and well-linked documentation: The FAQ is extensive and really does cover a lot of the common questions. Also there is a list specifically for pygtk questions: Google, or Bing, or even DuckDuckGo, are *not* your friends. They are enormous and inefficient time-sinks. They are a *BAD* way to solve problems. Use the documentation. From sturlamolden at yahoo.no Mon Jul 11 06:34:03 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 03:34:03 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <9b368b53-6de3-4bbd-8dca-1fc3bb4af5bb@gh5g2000vbb.googlegroups.com> On 11 Jul, 00:50, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? If you by "RAD tool" mean "GUI builder", I'd recommend wxFormBuilder for wxPython, QtCreator for PyQt or PySide, and GLADE for PyGTK. Personally I prefer wxFormBuilder and wxPython, but it's a matter of taste. Sturla From sturlamolden at yahoo.no Mon Jul 11 06:47:02 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 03:47:02 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On 11 Jul, 02:43, Adam Tauno Williams wrote: > >Because RAD tools are for GUI toolkits, not for languages. If you're > >using GTK, Glade works fine. Same with QT and QTDesigner. If you're > >using WPF with IronPython, t > > These [Glade, etc...] are *NOT* RAD tools. ?They are GUI designers. ?A > RAD tool provides a GUI designer that can be bound to a backend > [typically an SQL database]. ?RAD = GUI + ORM. The type speciemens for "RAD tools" were Borland Delphi and Microsoft Visual Basic. They were not a combination of GUI designer and SQL/ORM backend. They were a combination of GUI designer, code editor, compiler, and debugger. Sturla From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jul 11 08:05:17 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Jul 2011 14:05:17 +0200 Subject: parsing packets In-Reply-To: References: Message-ID: Am 10.07.2011 22:59 schrieb Littlefield, Tyler: > Hello all: > I'm working on a server that will need to parse packets sent from a > client, and construct it's own packets. Are these packets sent as separate UDP packets or embedded in a TCP stream? In the first case, you already have packets and only have to parse them. In a stream, you first have to split them up. In the following, I will talk about UDP datagrams. For TCP, further work is needed. > The setup is something like this: the first two bytes is the type of the > packet. Then you have type = struct.unpack(">H", packet), payload1 = packet[2:] > So, lets say we have a packet set to connect. There are two types of > connect packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that > notes that it is a connect packet, and 4 bytes that contains the version > of the client. if type == CONNECT: subtype = struct.unpack("B", payload1) payload2 = payload1[1:] if subtype == CONNECT: upx = payload2.split("\0") assert len(upx) == 3 and upx[-1] == '' username, password = upx[:2] else: assert len(payload2) == 4 version = struct.unpack(">L", payload2) > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, > and a password and a NULL character. > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), I. e., you already have your packets distinct? That's fine. > and how I get the length of the packet with multiple NULL values. With len(), how else? > I'm also looking to build a packet and send it back out, is > there something that will allow me to designate two bytes, set > individual bits, then put it altogether in a packet to be sent out? The same: with struct.pack(). Thomas From bruno.desthuilliers at gmail.com Mon Jul 11 08:09:07 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Mon, 11 Jul 2011 05:09:07 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> On Jul 11, 2:42?am, Adam Tauno Williams wrote: > > But Open Source land is simply too fragmented. ?There are too many > database bindings [and RAD requires something like an ORM (think > SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list > goes on and on]. > > Nothing can muster the gravity required to bring a quality RAD tool into > existence. Why "too many" ? Natural selection is a GoodThing. Python is known as "the language with more web frameworks than keywords", and this doesn't prevent some of these frameworks to be 1/ pretty good and 2/ becoming de facto standards. > I also suspect - seeing some of the articles that float across the > FLOSS-o-sphere mentioning "RAD" - that many Open Source developers have > never had the pleasure [yes, it is a pleasure] of using a professional > RAD tool. This is slightly arrogant. Did you occur to you that quite a few OSS developers may have at least as much experience as you do with these kind of tools and just happen to actually prefer the unix way of doing things ? From fluxius at gmail.com Mon Jul 11 08:24:47 2011 From: fluxius at gmail.com (Sebastien Dudek) Date: Mon, 11 Jul 2011 05:24:47 -0700 (PDT) Subject: Freeze statically Message-ID: <41e815ee-e00b-41ef-9b95-f84018d86dab@q15g2000yqk.googlegroups.com> Hi everyone! Let me explain you my big adventure. So I trying to make a static python executable using the native Python freeze. I've modified the file Modules/Setup.dist using this perl cli : perl -pi -e 's!(^# \*shared\*)!*static*\n$1!' Modules/Setup.dist Then ./configure, make && make install If I'm using my python interpreter to build with freeze a simple project that we can call "hello world". It works perfectly but it is still : "dynamically linked (uses shared libs)". So modifying the Makefile using '-static' for linking, I hopped I could make it static. But... it fail : +------------------------------------------------------------------------------------------------------------------------------------------ + ... /home/fluxius/Python-2.7.2/./Modules/pwdmodule.c:156: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /home/fluxius/Python-2.7.2/./Modules/pwdmodule.c:168: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/ 4.5.2/../../../libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie collect2: ld returned 1 exit status make: *** [hello] Erreur 1 +------------------------------------------------------------------------------------------------------------------------------------------ + Help me please!! =) From ben+python at benfinney.id.au Mon Jul 11 08:39:46 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2011 22:39:46 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> Message-ID: <871uxxf0tp.fsf@benfinney.id.au> "bruno.desthuilliers at gmail.com" writes: > On Jul 11, 2:42?am, Adam Tauno Williams > wrote: > > > > But Open Source land is simply too fragmented. ?There are too many > > database bindings [and RAD requires something like an ORM (think > > SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list > > goes on and on]. > > Why "too many" ? Natural selection is a GoodThing. Natural selection is not a good thing. It is blind and unthinking and cruel and wasteful and haphazard and purposeless. Those aren't traits to recommend it, IMO. (It's also not a bad thing. Natural selection just is.) Natural selection is not what's happening here. Rather, *artifical* selection, with people as the agents of selection, have purposes and wants that guide their selections. It would be better to say: Competition can be (not an unalloyed ?is?) a Good Thing. > Python is known as "the language with more web frameworks than > keywords", and this doesn't prevent some of these frameworks to be 1/ > pretty good and 2/ becoming de facto standards. Right. People are selecting web frameworks for their fitness to purposes, but their purposes are many and change over time. So there can be many such frameworks, of varying popularity, and that's a good thing. > > I also suspect - seeing some of the articles that float across the > > FLOSS-o-sphere mentioning "RAD" - that many Open Source developers > > have never had the pleasure [yes, it is a pleasure] of using a > > professional RAD tool. > > This is slightly arrogant. Did you occur to you that quite a few OSS > developers may have at least as much experience as you do with these > kind of tools and just happen to actually prefer the unix way of doing > things ? Yes. As someone who has used some of those all-in-one one-size-fits-most tools, I can testify that their usefulness is severely limited when compared with the Unix model. The Unix model is: a collection of general-purpose, customisable tools, with clear standard interfaces that work together well, and are easily replaceable without losing the benefit of all the others. -- \ ?Are you pondering what I'm pondering?? ?Umm, I think so, | `\ Brain, but what if the chicken won't wear the nylons?? ?_Pinky | _o__) and The Brain_ | Ben Finney From rantingrick at gmail.com Mon Jul 11 09:42:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 06:42:50 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> Message-ID: <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> On Jul 10, 11:45?pm, Michael Hrivnak wrote: > I can't believe you're saying that you will create a sub-class without > taking the time to understand the base class. I'm NOT saying that so stop putting words in my mouth! > Seriously? ?That right > there is why you are seeing method overrides that aren't documented. You being a bit bombastic now with this *rolls-eyes* > How can you document something you don't understand? ?Furthermore, how > can you have any confidence in your subclass if you don't understand > what its base class is doing? ?Do you write unit tests? ?How do you > know what to test if you don't understand the code you are > subclassing? You took my simple statement of... " It is not ALWAYS necessary to have an intimate knowledge of the base class when creating derived classes"... and extrapolated THAT nonsense? Okay let me show you a simple example of not needing to know the base class intimatly. I'll use the tkSimpleDialog... class MyDialog(tkSimpleDialog.Dialog): def body(self, master): #imagine i created widgets here. NOW. Would it really be nessesary at this point to have an intimate knowledge of the base class? Hmm? > Suggesting that no developers document their methods? ?Incredible. Very, very few document clobbered virtual methods. yes. > Clobbered methods have "magic"? ?Multi-layered "magic"? Of course! That is, in the perverted case of Clarke's third law[1]... "Any sufficiently advanced technology is indistinguishable from magic"... And since class inheritance can be multi-layered, um, you get the idea. > ?Perhaps when > you take the time to 1) document the base class and 2) understand that > base class before subclassing it, that "magic" will start to look like > reasonable and logical processes. You're preaching to the choir reverend! > Professional developers document their code. ?They take the time to > understand the code they are working on. ?If you don't want to do > those things, that's your business, and I'm sure you can find other > people who also don't do those things. ?But I really don't think > you'll have much success changing the language to accommodate your > refusal to follow the most basic best practices. It's not me that needs to change kind sir, it is the community in general. I document my code. I follow the python style guide. I always create unit tests. Unfortunately no matter how well i write code i cannot force others to do so. Heck i have posted many fixes for the abomination called tkSimpleDialog and not only do they refuse to upgrade the code, they refuse to even post comments! This mandate must be handed down from the gods who reside on "Mount REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" [1] http://en.wikipedia.org/wiki/Clarke's_three_laws From sturlamolden at yahoo.no Mon Jul 11 09:44:22 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 06:44:22 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> Message-ID: <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> On 11 Jul, 14:39, Ben Finney wrote: > The Unix model is: a collection of general-purpose, customisable tools, > with clear standard interfaces that work together well, and are easily > replaceable without losing the benefit of all the others. This is opposed to the "Windows model" of a one-click installer for a monolithic application. Many Windows users get extremely frustrated when they have to use more than one tool. There is also a deep anxiety of using the keyboard. This means that command line tools are out of the question (everything needs a GUI). In the Windows world, even programming should be drag-and-drop with the mouse. Windows programmers will go to extreme measures to avoid typing code on their own, as tke keyboard is so scary. The most extreme case is not Visual Basic but LabView, where even business logic is drag-and-drop. A side-effect is that many Windows developers are too dumb to write code on their own, and rely on pre-coded "components" that can be dropped on a "form". A common fail-case is multiuser applications, where the developers do not understand anything about what is going on, and scalability is non-existent. Sturla From anthony.hw.kong at gmail.com Mon Jul 11 09:51:30 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Mon, 11 Jul 2011 23:51:30 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? Message-ID: Hi, all, Lately I am giving some presentations to my colleagues about the python language. A new internal project is coming up which will require the use of python. One of my colleague asked an interesting: *If Python use indentation to denote scope, why it still needs semi-colon at the end of function declaration and for/while/if loop?* My immediate response is: it allows us to fit statements into one line. e.g. if a == 1: print a However I do not find it to be a particularly strong argument. I think PEP8 does not recommend this kind of coding style anyway, so one-liner should not be used in the first place! Is there any other reasons for use of semi-colon in python? Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Mon Jul 11 09:58:10 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Jul 2011 09:58:10 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <769cc$4e1b01fb$4275d90a$18434@FUSE.NET> On 7/10/11 6:50 PM, Ivan Kljaic wrote: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? http://pyobjc.sourceforge.net/ -- Kevin Walzer Code by Kevin http://www.codebykevin.com From thorsten at thorstenkampe.de Mon Jul 11 10:10:28 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 11 Jul 2011 16:10:28 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: * sturlamolden (Mon, 11 Jul 2011 06:44:22 -0700 (PDT)) > On 11 Jul, 14:39, Ben Finney wrote: > > The Unix model is: a collection of general-purpose, customisable > > tools, with clear standard interfaces that work together well, and > > are easily replaceable without losing the benefit of all the others. > > This is opposed to the "Windows model" of a one-click installer for a > monolithic application. Many Windows users get extremely frustrated > when they have to use more than one tool. *sigh* There is no Windows nor Unix "model". There is only you-get-what- you-pay-for. On Windows, you're a customer and the developer wants to make using his application as convenient as possible for you, the customer. On Unix you don't pay and the developer couldn't care less if his application works together with application b or how much it takes you to actually get this damn thing running. And as soon as developers start developing for Unix customers (say Komodo, for instance), they start following the "Windows model" - as you call it. Thorsten From t at jollybox.de Mon Jul 11 10:16:17 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 16:16:17 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: <4E1B05B1.1050201@jollybox.de> On 07/11/2011 03:51 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use > of python. > > One of my colleague asked an interesting: > > /If Python use indentation to denote scope, why it still needs > semi-colon at the end of function declaration and for/while/if loop?/ > > My immediate response is: it allows us to fit statements into one line. > e.g. if a == 1: print a > > However I do not find it to be a particularly strong argument. I think > PEP8 does not recommend this kind of coding style anyway, so one-liner > should not be used in the first place! Basically, it looks better, and is more readable. A colon, in English like in Python, means that something follows that is related to what was before the colon. So the colon makes it abundantly clear to the human reader that a block follows, and that that block is to be considered in relation to what was just said, before the colon. Coincidentally, Guido wrote this blog post just last week, without which I'd be just as much at a loss as you: http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html From sturlamolden at yahoo.no Mon Jul 11 10:21:37 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 07:21:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> On 11 Jul, 16:10, Thorsten Kampe wrote: > And as soon as developers start developing for Unix customers (say > Komodo, for instance), they start following the "Windows model" - as you > call it. You are probably aware that Unix and Unix customers have been around since the 1970s. I would expect the paradigm to be changed by now. S.M. From call_me_not_now at yahoo.it Mon Jul 11 10:21:37 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:21:37 +0800 Subject: Saving emails Message-ID: Hello, my curiosity these day lay around the problem given by Kmail2. I'd like to keep my old emails and a backup would satisfy my needs. The only conditions should be that the mails will come back in a quick way. I found this page http://www.ducea.com/2006/11/25/cleanup-maildir-folders-archive-delete-old- mails/ Which gives me some point, but the program is too old and I'd like to use Python 3. Another chance it would be to implement an IMAP server which move old emails in and out of an archive. Then it will be simple to recall old emails. Some docs about email deciphering. Kmail uses a maildir and several subfolders. I'd like to export the emails in mbox file and perhaps to separate by a period of time, say July2010, September2010 end so forth. Thanks in advance From anthony.hw.kong at gmail.com Mon Jul 11 10:23:43 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 00:23:43 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B05B1.1050201@jollybox.de> References: <4E1B05B1.1050201@jollybox.de> Message-ID: Awesome! Thanks for blog post link Cheers On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans wrote: > On 07/11/2011 03:51 PM, Anthony Kong wrote: > > Hi, all, > > > > Lately I am giving some presentations to my colleagues about the python > > language. A new internal project is coming up which will require the use > > of python. > > > > One of my colleague asked an interesting: > > > > /If Python use indentation to denote scope, why it still needs > > semi-colon at the end of function declaration and for/while/if loop?/ > > > > My immediate response is: it allows us to fit statements into one line. > > e.g. if a == 1: print a > > > > However I do not find it to be a particularly strong argument. I think > > PEP8 does not recommend this kind of coding style anyway, so one-liner > > should not be used in the first place! > > Basically, it looks better, and is more readable. A colon, in English > like in Python, means that something follows that is related to what was > before the colon. So the colon makes it abundantly clear to the human > reader that a block follows, and that that block is to be considered in > relation to what was just said, before the colon. > > Coincidentally, Guido wrote this blog post just last week, without which > I'd be just as much at a loss as you: > > > http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html > > -- > http://mail.python.org/mailman/listinfo/python-list > -- /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Jul 11 10:24:57 2011 From: gordon at panix.com (John Gordon) Date: Mon, 11 Jul 2011 14:24:57 +0000 (UTC) Subject: How to get or set the text of a textfield? References: Message-ID: In Adam Tauno Williams writes: > Google, or Bing, or even DuckDuckGo, are *not* your friends. They are > enormous and inefficient time-sinks. They are a *BAD* way to solve > problems. Use the documentation. One would hope that a Google search might lead to the documentation. -- 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 davea at ieee.org Mon Jul 11 10:36:48 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 11 Jul 2011 10:36:48 -0400 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: <4E1B0A80.3060305@ieee.org> On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use of > python. > > One of my colleague asked an interesting: > > *If Python use indentation to denote scope, why it still needs semi-colon at > the end of function declaration and for/while/if loop?* > > My immediate response is: it allows us to fit statements into one line. e.g. > if a == 1: print a > > However I do not find it to be a particularly strong argument. I think PEP8 > does not recommend this kind of coding style anyway, so one-liner should not > be used in the first place! > > Is there any other reasons for use of semi-colon in python? > > > Cheers > You're confusing the colon with the semi-colon. If you want two statements on the same line, you use a semi-colon. The character you're asking about is the colon. It goes at the end of an if, else, for, with, while statement. I doubt it's absolutely essential, but it helps readability, since a conditional expression might span multiple lines. if someexpression == someotherexpression: body_of_the_conditional DaveA From thorsten at thorstenkampe.de Mon Jul 11 10:38:05 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 11 Jul 2011 16:38:05 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: * sturlamolden (Mon, 11 Jul 2011 07:21:37 -0700 (PDT)) > On 11 Jul, 16:10, Thorsten Kampe wrote: > > And as soon as developers start developing for Unix customers (say > > Komodo, for instance), they start following the "Windows model" - as > > you call it. > > You are probably aware that Unix and Unix customers have been around > since the 1970s. I would expect the paradigm to be changed by now. For the /customers/ on Unix it never was a paradigm. They would have laughed in their vendor's face if they had gotten the "here are the tools, just make them work together as you like" attitude[1]. Thorsten [1] at least starting from the beginning of the nineties when commercial alternatives to Unix began to emerge From rosuav at gmail.com Mon Jul 11 10:39:17 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 00:39:17 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 12:21 AM, sturlamolden wrote: > You are probably aware that Unix and Unix customers have been around > since the 1970s. I would expect the paradigm to be changed by now. > The paradigm of small tools that do exactly what they're supposed to, and can be combined? Nope. There's still a philosophy of services that fit together like a jigsaw puzzle, rather than expecting each application to do everything you want it to. A standard Unix command line might consist of three or more tools, piping from one into another - grep the Apache log for lines containing the name of a PHP script, pipe that into awk to pick up just the user name, IP address, and date (without time), then pipe into uniq (deliberately without first going through sort) to show who's been using the script lately. And then piped it through sed to clean up the format a bit. Yep, that's something I did recently. Point to note: This is the Unix *philosophy* versus the Windows *philosophy*, not Unix *programs* versus Windows *programs*. There are Windows programs that follow the Unix philosophy. ChrisA From rosuav at gmail.com Mon Jul 11 10:41:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 00:41:59 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 11:42 PM, rantingrick wrote: > This mandate must be handed down from the gods who reside on "Mount > REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" > I assume you're trying to reference Mount Olympus where the Greek gods live, but I'm left thinking more of Mount Vesuvius... possibly not the best reference for what you're saying. But once again, Ranting Rick posts something saying that he is perfect and everyone else needs to change. I can see why you keep landing in killfiles [1]. ChrisA [1] http://bofh.ch/bofh/bsmh2.html From call_me_not_now at yahoo.it Mon Jul 11 10:42:19 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:42:19 +0800 Subject: Finding duplicated photo References: Message-ID: Thomas Jollans wrote: > If Gwenview simply moves/renames the images, is it not enough to compare > the actual files, byte by byte? For the work at the spot I found Geeqie, doing right. In the other hand learning some PIL function is one of my interest. From invalid at invalid.invalid Mon Jul 11 10:43:53 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Jul 2011 14:43:53 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-11, Thomas Jollans wrote: > On 07/11/2011 03:51 PM, Anthony Kong wrote: >> Hi, all, >> >> Lately I am giving some presentations to my colleagues about the python >> language. A new internal project is coming up which will require the use >> of python. >> >> One of my colleague asked an interesting: >> >> /If Python use indentation to denote scope, why it still needs >> semi-colon at the end of function declaration and for/while/if loop?/ >> >> My immediate response is: it allows us to fit statements into one line. >> e.g. if a == 1: print a >> >> However I do not find it to be a particularly strong argument. I think >> PEP8 does not recommend this kind of coding style anyway, so one-liner >> should not be used in the first place! > > Basically, it looks better, and is more readable. And it makes adding a "python mode" to a programming editor almost trivial. -- Grant Edwards grant.b.edwards Yow! I am a jelly donut. at I am a jelly donut. gmail.com From call_me_not_now at yahoo.it Mon Jul 11 10:50:00 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:50 +0800 Subject: Finding duplicated photo References: Message-ID: Kevin Zhang wrote: > If anyone's interested, pleas checkout the source code in the attachment > and welcome any advise. I found that isn't python 3 code :( Then the code should go into some other program to allow actions on those pictures which are matching each other. Am I right? From sebastien.volle at gmail.com Mon Jul 11 10:50:20 2011 From: sebastien.volle at gmail.com (=?ISO-8859-1?Q?S=E9bastien_Volle?=) Date: Mon, 11 Jul 2011 16:50:20 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: Could it have been made optional, like the trailing comma in list declaration? -- Seb 2011/7/11 Anthony Kong > Awesome! Thanks for blog post link > > Cheers > > > On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans wrote: > >> On 07/11/2011 03:51 PM, Anthony Kong wrote: >> > Hi, all, >> > >> > Lately I am giving some presentations to my colleagues about the python >> > language. A new internal project is coming up which will require the use >> > of python. >> > >> > One of my colleague asked an interesting: >> > >> > /If Python use indentation to denote scope, why it still needs >> > semi-colon at the end of function declaration and for/while/if loop?/ >> > >> > My immediate response is: it allows us to fit statements into one line. >> > e.g. if a == 1: print a >> > >> > However I do not find it to be a particularly strong argument. I think >> > PEP8 does not recommend this kind of coding style anyway, so one-liner >> > should not be used in the first place! >> >> Basically, it looks better, and is more readable. A colon, in English >> like in Python, means that something follows that is related to what was >> before the colon. So the colon makes it abundantly clear to the human >> reader that a block follows, and that that block is to be considered in >> relation to what was just said, before the colon. >> >> Coincidentally, Guido wrote this blog post just last week, without which >> I'd be just as much at a loss as you: >> >> >> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > /*--*/ > Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence _much_ too much credit. > > - Linus Torvalds > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From call_me_not_now at yahoo.it Mon Jul 11 10:54:44 2011 From: call_me_not_now at yahoo.it (Fulvio) Date: Mon, 11 Jul 2011 22:54:44 +0800 Subject: Finding duplicated photo References: Message-ID: Dave Angel wrote: > If your real problem is identifying a renamed file amongst thousands of > others, why not just compare the metadata? it'll be much faster. > This was the primer situation, then to get into the dirt I tought something more sophisticated. There was a program some year's back which was brilliant an fast to find similar pictures on several thousand of them. Now I can't recall what was the program name and very interesting to do some of mine experiments. From t at jollybox.de Mon Jul 11 11:01:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 17:01:58 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B0A80.3060305@ieee.org> References: <4E1B0A80.3060305@ieee.org> Message-ID: <4E1B1066.5070107@jollybox.de> On 07/11/2011 04:36 PM, Dave Angel wrote: > The character you're asking about is the colon. It goes at the end of > an if, else, for, with, while statement. I doubt it's absolutely > essential, but it helps readability, since a conditional expression > might span multiple lines. > if someexpression == > someotherexpression: > body_of_the_conditional That, of course, is not legal Python. Your point stands when you add brackets or a backslash to hold the condition together. From anthony.hw.kong at gmail.com Mon Jul 11 11:07:17 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:07:17 +1000 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? Message-ID: Hi, all, Lately I am giving some presentations to my colleagues about the python language. A new internal project is coming up which will require the use of python. One of the goals of the presentations, as told by the 'sponsor' of the presentation, is to help the existing Java/Excel VBA programming team to become productive in python asap. I have a feeling that they are asking it based on their Java/Eclipse experience. By productive they are actually looking for some GUI tools that are as helpful as Eclipse. Having done Java programming before, I am thinking of answering the question this way: 1) For many of us, vi/emacs are sufficient for python development. (I used vim + ctags as my primary IDE for a very long time) 2) For a feature-rich GUI environment, we can consider pyCharm. (I was totally 'wowed' by it, and has convinced my last employer to purchased a few enterprise licenses) 3) The Python language itself is actually small and concise. The need for a full-blown IDE is less. The language itself could be counted as a part of the productive tool. 4) The functional aspect of the language (e.g. map, reduce, partial) helps to make program shorter and easier to understand 5) The 'battery included' standard library helps to avoid the need of complicated build tool. 6) The interactive shell helps to test out solutions in smaller units. It is probably not the team is expecting. Do you have more to add? What do you think about this 'answer'? Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.hw.kong at gmail.com Mon Jul 11 11:10:44 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:10:44 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4E1B0A80.3060305@ieee.org> References: <4E1B0A80.3060305@ieee.org> Message-ID: Sorry, typo in my original question. I do mean 'colon'. It should have read *If Python use indentation to denote scope, why it still needs colon at the end of function declaration and for/while/if loop?* Thanks On Tue, Jul 12, 2011 at 12:36 AM, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > >> Hi, all, >> >> Lately I am giving some presentations to my colleagues about the python >> language. A new internal project is coming up which will require the use >> of >> python. >> >> One of my colleague asked an interesting: >> >> *If Python use indentation to denote scope, why it still needs semi-colon >> at >> the end of function declaration and for/while/if loop?* >> >> My immediate response is: it allows us to fit statements into one line. >> e.g. >> if a == 1: print a >> >> However I do not find it to be a particularly strong argument. I think >> PEP8 >> does not recommend this kind of coding style anyway, so one-liner should >> not >> be used in the first place! >> >> Is there any other reasons for use of semi-colon in python? >> >> >> Cheers >> >> You're confusing the colon with the semi-colon. If you want two > statements on the same line, you use a semi-colon. > > The character you're asking about is the colon. It goes at the end of an > if, else, for, with, while statement. I doubt it's absolutely essential, > but it helps readability, since a conditional expression might span multiple > lines. > if someexpression == > someotherexpression: > body_of_the_conditional > > DaveA > > -- /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 11 11:28:11 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 09:28:11 -0600 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle wrote: > Could it have been made optional, like the trailing comma in list > declaration? Cobra makes the colons optional, so probably yes. From chris.hulan at gmail.com Mon Jul 11 11:33:45 2011 From: chris.hulan at gmail.com (Chris Hulan) Date: Mon, 11 Jul 2011 08:33:45 -0700 (PDT) Subject: OK, I lied, I do have another question... In-Reply-To: Message-ID: The callback is a method so you need to specify the owner builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : self.btnExit_clicked}) Got this info from http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm cheers From chris.hulan at gmail.com Mon Jul 11 11:33:45 2011 From: chris.hulan at gmail.com (Chris Hulan) Date: Mon, 11 Jul 2011 08:33:45 -0700 (PDT) Subject: OK, I lied, I do have another question... In-Reply-To: Message-ID: The callback is a method so you need to specify the owner builder.connect_signals({"on_window_destroy" : gtk.main_quit, "on_btnExit_clicked" : self.btnExit_clicked}) Got this info from http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm cheers From anthony.hw.kong at gmail.com Mon Jul 11 11:54:18 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 01:54:18 +1000 Subject: Property setter and lambda question Message-ID: Hi, all, This question is in the same context of my two earlier questions. This question was raised by some python beginners, and I would like to check with the list to ensure I provide a correct answer. Here is a code snippet I used to demonstrate the keyword *property*: class A(object): def __init__(self): self.__not_here = 1 def __get_not_here(self): return self.__not_here def __set_not_here(self, v): print "I am called" self.__not_here = v not_here = property(lambda self: self.__get_not_here(), lambda self, v: self.__set_not_here(v)) # not_here = property(lambda self: self.__not_here, lambda self, v: self.__not_here = v) So the question: is it possible to use lambda expression at all for the setter? (As in the last, commented-out line) Python interpreter will throw an exception right there if I use the last line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a setter method anyway. What is your preferred solution? -- Tony Kong *blog:* www.ahwkong.com /*--*/ Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence _much_ too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Jul 11 12:00:55 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:00:55 +0200 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: References: Message-ID: <4E1B1E37.4050900@jollybox.de> On 07/11/2011 05:07 PM, Anthony Kong wrote: > Hi, all, > > Lately I am giving some presentations to my colleagues about the python > language. A new internal project is coming up which will require the use > of python. > > One of the goals of the presentations, as told by the 'sponsor' of the > presentation, is to help the existing Java/Excel VBA programming team to > become productive in python asap. > > I have a feeling that they are asking it based on their Java/Eclipse > experience. By productive they are actually looking for some GUI tools > that are as helpful as Eclipse. > > Having done Java programming before, I am thinking of answering the > question this way: > > 1) For many of us, vi/emacs are sufficient for python development. (I > used vim + ctags as my primary IDE for a very long time) > > 2) For a feature-rich GUI environment, we can consider pyCharm. (I was > totally 'wowed' by it, and has convinced my last employer to purchased a > few enterprise licenses) > > 3) The Python language itself is actually small and concise. The need > for a full-blown IDE is less. The language itself could be counted as a > part of the productive tool. If your colleagues are used to Eclipse, it's almost certainly best to continue using Eclipse, with PyDev. Don't make a big deal of the tools, just say that many Pythonista don't use a heavy IDE, mention PyDev, and, if you want to, recommend pyCharm. > 4) The functional aspect of the language (e.g. map, reduce, partial) > helps to make program shorter and easier to understand Don't overemphasize this. Those functions can be very useful, and using them can lead to very concise and simple code, but (big BUT) more often than not, they're overly cryptic when compared to list comprehension and generator expressions. Do make a huge case for generator expressions/list comprehension, and generators. > 5) The 'battery included' standard library helps to avoid the need of > complicated build tool. > > 6) The interactive shell helps to test out solutions in smaller units. Speaking of testing: introduce them to the doctest module. > It is probably not the team is expecting. Do you have more to add? What > do you think about this 'answer'? If using Jython is an option, present it! Jython will allow Java programmers to use their existing knowledge of the Java standard library. Explain, and make the case for, duck typing. While actual functional programming is, as I said, a bit "out there" from a Java/VBA standpoint, do show off function objects. If you know what they're going to do with Python, you should point them to relevant libraries/modules. From wanderer at dialup4less.com Mon Jul 11 12:04:10 2011 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 11 Jul 2011 09:04:10 -0700 (PDT) Subject: ctypes: point to buffer in structure References: Message-ID: <2ffb0be9-923b-4122-b68d-9a5813a579a9@a31g2000vbt.googlegroups.com> On Jul 11, 1:12?am, Tim Roberts wrote: > Jesse R wrote: > > >Hey I've been trying to convert this to run through ctypes and i'm > >having a hard time > > >typedef struct _SYSTEM_PROCESS_ID_INFORMATION > >{ > > ? ?HANDLE ProcessId; > > ? ?UNICODE_STRING ImageName; > >} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, > >*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION; > > >to > > >class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): > > ? ?_fields_ = [('pid', ctypes.c_ulong), > > ? ? ? ? ? ? ? ? ? ?('imageName', ctypes.c_wchar_p)] > >... > >does anyone know how to get this working? > > UNICODE_STRING is not just a pointer to wide characters. ?It is itself a > structure: > > typedef struct _UNICODE_STRING { > ? ? USHORT Length; > ? ? USHORT MaximumLength; > ? ? PWSTR ?Buffer; > > } UNICODE_STRING; > > So, I think you want fields of ctypes.c_ulong, ctypes.c_ushort, > ctypes.c_ushort, and ctypes.c_wchar_p. ?MaximumLength gives the allocated > size of the buffer. ?Length gives the length of the string currently held > in the buffer. ?It can be less than the maximum length, and the buffer does > NOT necessarily contain a zero-terminator. > > UNICODE_STRING and ANSI_STRING are used in kernel programming to avoid the > potential ambiguities of counted strings. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. if UNICODE_STRING is a structure you will want a structure for it class UNICODE_STRING(ctypes.Structure): _fields_ = [("Length", ctypes.c_ushort), ("MaximumLength" ,ctypes.c_ushort), ("Buffer", ctypes.c_wchar_p)] class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure): _fields_ = [("pid", ctypes.c_ulong), ("imageName", UNICODE_STRING)] From t at jollybox.de Mon Jul 11 12:23:39 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:23:39 +0200 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: <4E1B238B.7050607@jollybox.de> On 07/11/2011 05:54 PM, Anthony Kong wrote: > Hi, all, > > This question is in the same context of my two earlier questions. This > question was raised by some python beginners, and I would like to check > with the list to ensure I provide a correct answer. > > Here is a code snippet I used to demonstrate the keyword *property*: > > > class A(object): > > def __init__(self): > self.__not_here = 1 > > def __get_not_here(self): > return self.__not_here > > def __set_not_here(self, v): > print "I am called" > self.__not_here = v > > not_here = property(lambda self: self.__get_not_here(), lambda self, > v: self.__set_not_here(v)) > # not_here = property(lambda self: self.__not_here, lambda self, v: > self.__not_here = v) > > So the question: is it possible to use lambda expression at all for the > setter? (As in the last, commented-out line) > > Python interpreter will throw an exception right there if I use the last > line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a > setter method anyway. > > What is your preferred solution? No, a lambda can only contain an expression, not a statement. This is not C, assignments are not expressions. As to what I would do: There's really no need to use lambdas at all here: class A(object): def __init__(self): self.not_here = 1 def __get_not_here(self): return self.__not_here def __set_not_here(self, val): self.__not_here = val not_here = property(__get_not_here, __set_not_here) My favourite way to create properties is of course with decorators: class A(object): def __init__(self): self.not_here = 1 @property def not_here(self): return self.__not_here @not_here.setter def not_here(self, val): self.__not_here = val From rustompmody at gmail.com Mon Jul 11 12:33:35 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 11 Jul 2011 09:33:35 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: On Jul 11, 7:39?pm, Chris Angelico wrote: > On Tue, Jul 12, 2011 at 12:21 AM, sturlamolden wrote: > > You are probably aware that Unix and Unix customers have been around > > since the 1970s. I would expect the paradigm to be changed by now. > > The paradigm of small tools that do exactly what they're supposed to, > and can be combined? Nope. There's still a philosophy of services that > fit together like a jigsaw puzzle, rather than expecting each > application to do everything you want it to. A standard Unix command > line might consist of three or more tools, piping from one into > another - grep the Apache log for lines containing the name of a PHP > script, pipe that into awk to pick up just the user name, IP address, > and date (without time), then pipe into uniq (deliberately without > first going through sort) to show who's been using the script lately. > And then piped it through sed to clean up the format a bit. Yep, > that's something I did recently. > > Point to note: This is the Unix *philosophy* versus the Windows > *philosophy*, not Unix *programs* versus Windows *programs*. There are > Windows programs that follow the Unix philosophy. > > ChrisA The intention of programming is to close the semantic gap. ------------- It is a fundamental task of software engineering to close the gap between application specific knowledge and technically doable formalization. For this purpose domain specific (high-level) knowledge must be transferred into an algorithm and its parameters (low-level). (from http://en.wikipedia.org/wiki/Semantic_gap ------------- A gui-builder reduces the semantic gap by showing a widget when the programmer things 'widget.' Banging out hundreds of lines in vi/emacs for the same purpose does a measurably poorer job. Note it can reduce but not close. By choosing fidelity to the gui we have corresponding less fidelity to the algos and data-structures [And one may assume that someone even using a gui toolkit wants to do something with the gui and not just paint the screen] Still it seems a bit naive to suggest that building a gui by a few point&clicks is 'windows-model' and banging out hundreds of lines in vi/emacs is 'unix-model.' It does disservice to python and to unix. If a student of mine came and said: Is Python better or Unix? he would receive a dressing down. And yet more than one person here seems to think such type-wrong comparisons are ok. I find this disturbing... From julio at techfuel.net Mon Jul 11 12:38:22 2011 From: julio at techfuel.net (Speedbird) Date: Mon, 11 Jul 2011 09:38:22 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <6609283c-27ec-4e9d-99b3-758c2cdc80ac@17g2000prr.googlegroups.com> > On Windows, you're a customer and the developer wants to make using his > application as convenient as possible for you, the customer. > So the well-behavioured, good-intentioned windows devs are making sure the customer feels pampered and cozy, how nice and dandy. > On Unix you don't pay and the developer couldn't care less if his > application works together with application b or how much it takes you > to actually get this damn thing running. > Now, on the other hand, the bad, bearded, grumpy and ugly unix devs want to make the customer's life miserable, bad boys.. What a load of bull, I am a unix developer and do _care_ for my customers, being them sysadmins, end users or even windows heads, and I am sure I am not the only one thinking this way. The windows "way of doing things" ("user friendly experience", "point and click", "plug and play") etc is not a bad one at all, it consists of tools to allow developers who have lesser understanding about computers to create applications that will be used by users with also little understanding about computers in general, on the other hand, unix/linus/posix devs develop applications that can potentially be used more efficiently by people with great understanding about computers in general. Both have their user base, and this is IMO the primary reason why windows is the dominant OS currently, those with little understanding about computers and technology in general far outnumber those who do. From anthony.hw.kong at gmail.com Mon Jul 11 12:42:56 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:42:56 +1000 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: <4E1B1E37.4050900@jollybox.de> References: <4E1B1E37.4050900@jollybox.de> Message-ID: Thomas, Thanks for the excellent suggestions. Generator is certainly an interesting subject. >From what i understand, the advantage of generator is mainly about saving memory, right? (i.e. no need to create a list in memory before iterate thru it) Duck typing... Although it can be easily demonstrated, I find it hard to explain its advantages to Java developers who are so used to Interfaces. (Is it about the certainty of type info... I am not sure about their concern actually) Jython is not a possibility, but I will show them an example anyway. We can use it to write some support script, I suppose. (Off topic) Monkey patching - It is a term used by Ruby developer a lot. If it means to change a function's implementation in run-time, i think python can achieve the same, right? Is it equivalent to Mixin? Cheers On Tue, Jul 12, 2011 at 2:00 AM, Thomas Jollans wrote: > On 07/11/2011 05:07 PM, Anthony Kong wrote: > > Hi, all, > > > > Lately I am giving some presentations to my colleagues about the python > > language. A new internal project is coming up which will require the use > > of python. > > > > One of the goals of the presentations, as told by the 'sponsor' of the > > presentation, is to help the existing Java/Excel VBA programming team to > > become productive in python asap. > > > > I have a feeling that they are asking it based on their Java/Eclipse > > experience. By productive they are actually looking for some GUI tools > > that are as helpful as Eclipse. > > > > Having done Java programming before, I am thinking of answering the > > question this way: > > > > 1) For many of us, vi/emacs are sufficient for python development. (I > > used vim + ctags as my primary IDE for a very long time) > > > > 2) For a feature-rich GUI environment, we can consider pyCharm. (I was > > totally 'wowed' by it, and has convinced my last employer to purchased a > > few enterprise licenses) > > > > 3) The Python language itself is actually small and concise. The need > > for a full-blown IDE is less. The language itself could be counted as a > > part of the productive tool. > > If your colleagues are used to Eclipse, it's almost certainly best to > continue using Eclipse, with PyDev. Don't make a big deal of the tools, > just say that many Pythonista don't use a heavy IDE, mention PyDev, and, > if you want to, recommend pyCharm. > > > 4) The functional aspect of the language (e.g. map, reduce, partial) > > helps to make program shorter and easier to understand > > Don't overemphasize this. Those functions can be very useful, and using > them can lead to very concise and simple code, but (big BUT) more often > than not, they're overly cryptic when compared to list comprehension and > generator expressions. > > Do make a huge case for generator expressions/list comprehension, and > generators. > > > 5) The 'battery included' standard library helps to avoid the need of > > complicated build tool. > > > > 6) The interactive shell helps to test out solutions in smaller units. > > Speaking of testing: introduce them to the doctest module. > > > It is probably not the team is expecting. Do you have more to add? What > > do you think about this 'answer'? > > If using Jython is an option, present it! Jython will allow Java > programmers to use their existing knowledge of the Java standard library. > > Explain, and make the case for, duck typing. > > While actual functional programming is, as I said, a bit "out there" > from a Java/VBA standpoint, do show off function objects. > > If you know what they're going to do with Python, you should point them > to relevant libraries/modules. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 11 12:43:56 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 10:43:56 -0600 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 9:54 AM, Anthony Kong wrote: > Hi, all, > This question is in the same context of my two earlier questions. This > question was raised by some python beginners, and I would like to check with > the list to ensure I provide a correct answer. > Here is a code?snippet?I used to demonstrate the keyword property: What Thomas said. But also, please note that "property" is a builtin, not a keyword. Cheers, Ian From anthony.hw.kong at gmail.com Mon Jul 11 12:53:29 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:53:29 +1000 Subject: Property setter and lambda question In-Reply-To: <4E1B238B.7050607@jollybox.de> References: <4E1B238B.7050607@jollybox.de> Message-ID: Thanks again for your input, Thomas. I normally prefer not_here = property(lambda self: self.__get_not_here(), lambda self, v: self.__set_not_here(v)) than not_here = property(__get_not_here, __set_not_here) Because it allows me to have a pair getter/setter (when there is a need for it). Use of lambda there is ensure derived class of A can provide their custom version of getter/setter. But decorator! Of course! Thanks for reminding me this. In your example, where does '@not_here' come from? (Sorry, this syntax is new to me) Cheers On Tue, Jul 12, 2011 at 2:23 AM, Thomas Jollans wrote: > On 07/11/2011 05:54 PM, Anthony Kong wrote: > > Hi, all, > > > > This question is in the same context of my two earlier questions. This > > question was raised by some python beginners, and I would like to check > > with the list to ensure I provide a correct answer. > > > > Here is a code snippet I used to demonstrate the keyword *property*: > > > > > > class A(object): > > > > def __init__(self): > > self.__not_here = 1 > > > > def __get_not_here(self): > > return self.__not_here > > > > def __set_not_here(self, v): > > print "I am called" > > self.__not_here = v > > > > not_here = property(lambda self: self.__get_not_here(), lambda self, > > v: self.__set_not_here(v)) > > # not_here = property(lambda self: self.__not_here, lambda self, v: > > self.__not_here = v) > > > > So the question: is it possible to use lambda expression at all for the > > setter? (As in the last, commented-out line) > > > > Python interpreter will throw an exception right there if I use the last > > line ('SyntaxError: lambda cannot contain assignment'). I'd use pass a > > setter method anyway. > > > > What is your preferred solution? > > No, a lambda can only contain an expression, not a statement. This is > not C, assignments are not expressions. > > As to what I would do: > There's really no need to use lambdas at all here: > > class A(object): > def __init__(self): > self.not_here = 1 > def __get_not_here(self): > return self.__not_here > def __set_not_here(self, val): > self.__not_here = val > not_here = property(__get_not_here, __set_not_here) > > My favourite way to create properties is of course with decorators: > > class A(object): > def __init__(self): > self.not_here = 1 > > @property > def not_here(self): > return self.__not_here > > @not_here.setter > def not_here(self, val): > self.__not_here = val > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony.hw.kong at gmail.com Mon Jul 11 12:54:17 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 02:54:17 +1000 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: Good point! Need to get my terminology right. Thanks On Tue, Jul 12, 2011 at 2:43 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 9:54 AM, Anthony Kong > wrote: > > Hi, all, > > This question is in the same context of my two earlier questions. This > > question was raised by some python beginners, and I would like to check > with > > the list to ensure I provide a correct answer. > > Here is a code snippet I used to demonstrate the keyword property: > > What Thomas said. But also, please note that "property" is a builtin, > not a keyword. > > > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Mon Jul 11 12:56:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 09:56:09 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> Message-ID: <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> On Jul 11, 11:33?am, rusi wrote: > A gui-builder reduces the semantic gap by showing a widget when the > programmer things 'widget.' > Banging out hundreds of lines in vi/emacs for the same purpose does a > measurably poorer job. It is very rare to need to "bang out" hundreds of lines of code to replace a mouse click interface. If properly designed a good API can compete with a GUI. In far less time than it takes me to scroll down a list of widgets, pick the appropriate one, drag it across the screen, tinker with it's absolute position, and set some attributes, i could have typed Widget(parent, **kw).geometry(blah, blah) and been done. > Note it can reduce but not close. ?By choosing fidelity to the gui we > have corresponding less fidelity to the algos and data-structures [And > one may assume that someone even using a gui toolkit wants to do > something with the gui and not just paint the screen] Exactly. For this very reason i have always refused to used any "point- and-click" GUI builders. I prefer to get up-close and personal with my code bases. Of course i use high levels of API abstraction for most of the work, however i already know what is happening in the lower levels if i need to dive down one tier. From t at jollybox.de Mon Jul 11 12:58:06 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 18:58:06 +0200 Subject: My take on 'Python Productivity tip for Java Programmer'. Could you give me more feedback? In-Reply-To: References: <4E1B1E37.4050900@jollybox.de> Message-ID: <4E1B2B9E.9080700@jollybox.de> On 07/11/2011 06:42 PM, Anthony Kong wrote: > Thomas, > > Thanks for the excellent suggestions. > > Generator is certainly an interesting subject. > > From what i understand, the advantage of generator is mainly about > saving memory, right? (i.e. no need to create a list in memory before > iterate thru it) When it comes to generator expression vs. list comprehension, yes. It also has the benefit that, if you're reading, say, from the network, you can do things with the content elegantly as it arrives: you can process the first bit when the last bit doesn't yet exist. "Classic" Python-2.3 (?) generators themselves are brilliant invention that makes it easy to create custom iterators. Java has iterators too, but nothing akin to this: def foo(): # do stuff: yield x > Duck typing... Although it can be easily demonstrated, I find it hard to > explain its advantages to Java developers who are so used to Interfaces. > (Is it about the certainty of type info... I am not sure about their > concern actually) They're used to interfaces, yes. Duck typing is little more than implicit interfaces. Python does support Java-style interfaces via ABC, but all the metaclasses and isinstance calls are needless complexity. > Jython is not a possibility, but I will show them an example anyway. We > can use it to write some support script, I suppose. > > (Off topic) Monkey patching - It is a term used by Ruby developer a lot. > If it means to change a function's implementation in run-time, i think > python can achieve the same, right? Is it equivalent to Mixin? Python doesn't have Ruby mixins as such. It's possible to replace functions and methods on any object, but it is almost always better (as in easier to understand and maintain) to modify the class/module you're using, or to subclass it. The only case when it's useful IMHO is when there's a bug or shortcoming in an external library you use, cannot modify, and if subclassing can't achieve the desired results. Don't show your Java programmers this. Being used to static typing, they'll be terrified, and rightly so. Cheers, Thomas From t at jollybox.de Mon Jul 11 13:06:05 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 11 Jul 2011 19:06:05 +0200 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> Message-ID: <4E1B2D7D.4030000@jollybox.de> # On 07/11/2011 06:53 PM, Anthony Kong wrote: # But decorator! Of course! Thanks for reminding me this. # # In your example, where does '@not_here' come from? (Sorry, this syntax # is new to me) class A(object): def __init__(self): self.not_here = 1 @property def not_here(self): return self.__not_here @not_here.setter def not_here(self, val): self.__not_here = val """ Let's translate that to non-decorator Python: """ class A(object): def __init__(self): self.not_here = 1 def _(self): return self.__not_here not_here = property(_) del _ def _(self, val): self.__not_here = val not_here = not_here.setter(_) del _ """ @not_here.setter exists because not_here.setter exists. not_here exists since we set it (when the getter/property was set). Cheers Thomas PS: are you sure the lambda self: self.__foo() trick works, with subclasses or otherwise? I haven't tested it, and I'm not saying it doesn't, but I have a feeling double-underscore name mangling might be a problem somewhere down the line? """ From stefan_ml at behnel.de Mon Jul 11 13:11:56 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 11 Jul 2011 19:11:56 +0200 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: Ivan Kljaic, 11.07.2011 00:50: > Ok Guys. I know that most of us have been expiriencing the need for a > nice Gui builder tool for RAD and most of us have been googling for it > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. Just a quick suggestion regarding the way you posed your question. It's usually better to ask if anyone knows a good tool to do a specific job (which you would describe in your post), instead of complaining about there being none. Even if you googled for it, you may have missed something because it's known under a different name or because it works differently than you expected. Also, as the answers show, your usage of the term "RAD" is ambiguous - not everyone seems to know what you mean with it. Stefan From anthony.hw.kong at gmail.com Mon Jul 11 13:21:14 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 03:21:14 +1000 Subject: Property setter and lambda question In-Reply-To: <4E1B2D7D.4030000@jollybox.de> References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: > > PS: are you sure the lambda self: self.__foo() trick works, with > subclasses or otherwise? I haven't tested it, and I'm not saying it > doesn't, but I have a feeling double-underscore name mangling might be a > problem somewhere down the line? > > Awesome, Thomas. The trick only works if there is only *one* leading underscore in the *method* names. The following example works as I expected for the derived class B. class A(object): def __init__(self): self.__not_here = 1 def _get_not_here(self): return self.__not_here def _set_not_here(self, v): print "I am called" self.__not_here = v not_here = property(lambda self: self._get_not_here(), lambda self, v: self._set_not_here(v)) class B(A): def _set_not_here(self, v): print "version B" self.__not_here = v a = A() # print a.__not_here print a.not_here # a.set_not_here(10) a.not_here = 10 print a.not_here b = B() print b.not_here b.not_here = 70 # print version B print b.not_here -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at codicesoftware.com Mon Jul 11 13:26:27 2011 From: jjposner at codicesoftware.com (John Posner) Date: Mon, 11 Jul 2011 13:26:27 -0400 Subject: Property setter and lambda question In-Reply-To: References: Message-ID: <4E1B3243.4060304@codicesoftware.com> On 2:59 PM, Anthony Kong wrote: > So the question: is it possible to use lambda expression at all for > the setter? (As in the last, commented-out line) > > Python interpreter will throw an exception right there if I use the > last line ('SyntaxError: lambda cannot contain assignment'). I'd use > pass a setter method anyway. > > What is your preferred solution? Anthony, you might take a look at this alternative writeup for "property", which I placed on the Python Wiki: http://wiki.python.org/moin/AlternativeDescriptionOfProperty HTH, John From ian.g.kelly at gmail.com Mon Jul 11 13:35:05 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 11:35:05 -0600 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 10:53 AM, Anthony Kong wrote: > Thanks again for your input, Thomas. > I normally prefer > not_here = property(lambda self: self.__get_not_here(), lambda self,?v: > self.__set_not_here(v)) > than > not_here = property(__get_not_here, __set_not_here) > Because it allows me to have a pair getter/setter (when there is a need for > it). Use of lambda there is ensure derived class of A can provide their > custom version of getter/setter. The .setter convenience method also makes it a bit easier for derived classes to modify getters and setters: class Base(object): def get_my_property(self): return self._my_property def set_my_property(self, value): self._my_property = value my_property = property(get_my_property, set_my_property) class Derived(Base): def set_my_property(self, value): super(Derived, self).set_my_property(convert(value)) my_property = Base.my_property.setter(set_my_property) From ian.g.kelly at gmail.com Mon Jul 11 13:41:41 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2011 11:41:41 -0600 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong wrote: > Awesome, Thomas. The trick only works if there is only?one?leading > underscore in the?method?names. > The following example works as I expected for the derived class B. > class A(object): > ? ? def __init__(self): > ? ? ? ? self.__not_here = 1 > ? ? def _get_not_here(self): > ? ? ? ? return self.__not_here > ? ? def _set_not_here(self, v): > ? ? ? ? print "I am called" > ? ? ? ? self.__not_here = v > ? ? not_here = property(lambda self: self._get_not_here(), lambda self, v: > self._set_not_here(v)) > class B(A): > ? ? def _set_not_here(self, v): > ? ? ? ? print "version B" > ? ? ? ? self.__not_here = v It shouldn't. You've still got the name __not_here used in both A and B, so that the B version is setting a different attribute than the A version (_B__not_here vs. _A__not_here). From anthony.hw.kong at gmail.com Mon Jul 11 13:56:19 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Tue, 12 Jul 2011 03:56:19 +1000 Subject: Property setter and lambda question In-Reply-To: References: <4E1B238B.7050607@jollybox.de> <4E1B2D7D.4030000@jollybox.de> Message-ID: So subclass B has no access to __not_here in A after all... OK, in one of legacy Python I supported there are a lot of code floating around like this. It works OK (in term of business logic and unit test). That's probably due to luck :-) It also uses a lot of __slot__ = ['attr_a', 'attr_b'...] in class definitions to prevent accidental creation of new variables (due to typo for example). Needless to say it was first written up by programmers of static lang background who want to enforce the java/.net behavior... (private variables, variable declaration) Cheers On Tue, Jul 12, 2011 at 3:41 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong > wrote: > > Awesome, Thomas. The trick only works if there is only one leading > > underscore in the method names. > > The following example works as I expected for the derived class B. > > class A(object): > > def __init__(self): > > self.__not_here = 1 > > def _get_not_here(self): > > return self.__not_here > > def _set_not_here(self, v): > > print "I am called" > > self.__not_here = v > > not_here = property(lambda self: self._get_not_here(), lambda self, > v: > > self._set_not_here(v)) > > class B(A): > > def _set_not_here(self, v): > > print "version B" > > self.__not_here = v > > It shouldn't. You've still got the name __not_here used in both A and > B, so that the B version is setting a different attribute than the A > version (_B__not_here vs. _A__not_here). > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what > you get from ruthless massively parallel trial-and-error with a feedback > cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jul 11 14:03:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 04:03:21 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 2:56 AM, rantingrick wrote: > It is very rare to need to "bang out" hundreds of lines of code to > replace a mouse click interface. If properly designed a good API can > compete with a GUI. In far less time than it takes me to scroll down a > list of widgets, pick the appropriate one, drag it across the screen, > tinker with it's absolute position, and set some attributes, ?i could > have typed Widget(parent, **kw).geometry(blah, blah) and been done. > Point to ponder: Human beings tend to memorize names better than images from long lists. Most widgets have names as well as appearances (although it's arguable that the appearance is more what the widget _is_, and the name is somewhat arbitrary), although in some cases there's odd pairings - some toolkits merge Radio Button and Check Box/Button into a single object, others call them two different things. To find the widget you need, you must either scroll a long list and pick the one you want, or key in - possibly with autocompletion assistance - the name. Which is easier to memorize? Which is easier to explain? I'd always rather work with the name. And even with the most point-and-clicky of interface designers, it's normal to be able to see the names of the objects you're working with. The one time where point and click is majorly superior to scripted design is with pixel positioning of widgets. You can drag things around until you're artistically happy with them, rather than have to fiddle with the numbers in code. That's how I learned to code GUIs, but when I started doing cross-platform work and discovered rule-based layouts (where you put objects in boxes and lay out the boxes in order, etc), suddenly life got a LOT easier. ChrisA From ikljaic at gmail.com Mon Jul 11 14:28:40 2011 From: ikljaic at gmail.com (Ivan Kljaic) Date: Mon, 11 Jul 2011 11:28:40 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Ok. I asked about this questio because I am working with python for the last 5 years and I am always in touch about signifigact things in Python. I am pissed of that I make my living by developing applications at work in Java an C#. My comPany would switch to python but they complained that there is not even one single gui builder or framework that can allow it to make a living from it. If you are going to say that there are also other libraries with every single one there is a significant problem that make the development painfull. About the natural selection... I'll say it with the words of penn&teller:bullshit For how many years are this vui library wars going on. How many. Look. I am a open source supporter but Windows will always kick the ass of open source because the open source comunity can not make a decision. Just imagine what we would have today if the effort of development would have been used to develop one really good library. We would have kicked the ass of MS and steve balmer. The average user wants something simple and not something to program to do something. It looks that the firs linux os to realize that is successfull. I am talking about android. And the python development team is doing nothing to improve the situatio to solve this dispute that lasts for the last years by including the worthless Tk library and now upgrading it with Tix. To summarize it. It would be very helpfull for python to spread if there qould be one single good rad gui builder similar to vs or netbeAns but for python. So right now if i need to make a gui app i need to work with an applicatio that is dicontinued for the last 5 years is pretty buggy but is ok. If it would only be maintained and the libraby updated it would be great. When it comes to other application, sorry but they are just bad. Their userfriendlyness is simmilar to most of Ms products, they are "user friendly" but the problem is that they very wisely chose their friends. The ony worthly ones mentioning as an gui builder are boa constructor fo wx, qtDesigner with the famous licence problems why companies do not want to work with it, sharpdevelop for ironpython and netbeans for jython. Did you notice that 2 of these 4 are not for python? One is out of dTe and one has a fucked up licence. Sorry guys but there is not even one single rad gui tool for python as long as there is no serious guibuilder. From igor.begic at gmail.com Mon Jul 11 14:31:18 2011 From: igor.begic at gmail.com (=?UTF-8?Q?Igor_Begi=C4=87?=) Date: Mon, 11 Jul 2011 20:31:18 +0200 Subject: perceptron feed forward neural networks in python Message-ID: Hi, I,m new to Python and i want to study and write programs about perceptron feed forward neural networks in python. Does anyone have a good book or link for this? Thx, Bye -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwatford+python at gmail.com Mon Jul 11 14:47:16 2011 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 11 Jul 2011 14:47:16 -0400 Subject: perceptron feed forward neural networks in python In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > Hi, > I,m new to Python and i want to study and write programs about?perceptron > feed forward neural networks in python. Does anyone have a good book or link > for this? Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". All example code is done in Python, and there's a chapter on multilayer perceptrons. The code for the book is available online here: http://www-ist.massey.ac.nz/smarsland/MLbook.html From rantingrick at gmail.com Mon Jul 11 14:52:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 11:52:14 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Jul 11, 1:03?pm, Chris Angelico wrote: > > The one time where point and click is majorly superior to scripted > design is with pixel positioning of widgets. You can drag things > around until you're artistically happy with them, rather than have to > fiddle with the numbers in code. This is true mostly for the new user of a GUI library or anyone unlucky enough to use a poorly designed API(which leads into my next response) > That's how I learned to code GUIs, > but when I started doing cross-platform work and discovered rule-based > layouts (where you put objects in boxes and lay out the boxes in > order, etc), suddenly life got a LOT easier. A bit tangential however still relevant... i had always considered Tkinter's three geometry managers (pack, place, and grid) to be perfect. However lately i have been musing on the idea of rewriting the pack API into something more intuitive like a "linear-box-style" which then manifests itself in two forms; horizontal and vertical. Of course you can create horizontal and vertical layouts ALREADY by passing the side=LEFT or side=RIGHT to the pack geometry manager of Tkinter widgets (TOP being the default BTW) but that fact isn't always apparent to the new user as the full set of options are side={TOP| BOTTOM|LEFT|RIGHT}. And besides, the current API allows you to pack in all sorts of ridiculous manners; BOTTOM, then TOP, then LEFT, then TOP, then RIGHT, then TOP, then LEFT, then RIGHT, THEN GHEE WHIZ! Are you trying to win the obfuscation award of the year here lad? As we all know you only need three types of geometry management: * Linear (horizontal&vertical) * Grid * Absolute Anything else is just multiplicity run a muck, again! And by propagating such API's we also induce ignorance into our ranks. Before we EVER consider a Python4000 we really need to clean up this atrocious stdlib! It's like i tell people: when you keep screwing your customers over then very soon you'll be out of buisness. Sure you can make a decent living for a short time but the whole house of cards comes crumbling down without the core base of repeat customers. PS: I noticed that Python.org has a suggestion box now for which modules we should be concentrating our community efforts. Well like they say... "imitation is the greatest form of flattery". And i am quite flattered. From egriffith92 at gmail.com Mon Jul 11 14:58:10 2011 From: egriffith92 at gmail.com (Eric Griffith) Date: Mon, 11 Jul 2011 14:58:10 -0400 Subject: A beginning programmer In-Reply-To: References: Message-ID: Shell scripts are ones that I do all the time, sometimes in BASH sometimes in python + system calls. A lot of the mainly for post-install setups of Ubuntu / Fedora / Arch trying to take some of the load off of my hands in a way that I actually know what is going on behind the scenes. But I'll definitely go and check out bugtrackers, I posted this same email to the kde mailing list and one of the developers told me to check out their Junior Jobs, which are things such as comment clean up, spelling errors and things like that so its an introduction to the code itself and I can ease my way in. Thanks or the quick responses guys! From efotinis at yahoo.com Mon Jul 11 14:59:32 2011 From: efotinis at yahoo.com (Elias Fotinis) Date: Mon, 11 Jul 2011 21:59:32 +0300 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel wrote: > Just a quick suggestion regarding the way you posed your question. It's > usually better to ask if anyone knows a good tool to do a specific job > (which you would describe in your post), instead of complaining about there > being none. Opinion is divided on this? From rantingrick at gmail.com Mon Jul 11 15:03:37 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 12:03:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On Jul 11, 1:28?pm, Ivan Kljaic wrote: > To summarize it. It would be very helpfull for python to spread if > there qould be one single good rad gui builder similar to vs or > netbeAns but for python. Well don't hold your breath friend because i have been ranting for years about the sad state of GUI libraries (not just in Python but everywhere). However if somehow "we" (the Python community) could grow a collective brain and build the three tiered system (that i proposed on THIS very list!) then we would have something that no one has! Yes, we would have a future! * Layer1: A 3rd party low level GUI library (owned by the python community) that will be the base from which to build the cake. A Gui library that carries the torch of true 21st century GUI's look and feel, and widgets! (aka: lots of C code here). * Layer2: An abstraction of Layer1 (written in 100% python) for the python std library. (think "PythonGUI") * Layer3: A Graphical GUI builder front end for this expansive and beautiful library (so the kids can play along too). Yes, i DID mention a Graphical Builder. Even though i'd never use one, i DO realize the importance of such tools to this community. From rosuav at gmail.com Mon Jul 11 15:16:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 05:16:30 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 4:28 AM, Ivan Kljaic wrote: > For how many years are this vui library wars going on. How many. Look. > I am a open source supporter but Windows will always kick the ass of > open source because the open source comunity can not make a decision. You think Microsoft makes decisions and sticks with them? Look at Office's last few versions. They can't decide on a file format, an interface, a featureset... everything keeps changing. The difference is that in the open-source world, everything survives and can be seen as a set of alternatives, whereas in the closed-source world, it's either different versions of one program (like MS Office), or competing products (which usually means one of them dies for lack of money - or is bought out by the other). What we have is not indecision, it is options. Imagine if you went to a hardware shop and were offered only one tool: a magnet. Would you laud them for making a decision and sticking with it? No, you'd wonder what they have against hammers and screwdrivers. I like to have tools available to my use, not someone else making my decisions for me. There's competition in the open source world, too; primarily competition for developer time, a quite scarce resource. If a toolkit is not of value to people, it won't get as many dev hours, so you can often gauge popularity and usefulness by the VCS checkins. ChrisA From noway at nohow.com Mon Jul 11 15:21:40 2011 From: noway at nohow.com (Billy Mays) Date: Mon, 11 Jul 2011 15:21:40 -0400 Subject: Why isn't there a good RAD Gui tool for python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: On 07/11/2011 02:59 PM, Elias Fotinis wrote: > On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel > wrote: > >> Just a quick suggestion regarding the way you posed your question. It's >> usually better to ask if anyone knows a good tool to do a specific job >> (which you would describe in your post), instead of complaining about >> there >> being none. > > Opinion is divided on this? > There is another way: http://bash.org/?684045 From rosuav at gmail.com Mon Jul 11 15:27:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 05:27:35 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 4:52 AM, rantingrick wrote: > As we all know you only need three types of geometry management: > ?* Linear (horizontal&vertical) > ?* Grid > ?* Absolute > I contend that Absolute is unnecessary and potentially dangerous. Grid and Box (linear) are the most flexible, but there are others that come in handy too. GTK has quite a few [1] including a scrollable, a notebook, hor/vert panes (where the user can adjust the size between the two panes), and so on. Once again, Ranting Rick is asking for all tools to be destroyed except his preferred minimal set. I think this strongly suggests that Rick is, in point of fact, either brain something'd (keeping this G-rated) or an orangutan, because the ultimate end of his logic is coding in either Brain-*[2] or Ook [3]. ChrisA [1] http://developer.gnome.org/gtk3/stable/LayoutContainers.html [2] http://www.muppetlabs.com/~breadbox/bf/ [3] http://www.dangermouse.net/esoteric/ook.html From sturlamolden at yahoo.no Mon Jul 11 15:37:32 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 12:37:32 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 11 Jul, 20:28, Ivan Kljaic wrote: > The ony worthly ones mentioning as an gui builder are boa constructor > fo wx, qtDesigner with the famous licence problems why companies do > not want to work with it, sharpdevelop for ironpython and netbeans for > jython. There is wxFormBuilder for wxPython, I suppose you've missed it. Of three GUI builders for wxPython (wxFormBuilder, wxGLADE, Boa Constructor), you managed to pick the lesser. The license for Qt is LGPL, the same as for wxWidgets. Both have LGPL Python bindings (PySide and wxPython), so why is Qt's license more scary than wxWidgets? I have an idea why you think QtCreator cannot be used with Python. If you had actually used it, you would have noticed that the XML output file can be compiled by PyQt and PySide. SharpDevelop for IronPython means you've missed Microsoft Visual Studio. Bummer. And I am not going to mention IBM's alternative to NetBeans, as I am sure you can Google it. And did you forget abpout GLADE, or do you disregard GTK (PyGTK) as a toolkit completely? Regards, Sturla From bahamutzero8825 at gmail.com Mon Jul 11 15:48:33 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 11 Jul 2011 14:48:33 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <4E1B5391.1070807@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.11 02:16 PM, Chris Angelico wrote: > You think Microsoft makes decisions and sticks with them? Look at > Office's last few versions. They can't decide on a file format, an > interface, a featureset... everything keeps changing. Of course they do. They've decided to change things in each major version to give people a reason to pay for the new version when there's nothing wrong with the old one (at least nothing that's been fixed in the new version :P ). Of course, MS is not the only software company that employs such a strategy... - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOG1ORAAoJEPiOA0Bgp4/LF7oH/Al6RTGIQ2hAKztEiob/oXnz +eV8HZ0K+OBpd/FtRBkiMTJaQm5LU1jKPdwsf/RhF7UU69FfCQNfhzW5LsdMMQYE +lh4YwbJ8cXVEkCgdkf2zh7BElJ9/95nYedd64Ev4sG+QECvLFYoeql5mjcO45S9 V+iElE9y4FsPr1E0tC2BhFPQuiRMRIIOjQQ7UKP28dnIOKf6u9QM4UdN4WYKOy+n jgXRaFtstA3YtbzqmKfVoj9Go8SstF71XnGjSzAQeq4j96IfbvW/PTaPhkvyfB7y tHG861oW19orvZ1ESJue/lvd/KQ7rRDRn7IjH+fKvKuYlgjM3+Q7hR7hcXi97Wg= =a5A/ -----END PGP SIGNATURE----- From sturlamolden at yahoo.no Mon Jul 11 15:58:26 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 12:58:26 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> On 11 Jul, 20:28, Ivan Kljaic wrote: > To summarize it. It would be very helpfull for python to spread if > there qould be one single good rad gui builder similar to vs or > netbeAns but for python. So right now if i need to make a gui app i > need to work with an applicatio that is dicontinued for the last 5 > years is pretty buggy but is ok. http://wxformbuilder.org/ Shut up. > The ony worthly ones mentioning as an gui builder are boa constructor > fo wx, qtDesigner with the famous licence problems why companies do > not want to work with it, sharpdevelop for ironpython and netbeans for > jython. > Did you notice that 2 of these 4 are not for python? One is out of dTe > and one has a fucked up licence. Qt and PySide have LGPL license. QtCreator can be used with Python (there is a Python uic). SharpDevelop has an IronPython GUI builder. Boa Constructor is abandonware, yes. Is it just me, or did I count to three? And yes, you forgot: Visual Studio for IronPython wxGLADE for wxPython GLADE for PyGTK BlackAdder for Python and Qt SpecTcl for Tkinter That's eight. From sturlamolden at yahoo.no Mon Jul 11 16:02:44 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:02:44 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> Message-ID: <111958c7-5b36-4940-9c44-511e17ae37ed@u30g2000vby.googlegroups.com> On 11 Jul, 21:58, sturlamolden wrote: > That's eight. Sorry, nine ;) From caleb.hattingh at gmail.com Mon Jul 11 16:13:11 2011 From: caleb.hattingh at gmail.com (cjrh) Date: Mon, 11 Jul 2011 13:13:11 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <0092c388-20f0-4dd1-a74a-9bf96af45c34@glegroupsg2000goo.googlegroups.com> On Monday, 11 July 2011 00:50:31 UTC+2, Ivan Kljaic wrote: > But seriously. Why is the not even one single RAD tool > for Python. I simply do not see any reasons why there isn't anything. > Please help me understand it. Any insights? The set of reasons that nobody else has made one is *exactly* the same set of reasons that you're not going to make one. Note that if you prove me wrong, and make one, I still win ;) I am in the somewhat interesting position of having worked continuously with both Python and Delphi (yes, formerly by Borland) for the last decade. I like to think I use both languages/tools idiomatically. I used to lament not having a GUI builder like the Delphi IDE for Python, but I don't any more. Use the right tool for the job, and all that old-timer stuff is starting to make sense. From sturlamolden at yahoo.no Mon Jul 11 16:19:45 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:19:45 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <99dcbad8-a424-4a5d-9909-20e59773ae8e@q1g2000vbj.googlegroups.com> Message-ID: <9ecbc879-9719-4276-8517-e6bdb29f3b12@v12g2000vby.googlegroups.com> On 11 Jul, 21:58, sturlamolden wrote: > http://wxformbuilder.org/ This Demo is using C++, it works the same with Python (wxPython code is generated similarly). http://zamestnanci.fai.utb.cz/~bliznak/screencast/wxfbtut1/wxFBTut1_controller.swf Sturla From kw at codebykevin.com Mon Jul 11 16:35:27 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Jul 2011 16:35:27 -0400 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 7/11/11 2:28 PM, Ivan Kljaic wrote: > Did you notice that 2 of these 4 are not for python? One is out of dTe > and one has a fucked up licence. Sorry guys but there is not even one > single rad gui tool for python as long as there is no serious > guibuilder. One reason there hasn't been much demand for a GUI builder is that, in many cases, it's just as simpler or simpler to code a GUI by hand. Certainly with the Tkinter library this is trivial. The only GUI builder I've ever used that was arguably superior to hand-coding is Interface Builder, on Mac OS X, and it's truly needed there. (The Cocoa frameworks don't really lend themselves to hand-coding.) Otherwise I find GUI builders inflexible, and more trouble than they are worth. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From sturlamolden at yahoo.no Mon Jul 11 16:52:48 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 13:52:48 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: On 11 Jul, 22:35, Kevin Walzer wrote: > One reason there hasn't been much demand for a GUI builder is that, in > many cases, it's just as simpler or simpler to code a GUI by hand. Often a GUI builder is used as a bad replacement for sketch-pad and pencil. With layout managers (cf. wxWidgets, Qt, Swing, SWT, Tkinter) it is easier to "sketch and code" than with common MS Windows toolkits (eg. MFC, .NET Forms, Visual Basic, Delphi) which use absolute positioning and anchors. Using a GUI builder with layout managers might actually feel awkward. But with absolute positioning and anchors, there is no way to avoid a GUI builder. That said, we have good GUI builders for all the common Python GUI toolkits. Sometimes a mock-up GUI designer like DesignerVista might help. Yes, and actually hiring a graphical designer helps too. Sturla From sturlamolden at yahoo.no Mon Jul 11 17:07:36 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 14:07:36 -0700 (PDT) Subject: perceptron feed forward neural networks in python References: Message-ID: <9bbb3188-9f96-4dd4-833a-3ce60fd7421e@h14g2000yqd.googlegroups.com> On 11 Jul, 20:47, Ken Watford wrote: > On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > > Hi, > > I,m new to Python and i want to study and write programs about?perceptron > > feed forward neural networks in python. Does anyone have a good book or link > > for this? > > Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". > All example code is done in Python, and there's a chapter on > multilayer perceptrons. > > The code for the book is available online here:http://www-ist.massey.ac.nz/smarsland/MLbook.html This is quite simple with tools like NumPy and SciPy. E.g. use numpy.dot (level-3 BLAS matrix multiply) for the forward pass, and scipy.optimize.leastsq (MINPACK Levenberg-Marquardt) for the training. Sturla From rantingrick at gmail.com Mon Jul 11 17:46:51 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 11 Jul 2011 14:46:51 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> On Jul 11, 9:41?am, Chris Angelico wrote: > On Mon, Jul 11, 2011 at 11:42 PM, rantingrick wrote: > > This mandate must be handed down from the gods who reside on "Mount > > REFUSE-E-OUS to RECOGNIZE-E-OUS a major PROBLEM-O-MOUS" > > I assume you're trying to reference Mount Olympus where the Greek gods > live, but I'm left thinking more of Mount Vesuvius... possibly not the > best reference for what you're saying. Actually no i was purposely implying Mt. Vesuvius. You know, the VOLCANO that erupted and left poor Pompeii in ruins? Here is some text from the wiki verbatim: """Mount Vesuvius is best known for its eruption in AD 79 that led to the burying and destruction of the Roman cities of Pompeii and Herculaneum. They were never rebuilt, although surviving townspeople and probably looters did undertake extensive salvage work after the destructions.""" I modified the text "slightly" to reflect our current conundrum: """Guido and Pydev are best known for their absence around 2000, which led to the burying and destruction of comp.lang.Python (and the community as a whole) in ash clowns. They were never rebuilt, although a few surviving "good" townspeople did undertake extensive attacks from trolls after the destruction.""" From bruce at whealton.info Mon Jul 11 18:04:18 2011 From: bruce at whealton.info (Bruce Whealton) Date: Mon, 11 Jul 2011 18:04:18 -0400 Subject: Newbie help - Programming the Semantic Web with Python In-Reply-To: References: <1356CE18703044AEA015CB1C4BA9A3C7@BrucePC> Message-ID: This didn't seem to work either. I was getting errors the number of arguments expected being two, when I changed to def add (self, args): I seem to remember that if I removed the parentheses around sub, pred, obj, it worked. I thought that was how it worked. What is strange is that this is not reported as an error on the books page. So, it should have worked as is with either Python 2.7, which I have installed or Python 3.0 which I also have installed. So, it seems like it would have worked as is for one of the versions of Python, but it doesn't seem to work that way. I'll paste a link to where the code exists. Could someone help me figure it out please. The code is here on the site: http://semprog.com/content/the-book/ I wonder if I can also try it out from the IDLE interactive session. Thanks, Bruce On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton wrote: problem with is this line: > def add(self, (sub, pred, obj)): > I think the problem is with the parentheses before the sub. I removed > those and that seemed to fix that error or make it go away. I don?t > remember how I figured that out, It should be on the Errata page for > sure. > Then it has a problem with this line: > print list(g.triples((None, None, None))) > If I was using python 3, it would require () around the thing that is > going to be printed, right? Maybe python 2.7 doesn?t like this line for > the same reason. > The issue there is with tuple unpacking. To match the older syntax, don't touch the call, but change the definition thus: def add(self, args): (sub, pred, obj)=args Or, of course, simply list the arguments directly, rather than in a tuple; but that requires changing every call (if it's a small program that may not be a problem). You're right about needing parentheses around the print() call; in Python 2 it's a statement, but in Python 3, print is a function like any other. Regarding the module search path, this may help: http://docs.python.org/dev/tutorial/modules.html#the-module-search-path Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list From pavlovevidence at gmail.com Mon Jul 11 18:11:17 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 11 Jul 2011 15:11:17 -0700 (PDT) Subject: Function docstring as a local variable In-Reply-To: Message-ID: <667f794a-33f6-4b71-a4f5-fe44b96b8d70@glegroupsg2000goo.googlegroups.com> On Sunday, July 10, 2011 4:06:27 PM UTC-7, Corey Richardson wrote: > Excerpts from Carl Banks's message of Sun Jul 10 18:59:02 -0400 2011: > > print __doc__ > > > > Python 2.7.1 (r271:86832, Jul 8 2011, 22:48:46) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def foo(): > ... "Docstring" > ... print __doc__ > ... > >>> foo() > None > >>> > > What does yours do? It prints the module docstring, same as your example does. You did realize that was the question I was answering, right? Carl Banks From nad at acm.org Mon Jul 11 18:22:09 2011 From: nad at acm.org (Ned Deily) Date: Mon, 11 Jul 2011 15:22:09 -0700 Subject: How to compile on OS X PPC? was: Re: [RELEASED] Python 3.2 References: <4d640175$0$81482$e4fe514c@news.xs4all.nl> Message-ID: In article , Ned Deily wrote: > In article <4d640175$0$81482$e4fe514c at news.xs4all.nl>, > Irmen de Jong wrote: > > However, I'm having trouble compiling a framework build from source on > > Mac OS 10.5.8 on PowerPC. No matter what I try (gcc 4.0, gcc 4.2, > > different compiler options), the compilation aborts with the following > > error: > > > > Undefined symbols: > > "___fixdfdi", referenced from: > > _rlock_acquire in libpython3.2m.a(_threadmodule.o) > > _lock_PyThread_acquire_lock in libpython3.2m.a(_threadmodule.o) > > "___moddi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > "___divdi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > ld: symbol(s) not found > > /usr/bin/libtool: internal link edit command failed > > Unfortunately, this is a variation of an old issue that hasn't yet been > fixed (http://bugs.python.org/issue1099). UPDATE: this problem has been fixed in the newly-release Python 3.2.1. On a 10.4 or 10.5 PPC machine, you should now be able to successfully build a PPC-only 3.2 framework with just: ./configure --enable-framework ; make On 10.5, you may want to use: ./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.5 ; make -- Ned Deily, nad at acm.org From RJones at iso.com Mon Jul 11 18:30:34 2011 From: RJones at iso.com (Jones, Rebecca) Date: Mon, 11 Jul 2011 18:30:34 -0400 Subject: Read SAS files with Python? Message-ID: <3F4E4D643FA05D499A93FB483D68C3020BC757A5@ISOEMAILP6.iso.com> Apologies in advance if this is already a time-worn question! We are essentially a "SAS shop" and use Base SAS, Enterprise Guide and E-Miner for statistical and predictive modeling purposes, often working on big datasets (30M rows of 100+ columns). There are some applications for which we have had to craft Python solutions, such as interfacing with ArcView to automate the generation of map overelays from shapefiles, but the vast majority of our work is well-handled by our SAS suite. However, in the interest of expanding our skillset (and hedging our bets), we are investigating whether anyone has yet developed a Python module that can read SAS datasets directly? Thank you! RJones -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Mon Jul 11 18:33:27 2011 From: nad at acm.org (Ned Deily) Date: Mon, 11 Jul 2011 15:33:27 -0700 Subject: Problem compiling Python 3.2 in 32bit on Snow Leopard References: <8t5vunFcasU1@mid.individual.net> Message-ID: In article , Ned Deily wrote: > In article <8t5vunFcasU1 at mid.individual.net>, > Gregory Ewing wrote: > > Attempting to compile Python 3.2 in 32-bit mode > > on MacOSX 10.6.4 I get: > > > > Undefined symbols: > > "___moddi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > "___divdi3", referenced from: > > _PyThread_acquire_lock_timed in libpython3.2m.a(thread.o) > > _acquire_timed in libpython3.2m.a(_threadmodule.o) > > ld: symbol(s) not found > > /usr/bin/libtool: internal link edit command failed > > > > Any suggestions? > > http://article.gmane.org/gmane.comp.python.general/685151 UPDATE: this problem has been fixed in the newly-released Python 3.2.1. On OX X 10.6, you should be able to build a 10.6 32-bit-only framework with: ./configure --enable-framework CFLAGS="-arch i386" \ LDFLAGS="-arch i386" MACOSX_DEPLOYMENT_TARGET=10.6 -- Ned Deily, nad at acm.org From igor.begic at gmail.com Mon Jul 11 19:04:14 2011 From: igor.begic at gmail.com (=?UTF-8?Q?Igor_Begi=C4=87?=) Date: Tue, 12 Jul 2011 01:04:14 +0200 Subject: perceptron feed forward neural networks in python In-Reply-To: References: Message-ID: thx, bye On Mon, Jul 11, 2011 at 8:47 PM, Ken Watford wrote: > On Mon, Jul 11, 2011 at 2:31 PM, Igor Begi? wrote: > > Hi, > > I,m new to Python and i want to study and write programs about perceptron > > feed forward neural networks in python. Does anyone have a good book or > link > > for this? > > Try Stephen Marsland's "Machine Learning: An Algorithmic Perspective". > All example code is done in Python, and there's a chapter on > multilayer perceptrons. > > The code for the book is available online here: > http://www-ist.massey.ac.nz/smarsland/MLbook.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Jul 11 19:11:26 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:11:26 -0700 Subject: parsing packets In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 5:05 AM, Thomas Rachel < nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de> wrote: > Am 10.07.2011 22:59 schrieb Littlefield, Tyler: > > Hello all: >> I'm working on a server that will need to parse packets sent from a >> client, and construct it's own packets. >> > > Are these packets sent as separate UDP packets or embedded in a TCP stream? > In the first case, you already have packets and only have to parse them. In > a stream, you first have to split them up. > Aren't UDP packets subject to fragmentation and aggregation? -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Jul 11 19:16:32 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:16:32 -0700 Subject: parsing packets In-Reply-To: <4E1A12B1.8060205@tysdomain.com> References: <4E1A12B1.8060205@tysdomain.com> Message-ID: On Sun, Jul 10, 2011 at 1:59 PM, Littlefield, Tyler wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > I like to use this module (I wrote while in the employ of UCI, so it's under a UCI - BSDesque - license, but they've given redistribution permission so long as the module is under their license) to extract pieces from a data source with varied field lengths: http://stromberg.dnsalias.org/~dstromberg/bufsock.html I use it often with TCP. For UDP, I'd probably catentate the blocks recieved and then pull data back out of the aggregate using bufsock - to deal with the possibility of fragmentation or aggregation in transit. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davecook at nowhere.net Mon Jul 11 19:33:46 2011 From: davecook at nowhere.net (Dave Cook) Date: 11 Jul 2011 23:33:46 GMT Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> On 2011-07-10, Ivan Kljaic wrote: > a lot of times. But seriously. Why is the not even one single RAD tool > for Python. I mean what happened to boa constructor that it stopped > developing. I simply do not see any reasons why there isn't anything. I prefer spec-generators (almost all generate XML these days) like QtDesigner to code-generators like Boa. I've only seen one good argument for code generation, and that's to generate code for a layout to "see how it's done". But code could always be generated automatically from a spec. I already have an editor I like, I don't see the need to tie GUI layout to a code editor. If you want something with more sophisticated Python specific features, there's PyDev. Dave Cook From drsalists at gmail.com Mon Jul 11 19:35:53 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 16:35:53 -0700 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4E1B05B1.1050201@jollybox.de> Message-ID: On Mon, Jul 11, 2011 at 8:28 AM, Ian Kelly wrote: > On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle > wrote: > > Could it have been made optional, like the trailing comma in list > > declaration? > > Cobra makes the colons optional, so probably yes. > -- > http://mail.python.org/mailman/listinfo/python-list > A little redundancy in a computer language facilitates error checking - much like the bits of redundancy in one's English make written and voice communication less error prone. But strictly speaking, the colon could've been left out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon Jul 11 20:40:33 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jul 2011 12:40:33 +1200 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> Message-ID: <981jg1F6e9U1@mid.individual.net> Chris Angelico wrote: > either brain something'd (keeping this > G-rated) or an orangutan, There's a certain librarian who might take issue with your lumping orangutans in with the brain-something'd... -- Greg From nambo4jb at gmail.com Mon Jul 11 20:42:10 2011 From: nambo4jb at gmail.com (Cathy James) Date: Mon, 11 Jul 2011 19:42:10 -0500 Subject: Please Help with vertical histogram Message-ID: Please kindly help- i have a project where I need to plot dict results as a histogram. I just can't get the y- axis to print right. May someone please help? I have pulled my hair for the past two weeks, I am a few steps ahead, but stuck for now. def histo(his_dict = {1:16, 2:267, 3:267, 4:169, 5:140, 6:112, 7:99, 8:68, 9:61, 10:56, 11:35, 12:13, 13:9, 14: 7, 15:2}): x_max = 17 #get maximum value of x y_max = 400 #get minimum value of y # print each line print ('^') for j in range(y_max, 0, -100):# draw s = '|' for i in range(1, x_max): if i in his_dict.keys() and his_dict[i] >= j: s += '***' else: s += ' ' print (s) print (j) # print x axis s = '+' for i in range(1, x_max): s += '-+-' s += '>' print (s) # print indexes s = ' ' for i in range(1, x_max): s += ' %d ' % i print (s) histo() # I need it to look like this: 400 -| | | | | 300 -| | | ****** | ****** | ****** 200 -| ****** | ****** | ********* | ************ | ************ 100 -| *************** | ****************** | ************************ | *************************** |********************************* 0 -+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 From drsalists at gmail.com Mon Jul 11 21:06:20 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jul 2011 18:06:20 -0700 Subject: Please Help with vertical histogram In-Reply-To: References: Message-ID: I have a histogram script in Python at http://stromberg.dnsalias.org/svn/histogram/trunk/ It's under a UCI (BSD-like) license. Feel free to use it or borrow ideas from it. On Mon, Jul 11, 2011 at 5:42 PM, Cathy James wrote: > Please kindly help- i have a project where I need to plot dict results > as a histogram. I just can't get the y- axis to print right. May > someone please help? I have pulled my hair for the past two weeks, I > am a few steps ahead, but stuck for now. > > > def histo(his_dict = {1:16, 2:267, 3:267, 4:169, 5:140, 6:112, 7:99, > 8:68, 9:61, 10:56, 11:35, 12:13, 13:9, 14: 7, 15:2}): > > x_max = 17 #get maximum value of x > y_max = 400 #get minimum value of y > # print each line > print ('^') > for j in range(y_max, 0, -100):# draw > > s = '|' > for i in range(1, x_max): > if i in his_dict.keys() and his_dict[i] >= j: > s += '***' > else: > s += ' ' > print (s) > print (j) > # print x axis > s = '+' > for i in range(1, x_max): > s += '-+-' > s += '>' > print (s) > > # print indexes > s = ' ' > for i in range(1, x_max): > s += ' %d ' % i > print (s) > > histo() > > # I need it to look like this: > 400 -| > | > | > | > | > 300 -| > | > | ****** > | ****** > | ****** > 200 -| ****** > | ****** > | ********* > | ************ > | ************ > 100 -| *************** > | ****************** > | ************************ > | *************************** > |********************************* > 0 -+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Jul 11 21:10:26 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2011 11:10:26 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <87wrfoe22l.fsf@benfinney.id.au> Ivan Kljaic writes: > My comPany would switch to python but they complained that there is > not even one single gui builder or framework that can allow it to make > a living from it. That response from your company is a non sequitur. What does ?one single gui builder or framework? have to do with ?allow it to make a living from it?? Evidently many organisations are making a living with Python, so that statement is just false. > For how many years are this vui library wars going on. How many. Why see it as a war that must have one clear winner? You have options. > I am a open source supporter but Windows will always kick the ass of > open source because the open source comunity can not make a decision. Different people make different decisions. If you want a monolithic organisation that makes a single decision for everyone, you don't want software freedom. > To summarize it. It would be very helpfull for python to spread Please find a different language to ?fix?; Python is spreading quite successfully. -- \ ?I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means ?put down?.? ?Bob Newhart | Ben Finney From kevin.misc.10 at gmail.com Mon Jul 11 21:30:28 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Tue, 12 Jul 2011 09:30:28 +0800 Subject: Finding duplicated photo In-Reply-To: References: Message-ID: On Mon, Jul 11, 2011 at 10:50 PM, Fulvio wrote: > > > I found that isn't python 3 code :( > > It's written in python 2.6. > Then the code should go into some other program to allow actions on those > pictures which are matching each other. Am I right? > > The leverages PIL to get the job done. The performance from PIL's quite poor, though not precisely measured, most of the time was spent on resizing pictures with PIL. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Mon Jul 11 21:38:21 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 18:38:21 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <469cd063-7dd8-41f2-af16-55269f67fa29@g16g2000yqg.googlegroups.com> On 12 Jul, 01:33, Dave Cook wrote: > I prefer spec-generators (almost all generate XML these days) like > QtDesigner to code-generators like Boa. I've only seen one good > argument for code generation, and that's to generate code for a layout > to "see how it's done". ?But code could always be generated > automatically from a spec. wxFormBuilder will produce C++, Python and XML. Pick the one you like! The advantage of using XML in tools like GLADE, QtCreator, and more recently Visual C#, is separation of layout and program logic. The problem with code generators like Visual C++ or Delphi was the mixing of generated and hand-written code. However, there is no real advantage over using XML instead of C++ or Python: C++ and Python code are also structured text. One structured text is as good as another: "There once was a man who had a problem. He said: 'I know, I will use XML.' Now he had two problems." When using wxFormBuilder, the generated .cpp, .h, .py or .xrc files are not to be edited. To write event handlers, we inherit from the generated classes. Thus, program view (generated code) and program control (hand-written code) are kept in separate source files. Because C++ and Python have multiple inheritance, we can even separate the program control into multiple classes. What we instantate is a class that inherit the designed dialog class (generated) and event handler classes (hand-written). Therefore, XML has no advantage over Python in the case of wxFormBuilder. XML just adds a second layer of complexity we don't need: I.e. not only must we write the same program logic, we must also write code to manage the XML resources. Hence, we are left with two problems instead of one. This is not special for wxFormBuilder: In many cases when working with Python (and to somewhat lesser extent C++), one is left to conclude that XML serves no real purpose. Sturla From sturlamolden at yahoo.no Mon Jul 11 21:42:09 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 11 Jul 2011 18:42:09 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <4e1b885a$0$2216$c3e8da3$76a7c58f@news.astraweb.com> Message-ID: <46ca0ce1-2817-499b-bc7b-ca41d97a97a0@b21g2000yqc.googlegroups.com> On 12 Jul, 01:33, Dave Cook wrote: > I prefer spec-generators (almost all generate XML these days) like > QtDesigner to code-generators like Boa. I've only seen one good > argument for code generation, and that's to generate code for a layout > to "see how it's done". But code could always be generated > automatically from a spec. wxFormBuilder will produce C++, Python and XML. Pick the one you like! The advantage of using XML in tools like GLADE, QtCreator, and more recently Visual C#, is separation of layout and program logic. The problem with code generators like Visual C++ or Delphi was the mixing of generated and hand-written code. However, there is no real advantage over using XML instead of C++ or Python: C++ and Python code are also structured text. One structured text is as good as another: "There once was a man who had a problem. He said: 'I know, I will use XML.' Now he had two problems." When using wxFormBuilder, the generated .cpp, .h, .py or .xrc files are not to be edited. To write event handlers, we inherit from the generated classes. Thus, program view (generated code) and program control (hand-written code) are kept in separate source files. Because C++ and Python have multiple inheritance, we can even separate the program control into multiple classes. What we instantate is a class that inherit the designed dialog class (generated) and event handler classes (hand-written). Therefore, XML has no advantage over Python in the case of wxFormBuilder. XML just adds a second layer of complexity we don't need: I.e. not only must we write the same program logic, we must also write code to manage the XML resources. Hence, we are left with two problems instead of one. This is not special for wxFormBuilder: In many cases when working with Python (and to somewhat lesser extent C++), one is left to conclude that XML serves no real purpose. Sturla From xahlee at gmail.com Mon Jul 11 23:37:30 2011 From: xahlee at gmail.com (Xah Lee) Date: Mon, 11 Jul 2011 20:37:30 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> Message-ID: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> 2011-07-11 On Jul 11, 6:51?am, jvt wrote: > I might as well toss my two cents in here. ?Xah, I don't believe that > the functional programming idiom demands that we construct our entire > program out of compositions and other combinators without ever naming > anything. ?That is much more the province of so-called "function- > level" programming languages like APL/J and to a more limited extent > concatenative languages where data (but not code) is mostly left > without names. > > Functional programming, in my mind, is about identifying reproducibly > useful abstractions, _naming them_, and constructing other > abstractions from them. ?Your piece of code above probably needs to be > factored out into named pieces so that the composition is more > sensible. ?If a piece of code isn't comprehensible, it might be > because it isn't using the right abstractions in the right way, not > because the notion of functional programming is itself problematic. > > One might instead provide a nightmare nest of procedural code and > claim that procedural programming has problems. Of course, this > particular kind of problem might be less common in procedural code, > since it depends heavily on naming and side effecting values, but it > isn't hard to find procedural code with a long list of operations and > namings wherein the chose names are random or otherwise unrelated to > the problem domain. ?My adviser in grad school used to name variables > after pieces of furniture in dutch, but that didn't cause me to > impeach the _notion_ of procedural code. hi jvt, of course, you are right. But i wasn't criticising functional programing in anyway. was just putting out my tale as a caution, to those of us ? e.g. academic scheme lispers and haskell types ? who are perpetually mangling their code for the ultimate elegant constructs. but speaking on this now... as you guys may know, i was a naive master of Mathematica while being absolute illiterate in computer science or any other lang. (see ?Xah Lee's Computing Experience (Impression Of Lisp from Mathematica)? @ http://xahlee.org/PageTwo_dir/Personal_dir/xah_comp_exp.html ) When i didn't know anything about lisp, i thought lisp would be similar, or even better, as a highlevel lang in comparison to Mathematica. In retrospect now, i was totally wrong. lisp, or scheme lisp, is a magnitude more highlevel in comparison to C or C derivatives such as C++, Java. However, in comparison to Mathematica, it's one magnitude low level. (it pains me to see lisp experts here talking about cons and macros all day, even bigshot names such as one Paul Graham and in lisp books praising lisp macros. Quite ridiculous.) over the years, i had curiosity whether perhaps ML/OCaml, Haskell, would be equivalent high-level as Mathematica as i thought. Unfortunately, my study of them didn't went far. (best result is my incomplete ?OCaml Tutorial? @ http://xahlee.org/ocaml/ocaml.html ) Am not qualified to comment on this, but i think that even Haskell, OCaml, are still quite low in comparison to Mathematica. it's funny, in all these supposedly modern high-level langs, they don't provide even simple list manipulation functions such as union, intersection, and the like. Not in perl, not in python, not in lisps. (sure, lib exists, but it's a ride in the wild) It's really exceedingly curious to me. And it seems that lang authors or its users, have all sorts of execuse or debate about whether those should be builtin if you force them to answer. (i.e. they don't get it) While, we see here regularly questions about implementing union etc with follow up of wild answers and re-invention the thousandth time. Of course, Mathematica has Union, Intersection, and a host of others some 20 years ago, and today it has a complete set of combinatorics functions as *builtin* functions (as opposed to add-on libs of second- rate quality). (this is not a question. No need to suggest some possible reasons why lang might not want to have a whole set of list manipulation builtin. You (the lisper/python/perl regulars and other lang fans) are a complete idiot, that's what i'm saying. COMPLETE IDIOT. (actually, this is not surprising, since genius and true thinkers are rare and few. (such as myself. As they say, beyond the times))) i also wondered, if Mathematica is truely a magnitude higher level than lisp, why we don't see any computer scientists talk about it? (of course there are, but almost non-existant in comparison to, say, academic publications on Scheme, Haskell, even Java) I think the reason is social, again. Proprietary langs isn't a revue of academicians, together with the fact that Stephen Wolfram goes about as if the entire science of computer science comprises of himself. Want Mathematica? Pay $2k+. recently i spent several days studying and watching a talk by Douglas Crockford. it is incredible. He went thru history, and explained, how it is the very people in computing community who laughed and stifled all the great innovations in computing (e.g. innovations in computer languages). Many of these innovations we enjoy today (e.g web) took few decades to finally be accepted (usually in a inferior form (and he showed, how the web came to be thru Tim, and Mosaic etc folks, and cookies and javascript of Netscape by utterly ignoring the tech geeker's loud cries of pain about how things ?should? be. e.g. Tim ignored SGML folk's cries. Mosaic added the image tag, ignoring Tim's cries. ?)). These people, i call tech geekers. (e.g. as we witness here recently, where lisper idiots siging the tunes of cons ? a concept based on hardware that's obsolete for like 30 years.) Douglas Crockford gave many examples thru-out his lectures. i had similar impressions about how new tech is always sneered upon first by the very people of that field (e.g. cookies, js, web email, blogs, instant messaging, and in recent years youtube, twitter, facebook), and old habit really are impossible to die. Progress on comp lang is exceedingly slow, usually in the form of tiny improvements (think of the C C++ Java C# C-go spanning 40 years of minor tweaks, or think of acceptance of functional programing langs). (Douglas says it take a generation to swap people out) For example, lisp cons business, computer language formatting, 80 char line truncation business, unix line truncation business, netquette issues, RFC idiocies and RFC idolization, unix philosphy shit, emacs meta key and UI gospels ?. (you can read bout my take here: ?Computing ? its People? http://xahlee.org/Periodic_dosage_dir/skami_prosa.html ) watch the first episode of Douglas Crockford's talk here: http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 it's a hour and 42 minutes, worth every minute. There are 5 more. Xah From zjuwufan at gmail.com Mon Jul 11 23:59:29 2011 From: zjuwufan at gmail.com (Fan) Date: Mon, 11 Jul 2011 20:59:29 -0700 (PDT) Subject: Questions about os.waitpid(pid, options) on windows Message-ID: <05e436fe-ad07-4e28-a65b-11ea2ad07d3e@eb1g2000vbb.googlegroups.com> It seems that waitpid take process handle instead of process id as the first parameter on Windows. On Unices platform, the first parameter is process id. This interface is a little bit confusing. What's the purpose for such a design? Thanks a lot, Fan From hansmeetschool at gmail.com Tue Jul 12 00:05:45 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Mon, 11 Jul 2011 20:05:45 -0800 Subject: Why isn't there a good RAD Gui tool for python In-Reply-To: References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> Message-ID: lol isnt billy mays dead On 7/11/11, Billy Mays wrote: > On 07/11/2011 02:59 PM, Elias Fotinis wrote: >> On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel >> wrote: >> >>> Just a quick suggestion regarding the way you posed your question. It's >>> usually better to ask if anyone knows a good tool to do a specific job >>> (which you would describe in your post), instead of complaining about >>> there >>> being none. >> >> Opinion is divided on this? >> > > There is another way: http://bash.org/?684045 > -- > http://mail.python.org/mailman/listinfo/python-list > From davidbtdt at gmail.com Tue Jul 12 01:39:55 2011 From: davidbtdt at gmail.com (David) Date: Mon, 11 Jul 2011 22:39:55 -0700 (PDT) Subject: Python bug? Indexing to matrices Message-ID: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Should the following line work for defining a matrix with zeros? c= [[0]*col]*row where "col" is the number of columns in the matrix and "row" is of course the number of rows. If this a valid way of initializing a matrix in Python 3.2.1, then it appears to me that a bug surfaces in Python when performing this line: c[i][j] = c[i][j] + a[i][k] * b[k][j] It writes to the jth column rather than just the i,j cell. I'm new at Python and am not sure if I'm just doing something wrong if there is really a bug in Python. The script works fine if I initialize the matrix with numpy instead: c = np.zeros((row,col)) So, I know my matrix multiply algorithm is correct (I know I could use numpy for matrix multiplication, this was just to learn Python). I've attached my source code below. TIA, David ----- #!python # dot.py - Matrix multiply in matricies: [c] = [a] * [b] import numpy as np a = [[3, 7], [-2, 1], [2, 4]] b = [[2, 1, -3, 1], [4, 3, -2, 3]] print("a = {0}, b = {1}".format(a,b)) row = len(a) col = len(b[0]) #c = np.zeros((row,col)) # <----- Correct results when using this line c= [[0]*col]*row # <----- Incorrect results when using this line print(c) for i in range(row): # Index into rows of [a] for j in range(col): # Index into columns of [b] c[i][j] = 0 for k in range(len(b)): # Index into columns of [a] and rows of [b] print("c[{0}][{1}] + a[{2}][{3}] * b[{4}][{5}] = {6} + {7} * {8}".format(i,j,i,k,k,j,c[i][j],a[i][k],b[k][j])) c[i][j] = c[i][j] + a[i][k] * b[k][j] print(c) From clp2 at rebertia.com Tue Jul 12 01:44:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 11 Jul 2011 22:44:05 -0700 Subject: Python bug? Indexing to matrices In-Reply-To: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 10:39 PM, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row > > where "col" is the number of columns in the matrix and "row" is of > course the number of rows. Nope. See the FAQ: http://docs.python.org/faq/programming.html#how-do-i-create-a-multidimensional-list Cheers, Chris From thorsten at thorstenkampe.de Tue Jul 12 01:50:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 12 Jul 2011 07:50:50 +0200 Subject: Please Help with vertical histogram References: Message-ID: * Cathy James (Mon, 11 Jul 2011 19:42:10 -0500) > Please kindly help- i have a project where I need to plot dict results > as a histogram. I just can't get the y- axis to print right. May > someone please help? I have pulled my hair for the past two weeks, I > am a few steps ahead, but stuck for now. This sounds like homework. There's the Python Tutor mailing list where you will receive help. Thorsten From ben+python at benfinney.id.au Tue Jul 12 01:59:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2011 15:59:59 +1000 Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: <87sjqcdoo0.fsf@benfinney.id.au> David writes: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. Python lists are not matrixes and are not arrays. If you want good implementations of arrays and matrices, use NumPy . -- \ ?Properly read, the Bible is the most potent force for atheism | `\ ever conceived.? ?Isaac Asimov | _o__) | Ben Finney From rosuav at gmail.com Tue Jul 12 04:40:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 18:40:56 +1000 Subject: Virtual functions are virtually invisible! In-Reply-To: <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> <4f41df46-ce82-4c4e-aac3-bd5e82834bc1@z14g2000yqh.googlegroups.com> Message-ID: On Tue, Jul 12, 2011 at 7:46 AM, rantingrick wrote: > Actually no i was purposely implying Mt. Vesuvius. You know, the > VOLCANO that erupted and left poor Pompeii in ruins? Here is some text > from the wiki verbatim: > Yes, I do know that mountain. But it doesn't have very many gods sitting on it... maybe a magma elemental, but that's all. Anyhow, this is quite off-topic for Python I think. (Though not off-topic for rantingrick.) ChrisA From steve+comp.lang.python at pearwood.info Tue Jul 12 06:24:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2011 20:24:02 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> Message-ID: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Thorsten Kampe wrote: > * sturlamolden (Mon, 11 Jul 2011 06:44:22 -0700 (PDT)) >> On 11 Jul, 14:39, Ben Finney wrote: >> > The Unix model is: a collection of general-purpose, customisable >> > tools, with clear standard interfaces that work together well, and >> > are easily replaceable without losing the benefit of all the others. >> >> This is opposed to the "Windows model" of a one-click installer for a >> monolithic application. Many Windows users get extremely frustrated >> when they have to use more than one tool. > > *sigh* There is no Windows nor Unix "model". There is only you-get-what- > you-pay-for. > > On Windows, you're a customer and the developer wants to make using his > application as convenient as possible for you, the customer. That's an astonishing statement. Today, I started to update a commercial, proprietary Windows application, Quickbooks. I didn't actually get around to running the installer application yet, on account of the installer having trouble if your data is on a network share. (Apparently the developers of Quickbooks never considered that when you have multiple users connected to the same database at once, at least one of them must be accessing it over the network.) But in preparation for the process, I took note of the information needed to make QB run. I don't have the list in front of me, but there were something like 6 or 8 keys needed to make the software work: Customer account number Licence key Upgrade key Validation code etc. (I don't remember the full list. I try not to bring that part of my work home :) Or consider the Windows licence key, product activation code, etc. If "as convenient as possible" was their aim (as opposed to "making a profit from licencing"), then you wouldn't need all that. Why on earth should I have to install a "Amazon MP3 Downloader" app to purchase mp3s? Or the iTunes app? The internet and web browsers excel at making it easy to download files. Rather than taking advantage of that convenience, commercial vendors put barriers in the way and try to carve out little walled gardens. Did they not learn anything from AOL? Where is the Windows equivalent of yum or apt-get? Why isn't there a central repository of independent and third party Windows software? It seems clear to me that it is the major open source communities that aim for convenience, at the cost of the opportunity to sell licences. In fairness though, open source developers' idea of "convenient" is not always the same as mine. > On Unix you don't pay and the developer couldn't care less if his > application works together with application b or how much it takes you > to actually get this damn thing running. That might have been true, oh, 20 years ago, but today, that's far less of a rule. Linux distros make interoperability far simpler. Some level of savvy is needed, but it is remarkable how much Linux software Just Works. In my experience, two categories of Linux software are generally hard to deal with: one-man projects (usually stuck on version 0.2b for the last seven years), and big, popular projects that have been taken over by developers from the Windows world (I'm looking at you, Firefox). YMMV. > And as soon as developers start developing for Unix customers (say > Komodo, for instance), they start following the "Windows model" - as you > call it. Surely that's because Komodo started off as a Windows application before being ported to Unix? -- Steven From bahamutzero8825 at gmail.com Tue Jul 12 07:20:36 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 12 Jul 2011 06:20:36 -0500 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E1C2E04.9020704@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.12 05:24 AM, Steven D'Aprano wrote: > Rather than taking advantage of that convenience, commercial vendors > put barriers in the way and try to carve out little walled gardens. > Did they not learn anything from AOL? DRM and activation schemes will /always/ make things harder, but that is the cost of doing business, at least in the minds of commercial software vendors. There are actually a lot of good freeware (proprietary, but zero cost) apps out there. Some even better than open-source alternatives. I avoid commercial apps, though, since they tend to be far inferior to the alternatives (inconvenience aside). > Where is the Windows equivalent of yum or apt-get? Why isn't there a > central repository of independent and third party Windows software? If Microsoft made such a repository, how much of the repository would be high-quality open-source software, and how much would be commercial shovelware? Attempts at independent repos have been made, but they all fail because there's no effort among developers (especially developers of proprietary software), to package their software this way. These attempts also fail because they fail to gain support from users (a catch-22 where users don't bother because there's not much in the repo and there's not much in the repo because users don't bother). > It seems clear to me that it is the major open source communities > that aim for convenience, at the cost of the opportunity to sell > licences. The developers of open-source projects often aim to please the user rather than make money. You'd think pleasing the user and making money would go hand-in-hand, but history has shown that the latter can be achieved with little thought of the former. > That might have been true, oh, 20 years ago, but today, that's far > less of a rule. Linux distros make interoperability far simpler. Some > level of savvy is needed, but it is remarkable how much Linux > software Just Works. At first, Linux had to learn how to crawl and then walk. Now it's doing gymnastics. :) > In my experience, two categories of Linux software are generally hard > to deal with: one-man projects (usually stuck on version 0.2b for the > last seven years), and big, popular projects that have been taken > over by developers from the Windows world (I'm looking at you, > Firefox). YMMV. Firefox (and Thunderbird with it) are falling into the same trap that many fall into when they become popular. This is more prevalent among commercial apps, but it's not too surprising considering Firefox's popularity. The trap is making things shiny. That is, using UI designs (and to a lesser extent adding neat, but generally useless features) that appeal to the computer-illiterate masses who cling to something that looks neat, regardless of how useful it ultimately is. AFAICT, Mozilla's problem isn't that incompetent Windows-centric devs took over, but rather that Google and MS were stepping up their game with their respective browsers and is desperately trying not to lose market share. - -- CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHC4EAAoJEPiOA0Bgp4/Lgm0IAOT+/LQNalPHm5pvt4ilF1yt RM9fPBSgAF5k9U8jWBuQy/V6QJ/a1Sfkzu8ulZ8TyAYS64quucIqTwMJugdTUmct KsGbDsyXg0FObMxNiKKFuZblVYOtnULkYtYZOxeE33qy+85X6NMuFUv7ARHaLi/3 1Bdmnsj43hRrzJ1Rwb8x+xbOmiq+fJ7199loPQ+unSu7s37NJoL1e1vFNnsmGz8A Jg58Q0MbGiwettPdM9ZySYWgTJhiawtEX4SF6YiQqf22e04OyPWyxUfejixnZNoQ 7vbksr9k8PQzuTlG2y3G1pJx6XGrxgOQuEoVjInMGbZW0tx43paJLEWCOcd38FI= =3FGv -----END PGP SIGNATURE----- From xahlee at gmail.com Tue Jul 12 07:54:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 12 Jul 2011 04:54:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? Message-ID: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> maybe this will be of interest. ?What Programing Language Are the Largest Website Written In?? http://xahlee.org/comp/website_lang_popularity.html --------------------------------- i don't remember how, but today i suddenly got reminded that Facebook is written in PHP. So, on the spur of the moment, i twitted: ?Remember folks, the world's largest sites {Facebook, Wikipedia, ?Yahoo!?, etc} are written in Pretty Home Page!? and followed with: ?To Chinese friends, what's Baido, QQ, Taobao, Sina written in?? Then, this question piqued me, even i tried to not waste my time. But it overpowered me before i resisted, becuase i quickly spend 15 min to write this list (with help of Google): 1 Google ? Java 2 Facebook ? PHP 3 YouTube ? Python 4 Yahoo! ? PHP 5 blogger.com ? Java 6 baidu.com ? C/C++. perl/python/ruby 7 Wikipedia ? PHP 8 Windows Live live.com 9 Twitter.com ? Scala and Ruby? 10 QQ.com ? ? 11 MSN.com ? ? 13 LinkedIn ? PHP? 15 TaoBao.com ? ? 16 sina.com.cn ? ? 17 Amazon.com ? ? 18 WordPress.com ? PHP 22 eBay.com ? ? 23 yandex.ru (Russian) ? ? 24 Bing ? ? 27 Microsoft.com ? ? 28 ?? 163.com ? ? 29 PayPal.com ? Java? 31 ???? weibo.com ? ? 32 Flickr.com ? ? 34 mail.ru ? ? 35 Craiglist.org ? perl 36 FC2.com ? ? 38 Apple.com ? Objective J? 39 imdb.com ? ? 41 VKontakte.ru ? ? 43 ??? sohu.com ? ? 44 Ask.com ? ? 45 BBC.co.uk ? ? 46 tumblr.com ? PHP 47 LiveJasmin.com (porn) ? ? 48 xvideos.com (porn) ? ? ? 56 ??? Todou.com ? ? 81 YouPorn.com ? ? StumbleUpon.com ? PHP, Perl, C++ ? the numbers is site ranking, from alexa.com. (missing ones are mostly duplicates, such as google japan, google india, etc.) i think notable interest is that twitter stands out, with Scala and Ruby. Those with perl are probably going back to the first dot com era (aka Web 1.0, ~1995 to ~2002). At that time, perl was basically the only game in town (secondarily: Java). (i don't recall what amazon and ebay were in... was it perl or php? how about imdb.com?) most php follows starting in early 2000s, that's when PHP quietly surpassed perl in all battle fronts. it'd be interesting to know what some of the chinese sites uses, and porn sites (e.g. livejasmin, xvideos, youporn) as for Microsoft sites... are they in C/C++ and or dotnet? Xah From xahlee at gmail.com Tue Jul 12 07:54:47 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 12 Jul 2011 04:54:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? Message-ID: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> maybe this will be of interest. ?What Programing Language Are the Largest Website Written In?? http://xahlee.org/comp/website_lang_popularity.html --------------------------------- i don't remember how, but today i suddenly got reminded that Facebook is written in PHP. So, on the spur of the moment, i twitted: ?Remember folks, the world's largest sites {Facebook, Wikipedia, ?Yahoo!?, etc} are written in Pretty Home Page!? and followed with: ?To Chinese friends, what's Baido, QQ, Taobao, Sina written in?? Then, this question piqued me, even i tried to not waste my time. But it overpowered me before i resisted, becuase i quickly spend 15 min to write this list (with help of Google): 1 Google ? Java 2 Facebook ? PHP 3 YouTube ? Python 4 Yahoo! ? PHP 5 blogger.com ? Java 6 baidu.com ? C/C++. perl/python/ruby 7 Wikipedia ? PHP 8 Windows Live live.com 9 Twitter.com ? Scala and Ruby? 10 QQ.com ? ? 11 MSN.com ? ? 13 LinkedIn ? PHP? 15 TaoBao.com ? ? 16 sina.com.cn ? ? 17 Amazon.com ? ? 18 WordPress.com ? PHP 22 eBay.com ? ? 23 yandex.ru (Russian) ? ? 24 Bing ? ? 27 Microsoft.com ? ? 28 ?? 163.com ? ? 29 PayPal.com ? Java? 31 ???? weibo.com ? ? 32 Flickr.com ? ? 34 mail.ru ? ? 35 Craiglist.org ? perl 36 FC2.com ? ? 38 Apple.com ? Objective J? 39 imdb.com ? ? 41 VKontakte.ru ? ? 43 ??? sohu.com ? ? 44 Ask.com ? ? 45 BBC.co.uk ? ? 46 tumblr.com ? PHP 47 LiveJasmin.com (porn) ? ? 48 xvideos.com (porn) ? ? ? 56 ??? Todou.com ? ? 81 YouPorn.com ? ? StumbleUpon.com ? PHP, Perl, C++ ? the numbers is site ranking, from alexa.com. (missing ones are mostly duplicates, such as google japan, google india, etc.) i think notable interest is that twitter stands out, with Scala and Ruby. Those with perl are probably going back to the first dot com era (aka Web 1.0, ~1995 to ~2002). At that time, perl was basically the only game in town (secondarily: Java). (i don't recall what amazon and ebay were in... was it perl or php? how about imdb.com?) most php follows starting in early 2000s, that's when PHP quietly surpassed perl in all battle fronts. it'd be interesting to know what some of the chinese sites uses, and porn sites (e.g. livejasmin, xvideos, youporn) as for Microsoft sites... are they in C/C++ and or dotnet? Xah From rosuav at gmail.com Tue Jul 12 08:27:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2011 22:27:18 +1000 Subject: Wgy isn't there a good RAD Gui tool fo python In-Reply-To: <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <4e1c20c2$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 12, 2011 at 8:24 PM, Steven D'Aprano wrote: > Where is the Windows equivalent of yum or apt-get? Why isn't there a central > repository of independent and third party Windows software? It seems clear > to me that it is the major open source communities that aim for > convenience, at the cost of the opportunity to sell licences. > The nearest commercial equivalent is probably Apple's iTunes store. It manages to be the "one place to go" for iphone apps, many of which cost money. Upside: Developers know where to host their stuff if they want it to sell. Downside: Developers have to host it there if they want it to sell - and Apple snag 30% on the way through. I've not seen a Windows equivalent, but Microsoft could make one if they wanted to. All they need is for the next version of Windows to recommend that all software be signed, and make it somewhat awkward to install unsigned software, and that would be that. It would probably be the knell of Windows, but it could be done. ChrisA From sturlamolden at yahoo.no Tue Jul 12 08:59:12 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 05:59:12 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> Message-ID: <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> On 12 Jul, 07:39, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. The rows will be aliased. This will work: c = [[0]*col for i in range(row)] Note that Python lists are not ment to be used as matrices. We have NumPy or the array module for that. > If this a valid way of initializing a matrix in Python 3.2.1, then it > appears to me that a bug surfaces in Python when performing this line: > > c[i][j] = c[i][j] + a[i][k] * b[k][j] > > It writes to the jth column rather than just the i,j cell. That is due to aliasing. > I'm new at Python and am not sure if I'm just doing something wrong if > there is really a bug in Python. ?The script works fine if I > initialize the matrix with numpy instead: > > c = np.zeros((row,col)) > > So, I know my matrix multiply algorithm is correct (I know I could use > numpy for matrix multiplication, this was just to learn Python). Like so: np.dot(a,b) or ma = np.matrix(a) mb = np.matrix(b) a*b or call BLAS directly: scipy.linalg.fblas.dgemm Sturla From sturlamolden at yahoo.no Tue Jul 12 09:03:25 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 06:03:25 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> Message-ID: <0e81b1d3-da91-45ca-8f2f-be2c4790300e@t5g2000yqj.googlegroups.com> On 12 Jul, 14:59, sturlamolden wrote: > ? ?ma = np.matrix(a) > ? ?mb = np.matrix(b) > ? ?a*b ma*mb Sorry for the typo. From davidbtdt at gmail.com Tue Jul 12 09:23:25 2011 From: davidbtdt at gmail.com (David) Date: Tue, 12 Jul 2011 06:23:25 -0700 (PDT) Subject: Python bug? Indexing to matrices References: <394aae4f-92ac-406e-bd44-2d2bd3debd91@l1g2000yql.googlegroups.com> <82b0e789-05bc-4e87-bd00-8338a95b2e1e@u42g2000yqm.googlegroups.com> Message-ID: Thank all for the very helpful replies. The goal of the matrix multiply exercise was just to help my son and I learn Python better. I now understand *why* my initialization of [c] was wrong and I am continuing to check out numpy and scipy. Regards, David From gnarlodious at gmail.com Tue Jul 12 09:32:32 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 06:32:32 -0700 (PDT) Subject: Set run vars with each call Message-ID: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Question. Is there a special method or easy way to set default values with each call to an instance? Any ideas to make it easier? What I want to do is have a constantly updating set of values which can be overridden. Just thought there was an easy way to set that up. -- Gnarlie From vincent.toups at gmail.com Tue Jul 12 10:30:59 2011 From: vincent.toups at gmail.com (jvt) Date: Tue, 12 Jul 2011 07:30:59 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: I might argue that it isn't quite right (or politic) to call those who resist technological changes "idiots" so much as to observe they often have goals which cannot wait for the ideal expressive system. People love python not because Python is the platonic programming language, but because it does what they need it to do right now. Ditto (often) for Lisp. It is easy to point out an example of forward thinking languages like Mathematica, and who knows, perhaps it will be the template upon which languages are built in the next 100 years. But if it is, there will be tons of other technologies which _didn't_ make it but which might have seemed equally advanced. Early adoption is always a risk, and few people want to deal with it when technology exists now that solves their problem now, however sub-optimally. That is hardly idiotic, Xah. From alister.ware at ntlworld.com Tue Jul 12 10:46:01 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Tue, 12 Jul 2011 14:46:01 GMT Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: On Tue, 12 Jul 2011 06:32:32 -0700, Gnarlodious wrote: > Question. Is there a special method or easy way to set default values > with each call to an instance? Any ideas to make it easier? What I want > to do is have a constantly updating set of values which can be > overridden. Just thought there was an easy way to set that up. > > -- Gnarlie I thought that was the role of the __init__ function class Something: def __init__(self): self.value="some value" -- No matter how subtle the wizard, a knife in the shoulder blades will seriously cramp his style. From noway at nohow.com Tue Jul 12 10:46:38 2011 From: noway at nohow.com (Billy Mays) Date: Tue, 12 Jul 2011 10:46:38 -0400 Subject: How to write a file generator Message-ID: I want to make a generator that will return lines from the tail of /var/log/syslog if there are any, but my function is reopening the file each call: def getLines(): with open('/var/log/syslog', 'rb') as f: while True: line = f.readline() if line: yield line else: raise StopIteration I know the problem lies with the StopIteration, but I'm not sure how to tell the caller that there are no more lines for now. -- Bill From tjreedy at udel.edu Tue Jul 12 11:03:08 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 15:03:08 -0000 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On 7/11/2011 11:37 PM, Xah Lee wrote: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, Union and intersection are set operations, not list operations. Python has had a set type with a full set of set operations for several years. It has list concatenation, which is the list equivalent of union. It has lots of other useful list operations. > Mathematica has Union, Intersection, and a host of others > some 20 years ago, and today it has a complete set of combinatorics > functions as *builtin* functions Python has the basic combinatoric function in the itertools module, though they are not used much. If Mathematica has Catalan sequences builtin, I wonder how much they are used. Since Python is free, in both meanings, it does not have paid people sitting around writing things to pad numbers to justify a $2k price tag. On the other hand, lots of people have added and made available lots of good add-ons. Mathematica should probably be most fairly compared with Python+numpy+scipy and maybe a few other things. -- Terry Jan Reedy From w_a_x_man at yahoo.com Tue Jul 12 11:27:27 2011 From: w_a_x_man at yahoo.com (WJ) Date: 12 Jul 2011 15:27:27 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: Xah Lee wrote: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. Ruby has them. Intersection: [2,3,5,8] & [0,2,4,6,8] ==>[2, 8] Union: [2,3,5,8] | [0,2,4,6,8] ==>[2, 3, 5, 8, 0, 4, 6] From bruno.desthuilliers at gmail.com Tue Jul 12 11:34:36 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 12 Jul 2011 08:34:36 -0700 (PDT) Subject: How to write a file generator References: Message-ID: On Jul 12, 4:46?pm, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any Err... I must have missed something, but python files are their own iterators. Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. pythonrc start pythonrc done >>> f = open("/var/log/syslog") >>> for line in f: ... print line ... (snip unintersting syslog stuff)) >, but my function is reopening the file > each call: How do you know, and how do you call your function ? > def getLines(): > ? ? ?with open('/var/log/syslog', 'rb') as f: > ? ? ? ? ?while True: > ? ? ? ? ? ? ?line = f.readline() > ? ? ? ? ? ? ?if line: > ? ? ? ? ? ? ? ? ?yield line > ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ?raise StopIteration > > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. If you want the generator to wait until new content is available, just remove the raise part - but you'll have a blocking call... Else, I don't see what behaviour you are expecting exactly. From ckaynor at zindagigames.com Tue Jul 12 11:47:47 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 12 Jul 2011 08:47:47 -0700 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On Mon, Jul 11, 2011 at 8:37 PM, Xah Lee wrote: > > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. > (sure, lib exists, but it's a ride in the wild) Python has them, but, as they are set functions, not list functions, they exist for the set type: Intersection: >>> set((1, 2, 3)) & set((2,3,4)) set([2, 3]) Union: >>> set((1, 2, 3)) | set((2,3,4)) set([1, 2, 3, 4]) Symmetric Difference: >>> set((1, 2, 3)) ^ set((2,3,4)) set([1, 4]) You can also get a non-symmetric difference by calling the difference method of the set: >>> set((1, 2, 3)).difference(set((2,3,4))) set([1]) >>> set((2, 3, 4)).difference(set((1,2,3))) set([4]) >>> In Python 3 (2.7?) there is even more syntactical sugar for them: {1, 2, 3} ^ {2, 3, 4} produces {1, 4}. -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Tue Jul 12 11:52:50 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 17:52:50 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C6DD2.5050707@jollybox.de> On 07/12/2011 04:46 PM, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call: > > def getLines(): > with open('/var/log/syslog', 'rb') as f: > while True: > line = f.readline() > if line: > yield line > else: > raise StopIteration > > > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. > > -- > Bill http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep From daniel.eliason at excite.com Tue Jul 12 12:16:33 2011 From: daniel.eliason at excite.com (fortunatus) Date: Tue, 12 Jul 2011 09:16:33 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <39f3f8c3-67e6-4c14-9e20-286dcef106ea@o4g2000vbv.googlegroups.com> I think the problem with so-called "forward looking" or "highest level" languages is that they tend to become domain specific. What Lispers are always saying is construct your own high level language out of your favorite Lisp. Of course no one else will use it then, or even discuss it, unless you have some good buddies. What happens is that high level languages don't end up addressing needs across a large community. The lower down languages can be common denominators across wide swaths of programmers. So we live in this world of roll-your-own on top of the common denominator language. One exception to this is in data base development, where there were some "4th generation" languages that had some success, where the needs of mapping business data models onto data base oriented implementation has had a large community. I guess Mathematica, or MatLab in my environment, also address a community of needs for modelling mathematical algorithms, or for doing analysis of data sets. However both the data base field and the math/arithmetic tool field are examples of domains that are narrower than programming in general. Hence those higher level languages could be seen as domain specific, but for domains with lots of users. From maththespian87 at gmail.com Tue Jul 12 12:40:23 2011 From: maththespian87 at gmail.com (John Keisling) Date: Tue, 12 Jul 2011 09:40:23 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who Message-ID: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> After too much time coding Python scripts and reading Mark Lutz's Python books, I was inspired to write the following lyrics. For those too young to remember, the tune is that of "Pinball Wizard," by The Who. May it bring you as much joy as it brought me! I cut my teeth on BASIC At scripting I'm no pawn >From C++ to Java My code goes on and on But I ain't seen nothing like this In any place I've gone That modeling and sim guy Sure codes some mean Python! He knows his dictionaries His exceptions never pass His polymorphic methods Extend each superclass He uses indentation Its lines are clearly drawn That modeling and sim guy Sure codes some mean Python! He's a Python wizard His code just never wrecks A Python wizard He knows simple beats complex How do you think he does it? (I don't know) What makes him so good? He codes with TkInter He can render treble clefs He uses lamdba functions With *args in their defs Defines his module search path Of tuples he's the don That modeling and sim guy Sure codes some mean Python! I thought I was The scripting language king But I just handed My Python crown to him He links in to libraries All optimized in C He always uses docstrings For readability He knows file iterators He bids all bugs begone That modeling and sim guy Sure codes some mean Python! From noway at nohow.com Tue Jul 12 12:42:34 2011 From: noway at nohow.com (Billy Mays) Date: Tue, 12 Jul 2011 12:42:34 -0400 Subject: How to write a file generator References: Message-ID: On 07/12/2011 11:52 AM, Thomas Jollans wrote: > On 07/12/2011 04:46 PM, Billy Mays wrote: >> I want to make a generator that will return lines from the tail of >> /var/log/syslog if there are any, but my function is reopening the file >> each call: >> >> def getLines(): >> with open('/var/log/syslog', 'rb') as f: >> while True: >> line = f.readline() >> if line: >> yield line >> else: >> raise StopIteration >> >> >> I know the problem lies with the StopIteration, but I'm not sure how to >> tell the caller that there are no more lines for now. >> >> -- >> Bill > > http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep That was actually the behavior I was trying to avoid. If there is no data to be read, the call will hang. That function is actually called by a webserver (from wsgiref) so it cannot hang indefinitely. -- Bill From msarro at gmail.com Tue Jul 12 12:48:37 2011 From: msarro at gmail.com (Matty Sarro) Date: Tue, 12 Jul 2011 12:48:37 -0400 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: I don't know whether to LOL or mourn the part of me that just died inside :-P j/k j/k clever song, and it made me laugh :) On Tue, Jul 12, 2011 at 12:40 PM, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > > > I cut my teeth on BASIC > At scripting I'm no pawn > >From C++ to Java > My code goes on and on > But I ain't seen nothing like this > In any place I've gone > That modeling and sim guy > Sure codes some mean Python! > > He knows his dictionaries > His exceptions never pass > His polymorphic methods > Extend each superclass > He uses indentation > Its lines are clearly drawn > That modeling and sim guy > Sure codes some mean Python! > > He's a Python wizard > His code just never wrecks > A Python wizard > He knows simple beats complex > > How do you think he does it? > (I don't know) > What makes him so good? > > He codes with TkInter > He can render treble clefs > He uses lamdba functions > With *args in their defs > Defines his module search path > Of tuples he's the don > That modeling and sim guy > Sure codes some mean Python! > > I thought I was > The scripting language king > But I just handed > My Python crown to him > > He links in to libraries > All optimized in C > He always uses docstrings > For readability > He knows file iterators > He bids all bugs begone > That modeling and sim guy > Sure codes some mean Python! > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Tue Jul 12 12:49:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 16:49:40 -0000 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: On 7/11/2011 11:37 PM, Xah Lee wrote: > watch the first episode of Douglas Crockford's talk here: > http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 The link includes a transcript of the talk, which I read I suspect Lee likes Crockford because they both think they are smarter than everyone else. Writing about Smalltalk, for instance, Crockford says: "I don't know why it is, but a lot of programmers just couldn't get used to this syntax. [everything is done by sending a message with arguments to some object] ...So this may be a superior notation, but it was profoundly rejected. By who? By us, by the programmers, because we couldn't understand it." Actually, I and others see Smalltalk as deeply flawed because its message passing syntax arbitrarily breaks symmetries in operations. For instance, in the expression 'a+b', both operands have equivalent roles in the operation for all normal interpretations of '+'.# On the other hand, in the expression 'a.extend(b)', where a is a list and b any iterable and the result is to mutate a but not b, a and b have very different roles in both the operation and the expression that invokes it. # Under the covers, Python implements 'a+b' as first 'a.__add__(b)', but it also tries 'b.__radd__(a)' if the first does not work. This introduces a slight asymmetry in that a gets first say at defining the meaning of 'a+b', but it does not get the only say. And, as far as I can presently remember, this asymmetry is never visible with builtins. In fact, this implementation makes it possible for 'a+b' and 'b+a' to both give the same answer when a is a builtin and b is a user-class instance. Crockford is right that he does not 'know why it is' that not everyone loves Smalltalk. He should have stopped there instead of projecting his ignorance on everyone else. As a side note, the same principle of expressions matching operations in symmetry suggest that majority of up are quite sensible and not dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a function call, the function has a different role than the arguments, so it is appropriate that it have a different role in the expression. -- Terry Jan Reedy From sturlamolden at yahoo.no Tue Jul 12 12:53:23 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 12 Jul 2011 09:53:23 -0700 (PDT) Subject: How to write a file generator References: Message-ID: <2ed7d9e9-3b58-404d-a1dd-8f2688fb4012@e7g2000vbw.googlegroups.com> On 12 Jul, 16:46, Billy Mays wrote: > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. Try 'yield None' instead of 'raise StopIteration'. Sturla From tundra at tundraware.com Tue Jul 12 13:08:53 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 12 Jul 2011 12:08:53 -0500 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <5mbue8-v3i.ln1@ozzie.tundraware.com> On 7/12/2011 11:40 AM, John Keisling said this: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > You realize that you must now reprise this with, "I'm your wicked Uncle Guido" ... right? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From shilparani9030 at gmail.com Tue Jul 12 13:22:39 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Tue, 12 Jul 2011 10:22:39 -0700 (PDT) Subject: SOUTH ACTRESS Message-ID: <625dcdf3-5dd7-49c3-a601-1d96482cd6cb@h7g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gnarlodious at gmail.com Tue Jul 12 13:32:12 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 10:32:12 -0700 (PDT) Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> On Jul 12, 8:46?am, Alister Ware wrote: > I thought that was the role of the __init__ function > > class Something: > ? ? ? ? def __init__(self): > ? ? ? ? ? ? ? ? self.value="some value" OK, that sets a value at init time. But is there a similar built-in to run whenever the class instance is called? -- Gnarlie From tundra at tundraware.com Tue Jul 12 13:34:17 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 12 Jul 2011 12:34:17 -0500 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <5mbue8-v3i.ln1@ozzie.tundraware.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <5mbue8-v3i.ln1@ozzie.tundraware.com> Message-ID: On 7/12/2011 12:08 PM, Tim Daneliuk said this: > On 7/12/2011 11:40 AM, John Keisling said this: >> After too much time coding Python scripts and reading Mark Lutz's >> Python books, I was inspired to write the following lyrics. For those >> too young to remember, the tune is that of "Pinball Wizard," by The >> Who. May it bring you as much joy as it brought me! >> > > > > You realize that you must now reprise this with, > "I'm your wicked Uncle Guido" ... right? > > While were on the subject: "T-t-t-alking 'bout my generator ...." -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From bahamutzero8825 at gmail.com Tue Jul 12 13:50:59 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 12 Jul 2011 12:50:59 -0500 Subject: Set run vars with each call In-Reply-To: <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> Message-ID: <4E1C8983.4070008@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.12 12:32 PM, Gnarlodious wrote: > OK, that sets a value at init time. But is there a similar built-in > to run whenever the class instance is called? What do you mean by call an instance? Do you want to run certain code whenever any method is called? Do you want to want certain code to run whenever an attribute is accessed? Calling an instance doesn't make any sense, especially if you're not referring to the __init__() method. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHImDAAoJEPiOA0Bgp4/LEzYH/1R+cXobysF02GiB45LcXjHm oQsSkrbXtlvutgOlVHOI8MRVRzMndgK+0jWsujYD4nZYf45GO3b0hw/zb9jy3bUI 7BafZMRAz+wI1BJFlDD3P+IjPDoW4WvpMP0q09H4f664DYwQNuXfeveNOwAQnPXl SpqpcvnTm0fqocC0o2G9jUuV50QXFFPntz/VVwl+3UpJLS95pCuAq+URs4OVhLM2 QB1ulmZ35PyfArdz5pYvoXvtfeURldfZhhAm1/mkVThzffUxAcCTANg6AeYd2JNb QO0jSCedhrzWfsK5J63Ax+nrmjvms8+gZ3TxNkdMaz0zICtDuq5lLSIml1JuUfk= =EMT2 -----END PGP SIGNATURE----- From rodneygomes at gmail.com Tue Jul 12 13:59:28 2011 From: rodneygomes at gmail.com (Rodney Gomes) Date: Tue, 12 Jul 2011 10:59:28 -0700 (PDT) Subject: new python contracts library Message-ID: Hey I recently created a contracts library for python and was wondering if anyone finds it useful or wants to have additional features added ? Feel free to open new issues on the github project. https://github.com/rlgomes/contracts This is just a v0.1 and I welcome any and all suggestions to make it into something really useful. I've found it useful for when I start putting together a few other project ideas I have and want to make sure that the certain functions are being used correctly and that bad arguments or return values don't end up blowing up the application in a completely unrelated function call sometime later than the original point where the bug actually occurred. If this is not the correct forum for this posting let me know and i'll move it elsewhere. From phlip2005 at gmail.com Tue Jul 12 14:01:59 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 12 Jul 2011 11:01:59 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <9c6b4082-4b62-4dfc-ab9a-96bf697abb60@k19g2000prn.googlegroups.com> > That modeling and sim guy > Sure codes some mean Python! C-; And he changes key on the fly, too! From tjreedy at udel.edu Tue Jul 12 14:02:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2011 18:02:15 -0000 Subject: How to write a file generator In-Reply-To: References: Message-ID: On 7/12/2011 10:46 AM, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call: > > def getLines(): > with open('/var/log/syslog', 'rb') as f: > while True: > line = f.readline() > if line: > yield line > else: > raise StopIteration Please use spaces rather than (disappearing) tabs in posted code. > I know the problem lies with the StopIteration, but I'm not sure how to > tell the caller that there are no more lines for now. The same way you currently decide when to raise StopIteration def tail(filename): with open(filename, 'rb') as f: while True: yield f.readline() When the caller gets '', it should go and do something else for awhile. -- Terry Jan Reedy From gheskett at wdtv.com Tue Jul 12 14:23:39 2011 From: gheskett at wdtv.com (gene heskett) Date: Tue, 12 Jul 2011 14:23:39 -0400 Subject: Lisp refactoring puzzle In-Reply-To: References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <201107121423.39951.gheskett@wdtv.com> On Tuesday, July 12, 2011 02:08:02 PM Terry Reedy did opine: > On 7/11/2011 11:37 PM, Xah Lee wrote: > > watch the first episode of Douglas Crockford's talk here: > > http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-1 > > The link includes a transcript of the talk, which I read > > I suspect Lee likes Crockford because they both think they are smarter > than everyone else. Writing about Smalltalk, for instance, Crockford > says: > > "I don't know why it is, but a lot of programmers just couldn't get used > to this syntax. [everything is done by sending a message with arguments > to some object] ...So this may be a superior notation, but it was > profoundly rejected. By who? By us, by the programmers, because we > couldn't understand it." > > Actually, I and others see Smalltalk as deeply flawed because its > message passing syntax arbitrarily breaks symmetries in operations. For > instance, in the expression 'a+b', both operands have equivalent roles > in the operation for all normal interpretations of '+'.# On the other > hand, in the expression 'a.extend(b)', where a is a list and b any > iterable and the result is to mutate a but not b, a and b have very > different roles in both the operation and the expression that invokes > it. > > # Under the covers, Python implements 'a+b' as first 'a.__add__(b)', but > it also tries 'b.__radd__(a)' if the first does not work. This > introduces a slight asymmetry in that a gets first say at defining the > meaning of 'a+b', but it does not get the only say. And, as far as I can > presently remember, this asymmetry is never visible with builtins. In > fact, this implementation makes it possible for 'a+b' and 'b+a' to both > give the same answer when a is a builtin and b is a user-class instance. > > Crockford is right that he does not 'know why it is' that not everyone > loves Smalltalk. He should have stopped there instead of projecting his > ignorance on everyone else. > I have my own reasons to hate smalltalk but won't elaborate. > As a side note, the same principle of expressions matching operations in > symmetry suggest that majority of up are quite sensible and not dumb > idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a function call, > the function has a different role than the arguments, so it is > appropriate that it have a different role in the expression. Which should be well documented if one expects the programmers to use it properly. So far, I have only found two languages that are adequately defined and implemented. K&R C, and the now essentially defunct Amiga ARexx. But I should preface that by saying that I have not yet adequately studied python, one of the reasons I joined this list. Specifically, I am trying to install the altera quartus software so I can program one of their DE1 boards, but because the majority of the linux distro's have not kept their repo's zlib packages up to date, one of the quartus imports, gzdirect is on the missing list and I am dead in the water until I install zlib version 1.2.5. I hope this list serves me as a tutorial to fill in the gaps of my python knowledge which at the moment seem too wide to jump over. I hope I can ask intelligent, if newbie, questions occasionally. Now, I hate to mention it Terry, but your clock seems to be about 126 months behind the rest of the world. Does your system not run ntpd by default? The date in the header from your machine is "Mon Jan 1 14:11:11 2001". Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) What makes us so bitter against people who outwit us is that they think themselves cleverer than we are. From cmpython at gmail.com Tue Jul 12 14:43:53 2011 From: cmpython at gmail.com (CM) Date: Tue, 12 Jul 2011 11:43:53 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> Message-ID: <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> > > One reason there hasn't been much demand for a GUI builder is that, in > > many cases, it's just as simpler or simpler to code a GUI by hand. I use a GUI builder because I'd rather click less than type more. I just tried that in Boa Constructor; with ~10 mouse clicks I produced 964 characters of Python code. Now, sure, depending on how I wrote the code I could do better than that, but for me, I just find it more intuitive and easier to use a GUI to make a GUI. > Often a GUI builder is used as a bad replacement for sketch-pad and > pencil. I would use a sketch-pad and pencil and *then* use the GUI builder. What's nice about a builder is one can move things around quickly and see the results in the real application, which one can never really see well on a paper sketch. You could use a mock-up program of course, but I feel you might as well do it in the builder because when you're satisfied with it you have a real runnable application instead of just a picture. > Using a GUI builder with layout managers might actually > feel awkward. It takes some getting used to in Boa, in my experience, but then it feels intuitive and I really like using sizers with Boa. It helps if you give your sizers descriptive names. Che From maththespian87 at gmail.com Tue Jul 12 14:47:13 2011 From: maththespian87 at gmail.com (John Keisling) Date: Tue, 12 Jul 2011 11:47:13 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <5mbue8-v3i.ln1@ozzie.tundraware.com> Message-ID: <8b876209-2146-418c-97d4-8ac63b2d33aa@g3g2000prf.googlegroups.com> On Jul 12, 11:34?am, Tim Daneliuk wrote: > On 7/12/2011 12:08 PM, Tim Daneliuk said this: > > > On 7/12/2011 11:40 AM, John Keisling said this: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. For those > >> too young to remember, the tune is that of "Pinball Wizard," by The > >> Who. May it bring you as much joy as it brought me! > > > > > > You realize that you must now reprise this with, > > "I'm your wicked Uncle Guido" ... right? > > While were on the subject: > > ? "T-t-t-alking 'bout my generator ...." > > -- > ------------------------------------------------------------------------ > Tim Daneliuk > tun... at tundraware.com Brilliant! LOL! From pavlovevidence at gmail.com Tue Jul 12 14:58:26 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 12 Jul 2011 11:58:26 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Tuesday, July 12, 2011 9:40:23 AM UTC-7, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! > > > I cut my teeth on BASIC > At scripting I'm no pawn > From C++ to Java > My code goes on and on > But I ain't seen nothing like this > In any place I've gone > That modeling and sim guy > Sure codes some mean Python! That's pretty funny. I knew what it would be even when I saw the cut-off subject line, and I am too young to remember it. Carl Banks From ian.g.kelly at gmail.com Tue Jul 12 14:59:18 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jul 2011 12:59:18 -0600 Subject: Set run vars with each call In-Reply-To: <4E1C8983.4070008@gmail.com> References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> <4E1C8983.4070008@gmail.com> Message-ID: On Tue, Jul 12, 2011 at 11:50 AM, Andrew Berg wrote: > On 2011.07.12 12:32 PM, Gnarlodious wrote: >> OK, that sets a value at init time. But is there a similar built-in >> to run whenever the class instance is called? > What do you mean by call an instance? Do you want to run certain code > whenever any method is called? Do you want to want certain code to run > whenever an attribute is accessed? Calling an instance doesn't make any > sense, especially if you're not referring to the __init__() method. If I'm understanding correctly, I think the OP wants to do something like this: class Gadget: def do_something(self, some_argument=some_default_value): # do stuff where the exact default value of some_argument depends on the current state of the Gadget instance. The canonical approach here would be: class Gadget: def do_something(self, some_argument=None): if some_argument is None: some_argument = self._some_argument_default # do stuff And then the other instance methods of Gadget can update the default by setting the value of the _some_argument_default attribute. From newsmailcomp6 at gustad.com Tue Jul 12 15:02:51 2011 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: Tue, 12 Jul 2011 21:02:51 +0200 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <87y603nwys.fsf@pangea.home.gustad.com> Xah Lee writes: > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. In Common Lisp you have: CL-USER> (union '(a b c) '(b c d)) (A B C D) CL-USER> (intersection '(a b c) '(b c d)) (C B) //Petter -- .sig removed by request. From t at jollybox.de Tue Jul 12 15:04:37 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 21:04:37 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C9AC5.4010204@jollybox.de> On 07/12/2011 06:42 PM, Billy Mays wrote: > On 07/12/2011 11:52 AM, Thomas Jollans wrote: >> On 07/12/2011 04:46 PM, Billy Mays wrote: >>> I want to make a generator that will return lines from the tail of >>> /var/log/syslog if there are any, but my function is reopening the file >>> each call: >>> >>> def getLines(): >>> with open('/var/log/syslog', 'rb') as f: >>> while True: >>> line = f.readline() >>> if line: >>> yield line >>> else: >>> raise StopIteration >>> >>> >>> I know the problem lies with the StopIteration, but I'm not sure how to >>> tell the caller that there are no more lines for now. >>> >>> -- >>> Bill >> >> http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep >> > > > That was actually the behavior I was trying to avoid. If there is no > data to be read, the call will hang. That function is actually called > by a webserver (from wsgiref) so it cannot hang indefinitely. In that case, what Bruno said. From t at jollybox.de Tue Jul 12 15:05:52 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 12 Jul 2011 21:05:52 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: <4E1C9B10.3020409@jollybox.de> On 07/12/2011 06:42 PM, Billy Mays wrote: > On 07/12/2011 11:52 AM, Thomas Jollans wrote: >> On 07/12/2011 04:46 PM, Billy Mays wrote: >>> I want to make a generator that will return lines from the tail of >>> /var/log/syslog if there are any, but my function is reopening the file >>> each call: >>> >>> def getLines(): >>> with open('/var/log/syslog', 'rb') as f: >>> while True: >>> line = f.readline() >>> if line: >>> yield line >>> else: >>> raise StopIteration >>> >>> >>> I know the problem lies with the StopIteration, but I'm not sure how to >>> tell the caller that there are no more lines for now. >>> >>> -- >>> Bill >> >> http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep >> > > > That was actually the behavior I was trying to avoid. If there is no > data to be read, the call will hang. That function is actually called > by a webserver (from wsgiref) so it cannot hang indefinitely. What Terry said, then. (Not Bruno, I confused that. Sorry for sending a mail both short and wrong.) From ameliagrace143 at gmail.com Tue Jul 12 15:07:50 2011 From: ameliagrace143 at gmail.com (Amelia Grace) Date: Tue, 12 Jul 2011 12:07:50 -0700 (PDT) Subject: Complete Google Advertising Solutions Message-ID: <40a1c4de-5774-4c8d-a4ea-1a8c728c72e8@fv14g2000vbb.googlegroups.com> TheItValley is a capable web development application, software combination, search engine optimization, E-commerce, E-banking and complete Google advertising solution Organization based in UK main branches office in Sweden, Norway and Pakistan. The Internet is the most efficient and greatest growing sales channel for many organizations. Through internet every organization can enhance the sale and purchase volume which is very effective and significant way. Therefore TheitValley is offering complete Google advertising solutions to evaluate the E commerce and E business solutions using the Internet to increase customers and generate more sales. Choosing the right E commerce supplier is a key decision: choosing one with a proven track record, experience and deep familiarity with all aspects of the online marketing, TIV is aimed at providing elevated quality and cost-induced web application/software solutions from small to medium organizations worldwide by combining the onsite analysis phase with offshore development & testing phase, followed by onsite implementation. With the help of TIV?s Global Delivery Model, software project costs of its clients worldwide can be reduced by about 50% without having to compromise on absolute quality and delivery schedules. The projects are executed on Fixed-Price or Time & Material basis, depending upon the nature of each project. Internet marketing is the origin link building for any quality Internet marketing operation. We Build Pages views links as ?votes? for your website, justification from the Internet society that your website and associated services and resources are valuable. The additional links, the more popular the website, and the higher it will rank in the search engines; but there is a catch, not all votes are the same. The more authoritative the site that links to another site, the more ?votes? its worth. We Build Pages targets the most authoritative sites to ensure that your link building efforts get the most bang for your buck. We all want more traffic, and more importantly, we want that traffic to turn into customers. With this common goal in mind, We Build Pages is dedicated to providing our clients with the tools and feedback to make your website and services successful. Search engine optimization is the permanent performance of civilizing search engine position of a website. We Build Pages Internet Marketing Services believes that by growing traffic to a website using link building services, proactive Internet marketing, and original SEO content creation to improve search engine positioning. With the latest organic link building services, We Build Pages provides the most significant and modified SEO services accessible. Web design and web application development is a complex process that requires a extensive range of creative, business and technical skills. Good design must impressively communicate key marketing messages and well as providing simple intuitive navigation. In web development felid, we have successfully established ourselves in providing high quality web design and web development from our wide range and verity to our client all around the world. The design also lays down a sequence of ?calls to action? designed to engage and facilitate the business process. TheitValley is the biggest and largest providing complete Google advertising solution after Google. The first and foremost priority of the TIV is to attain the customer objective without any compromise. The work procedure of the TIV is planning and analysis, user interface design, project management, documentation, onsite testing, implementation, post implementation, warranty support achieving the goal with effectively and efficiently work. http://www.theitvalley.com/seo.html From neilc at norwich.edu Tue Jul 12 15:44:33 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Jul 2011 19:44:33 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> Message-ID: <983mh1Fs7cU1@mid.individual.net> On 2011-07-12, Petter Gustad wrote: > Xah Lee writes: > >> it's funny, in all these supposedly modern high-level langs, they >> don't provide even simple list manipulation functions such as union, >> intersection, and the like. Not in perl, not in python, not in lisps. > > In Common Lisp you have: > > CL-USER> (union '(a b c) '(b c d)) > (A B C D) > CL-USER> (intersection '(a b c) '(b c d)) > (C B) What's the rationale for providing them? Are the definitions obvious for collections that a not sets? -- Neil Cerutti From w_a_x_man at yahoo.com Tue Jul 12 15:52:32 2011 From: w_a_x_man at yahoo.com (WJ) Date: 12 Jul 2011 19:52:32 GMT Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> Message-ID: Petter Gustad wrote: > Xah Lee writes: > > > it's funny, in all these supposedly modern high-level langs, they > > don't provide even simple list manipulation functions such as union, > > intersection, and the like. Not in perl, not in python, not in lisps. > > In Common Lisp you have: > > CL-USER> (union '(a b c) '(b c d)) > (A B C D) > CL-USER> (intersection '(a b c) '(b c d)) > (C B) The order was changed. COBOL Lisp is always mindless. * (union '(2 2 3 4) '(7 7 8 9)) (4 3 2 2 7 7 8 9) The right way (MatzLisp): [2,2,3,4] | [7,7,8,9] ==>[2, 3, 4, 7, 8, 9] From phlip2005 at gmail.com Tue Jul 12 16:31:00 2011 From: phlip2005 at gmail.com (Phlip) Date: Tue, 12 Jul 2011 13:31:00 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: Message-ID: > That's pretty funny. ?I knew what it would be even when I saw the cut-off subject line, and I am too young to remember it. > > Carl Banks TTTO "[She put the lime in the] Coconut": Brother wrote a database, he finish it on time His sister add requirements, refactor every line She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in that database, she called the doctor, woke him up, Sayin' "Doctor, now I got to pay my dues, I say, Doctor, to debug away my blues, I say, Doctor, such a big change has to break, I say, Doctor! I must'a made a bug mistake!" "Now let me get this straight, You change the design in the database, mix things all up You change the design in the database, mix it all up, You change the design in the database, mix it all up..." http://c2.com/cgi/wiki?SheChangeDesignInTheDatabase From rbanffy at gmail.com Tue Jul 12 16:35:38 2011 From: rbanffy at gmail.com (=?ISO-8859-1?Q?Ricardo_B=E1nffy?=) Date: Tue, 12 Jul 2011 17:35:38 -0300 Subject: Building Python 2.5.6 on Ubuntu Natty Message-ID: Hi folks. Has anyone succeeded in building Python 2.5.6 from sources in Ubuntu Natty? I installed all the build dependencies and keep getting running build_ext /usr/include/sqlite3.h: version 3.7.4 Traceback (most recent call last): File "./setup.py", line 1545, in main() File "./setup.py", line 1540, in main 'Lib/smtpd.py'] File "/tmp/Python-2.5.6/Lib/distutils/core.py", line 151, in setup File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 974, in run_commands File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 994, in run_command File "/tmp/Python-2.5.6/Lib/distutils/command/build.py", line 112, in run File "/root/Python-2.5.6/Lib/cmd.py", line 333, in run_command del help[cmd] File "/tmp/Python-2.5.6/Lib/distutils/dist.py", line 994, in run_command File "/tmp/Python-2.5.6/Lib/distutils/command/build_ext.py", line 290, in run File "./setup.py", line 97, in build_extensions self.detect_modules() File "./setup.py", line 810, in detect_modules sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] File "/root/Python-2.5.6/Lib/posixpath.py", line 119, in dirname return split(p)[0] File "/root/Python-2.5.6/Lib/posixpath.py", line 77, in split i = p.rfind('/') + 1 AttributeError: 'NoneType' object has no attribute 'rfind' make: *** [sharedmods] Error 1 when I do "make test" and Compiling /opt/python2.5/lib/python2.5/zipfile.py ... make: *** [libinstall] Error 1 when I do "make install" Any ideas? -- Ricardo B?nffy http://www.dieblinkenlights.com http://twitter.com/rbanffy -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Jul 12 17:18:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:18:13 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> Message-ID: <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> On Jul 12, 1:43?pm, CM wrote: > > > One reason there hasn't been much demand for a GUI builder is that, in > > > many cases, it's just as simpler or simpler to code a GUI by hand. > > I use a GUI builder because I'd rather click less than > type more. I just tried that in Boa Constructor; with ~10 > mouse clicks I produced 964 characters of Python code. Remember, it's NOT the length of the code that matters, no, it's the motion of the "sources" ocean. Did it produce rough seas full of spaghetti monsters? Or tranquil fjords worth pining over (sadly to death apparently?)? 1. Never judge the quality of code simply by it's length. Because if you do, some folks might suffer from "source envy"! Also, you MAY have created 964 chars of code with your ten or so clicks HOWEVER that is just template code. You'll need to set many attributes for the widgets before they are ready for prime time. Your "supposed" ten or so click estimate is very naive. It takes MUCH more to create even a simple GUI, because, we have NOT even discussed logic yet! > Now, sure, depending on how I wrote the code I could do > better than that, but for me, I just find it more > intuitive and easier to use a GUI to make a GUI. Personal opinions should always be respected, and as such i respect yours but later i would outline my GUI design workflow so pay close attention. > > Often a GUI builder is used as a bad replacement for > > sketch-pad and pencil. > > I would use a sketch-pad and pencil and *then* use the GUI builder. But do you really? Your following statements lead me to believe that you don't. > What's nice about a builder is one can move things around > quickly and see the results in the real application, which > one can never really see well on a paper sketch.? I prefer to skip any pencil and paper completely myself. I just use my imagination. UNLESS the GUI is EXTREMELY complicated. For me the design of a GUI starts in my brain. No pencil, no paper, no three hours using Auto Cad GUI designer. Next i start creating widgets and laying them out using geometry managers (in CODE). Finally i run a few tests, make a few changes, and design phase is over. Time for logic. --------------------------------------------- My argument against GUI builders is two fold. --------------------------------------------- 1. GUI builders remove us from the initial "mental design phase" and temp us to let our inner "click-ity-click" and "drag-ity-drag" child loose. This inner child likes to play but he hates to plan. Very soon he has the play room floor (source code) overflowing with toys (code) arranged in a completely haphazard way. Unlike the child however, there is no code mommy to spank this bad little boy when he is a programmer. So he just keeps messing up play room after play room making a complete fool of himself along the way. 2. GUI builders remove us from the source code. When you are playing "clicky-click" with yourself you could be in the trenches fighting the spaghetti code monster. Instead you are losing mental focus. Remember, playing with yourself makes you lazy! ---------------------------------------------- What happens is... you get lost "playing" and fail to keep your mental focus. A programmers metal focus is his most valuable weapon in the fight against the spaghetti code monster. I am a programmer. I love my source code more than i love most people in this world. I do not want to be away from my source. I am jealous of my source! And so too should you be. Kevin made the argument earlier that Tkinter (and others) are so easy to use that they render needing a GUI builder useless -- and he is correct! But did you know that there are GUI libraries EVEN more highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and using my imagination is so difficult" *crap* is really making me laugh. That is my argument people. Opinions may vary. Keep watch for the spaghetti code monster! Cheers folks. PS: if you don't like to type, programming IS NOT the best career (or hobby) choice for you. From ethan at stoneleaf.us Tue Jul 12 17:19:17 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jul 2011 14:19:17 -0700 Subject: Enhanced dir() function In-Reply-To: <4E0E1491.8070007@stoneleaf.us> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> <4E0E01F9.80803@tim.thechases.com> <4E0E1491.8070007@stoneleaf.us> Message-ID: <4E1CBA55.1090206@stoneleaf.us> Ethan Furman wrote: > Tim Chase wrote: >> If it came in as an effortless (i.e. O(1) where I do it once and never >> again; not an O(n) where n=the number of times I invoke Python) >> default replacement for dir(), I'd reach for it a lot more readily. I >> seem to recall there's some environment-var or magic file-name that >> gets sourced on every startup. > > interact.py > 8<----------------------------------------------- > import os, sys > sys.ps1 = '--> ' > > from cookbook.utils import dir # or whereever you keep your copy > sys.modules['__builtin__'].dir = dir > 8<----------------------------------------------- Imagine my amusement when I went to change an environment variable today and found: PYTHONSTARTUP=c:\python25\interact.py ~Ethan~ From ben+python at benfinney.id.au Tue Jul 12 17:36:49 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jul 2011 07:36:49 +1000 Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <06f3dc6e-2b9f-41df-afaf-2ae43fb52e00@s17g2000yqs.googlegroups.com> Message-ID: <87bowzdvv2.fsf@benfinney.id.au> Gnarlodious writes: > OK, [the ?__init__? method] sets a value at init time. But is there a > similar built-in to run whenever the class instance is called? You can write a ?__call__? method which will be called when the instance is called. But I suspect that's still not what you're asking. Maybe it will be quicker to ask: What is it you want to achieve? -- \ ?Compulsory unification of opinion achieves only the unanimity | `\ of the graveyard.? ?Justice Roberts in 319 U.S. 624 (1943) | _o__) | Ben Finney From rantingrick at gmail.com Tue Jul 12 17:38:11 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:38:11 -0700 (PDT) Subject: Enhanced dir() function References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56fefd0b-afee-4b94-bb3a-5a04aa42d1ae@x10g2000vbl.googlegroups.com> On Jun 30, 11:29?pm, Steven D'Aprano wrote: > The dir() function is designed for interactive use, inspecting objects for > the names of attributes and methods. > > Here is an enhanced version that allows you to pass a glob to filter the > names you see: meh, I have always believed in keeping my namespace squeaky clean so i never have this problem. Modules like Tkinter (where you yourself have supported the global import!) i always import as "tk". I think this IS more a housekeeping issue than a "nail on patch" issue. PS: However pay attention because i have some interesting ideas about "dir culling" in my next post to this thread. From rantingrick at gmail.com Tue Jul 12 17:46:44 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 12 Jul 2011 14:46:44 -0700 (PDT) Subject: Enhanced dir() function References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> On Jul 1, 12:20?pm, Tim Chase wrote: > If it came in as an effortless (i.e. O(1) where I do it once and > never again; not an O(n) where n=the number of times I invoke > Python) default replacement for dir(), I'd reach for it a lot > more readily. ?I seem to recall there's some environment-var or > magic file-name that gets sourced on every startup. > > I use the list-comp version on a regular basis: I strongly agree with this statement because i prefer the LC myself. HOWEVER i've always lamented the verbosity of dir(). --------------------------- Case in Point --------------------------- >>> dir([]) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] --------------------------- Do we really need to see all the built in methods EVERY time? I don't, i've had them memorized for years. HOWEVER i do understand the fact that n00bs need to see them every time. So why should old hats need to type this every time... >>> [x for x in dir([]) if not x.startswith('_')] ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] Because we have plenty of room for args in this function... >>> dir(verbose=False) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] Ahhh, i love it when a plan comes together! From kylotan at gmail.com Tue Jul 12 17:47:57 2011 From: kylotan at gmail.com (Ben Sizer) Date: Tue, 12 Jul 2011 14:47:57 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? Message-ID: <9c887bcb-e25f-4974-9fbe-c39a5f042a26@l18g2000yql.googlegroups.com> I'd like to evaluate the recent build of PyPy on the project I'm currently working on, but am not sure how best to go about it. So my question is simply - how would I go about installing PyPy alongside Python 2.7 on Windows? In particular, unzipping PyPy and adding it to the PATH is easy enough, but what about getting setuptools and easy_setup working to install various packages for it? Is there a virtualenv-based method I can use here? (And is pip a decent replacement for setuptools on Windows yet?) -- Ben Sizer From ethan at stoneleaf.us Tue Jul 12 18:19:06 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jul 2011 15:19:06 -0700 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <4E1CC85A.4030302@stoneleaf.us> John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! Absolutely hilarious! Thanks! ~Ethan~ From pjb at informatimago.com Tue Jul 12 18:51:51 2011 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 13 Jul 2011 00:51:51 +0200 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> <983mh1Fs7cU1@mid.individual.net> Message-ID: <87aacji03c.fsf@kuiper.lan.informatimago.com> Neil Cerutti writes: > What's the rationale for providing them? Are the definitions > obvious for collections that a not sets? The rational is to prove that Xah is dumb. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jul 12 19:26:01 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 13 Jul 2011 01:26:01 +0200 Subject: How to write a file generator In-Reply-To: References: Message-ID: Am 12.07.2011 16:46 schrieb Billy Mays: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any, but my function is reopening the file > each call ... I have another solution: an object which is not an iterator, but an iterable. class Follower(object): def __init__(self, file): self.file = file def __iter__(self): while True: l = self.file.readline() if not l: return yield l if __name__ == '__main__': f = Follower(open("/var/log/messages")) while True: for i in f: print i, print "foo" import time time.sleep(4) Here, you iterate over the object until it is exhausted, but you can iterate again to get the next entries. Thomas From cmpython at gmail.com Tue Jul 12 20:22:07 2011 From: cmpython at gmail.com (CM) Date: Tue, 12 Jul 2011 17:22:07 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <9685e55f-c5b4-4ff9-87b6-8c4646fe7698@e35g2000yqc.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> Message-ID: <79a7dab4-16ce-436e-ac54-62e314360fae@j25g2000vbr.googlegroups.com> On Jul 12, 5:18?pm, rantingrick wrote: > On Jul 12, 1:43?pm, CM wrote: > > > > > One reason there hasn't been much demand for a GUI builder is that, in > > > > many cases, it's just as simpler or simpler to code a GUI by hand. > > > I use a GUI builder because I'd rather click less than > > type more. I just tried that in Boa Constructor; with ~10 > > mouse clicks I produced 964 characters of Python code. > > Remember, it's NOT the length of the code that matters, no, it's the > motion of the "sources" ocean. Did it produce rough seas full of > spaghetti monsters? Or tranquil fjords worth pining over (sadly to > death apparently?)? In my experience, the GUI builder I use creates reasonable code that deals with the GUI in a separate portion of the code. It does not strike me as spaghetti-ish (though it's not perfect). > Also, you MAY have created 964 chars of code with your ten or so > clicks HOWEVER that is just template code. You'll need to set many > attributes for the widgets before they are ready for prime time. Your > "supposed" ten or so click estimate is very naive. It takes MUCH more > to create even a simple GUI, because, we have NOT even discussed logic > yet! Sure. But my point was just that to even get as far as I did (which was just a frame and two unspecified widgets) takes 964+ keystrokes, but only ~10 clicks. So the pacing of keystrokes:clicks is favorable. If I built a small functioning GUI application, it might take 100 clicks and 9,640 keystrokes (very roughly). But it is the same point. > > I would use a sketch-pad and pencil and *then* use the GUI builder. > > But do you really? Your following statements lead me to believe that > you don't. > > > What's nice about a builder is one can move things around > > quickly and see the results in the real application, which > > one can never really see well on a paper sketch.? I just meant that though I might start on paper, once it is on the screen I sometimes will shift things around a bit at that point to see how it looks. This is easily done with sizers and a sizer collection manager and an up/down arrow, so it is worth an extra minute to just see how it looks. > ?1. GUI builders remove us from the initial "mental design phase" and > temp us to let our inner "click-ity-click" and "drag-ity-drag" child > loose. This inner child likes to play but he hates to plan. Very soon > he has the play room floor (source code) overflowing with toys (code) > arranged in a completely haphazard way. Unlike the child however, > there is no code mommy to spank this bad little boy when he is a > programmer. So he just keeps messing up play room after play room > making a complete fool of himself along the way. > > ?2. GUI builders remove us from the source code. When you are playing > "clicky-click" with yourself you could be in the trenches fighting the > spaghetti code monster. Instead you are losing mental focus. Remember, > playing with yourself makes you lazy! I've certainly heard of others who feel that working with only code is "cleaner" for them, mentally speaking. I can understand that. I think it just depends on what one is used to. I don't find the GUI builder disrupts my ability to plan or keep things orderly. In fact, most of my disorder and spaghetti problems have been in the logic side of the applications, the part which the GUI builder doesn't have anything to do with. (That's my own issue to keep working on). > Kevin made the argument earlier that Tkinter (and others) are so easy > to use that they render needing a GUI builder useless -- and he is > correct! But did you know that there are GUI libraries EVEN more > highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and > using my imagination is so difficult" *crap* is really making me > laugh. My attitude is, if I could speak in English to an AI to tell it what I'd like the program to do, I'd do it. Yes, since I can't do that, I inevitably do sometimes enjoy puzzling things out, but only because I have to. > PS: if you don't like to type, programming IS NOT the best career (or > hobby) choice for you. I guess it is not so much that I dislike typing, as I dislike having to switch from visual mode to code mode, remember the keywords and such for the widgets, rather than quickly clicking around. The keystroke count is really just a proxy for that sort of effort. CM From steve+comp.lang.python at pearwood.info Tue Jul 12 20:44:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 10:44:54 +1000 Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> Message-ID: <4e1cea87$0$29974$c3e8da3$5496439d@news.astraweb.com> Gnarlodious wrote: > Question. Is there a special method or easy way to set default values > with each call to an instance? Any ideas to make it easier? What I > want to do is have a constantly updating set of values which can be > overridden. Just thought there was an easy way to set that up. All the words are in English, but the sentences make no sense :) Seriously, I don't understand what you mean. "Call to an instance"? Do mean treating instances as a callable (like a function), or do you mean calling an arbitrary method? To make an instance itself callable, define a __call__ method. What do you mean, "constantly updating set of values that can be overridden"? Perhaps a simple example might help. The closest thing I can think of, might be: you want to store a data attribute in an instance, and use that if the caller doesn't specify differently. Something like: class Parrot: name = "Polly" def speak(self, name=None): if name is None: name = self.name print("%s wants a cracker!" % name) And in use: >>> p = Parrot() >>> p.speak() Polly wants a cracker! >>> p.speak("Peter") Peter wants a cracker! >>> p.name = "Penelope" >>> p.speak() Penelope wants a cracker! If None is a legitimate value, then you can define your own sentinel to use instead: MISSING = object() # Unique object guaranteed not to be used by the caller. # (Guarantee void on planet Earth.) then replace None by MISSING in the code above. Is this the sort of scenario you are talking about? If not, I'm completely lost. -- Steven From jimmy at retzlaff.com Tue Jul 12 20:51:23 2011 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 12 Jul 2011 17:51:23 -0700 Subject: mrjob v0.2.7 released Message-ID: What is mrjob? ----------------- mrjob is a Python package that helps you write and run Hadoop Streaming jobs. mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which allows you to buy time on a Hadoop cluster on an hourly basis. It also works with your own Hadoop cluster. Some important features: * Run jobs on EMR, your own Hadoop cluster, or locally (for testing). * Write multi-step jobs (one map-reduce step feeds into the next) * Duplicate your production environment inside Hadoop * Upload your source tree and put it in your job's $PYTHONPATH * Run make and other setup scripts * Set environment variables (e.g. $TZ) * Easily install python packages from tarballs (EMR only) * Setup handled transparently by mrjob.conf config file * Automatically interpret error logs from EMR * SSH tunnel to hadoop job tracker on EMR * Minimal setup * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY * To run on your Hadoop cluster, install simplejson and make sure $HADOOP_HOME is set. More info: * Install mrjob: python setup.py install * Documentation: http://packages.python.org/mrjob/ * PyPI: http://pypi.python.org/pypi/mrjob * Development is hosted at github: http://github.com/Yelp/mrjob What's new? ------------- Big thank you to Yelp intern Steve Johnson, who wrote the majority of the code for this release. Wahbeh Qardaji, another Yelp intern, contributed as well, and has been working hard on features for v0.3.0. v0.2.7, 2011-07-12 -- Hooray for interns! * All runner options can be set from the command line (Issue #121) * Including for mrjob.tools.emr.create_job_flow (Issue #142) * New EMR options: * availability_zone (Issue #72) * bootstrap_actions (Issue #69) * enable_emr_debugging (Issue #133) * Read counters from EMR log files (Issue #134) * Clean old files out of S3 with mrjob.tools.emr.s3_tmpwatch (Issue #9) * EMR parses and reports job failure due to steps timing out (Issue #15) * EMR boostrap files are no longer made public on S3 (Issue #70) * mrjob.tools.emr.terminate_idle_job_flows handles custom hadoop streaming jars correctly (Issue #116) * LocalMRJobRunner separates out counters by step (Issue #28) * bootstrap_python_packages works regardless of tarball name (Issue #49) * mrjob always creates temp buckets in the correct AWS region (Issue #64) * Catch abuse of __main__ in jobs (Issue #78) * Added mr_travelling_salesman example -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Jul 12 21:02:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 11:02:12 +1000 Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. For those > too young to remember, the tune is that of "Pinball Wizard," by The > Who. May it bring you as much joy as it brought me! [...] I wouldn't know a good song parody if it kicked me in the head, but my wife is a (retired) professional musician with a history of writing parodies. She's not impressed by the work of most "filk singers" and supposed parodies, most of which are seventeen kinds of crap... but she gives you full marks. And trust me on this, she does not give compliments lightly. She says you got the rhyming scheme and number of syllables spot on. Technically, "That modeling and sim guy" needs to be slurred to make it fit, "That mod'ling and sim guy", but that's acceptable. (Most parodies get the syllable count wrong -- if a lyric goes dum-de-dum-de-dum, the parody ends up like dum-dum-de-dum-de-dum or dum-de-dum-de.) Have a +1 from me and the missus. -- Steven From greg.ewing at canterbury.ac.nz Tue Jul 12 21:47:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jul 2011 13:47:34 +1200 Subject: Lisp refactoring puzzle In-Reply-To: <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <4E1CF936.4050902@canterbury.ac.nz> Xah Lee wrote: > they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. Since 2.5 or so, Python has a built-in set type that provides these (which is arguably a better place for them than lists). -- Greg From roy at panix.com Tue Jul 12 21:58:45 2011 From: roy at panix.com (Roy Smith) Date: Tue, 12 Jul 2011 21:58:45 -0400 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <4E1CF936.4050902@canterbury.ac.nz> Message-ID: In article <4E1CF936.4050902 at canterbury.ac.nz>, Gregory Ewing wrote: > Xah Lee wrote: > > they > > don't provide even simple list manipulation functions such as union, > > intersection, and the like. Not in perl, not in python, not in lisps. > > Since 2.5 or so, Python has a built-in set type that > provides these (which is arguably a better place for them > than lists). Set is the best addition to Python since string methods. From gnarlodious at gmail.com Tue Jul 12 22:01:50 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 12 Jul 2011 19:01:50 -0700 (PDT) Subject: Set run vars with each call References: <7e727b00-0e90-4b7c-a4e6-1e7359f934e4@u30g2000vby.googlegroups.com> <4e1cea87$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3ab3cab1-fdab-414d-95e4-d5e55b2fcab0@v7g2000vbk.googlegroups.com> On Jul 12, 6:44?pm, Steven D'Aprano wrote: > All the words are in English, but the sentences make no sense :) LOL, impressive powers of mind-reading! Exactly what I needed: import time class Event: epoch=time.time() def doSomething(self, epoch=None): if epoch is None: epoch = self.epoch print(epoch) e = Event() e.doSomething() e.doSomething(123456789) e.epoch = 1310522110.404471 e.doSomething() Thanks for the help! -- Gnarlie http://Gnarlodious.com From ccassie58 at gmail.com Tue Jul 12 22:59:01 2011 From: ccassie58 at gmail.com (goodseller) Date: Tue, 12 Jul 2011 19:59:01 -0700 (PDT) Subject: A pair of comfortable basketball shoes can not only provide you great Message-ID: <518f60c6-51f5-474c-8dca-0fa852503b80@p10g2000prf.googlegroups.com> As we all know, the basketball game needs all the players pay much attention to the protection. The players, not only the profession players but also the basketball amour, needs to take lots measure to protect themselves. Basketball game is a fierce game on the playing court. Playing basketball,http:// www.cheap- nbabasketballshoes.com/ you need to run quickly, jump and stop suddenly. Not only the wrist cuff, but also the leg cuff is also necessary on the playing court. Protection is your first step to play basketball game. Well, the second should be your suitable basketball shoes. A pair of comfortable basketball shoes can not only provide you great support on the playing court, but also can protect your feet. The basketball shoes are divided into three http://www.cheap-nbabasketballshoes.com/tops ? low top, mid top and high top. The different top can be used for different place on the playing court. For example, the low top is used for the guard, who need to run much. The high top may avoid you running quickly, but they play an important role in protecting your ankle. You shouldn?t ignore the shoes on the playing court. From rosuav at gmail.com Wed Jul 13 00:20:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 14:20:42 +1000 Subject: Enhanced dir() function In-Reply-To: <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> References: <4e0d4d30$0$29990$c3e8da3$5496439d@news.astraweb.com> <2942f134-6c38-4a43-9322-b053ae61a14b@gc3g2000vbb.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 7:46 AM, rantingrick wrote: >>>> [x for x in dir([]) if not x.startswith('_')] > ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', > 'reverse', 'sort'] > > Because we have plenty of room for args in this function... > >>>> dir(verbose=False) > ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', > 'reverse', 'sort'] > #define my_dir(o,verbose) verbose?dir(o):[x for x in dir(o) if not x.startswith('_')] And there you are, out of your difficulty at once. Granted, you now have to run your code through cpp, but is that so big a problem? ChrisA (For the sarcasm-impaired: I am NOT advocating this.) From tjreedy at udel.edu Wed Jul 13 00:39:10 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 00:39:10 -0400 Subject: Lisp refactoring puzzle In-Reply-To: <201107121423.39951.gheskett@wdtv.com> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: On 7/12/2011 2:23 PM, gene heskett wrote: > Now, I hate to mention it Terry, but your clock seems to be about 126 > months behind the rest of the world. Please do not hate to be helpful. It was a bad malfunction perhaps due to a run-down battery on a machine turned off for two weeks. I will keep watch to see if it happens again overnight. > Does your system not run ntpd by default? Is that *nix or Windows? My XP system only checks the net time automatically once a week and refused to update at first on request because the dates did not match. Typically windows stupidity. If I click 'Update from internet', it should believe that I really mean it. -- Terry Jan Reedy From rustompmody at gmail.com Wed Jul 13 01:10:14 2011 From: rustompmody at gmail.com (rusi) Date: Tue, 12 Jul 2011 22:10:14 -0700 (PDT) Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: <7f92caef-9a98-4eb5-bae9-6568178bf4de@m6g2000prh.googlegroups.com> On Jul 13, 9:39?am, Terry Reedy wrote: > On 7/12/2011 2:23 PM, gene heskett wrote: > > > Now, I hate to mention it Terry, but your clock seems to be about 126 > > months behind the rest of the world. > > Please do not hate to be helpful. Ha Ha. Cute one. Thanks From wuwei23 at gmail.com Wed Jul 13 01:48:34 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 12 Jul 2011 22:48:34 -0700 (PDT) Subject: Virtual functions are virtually invisible! References: <97dcpqFdndU1@mid.individual.net> <90efb2d5-28d8-44e4-8c21-b53206547b6c@x10g2000vbl.googlegroups.com> <6cc8dbb3-d423-4a46-af3e-44123c6f5ba5@b21g2000yqc.googlegroups.com> Message-ID: <95ddb38a-ef54-41aa-a3bf-f7220d9a2be8@t8g2000prm.googlegroups.com> rantingrick wrote: > i cannot force others If only you really understood that. From wuwei23 at gmail.com Wed Jul 13 02:26:30 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 12 Jul 2011 23:26:30 -0700 (PDT) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> Thomas Jollans wrote: > Coincidentally, Guido wrote this blog post just last week, without which > I'd be just as much at a loss as you: > > http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an... It's also part of the Python FAQ: http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements From caleb.hattingh at gmail.com Wed Jul 13 02:29:09 2011 From: caleb.hattingh at gmail.com (cjrh) Date: Tue, 12 Jul 2011 23:29:09 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? In-Reply-To: <9c887bcb-e25f-4974-9fbe-c39a5f042a26@l18g2000yql.googlegroups.com> Message-ID: You can just extract the windows pypy 1.5 distribution to any folder and run "pypy.exe" from there as if it was called "python.exe". This is how I have been using it. In fact, pypy has been the default python for my portable eclipse for a good while now. From bahamutzero8825 at gmail.com Wed Jul 13 02:54:54 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 01:54:54 -0500 Subject: Code hosting services Message-ID: <4E1D413E.7080002@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 I know this isn't specific to Python, but it is somewhat on topic. Way back when I had a simple project, SourceForge was by far the most prominent place to host (and it still is, though to a lesser extent now). SourceForge is still an option for me, but I know there are many other hosts out there. The problem is I don't which one what the pros and cons of each are. Wikipedia has some information, but it's generally objective. This is useful, but it's not enough to narrow my choices down to one or two. What can you guys recommend? BTW, I'll likely be sticking with Mercurial for revision control. TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse working well. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHUE+AAoJEPiOA0Bgp4/LvRUIAOX4XcC2+am9uFzBH9BpYh4l epHZptB3qrNd0QV+TWXuOG6V6tOESsoQaECZYplykzD5/fxsuSgisv62mAEY+afw gqJbsVka1XuWJQTUYBVFcA5ytL3v07SYcQ1m9EsAkgBejRD7nuXuWBB2bNUcPhMY s3IfyVFZ82utxEnbWxGo6mK4NPXnhMXdJgLbDPzg3Xg2KjI29eJLHQsKv1GjnWJC 5tYxNpVqPaeYNzGxjWtwCuDxzGuGnpWWYhSx8dUhgQbZKlR9SGhfcs9onsIroM2j z9B8cuaQe8GxbU0vneMtiLGJt8+hsCpuFTAIrMTn6AGeK7He06LXYU49skg6Bxw= =5uDV -----END PGP SIGNATURE----- From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Jul 13 03:09:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 13 Jul 2011 09:09:57 +0200 Subject: Code hosting services In-Reply-To: References: Message-ID: Am 13.07.2011 08:54 schrieb Andrew Berg: > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. In this case, I would recommend bitbucket. Thomas From thorsten at thorstenkampe.de Wed Jul 13 03:36:39 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 09:36:39 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400) > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > > My immediate response is: it allows us to fit statements into one > > line. e.g. > > if a == 1: print a > > > You're confusing the colon with the semi-colon. If you want two > statements on the same line, you use a semi-colon. He's not confusing anything at all. His example made it pretty clear that he didn't mean "two statements" but "multiline statemements". Thorsten From benjokal at gmail.com Wed Jul 13 04:01:43 2011 From: benjokal at gmail.com (Benji Benjokal) Date: Wed, 13 Jul 2011 04:01:43 -0400 Subject: How do you get the value you entered using the Entry widget in Tkinter? Message-ID: What is the simplist way to get the value you entered from the Entry widget in Tkinter? Thanks Benji -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Wed Jul 13 04:08:53 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 10:08:53 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) > Basically, it looks better, and is more readable. People tend to overlook the colon for the same reason they tend to forget to set the colon in the first place: a) it's a very weak marker in comparison to indentation and b) it looks like doubling the markup to them (colon plus indentation) What makes the if syntax for me even more weird, is the fact that you can have an else clause with an else without a then clause with a then. if x > 5: print whatever else: print whatever in comparison to: if x > 5 then print whatever else print whatever > A colon, in English like in Python, means that something follows that > is related to what was before the colon. So the colon makes it > abundantly clear to the human reader that a block follows, The block that follows makes it abundantly clear to the human reader that a block follows. > and that that block is to be considered in relation to what was just > said, before the colon. The indentation makes it abundantly clear to the human reader that that indented block is to be considered in relation to what was just said, before the indentation. Thorsten From tlikonen at iki.fi Wed Jul 13 04:29:58 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 13 Jul 2011 11:29:58 +0300 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> Message-ID: <87mxgilh15.fsf@mithlond.arda> * 2001-01-01T14:11:11-05:00 * Terry Reedy wrote: > As a side note, the same principle of expressions matching operations > in symmetry suggest that majority of up are quite sensible and not > dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a > function call, the function has a different role than the arguments, > so it is appropriate that it have a different role in the expression. Please don't forget that the whole point of Lisps' (f x) syntax is that code is also Lisp data. It's not just a function call with arguments. First, it's literal data (two linked cons cells and symbols) and then the Lisp evaluating model makes it a function call in certain situations. Lisp is CL-USER> (let ((lisp (cons 'programmable nil))) (setf (rest lisp) lisp)) #1=(PROGRAMMABLE . #1#) programming language and it's totally irrelevant and pointless to say "which syntax someone prefers" because this feature (code being data) is very fundamental principle of the language. You know, it's easy to write programs that write programs. If we remove this feature (i.e., don't talk about Lisp at all) then it's perhaps relevant to discuss about such choices in syntax. You wouldn't want Python arrays have a read and print format "a[b, c]", that is, the first item of the array printed outside []'s. It would be silly. From gheskett at wdtv.com Wed Jul 13 05:46:32 2011 From: gheskett at wdtv.com (gene heskett) Date: Wed, 13 Jul 2011 05:46:32 -0400 Subject: Lisp refactoring puzzle In-Reply-To: References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <201107121423.39951.gheskett@wdtv.com> Message-ID: <201107130546.32114.gheskett@wdtv.com> On Wednesday, July 13, 2011 05:34:23 AM Terry Reedy did opine: > On 7/12/2011 2:23 PM, gene heskett wrote: > > Now, I hate to mention it Terry, but your clock seems to be about 126 > > months behind the rest of the world. > > Please do not hate to be helpful. It was a bad malfunction perhaps due > to a run-down battery on a machine turned off for two weeks. I will keep > watch to see if it happens again overnight. > > > Does your system not run ntpd by default? > > Is that *nix or Windows? That's a *nix name. I have no clue what winderz might call it as I've only ever had one winderz machine here. My laptop had a copy of XP on it when I bought it years ago, shrunk it to 10Gb and let it live for about 6 months, but its had several fedora's, 2 different MDV installs, and now PCLos on it after discovering the windows bcm4318 driver was a bigger POS than the current linux driver. Everything else here is either 25 years old & running nitros9, or some flavor of *buntu LTS. IOW, all my windows are glass. ;-) > My XP system only checks the net time > automatically once a week and refused to update at first on request > because the dates did not match. Typically windows stupidity. If I click > 'Update from internet', it should believe that I really mean it. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Swap read error. You lose your mind. From cs at zip.com.au Wed Jul 13 05:59:17 2011 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 13 Jul 2011 19:59:17 +1000 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <20110713095917.GA8232@cskk.homeip.net> On 13Jul2011 01:54, Andrew Berg wrote: | I know this isn't specific to Python, but it is somewhat on topic. Way | back when I had a simple project, SourceForge was by far the most | prominent place to host (and it still is, though to a lesser extent | now). SourceForge is still an option for me, but I know there are many | other hosts out there. The problem is I don't which one what the pros | and cons of each are. Wikipedia has some information, but it's generally | objective. This is useful, but it's not enough to narrow my choices down | to one or two. What can you guys recommend? | | BTW, I'll likely be sticking with Mercurial for revision control. | TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse | working well. I'm using bitbucket and liking it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If not for the one-percent inspiration, that would have just been a lot of sweat. - overhead by WIRED at the Intelligent Printing conference Oct2006 From t at jollybox.de Wed Jul 13 06:05:14 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:05:14 +0200 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <4E1D6DDA.5040808@jollybox.de> On 07/13/2011 08:54 AM, Andrew Berg wrote: > I know this isn't specific to Python, but it is somewhat on topic. Way > back when I had a simple project, SourceForge was by far the most > prominent place to host (and it still is, though to a lesser extent > now). SourceForge is still an option for me, but I know there are many > other hosts out there. The problem is I don't which one what the pros > and cons of each are. Wikipedia has some information, but it's generally > objective. This is useful, but it's not enough to narrow my choices down > to one or two. What can you guys recommend? > > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. GitHub is massively popular, and a great service. It's based on git (not mercurial), and is centred around the source repository, and has bug tracking, wiki, downloads, everything you'll need. What makes GitHub special (and popular) is the social aspect, allowing you to follow people, with great management of forks ? real distributed (git is a distributed VCS after all) collaboration. One of GitHub's great features is, in a way, the huge community ? kind of a self-fulfilling prophecy. Bitbucket, which Mr Rachel mentioned, is essentially a not-quite-as-good clone of GitHub, just using Mercurial. Don't get me wrong, it's a good product, and may be exactly what you want, but it is a clone, and it doesn't have the community GitHub has. Google Code is more SourceForge-style in that it focuses more on having the landing page linking downloads, not focusing so much on the code repository. It supports Mercurial repositories, as far as I know. I don't have much experience with it. All the standard features. There are a load of older sites, SourceForge, Savannah, Gna!, etc etc etc, but they don't support VCS other than CVS/Svn for the most part. From bahamutzero8825 at gmail.com Wed Jul 13 06:23:20 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 05:23:20 -0500 Subject: Code hosting services In-Reply-To: <4E1D6DDA.5040808@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> Message-ID: <4E1D7218.9010108@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.13 05:05 AM, Thomas Jollans wrote: > There are a load of older sites, SourceForge, Savannah, Gna!, etc > etc etc, but they don't support VCS other than CVS/Svn for the most > part. Many do support Mercurial. In fact, I have a Mercurial repo for one of my projects on SourceForge (Bazaar and Mercurial are available as extra features that have to be explicitly enabled). Google Code and Savannah support Mercurial (at least according to Wikipedia; I haven't set up a project on either). - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHXIYAAoJEPiOA0Bgp4/L+yYIAKaHlDF1Sx2yoxo6wENy5kVf QEvtf4cbHaFP+ORBDDhCdWxiQO6jzlrryphrv5BhZ1B2CqXmkFaMzhj7HIErG4i+ NI27+RPtQno3iOTtnOBxsAdGkQzoNG8PDb4qSxxUlzM8iApIGSotEuLrKJGzZrP0 /IFPw83X2sAwaRZGOxPIzMuN7MrUnvCpcNfq5tTqgBgBF5rvNaV8vb/zmFxw2gkh r0Df5Cik2MsaHAj0mHY4Ypusprwi9ClIpL21xuNbefdtJJyPbrnRGxW03yvExJjg OHmUtrFxxBvj8IYWAOjQr/Q76uPaHTX/oV2xEkigMjvhxaiWMjjO4HqJFE+ghR8= =AtfH -----END PGP SIGNATURE----- From awilliam at whitemice.org Wed Jul 13 06:23:32 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 13 Jul 2011 06:23:32 -0400 Subject: Code hosting services In-Reply-To: <4E1D413E.7080002@gmail.com> References: <4E1D413E.7080002@gmail.com> Message-ID: <1310552613.7271.1.camel@linux-yu4c.site> On Wed, 2011-07-13 at 01:54 -0500, Andrew Berg wrote: > I know this isn't specific to Python, but it is somewhat on topic. Way > back when I had a simple project, SourceForge was by far the most > prominent place to host (and it still is, though to a lesser extent > now). SourceForge is still an option for me, but I know there are many > other hosts out there. The problem is I don't which one what the pros > and cons of each are. Wikipedia has some information, but it's generally > objective. This is useful, but it's not enough to narrow my choices down > to one or two. What can you guys recommend? SourceForge; it is a comprehensive platform [in addition to being an Open Source platform: Allura]. It is a much improved platform over several years ago. > BTW, I'll likely be sticking with Mercurial for revision control. > TortoiseHg is a wonderful tool set and I managed to get MercurialEclipse > working well. I use Hg on SF, it works very well. From shankaraman.r at gmail.com Wed Jul 13 06:31:07 2011 From: shankaraman.r at gmail.com (Shankar Raman) Date: Wed, 13 Jul 2011 16:01:07 +0530 Subject: Python Contribution Message-ID: Hello everyone, My name is Shankarraman and I have been working with Python for past 5 months.I find it really interesting and cool and would like to know different ways I can contribute to it. Though I went through the bug lists, I was wondering if I could contribute to Python in other ways. -- Namashivaya, R.Shankarraman, Computer Science and Engineering, Amrita School of Engineering. -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Jul 13 06:34:28 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:34:28 +0200 Subject: Code hosting services In-Reply-To: <4E1D7218.9010108@gmail.com> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> Message-ID: <4E1D74B4.9030803@jollybox.de> On 07/13/2011 12:23 PM, Andrew Berg wrote: > On 2011.07.13 05:05 AM, Thomas Jollans wrote: >> There are a load of older sites, SourceForge, Savannah, Gna!, etc >> etc etc, but they don't support VCS other than CVS/Svn for the most >> part. > Many do support Mercurial. In fact, I have a Mercurial repo for one of > my projects on SourceForge (Bazaar and Mercurial are available as extra > features that have to be explicitly enabled). Google Code and Savannah > support Mercurial (at least according to Wikipedia; I haven't set up a > project on either). > Okay, fair enough. Question is, does it integrate with the bug tracker? It does for Google Plus. In the olden days when Mercurial was young, Savannah, IIRC, bolted on Mercurial hosting that didn't do any of the usual integration. Half the point of getting VCS hosting and bug tracking from the same service is being able to do "closes #4" in a commit. From anthony.hw.kong at gmail.com Wed Jul 13 06:40:40 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 20:40:40 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: Thanks, mate! I was writing that up really late at night. Somehow I changed term to semi-colon half way through, Cheers On Wed, Jul 13, 2011 at 5:36 PM, Thorsten Kampe wrote: > * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400) > > On 01/-10/-28163 02:59 PM, Anthony Kong wrote: > > > My immediate response is: it allows us to fit statements into one > > > line. e.g. > > > if a == 1: print a > > > > > You're confusing the colon with the semi-colon. If you want two > > statements on the same line, you use a semi-colon. > > He's not confusing anything at all. His example made it pretty clear > that he didn't mean "two statements" but "multiline statemements". > > Thorsten > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Jul 13 06:40:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 13 Jul 2011 12:40:58 +0200 Subject: Code hosting services In-Reply-To: <4E1D74B4.9030803@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> <4E1D74B4.9030803@jollybox.de> Message-ID: <4E1D763A.9050103@jollybox.de> On 07/13/2011 12:34 PM, Thomas Jollans wrote: > It does for Google Plus. Code. Code, not plus. Not concentrating. Argh. From anthony.hw.kong at gmail.com Wed Jul 13 06:59:09 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 20:59:09 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? Message-ID: Hi, all, If you have read my previous posts to the group, you probably have some idea why I asked this question. I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. I think I will go through the following items: - itertools module - functools module - concept of currying ('partial') I would therefore want to ask your input e.g. - Is there any good example to illustrate the concept? - What is the most important features you think I should cover? - What will happen if you overdo it? Cheers -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Wed Jul 13 06:59:56 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jul 2011 05:59:56 -0500 Subject: Code hosting services In-Reply-To: <4E1D74B4.9030803@jollybox.de> References: <4E1D413E.7080002@gmail.com> <4E1D6DDA.5040808@jollybox.de> <4E1D7218.9010108@gmail.com> <4E1D74B4.9030803@jollybox.de> Message-ID: <4E1D7AAC.2070302@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On 2011.07.13 05:34 AM, Thomas Jollans wrote: > Okay, fair enough. Question is, does it integrate with the bug > tracker? It does for Google Plus. In the olden days when Mercurial > was young, Savannah, IIRC, bolted on Mercurial hosting that didn't do > any of the usual integration. I don't know about SF. There's nothing special that happens during a commit, but I suppose it's possible that SF will recognize a word like "issue" or "bug" and automatically provide a link to the issue number referenced on its native bug tracker (or maybe even to an issue on Trac). I'm pretty new to this whole thing; my simple project from ages ago didn't use a bug tracker or a VCS. - -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAwAGBQJOHXqsAAoJEPiOA0Bgp4/LlpoH+wXxAPB57UOWa+ewDTw3MTUQ q1IiUJvWyyX8+NcYZ7oTMrnHjpPG0povnAq32HckzlCcyz+5YSRCKCgdvebcSSaQ BuGTrNQmwN+eiZFN5CJN9P2m8t2M2bdpEBeQoD01iezMrs5nDMTtgrlkDflV8B5J oynrN1uRzKVsy5Gb4carRGMza3vV+K8Tq8LVFDf+CPC7Sh20BwWxUXWikWCK8dOp fsEzBppkaHU9Po2N/nDTeszvDd+ZHqchNIG4lEo5ekY5yyKRjyN47LJHDTPRDNVy dG92kGjaumMLhHIyItlj5w7GpM7GbpQokbDKSEyK0kohEqPNyOKh49pLiQf8t9o= =LBnZ -----END PGP SIGNATURE----- From steve+comp.lang.python at pearwood.info Wed Jul 13 07:07:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2011 21:07:17 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Thorsten Kampe wrote: > * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) >> Basically, it looks better, and is more readable. > > People tend to overlook the colon for the same reason they tend to > forget to set the colon in the first place: > a) it's a very weak marker in comparison to indentation and > b) it looks like doubling the markup to them (colon plus indentation) I can't speak for others, but speaking for myself, I wonder whether this is a difference between English speakers and non-English speakers? To me, as a native English speaker, leaving the colon out of a header line, as follows below, just looks wrong. Nobody expects the Spanish Inquisition! Our three weapons are * fear * surprise * and ruthless efficiency * and an almost fanatical devotion to the Pope! Although the bullet list is indented, the header line "Our three weapons are" looks like something is missing, as if I had started to write something and forgotten to finish. It needs a colon to be complete: Nobody expects the Spanish Inquisition! Amongst our weapons are: * fear * surprise * ruthless efficiency * an almost fanatical devotion to the Pope * and nice red uniforms The colon indicates that the sentence has more to follow: I think of it as a pointer. It doesn't finish the thought, like a full stop, nor is it a mere pause, like a comma or semi-colon. An indented block on its own is surprising. It just hangs there, with no connection to what was going on before. Why is it indented? Is it connected to the previous sentence? On the other hand, a colon gives the reader that connection: It gives the reader a clue to expect additional information, that the indented block that follows is not an independent block, floating in space for its own reasons, but is intimately linked to the previous line. I know that Python is not English, and not all English conventions apply. For example, Python uses newlines to end "sentences" (lines of code) instead of a full stop. Nevertheless, as an English reader, it would look wrong and awkward to drop the colon. >> A colon, in English like in Python, means that something follows that >> is related to what was before the colon. So the colon makes it >> abundantly clear to the human reader that a block follows, > > The block that follows makes it abundantly clear to the human reader > that a block follows. But it's too late by then. You have to mentally backtrack. blah blah blah blah indented block blah blah blah blah colon indented block -- Steven From thorsten at thorstenkampe.de Wed Jul 13 07:26:21 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 13:26:21 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: * Steven D'Aprano (Wed, 13 Jul 2011 21:07:17 +1000) > Thorsten Kampe wrote: > > * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) > >> Basically, it looks better, and is more readable. > > > > People tend to overlook the colon for the same reason they tend to > > forget to set the colon in the first place: > > a) it's a very weak marker in comparison to indentation and > > b) it looks like doubling the markup to them (colon plus indentation) > > I can't speak for others, but speaking for myself, I wonder whether this is > a difference between English speakers and non-English speakers? It's not a difference between English and non-English speakers but the difference between a branch (if-then-else) and an enumeration (your example). > To me, as a native English speaker, leaving the colon out of a header > line, as follows below, just looks wrong. > [enumeration] > > Although the bullet list is indented, the header line "Our three weapons > are" looks like something is missing, as if I had started to write > something and forgotten to finish. It needs a colon to be complete: Sure, because it's an enumeration - and not a branch or loop. > An indented block on its own is surprising. It just hangs there, > with no connection to what was going on before. Why is it indented? > Is it connected to the previous sentence? In normal text: sure. You cannot "just indent" in Python as you like. Indentation always shows the connection. > >> A colon, in English like in Python, means that something follows > >> that is related to what was before the colon. So the colon makes it > >> abundantly clear to the human reader that a block follows, > > > > The block that follows makes it abundantly clear to the human reader > > that a block follows. > > But it's too late by then. You have to mentally backtrack. > > blah blah blah blah > indented block > > blah blah blah blah colon > indented block Source code is (unlike normal text) not read line by line. So you (at least I) don't have to backtrack from line 2 to line 1 because you see them both at the same time. Thorsten From rosuav at gmail.com Wed Jul 13 07:58:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 21:58:19 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 13, 2011 at 9:07 PM, Steven D'Aprano wrote: > The colon indicates that the sentence has more to follow: I think of it as a > pointer. It doesn't finish the thought, like a full stop, nor is it a mere > pause, like a comma or semi-colon. > > ? ?An indented block on its own is surprising. It just hangs there, > ? ?with no connection to what was going on before. Why is it indented? > ? ?Is it connected to the previous sentence? It's not necessarily surprising, depending on context; the brain automatically assumes that the indented block was originally said by someone else. The
tag defines a long quotation. A browser inserts white space before and after a blockquote element. It also insert margins for the blockquote element. http://www.w3schools.com/tags/tag_blockquote.asp (I didn't need to quote that, I just wanted to go meta and block quote something about blockquote.) Having the colon makes it clear that the content is part of the same general thought (paragraph or sentence). Chris Angelico From python.list at tim.thechases.com Wed Jul 13 08:16:07 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Jul 2011 07:16:07 -0500 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E1D8C87.4080301@tim.thechases.com> On 07/13/2011 06:26 AM, Thorsten Kampe wrote: > Source code is (unlike normal text) not read line by line. So > you (at least I) don't have to backtrack from line 2 to line 1 > because you see them both at the same time. $a You mean there are people who don't use "ed" to write their code? ;-) -tkc . w q From anthony.hw.kong at gmail.com Wed Jul 13 08:39:16 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Wed, 13 Jul 2011 05:39:16 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? Message-ID: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) Hi, all, If you have read my previous posts to the group, you probably have some idea why I asked this question. I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. I think I will go through the following items: itertools module functools module concept of currying ('partial') I would therefore want to ask your input e.g. Is there any good example to illustrate the concept? What is the most important features you think I should cover? What will happen if you overdo it? Cheers From bruno.desthuilliers at gmail.com Wed Jul 13 08:46:14 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 13 Jul 2011 05:46:14 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Jul 12, 6:40?pm, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. Brillant. This deserves to become a cpython easter egg along with import this or from __future__ import braces. From rosuav at gmail.com Wed Jul 13 08:53:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 22:53:55 +1000 Subject: "Python Wizard," with apologies to The Who In-Reply-To: References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilliers at gmail.com wrote: > On Jul 12, 6:40?pm, John Keisling wrote: >> After too much time coding Python scripts and reading Mark Lutz's >> Python books, I was inspired to write the following lyrics. > > Brillant. This deserves to become a cpython easter egg along with > import this or from __future__ import braces. Propose: from eastereggs import wizard ChrisA From invalid at invalid.invalid Wed Jul 13 09:03:22 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jul 2011 13:03:22 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-13, Thorsten Kampe wrote: >> and that that block is to be considered in relation to what was just >> said, before the colon. > > The indentation makes it abundantly clear to the human reader that > that indented block is to be considered in relation to what was just > said, before the indentation. You would think so, but human readers like redundancy. Most natural human languages have plenty of redundancy. For example in English when speaking of multiple subjects one not only uses a plural noun or pronoun (e.g. "they" rather than "him"), but one also uses a plural verb ("run" rather than "runs") even though the plural noun alone should make it abundantly clear to the human reader than we're talking about more than one person. The same holds true for objective and subjective case: the position of the noun in the sentence makes it abundantly clear whether the noun is an object or a subject, yet we still often have two cases (it's "I run" rather than "Me run"). -- Grant Edwards grant.b.edwards Yow! I'm having an at EMOTIONAL OUTBURST!! But, gmail.com uh, WHY is there a WAFFLE in my PAJAMA POCKET?? From rosuav at gmail.com Wed Jul 13 09:11:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2011 23:11:41 +1000 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 11:03 PM, Grant Edwards wrote: > You would think so, but human readers like redundancy. > One of the benefits of redundancy is error-trapping. If you see a list of numbers like this: 40 14 24 56 48 12 60 16 ===== 269 then you know the result can't be right, because they're all even numbers and the total isn't. The redundancy of having both the string of numbers and the total adds only a small amount to the transmission requirement, but it adds a lot to the reliability of transfer. ChrisA From invalid at invalid.invalid Wed Jul 13 09:18:30 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jul 2011 13:18:30 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-07-13, Steven D'Aprano wrote: > Thorsten Kampe wrote: > >> * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200) >>> Basically, it looks better, and is more readable. >> >> People tend to overlook the colon for the same reason they tend to >> forget to set the colon in the first place: >> a) it's a very weak marker in comparison to indentation and >> b) it looks like doubling the markup to them (colon plus indentation) > > I can't speak for others, but speaking for myself, I wonder whether this is > a difference between English speakers and non-English speakers? To me, as a > native English speaker, leaving the colon out of a header line, as follows > below, just looks wrong. > > Nobody expects the Spanish Inquisition! > Our three weapons are > * fear > * surprise > * and ruthless efficiency > * and an almost fanatical devotion to the Pope! Except that's wrong English[1]. At least that's not correct usage according to what I learned in school. A colon follows an independent clause: something that could in essence be a complete sentence and expresses a complete thought. The colon separates that independent clause from examples or an explanation or clarification of that independent clause. The phrase "Our three weapons are" isn't an independent clause. It has the transitive verb "are" but no predicate nominative. You've placed the colon in the middle of an independent clause between the verb "are" and the predicate nominative phrase "fear, surprise, and ruthless efficiency, and an almost fanatical devotion to the Pope". Your example should be something like this [accurace of the quotation aside]: The Spanish Inquisition has three main weapons: fear, surprise, ruthless efficiency, and an almost fanatical devotion to the Pope! > Although the bullet list is indented, the header line "Our three weapons > are" looks like something is missing, Something is missing. It's not a complete independent clause. > as if I had started to write something and forgotten to finish. Except a colon doesn't "complete" an independent clause that's otherwise incomplete. > It needs a colon to be complete: > > Nobody expects the Spanish Inquisition! Now, that usage is correct. > The colon indicates that the sentence has more to follow: I think of > it as a pointer. That is correct also. > On the other hand, a colon gives the reader that connection: > > It gives the reader a clue to expect additional information, > that the indented block that follows is not an independent > block, floating in space for its own reasons, but is intimately > linked to the previous line. Yup. [1] Since all posts criticising grammar or spelling will have an above average number of grammar and spelling errors, I thought I'd get a head start on it. -- Grant Edwards grant.b.edwards Yow! I'm ZIPPY the PINHEAD at and I'm totally committed gmail.com to the festive mode. From ramapraba2653 at gmail.com Wed Jul 13 09:24:44 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Wed, 13 Jul 2011 06:24:44 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <67e6e85c-70dc-4830-8f62-56aa4374a003@q34g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gheskett at wdtv.com Wed Jul 13 09:41:14 2011 From: gheskett at wdtv.com (gene heskett) Date: Wed, 13 Jul 2011 09:41:14 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <201107130941.14827.gheskett@wdtv.com> On Wednesday, July 13, 2011 09:38:26 AM Anthony Kong did opine: > (My post did not appear in the mailing list, so this is my second try. > Apology if it ends up posted twice) > Actually, it did, but gmail, in its infinite wisdom, thinks an echo of your post to a mailing list is a duplicate, and deletes it. For this exact reason, I only use gmail for two or 3 of the nearly 40 lists I'm on. [...] Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) He is considered a most graceful speaker who can say nothing in the most words. From vdidenko at Getcollc.com Wed Jul 13 09:42:34 2011 From: vdidenko at Getcollc.com (Vlad Didenko) Date: Wed, 13 Jul 2011 08:42:34 -0500 Subject: sys.tracebacklimit Message-ID: Colleagues, Per documentation at http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit : When [sys.tracebacklimit] set to 0 or less, all traceback information is suppressed and only the exception type and value are printed So, I expect to be able to have a program like: import sys sys.tracebacklimit=0 print(1/0) And see it's result as: ZeroDivisionError: division by zero However, the actual result is: Traceback (most recent call last): File "tbt.py", line 3, in print(1/0) ZeroDivisionError: division by zero Do I misunderstand the docs? Thank you! Vlad ________________________________ This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Wed Jul 13 09:50:42 2011 From: james at agentultra.com (J Kenneth King) Date: Wed, 13 Jul 2011 09:50:42 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <87aaci8f2l.fsf@agentultra.com> Anthony Kong writes: > (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) > > Hi, all, > > If you have read my previous posts to the group, you probably have some idea why I asked this question. > > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? > > > Cheers You might also want to cover gotchas like Python's references. If you have the time I'd introduce weakref too. From anthony.hw.kong at gmail.com Wed Jul 13 10:06:02 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 00:06:02 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <87aaci8f2l.fsf@agentultra.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <87aaci8f2l.fsf@agentultra.com> Message-ID: Hi, James, > > You might also want to cover gotchas like Python's references. > Not sure what it means in the context of functional programming. If you can give some code to demonstrate, it will be great. Cheers -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From justmailnaveen at gmail.com Wed Jul 13 10:06:37 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:06:37 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? Message-ID: Hey guys,i am a python newbie, i just read a qustion on quora where it said that quora quys used pypy (and pylon) to develop quora. So, i want to know what are the core diff btw PyPy and Python ? And they also talked about the lack of type check in python. So, how does it help (strongly typed) in debugging? Thanks From remi.druilhe at orange-ftgroup.com Wed Jul 13 10:19:31 2011 From: remi.druilhe at orange-ftgroup.com (remi.druilhe at orange-ftgroup.com) Date: Wed, 13 Jul 2011 16:19:31 +0200 Subject: Odd caracteres Message-ID: <1310566771.2520.18.camel@g-e6400-55> Hello everyone, I am using a Python script to get data from a BlueTooth device but it seems there is some problem when reading from the interface on Linux. I have a three devices (PowerSpy) that measure energy from an outlet (I plug a computer on a PowerSpy that I plug on an outlet). This device communicates using BlueTooth. So I connect my laptop via BT to get those data (using : sudo rfcomm bind /dev/rfcomm0 powerspy_mac_address). Then, I execute my Python script. This script reads data from /dev/rfcomm0 (with root priviledge). The first data is successfully read. The second and the third too. But the fourth time that I access /dev/rfcomm0, I get some odd caracteres: A I tried to access to this interface using minicom, no problem, I can read easily these data. I changed the computer that was under test, no change. I changed every physical devices by other, no change. That's why, I think I have a problem with my script. Here is the error: Traceback (most recent call last): 4107A6A File "./PowerSpy.py", line 64, in powerspy = PowerSpy("/dev/rfcomm0") File "./PowerSpy.py", line 33, in __init__ u = (struct.unpack('> ards, -- R?mi Druilhe RD-MAPS-GRE OLNC/MAPS/SHINE/MADE Phone: +33 (0)4 76 76 24 27 E-mail : remi.druilhe at orange-ftgroup.com Orange Labs Grenoble - 28 chemin du Vieux Ch?ne - BP98 38243 Meylan Cedex - France -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: orange_logo.gif Type: image/gif Size: 765 bytes Desc: orange_logo.gif URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PowerSpy.py Type: text/x-python Size: 2011 bytes Desc: PowerSpy.py URL: From anthony.hw.kong at gmail.com Wed Jul 13 10:19:35 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 00:19:35 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: One of the main difference is that pypy supports only R-Python, which stands for 'Restricted Python". It is a subset of C-python language. See here for more info: http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#rpython-definition-not Cheers On Thu, Jul 14, 2011 at 12:06 AM, ArrC wrote: > Hey guys,i am a python newbie, > i just read a qustion on quora where it said that quora quys used pypy (and > pylon) to develop quora. > > So, i want to know what are the core diff btw PyPy and Python ? > > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jul 13 10:21:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 00:21:14 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 12:06 AM, ArrC wrote: > So, i want to know what are the core diff btw PyPy and Python ? Python is a language; PyPy is one implementation of that language. The "classic" implementation of Python is CPython, not to be confused with Cython; there are a few others as well. If you talk of "installing Python", it probably means CPython. > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? Sloppy but brief explanation: Python's variables are typeless; its objects are strongly typed. Longer explanation: Every piece of data in Python is an object. Objects can be referenced by names; one object can have more than one name pointing to it. Any name can point to any value, which is somewhat the opposite of "strongly-typed variables" in other languages. For instance: a = "Hello" # a points to or "holds" a string a = 234 # a now points to an integer a = 1.0 # a now points to a float a = [1,2,3] # a now has a list (array) In debugging, all you generally care about is "what does this object point to". I guess whether or not this makes things easier or harder depends a lot on what sort of bugs you're tracking down. Hope that helps! Chris Angelico From tjreedy at udel.edu Wed Jul 13 10:34:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 10:34:41 -0400 Subject: Lisp refactoring puzzle In-Reply-To: <87mxgilh15.fsf@mithlond.arda> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: On 7/13/2011 4:29 AM, Teemu Likonen wrote: > * 2001-01-01T14:11:11-05:00 * Terry Reedy wrote: > >> As a side note, the same principle of expressions matching operations >> in symmetry suggest that majority of up are quite sensible and not >> dumb idiots for preferring 'f(x)' to the '(f x)' of Lisp. In a >> function call, the function has a different role than the arguments, >> so it is appropriate that it have a different role in the expression. > > Please don't forget that the whole point of Lisps' (f x) syntax is that > code is also Lisp data. Thank you for clarifying that. Some Lispers appear to promote the 'simple, uniform syntax' as a end in itself (making code=data a side effect) rather than as a means to accomplish a deeper end. > It's not just a function call with arguments. > First, it's literal data (two linked cons cells and symbols) and then > the Lisp evaluating model makes it a function call in certain > situations. > > Lisp is > > CL-USER> (let ((lisp (cons 'programmable nil))) > (setf (rest lisp) lisp)) This much looks like Lisp > #1=(PROGRAMMABLE . #1#) This must be some of the new-fangled Common LIsp stuff I never learned ;=). > programming language and it's totally irrelevant and pointless to say > "which syntax someone prefers" because this feature (code being data) is > very fundamental principle of the language. You know, it's easy to write > programs that write programs. If we remove this feature (i.e., don't > talk about Lisp at all) then it's perhaps relevant to discuss about such > choices in syntax. > > You wouldn't want Python arrays have a read and print format "a[b, c]", > that is, the first item of the array printed outside []'s. It would be > silly. -- Terry Jan Reedy From justmailnaveen at gmail.com Wed Jul 13 10:49:25 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:49:25 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: Message-ID: <301a47a4-cc74-46ba-920d-9104e2a59417@glegroupsg2000goo.googlegroups.com> Thanks Chris, That was a nice brief explanation,but i got the point. From justmailnaveen at gmail.com Wed Jul 13 10:49:25 2011 From: justmailnaveen at gmail.com (ArrC) Date: Wed, 13 Jul 2011 07:49:25 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: Message-ID: <301a47a4-cc74-46ba-920d-9104e2a59417@glegroupsg2000goo.googlegroups.com> Thanks Chris, That was a nice brief explanation,but i got the point. From rustompmody at gmail.com Wed Jul 13 10:59:37 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Jul 2011 07:59:37 -0700 (PDT) Subject: Wgy isn't there a good RAD Gui tool fo python References: <0439d15a-d6f3-435e-a4f9-416082596480@g9g2000yqb.googlegroups.com> <871uxxf0tp.fsf@benfinney.id.au> <9cb6df1c-52f0-472c-9b87-6be53c07d8a4@h4g2000vbw.googlegroups.com> <829d7e6d-29f6-4678-9f5c-270a4a10a7d5@y30g2000yqb.googlegroups.com> <813f5c03-9916-4a18-bf09-6037db66f7a1@m22g2000yqh.googlegroups.com> <9455da26-74ba-4f2b-a9b0-f2f747432bdd@h4g2000vbw.googlegroups.com> <4781c365-cfb2-45e1-9f94-37436bd5f6f6@j15g2000yqf.googlegroups.com> <9ec08bcc-95e8-4c2f-8528-a09c7bdeaff6@gv8g2000vbb.googlegroups.com> <79a7dab4-16ce-436e-ac54-62e314360fae@j25g2000vbr.googlegroups.com> Message-ID: On Jul 13, 5:22?am, CM wrote: > On Jul 12, 5:18?pm, rantingrick wrote: > > Kevin made the argument earlier that Tkinter (and others) are so easy > > to use that they render needing a GUI builder useless -- and he is > > correct! But did you know that there are GUI libraries EVEN more > > highly abstracted than Tkinter? Oh yes! So your "OMG, this typing and > > using my imagination is so difficult" *crap* is really making me > > laugh. > > My attitude is, if I could speak in English to an AI to tell it what I'd like the > program to do, I'd do it. Yes, since I can't do that, I inevitably > do sometimes enjoy puzzling things out, but only because I have to. > > > PS: if you don't like to type, programming IS NOT the best career (or > > hobby) choice for you. > > I guess it is not so much that I dislike typing, as I dislike having > to > switch from visual mode to code mode, remember the keywords and > such for the widgets, rather than quickly clicking around. ?The > keystroke count is really just a proxy for that sort of effort. Yes. This is what is called the semantic gap. Say you were a programmer who had to write software for numerical analysis. Would you write it in assembly even if, say, you knew assembly very well? I contend that most sane programmers would choose an algebraic language because they understand (formally or intuitively it does not matter) that minimizing semantic gaps are best for programming. Writing text that indirectly describes a gui rather than directly drawing it is analogous to writing assembly that implies an algebraic operation instead of writing the algebra directly. As for Kevin's point: > One reason there hasn't been much demand for a GUI builder is that, in > many cases, it's just as simpler or simpler to code a GUI by hand. I am not sure how to interpret that. If you are saying that most of today's gui builders are too close to suxware to be worth the time, I guess its true (and eminently practical) If on the other hand the claim is that the very idea of gui-builders is a flawed one I think the jury is still out on that. And the history of computer science repeatedly shows that very high level ideas take decades to enter the mainstream. Think of garbage collection in 1960 in the esoteric lisp finally getting mainlined in Java in 1995. From sturlamolden at yahoo.no Wed Jul 13 11:03:19 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 13 Jul 2011 08:03:19 -0700 (PDT) Subject: What is the difference between PyPy and Python? are there lot of differences? References: Message-ID: <4a7a95d5-e2b6-4c4c-8093-fd33203b7990@a11g2000yqm.googlegroups.com> On 13 Jul, 16:06, ArrC wrote: > And they also talked about the lack of type check in python. > > So, how does it help (strongly typed) in debugging? Python is strongly typed. There are no static type checks in Python. Type checks are done at runtime. Dynamic typing does not mean that Python is a weakly typed language. The question of debugging is often raised, particularly by Java heads: In Python, the "doctest" and "unittest" modules can be used to verify that code works according to specification (e.g. trap type errors), and are common alternatives to static type checks. http://docs.python.org/release/3.2/library/doctest.html http://docs.python.org/release/3.2/library/unittest.html It is a good practice to always write tests for your code. Python 3.x also has function argument and return value type annotations, which is a further guard against type errors: http://www.python.org/dev/peps/pep-3107/ Sturla From rustompmody at gmail.com Wed Jul 13 11:14:36 2011 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Jul 2011 08:14:36 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> On Jul 13, 5:53?pm, Chris Angelico wrote: > On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilli... at gmail.com > > wrote: > > On Jul 12, 6:40?pm, John Keisling wrote: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. > > > Brillant. This deserves to become a cpython easter egg along with > > import this or from __future__ import braces. Well written, funny, educative. Thanks But whats 'the modeling and sym guy' reference? From ian.g.kelly at gmail.com Wed Jul 13 11:18:59 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2011 09:18:59 -0600 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong wrote: > One of the main difference is that pypy supports only R-Python, which stands > for 'Restricted Python". > It is a subset of C-python language. This is wrong. The PyPy *interpreter* is written in RPython. At the application level, PyPy supports the full syntax and semantics of Python (with a few minor differences of the same sort that you find in Jython or IronPython). From tlikonen at iki.fi Wed Jul 13 11:25:00 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Wed, 13 Jul 2011 18:25:00 +0300 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: <87oc0ydwz7.fsf@mithlond.arda> * 2011-07-13T10:34:41-04:00 * Terry Reedy wrote: > On 7/13/2011 4:29 AM, Teemu Likonen wrote: >> Please don't forget that the whole point of Lisps' (f x) syntax is >> that code is also Lisp data. > > Thank you for clarifying that. Some Lispers appear to promote the > simple, uniform syntax' as a end in itself (making code=data a side > effect) rather than as a means to accomplish a deeper end. Perhaps, yes. We can't really speak of Lisp's syntax in the same sense as syntax in other languages. >> CL-USER> (let ((lisp (cons 'programmable nil))) >> (setf (rest lisp) lisp)) > > This much looks like Lisp > >> #1=(PROGRAMMABLE . #1#) > > This must be some of the new-fangled Common LIsp stuff I never learned > ;=). It's a way for the Lisp printer to show circular structures. In this case it shows a cons cell. Its first part is the symbol PROGRAMMABLE and the second part is a pointer back to the cons cell itself. So, it's a kind of infinite linked list with the same item PROGRAMMABLE all the time. With Lisp printer settings (setf *print-circle* nil *print-length* 5) the same thing would be printed this way: (PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE PROGRAMMABLE ...) From anthony.hw.kong at gmail.com Wed Jul 13 11:54:05 2011 From: anthony.hw.kong at gmail.com (Anthony Kong) Date: Thu, 14 Jul 2011 01:54:05 +1000 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: I stand corrected. Thanks Ian Cheers On Thu, Jul 14, 2011 at 1:18 AM, Ian Kelly wrote: > On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong > wrote: > > One of the main difference is that pypy supports only R-Python, which > stands > > for 'Restricted Python". > > It is a subset of C-python language. > > This is wrong. The PyPy *interpreter* is written in RPython. At the > application level, PyPy supports the full syntax and semantics of > Python (with a few minor differences of the same sort that you find in > Jython or IronPython). > -- Tony Kong *blog:* www.ahwkong.com Don?t EVER make the mistake that you can design something better than what you get from ruthless massively parallel trial-and-error with a feedback cycle. That?s giving your intelligence *much* too much credit. - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Wed Jul 13 11:55:36 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 13 Jul 2011 09:55:36 -0600 Subject: Python Contribution In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 4:31 AM, Shankar Raman wrote: > ?Hello everyone, > ? ?? My name is Shankarraman and I have been working with Python for past 5 > months.I find it really interesting and cool and would like to know > different ways I can contribute to it. Though I went through the bug lists, > I was wondering if I could contribute to Python in other ways. > You're in luck, Shankar. You can you hop into the dev guide (http://docs.python.org/devguide/) which will at least get you [very] started. Not only that, but there is also a mailing list specifically for mentoring people that want to get started at contributing to Python: core-mentorship at python.org. This a wonderful community and I hope you find the opportunity to jump right in! -eric > -- > Namashivaya, > R.Shankarraman, > Computer Science and Engineering, > Amrita School of Engineering. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From ericsnowcurrently at gmail.com Wed Jul 13 12:04:56 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 13 Jul 2011 10:04:56 -0600 Subject: Code hosting services In-Reply-To: <1310552613.7271.1.camel@linux-yu4c.site> References: <4E1D413E.7080002@gmail.com> <1310552613.7271.1.camel@linux-yu4c.site> Message-ID: On Wed, Jul 13, 2011 at 4:23 AM, Adam Tauno Williams wrote: > On Wed, 2011-07-13 at 01:54 -0500, Andrew Berg wrote: >> What can you guys recommend? > > SourceForge; ?it is a comprehensive platform [in addition to being an > Open Source platform: Allura]. ?It is a much improved platform over > several years ago. > Incidently, Mark Ramm of TurboGears fame went to work at SF and they have relatively recently moved a large chunk of their stuff to Python[1]. -eric [1] http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-scaling-python-past-100-4899197 From godson.g at gmail.com Wed Jul 13 12:07:15 2011 From: godson.g at gmail.com (Godson Gera) Date: Wed, 13 Jul 2011 21:37:15 +0530 Subject: How do you get the value you entered using the Entry widget in Tkinter? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 1:31 PM, Benji Benjokal wrote: > What is the simplist way to get the value you entered from the Entry widget > in Tkinter? > Have you tried the get method of Entry widget ? Here is a crude example from Tkinter import* r = Tk() e = Entry(r) e.pack() def printData(): print e.get() b = Button(r,text='getdata',command=printData) b.pack() r.mainloop() -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Wed Jul 13 12:17:58 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 13 Jul 2011 18:17:58 +0200 Subject: How do you get the value you entered using the Entry widget in Tkinter? In-Reply-To: References: Message-ID: 2011/7/13 Benji Benjokal : > What is the simplist way to get the value you entered from the Entry widget > in ?Tkinter? > Thanks Benji > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, you can use the get() method of that widget; see e.g. http://effbot.org/tkinterbook/entry.htm for a sample code. hth, vbr From tjreedy at udel.edu Wed Jul 13 12:18:18 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:18:18 -0400 Subject: An interesting beginner question: why we need colon at all in the python language? In-Reply-To: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> References: <641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com> Message-ID: On 7/13/2011 2:26 AM, alex23 wrote: > Thomas Jollans wrote: >> Coincidentally, Guido wrote this blog post just last week, without which >> I'd be just as much at a loss as you: >> >> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an... > > It's also part of the Python FAQ: > > http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements An added note: the header lines of compound statements do not necessarily occupy just one physical line. The : signals the end of the logical line. Editors can use to to indent intelligently. Consider def myfunc(a, b, c): return a+b+c All indentation was done automatically by IDLE's editor. -- Terry Jan Reedy From drsalists at gmail.com Wed Jul 13 12:22:39 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 13 Jul 2011 09:22:39 -0700 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 8:18 AM, Ian Kelly wrote: > On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong > wrote: > > One of the main difference is that pypy supports only R-Python, which > stands > > for 'Restricted Python". > > It is a subset of C-python language. > > This is wrong. The PyPy *interpreter* is written in RPython. At the > application level, PyPy supports the full syntax and semantics of > Python (with a few minor differences of the same sort that you find in > Jython or IronPython). > PyPy (2.7) and Jython (2.5) are pretty close to each other, though PyPy is quite a bit faster than Jython or CPython. Both PyPy and Jython are good implementations of the Python language, at least if you don't need a lot of C extension modules. IronPython doesn't appear to have a standard library. :( Or rather, it can use a CPython install's standard library, but a significant fraction of it doesn't work on IronPython - it doesn't appear to have been tested or adapted. There's something called FePy that includes IronPython and a better standard library, but AFAIK, it only works on windows. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 13 12:29:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:29:50 -0400 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: On 7/13/2011 8:39 AM, Anthony Kong wrote: > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module The iteration protocol and the notion of iteraables as the common data exchange format, with associated notions of iterators, generator functions, and generators, are important features of Python. Not really functional style, I guess. > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? Functions are first-class objects, like everything else. Use of closures to create functions to be returned. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jul 13 12:31:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 12:31:59 -0400 Subject: What is the difference between PyPy and Python? are there lot of differences? In-Reply-To: References: Message-ID: On 7/13/2011 10:19 AM, Anthony Kong wrote: > One of the main difference is that pypy supports only R-Python, which > stands for 'Restricted Python". Not true. PyPy is *written* in rpython. It runs standard Python. -- Terry Jan Reedy From k.sahithi2862 at gmail.com Wed Jul 13 12:35:26 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 13 Jul 2011 09:35:26 -0700 (PDT) Subject: XXX HOT PHOTOS & VIDEOS Message-ID: <17fd9e70-8091-4c80-a785-410b694b275b@z7g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From ian.g.kelly at gmail.com Wed Jul 13 13:09:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2011 11:09:16 -0600 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: On Wed, Jul 13, 2011 at 10:29 AM, Terry Reedy wrote: > The iteration protocol and the notion of iteraables as the common data > exchange format, with associated notions of iterators, generator functions, > and generators, are important features of Python. Not really functional > style, I guess. Xah Lee's assertion to the contrary notwithstanding, it seems to me that list comprehensions are basically functional in style. They are, after all, equivalent to "map(f, filter(g, x))". Iterators, on the other hand, by definition have the property that each call to iter.next() has the side effect of changing the iterator's state. Therefore, although they can effectively be used as a functional building block (e.g. by masking their use with a comprehension), the iterators themselves are not actually functional. From clp2 at rebertia.com Wed Jul 13 13:10:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 13 Jul 2011 10:10:45 -0700 Subject: sys.tracebacklimit In-Reply-To: References: Message-ID: On Wed, Jul 13, 2011 at 6:42 AM, Vlad Didenko wrote: > Colleagues, > Per documentation > at?http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit?: > ?? ? When [sys.tracebacklimit]?set to 0 or less, all traceback information > is suppressed and only the exception type and value are printed > So, I expect to be able to have a program like: > ?? ?import sys > ?? ?sys.tracebacklimit=0 > ?? ?print(1/0) > And see it's result as: > ?? ??ZeroDivisionError: division by zero > However, the actual result is: > ?? ??Traceback (most recent call last): > ?? ????File "tbt.py", line 3, in > ?? ???? ?print(1/0) > ?? ??ZeroDivisionError: division by zero > Do I misunderstand the docs? Nope. It's a known bug: http://bugs.python.org/issue12276 Cheers, Chris From stratfordtenants at gmail.com Wed Jul 13 13:11:51 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 10:11:51 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in Message-ID: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Hello I am using the zxJDBC package with jython (similar to python), and I am having "python error PLS-00306: wrong number or types of arguments" error when using the "callproc()" method to execute a stored procedure. The Oracle stored procedure takes a single OUT varchar2 parameter. My code is as follows: p = [None] c.callproc('pkg1_returns', p); ... What I am doing corresponds to the examples..but I can seem to know why it is not working. Help. "Adeoluwa" From thorsten at thorstenkampe.de Wed Jul 13 13:27:02 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 13 Jul 2011 19:27:02 +0200 Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) > On 2011-07-13, Thorsten Kampe wrote: > > >> and that that block is to be considered in relation to what was just > >> said, before the colon. > > > > The indentation makes it abundantly clear to the human reader that > > that indented block is to be considered in relation to what was just > > said, before the indentation. > You would think so, but human readers like redundancy. I also like redundancy (and consistency). That's why I'd much more prefer a "then" than a colon which is easily overlooked while reading /and/ while writing. Thorsten From shilparani9030 at gmail.com Wed Jul 13 13:28:29 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Wed, 13 Jul 2011 10:28:29 -0700 (PDT) Subject: EXCLUSIVE HOT PHOTOS Message-ID: <5bc4a35f-2128-4bf2-9edf-9fdeddd7d3ab@j9g2000prj.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html GOOD LOOKING DEEPIKA PADUKONE http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html AISHWARYA RAI UNBELIVABLE PHOTO http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html TAPSEE RARE PHOTOS http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY http://allyouwants.blogspot.com From gordon at panix.com Wed Jul 13 13:40:35 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 17:40:35 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Message-ID: In <01efb6ac-deaa-4bdb-8b2d-b603bdddec57 at n5g2000yqh.googlegroups.com> Adeoluwa Odein writes: > Hello > I am using the zxJDBC package with jython (similar to python), and I > am having "python error PLS-00306: wrong number or types of arguments" > error when using the "callproc()" method to execute a stored > procedure. > The Oracle stored procedure takes a single OUT varchar2 parameter. My > code is as follows: > p = [None] > c.callproc('pkg1_returns', p); If the procedure takes a varchar2 parameter, why are you passing [None]? It might help if you posted the method signature of the Oracle stored procedure you're trying to call. -- 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 stratfordtenants at gmail.com Wed Jul 13 13:58:06 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 10:58:06 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> Message-ID: <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Thanks, your assistance will be greatly appreciated on the right way forward. See the Stored Procedure Below -very simple: create or replace package c2_pkg as procedure openc; procedure closec; procedure RS22(v out varchar); end; / create or replace package body c2_pkg as v_first_time boolean := TRUE; v_cursor number; cursor srvr_cur is select distinct b.mid from SVR a,VAR b where a.mid = b.mid; procedure openc as begin if not srvr_cur%ISOPEN then open srvr_cur; end if; end openc; procedure closec as begin close srvr_cur; end closec; procedure RS22(v out varchar2) as -- Server varchar2(64); begin Server := NULL; fetch srvr_cur into Server; v := Server; end RS22; end; / On Jul 13, 1:40?pm, John Gordon wrote: > In <01efb6ac-deaa-4bdb-8b2d-b603bddde... at n5g2000yqh.googlegroups.com> Adeoluwa Odein writes: > > > Hello > > I am using the zxJDBC package with jython (similar to python), and I > > am having "python error PLS-00306: wrong number or types of arguments" > > error when using the "callproc()" method to execute a stored > > procedure. > > The Oracle stored procedure takes a single OUT varchar2 parameter. ?My > > code is as follows: > > p = [None] > > c.callproc('pkg1_returns', p); > > If the procedure takes a varchar2 parameter, why are you passing [None]? > > It might help if you posted the method signature of the Oracle stored > procedure you're trying to call. > > -- > 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" From gordon at panix.com Wed Jul 13 14:10:06 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 18:10:06 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: In <9e937261-d05d-477a-90d2-a690e85e124d at h17g2000yqn.googlegroups.com> Adeoluwa Odein writes: > Thanks, your assistance will be greatly appreciated on the right way > forward. See the Stored Procedure Below -very simple: I don't see a procedure named "pkg1_returns", which is the prodecure called by your code. Where is this procedure? -- 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 stratfordtenants at gmail.com Wed Jul 13 14:18:30 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:18:30 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: The actual jython/python call is: p = [None] c.callproc('c2_pkg.RS22', p); I used a placeholder initially; now that you have the SQL code, there it is. It essentially invokes the stored procedure, and it should return the OUT variable p, with some value. It doesn't have to be a cursor fetch; even a minor text assignment. On Jul 13, 2:10?pm, John Gordon wrote: > In <9e937261-d05d-477a-90d2-a690e85e1... at h17g2000yqn.googlegroups.com> Adeoluwa Odein writes: > > > Thanks, your assistance will be greatly appreciated on the right way > > forward. ?See the Stored Procedure Below -very simple: > > I don't see a procedure named "pkg1_returns", which is the prodecure > called by your code. ?Where is this procedure? > > -- > 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" From gordon at panix.com Wed Jul 13 14:26:40 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 18:26:40 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: In Adeoluwa Odein writes: > The actual jython/python call is: > p =3D [None] > c.callproc('c2_pkg.RS22', p); > I used a placeholder initially; now that you have the SQL code, there > it is. It essentially invokes the stored procedure, and it should > return the OUT variable p, with some value. It doesn't have to be a > cursor fetch; even a minor text assignment. That procedure is defined as taking one parameter, but you're passing an empty parameter list. Why? -- 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 stratfordtenants at gmail.com Wed Jul 13 14:32:18 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:32:18 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: On Jul 13, 2:26?pm, John Gordon wrote: > In Adeoluwa Odein writes: > > > The actual jython/python call is: It's taking an OUT parameter.. I'm just following the examples as documented by zxJDBC. How can I fix it? > > p =3D [None] > > c.callproc('c2_pkg.RS22', p); > > I used a placeholder initially; now that you have the SQL code, there > > it is. ?It essentially invokes the stored procedure, and it should > > return the OUT variable p, with some value. ?It doesn't have to be a > > cursor fetch; even a minor text assignment. > > That procedure is defined as taking one parameter, but you're passing > an empty parameter list. ?Why? > > -- > 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" From rantingrick at gmail.com Wed Jul 13 14:32:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 13 Jul 2011 11:32:50 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> Message-ID: <000e90cf-4dc8-4499-88d7-43c294499d70@z12g2000yqj.googlegroups.com> On Jul 13, 10:14?am, rusi wrote: > Well written, funny, educative. Thanks > But whats 'the modeling and sym guy' reference? I believe it's "esoteric". From stratfordtenants at gmail.com Wed Jul 13 14:33:28 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 11:33:28 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: <5f0ba12a-4de1-4032-941e-59f3b6878c4b@y13g2000yqy.googlegroups.com> On Jul 13, 2:26?pm, John Gordon wrote: > In Adeoluwa Odein writes: > > > The actual jython/python call is: > > p =3D [None] > > c.callproc('c2_pkg.RS22', p); > > I used a placeholder initially; now that you have the SQL code, there > > it is. ?It essentially invokes the stored procedure, and it should > > return the OUT variable p, with some value. ?It doesn't have to be a > > cursor fetch; even a minor text assignment. > > That procedure is defined as taking one parameter, but you're passing > an empty parameter list. ?Why? > > -- > 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" I'm new to jython... From kylotan at gmail.com Wed Jul 13 15:21:16 2011 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 13 Jul 2011 12:21:16 -0700 (PDT) Subject: Installing PyPy alongside Python 2.7 on Windows? References: Message-ID: On Jul 13, 7:29?am, cjrh wrote: > You can just extract the windows pypy 1.5 distribution to any folder and run "pypy.exe" from there as if it was called "python.exe". ?This is how I have been using it. ?In fact, pypy has been the default python for my portable eclipse for a good while now. That doesn't give access to existing site-packages, or allow me to install binary packages that it can access. Hence me asking about that specifically. From maththespian87 at gmail.com Wed Jul 13 15:31:30 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:31:30 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> On Jul 12, 7:02?pm, Steven D'Aprano wrote: > John Keisling wrote: > > After too much time coding Python scripts and reading Mark Lutz's > > Python books, I was inspired to write the following lyrics. For those > > too young to remember, the tune is that of "Pinball Wizard," by The > > Who. May it bring you as much joy as it brought me! > > [...] > > I wouldn't know a good song parody if it kicked me in the head, but my wife > is a (retired) professional musician with a history of writing parodies. > She's not impressed by the work of most "filk singers" and supposed > parodies, most of which are seventeen kinds of crap... but she gives you > full marks. And trust me on this, she does not give compliments lightly. > > She says you got the rhyming scheme and number of syllables spot on. > Technically, "That modeling and sim guy" needs to be slurred to make it > fit, "That mod'ling and sim guy", but that's acceptable. > > (Most parodies get the syllable count wrong -- if a lyric goes > dum-de-dum-de-dum, the parody ends up like dum-dum-de-dum-de-dum or > dum-de-dum-de.) > > Have a +1 from me and the missus. > > -- > Steven I very much appreciate that, coming from someone who clearly values well-written poetry and lyrics as much as I do! I double majored in math and English, and I always liked structured poetry. It's very important to match not only the syllable count, but the meter too. I also pride myself on never using the same rhyme twice in a song, which even the original does not manage to do (they used "fall" twice). Very glad you and the missus enjoyed it! From maththespian87 at gmail.com Wed Jul 13 15:32:54 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:32:54 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> Message-ID: <60e495ba-8a03-42d5-bf0a-995948d2ab26@p29g2000pre.googlegroups.com> On Jul 13, 6:53?am, Chris Angelico wrote: > On Wed, Jul 13, 2011 at 10:46 PM, bruno.desthuilli... at gmail.com > > wrote: > > On Jul 12, 6:40?pm, John Keisling wrote: > >> After too much time coding Python scripts and reading Mark Lutz's > >> Python books, I was inspired to write the following lyrics. > > > Brillant. This deserves to become a cpython easter egg along with > > import this or from __future__ import braces. > > Propose: from eastereggs import wizard > > ChrisA I would be honored beyond words to have this become a Python Easter egg! Does anyone know how to make that happen? From maththespian87 at gmail.com Wed Jul 13 15:35:27 2011 From: maththespian87 at gmail.com (John Keisling) Date: Wed, 13 Jul 2011 12:35:27 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <77c057d4-eb7e-4dfd-b021-2fdaa1e5f68d@f39g2000prb.googlegroups.com> <000e90cf-4dc8-4499-88d7-43c294499d70@z12g2000yqj.googlegroups.com> Message-ID: <4d025ec6-d603-4206-b78f-5dac6aba1e19@k23g2000pri.googlegroups.com> On Jul 13, 12:32?pm, rantingrick wrote: > On Jul 13, 10:14?am, rusi wrote: > > > Well written, funny, educative. Thanks > > But whats 'the modeling and sym guy' reference? > > I believe it's "esoteric". I actually had myself in mind, with tongue in cheek, of course! I work in modeling and simulation and write Python scripts to automate data visualization and analysis. Of course, that line could also refer to a few of my co-workers. Glad you all enjoyed the song! From cartercc at gmail.com Wed Jul 13 16:04:47 2011 From: cartercc at gmail.com (ccc31807) Date: Wed, 13 Jul 2011 13:04:47 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: On Jul 12, 7:54 am, Xah Lee wrote: > maybe this will be of interest. > > ?What Programing Language Are the Largest Website Written In??http://xahlee.org/comp/website_lang_popularity.html About five years ago, I did some pretty extensive research, and concluded that the biggest sites were written serverside with JSP. Obviously, this wouldn't include The Biggest site, but if you were a big, multinational corporation, or listed on the NYSE, you used JSP for your web programming. I doubt very seriously PHP is used for the biggest sites -- I'd still guess JSP, or maybe a MS technology (not VB), but it's only a guess. CC. From gordon at panix.com Wed Jul 13 16:09:12 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 20:09:12 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: > It's taking an OUT parameter.. I'm just following the examples as > documented by zxJDBC. How can I fix it? I suspect the example you're looking at was for a procedure which has no arguments, so in that case it would make sense to pass an empty parameter list. I haven't worked with OUT parameters so I don't know if this will work, but try it and see what happens: my_string = "" p = [my_string] c.callproc('c2_pkg.RS22', p); print p -- 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 nberg at atmos.ucla.edu Wed Jul 13 16:22:34 2011 From: nberg at atmos.ucla.edu (Neil Berg) Date: Wed, 13 Jul 2011 13:22:34 -0700 Subject: losing-end-of-row values when manipulating CSV input Message-ID: Hello all, I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. Do you have any suggestions on how to fix this issue? Many thanks in advance, Neil Berg -------------- next part -------------- A non-text attachment was scrubbed... Name: csv_test.py Type: text/x-python-script Size: 1136 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: csv_sample.csv Type: text/csv Size: 416 bytes Desc: not available URL: From stratfordtenants at gmail.com Wed Jul 13 16:33:22 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 13:33:22 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> Message-ID: <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> On Jul 13, 4:09?pm, John Gordon wrote: > > It's taking an OUT parameter.. I'm just following the examples as > > documented by zxJDBC. ?How can I fix it? > > I suspect the example you're looking at was for a procedure which has no > arguments, so in that case it would make sense to pass an empty parameter > list. > > I haven't worked with OUT parameters so I don't know if this will work, > but try it and see what happens: > > ? my_string = "" > ? p = [my_string] > ? c.callproc('c2_pkg.RS22', p); > ? print p > > -- > 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 same error. The sample were found on the following site --I copied exactly what is written there: 1. http://www.jython.org/archive/21/docs/zxjdbc.html From nawijn at gmail.com Wed Jul 13 16:42:10 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Wed, 13 Jul 2011 13:42:10 -0700 (PDT) Subject: losing-end-of-row values when manipulating CSV input References: Message-ID: On Jul 13, 10:22?pm, Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. ?I have attached both a sample of the CSV data and my script. ? > > The attached CSV file contains two rows and 27 columns of data. ?The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". ? > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. ? > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. ?My script, however, is returning 23. ?I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. ?I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > ?csv_test.py > 1KViewDownload > > ?csv_sample.csv > < 1KViewDownload Hello Neil, I just had a quick look at your script. To remove the trailing "\" you can use val = val.rstrip('\\') in your script. Note the double backslash. The script now returns 24 items in the hour_list. Good luck! Marco From nawijn at gmail.com Wed Jul 13 16:44:45 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Wed, 13 Jul 2011 13:44:45 -0700 (PDT) Subject: losing-end-of-row values when manipulating CSV input References: Message-ID: On Jul 13, 10:22?pm, Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. ?I have attached both a sample of the CSV data and my script. ? > > The attached CSV file contains two rows and 27 columns of data. ?The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". ? > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. ? > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. ?My script, however, is returning 23. ?I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. ?I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > ?csv_test.py > 1KViewDownload > > ?csv_sample.csv > < 1KViewDownload Dear Neil, Don't know if this is a double post (previous post seems to be gone), but val = val.rstrip('\\') should fix your problem. Note the double backslash. Kind regards, Marco From gordon at panix.com Wed Jul 13 17:02:37 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 21:02:37 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: In <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592 at f35g2000vbr.googlegroups.com> Adeoluwa Odein writes: > The same error. The sample were found on the following site --I copied > exactly what is written there: > 1. http://www.jython.org/archive/21/docs/zxjdbc.html Ah, I see. You're supposed to call c.fetchall() afterwards to retrieve the OUT parameter. Also, the example page defines the called object as a function, not a procedure. Maybe that's the problem? Try defining RS22 as a function and see if that helps. You might also try defining it outside of a package, as that is how the example code does it. -- 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 stratfordtenants at gmail.com Wed Jul 13 17:06:03 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:06:03 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> On Jul 13, 5:02?pm, John Gordon wrote: > In <86b9e6f2-e18e-41b9-92a2-86ea8d7b4... at f35g2000vbr.googlegroups.com> Adeoluwa Odein writes: > > > The same error. The sample were found on the following site --I copied > > exactly what is written there: > > 1.http://www.jython.org/archive/21/docs/zxjdbc.html > if you define the function in the execute() method, it works (as seen on the page). But this is a stored procedure already residing on the DB. A function/procedure outside of a package, actually works, but then you lose access to private data; which is while I used a package. > Ah, I see. ?You're supposed to call c.fetchall() afterwards to retrieve > the OUT parameter. > > Also, the example page defines the called object as a function, not a > procedure. ?Maybe that's the problem? ?Try defining RS22 as a function > and see if that helps. > > You might also try defining it outside of a package, as that is how the > example code does it. > > -- > 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" From vlastimil.brom at gmail.com Wed Jul 13 17:13:16 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 13 Jul 2011 23:13:16 +0200 Subject: difflib-like library supporting moved blocks detection? Message-ID: Hi all, I'd like to ask about the availability of a text diff library, like difflib, which would support the detection of moved text blocks. Currently I am almost happy with the results of difflib.SequenceMatcher in my app (comparing different versions of natural language texts), however the only drawback seems to be the missing detection of moves of the text parts. I was thinking of simply recomparing the deleted and inserted blocks using difflib again, but this obviously won't be a general solution. I found several algorithm discussions, but unfortunately no suitable python implementation. (E.g. Medite - http://www-poleia.lip6.fr/~ganascia/Medite_Project - seems to be implemented in Python but it targets some rather special and probably much more complex textological issues, than my current needs.) Does maybe someone know such python library (or possibly a way of enhancing difflib) for this task (i.e character-wise comparing of texts - detecting insertion, deletion, substitution and move of text blocks)? Thanks in advance, Vlastimil Brom From EEllerbee at BBandT.com Wed Jul 13 17:13:23 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Wed, 13 Jul 2011 17:13:23 -0400 Subject: I don't know list, I not good at list. Message-ID: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> I've been beating my head against the desk trying to figure out a method to accomplish this: Take a list (this example is 5 items, It could be 150 or more - i.e. it's variable length depending on the city/local calling zones) The first 6 digits of phone numbers(NPA/NXX) in a local calling area. I want to concatenate the last digit for insertion into a call routing pattern. I tried this and failed miserably: list1=['252205','252246','252206','252247','252248'] for item in list1: try: item1=list1[0] item2=list1[1] if item1[0:5] == item2[0:5]: print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' list1.pop(0) else: print item1 list1.pop(0) except: try: print item1 list1.pop(0) except: pass #----------------------------------------------------------------- My intent is to have the end data come out (from the example list above) in the format of 25220[56] 25224[678] I tried putting together a variable inserted into a regular expression, and it doesn't seem to like: Item1=list1[0] Itemreg = re.compile(Item1[0:5]) For stuff in itemreg.list1: #do something Can somebody throw me a bone, code example or module to read on python.org? I'm a n00b, so I'm still trying to understand functions and classes. I thought the experts on this list might take pity on my pathetic code skillz! Thanks so much :) Ed Ellerbee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Jul 13 17:17:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Jul 2011 14:17:41 -0700 Subject: losing-end-of-row values when manipulating CSV input In-Reply-To: References: Message-ID: <4E1E0B75.3000304@stoneleaf.us> Neil Berg wrote: > Hello all, > > I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. > > The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. > > In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". > > Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. > > But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. > > Do you have any suggestions on how to fix this issue? > > Many thanks in advance, > > Neil Berg > > Your 'csv' file isn't -- it looks like rich text. An actual csv file looks more like this (which is probably what you're seeing in notepad, but is not what is stored on disk): 8<------------------------------------------------------------------------------------ BLS,4,19981101,37,m,36,34,36,35,34,34,35,36,38,39,43,42,42,42,38,36,34,32,33,33,35,34 BLS,4,19981102,34,32,33,32,34,32,33,32,34,38,40,41,44,47,43,42,39,36,35,35,36,36,35,33 8<------------------------------------------------------------------------------------ Try saving in text-only format. ~Ethan~ From tjreedy at udel.edu Wed Jul 13 17:18:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jul 2011 17:18:12 -0400 Subject: python error PLS-00306: wrong number or types of arguments in In-Reply-To: <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> Message-ID: On 7/13/2011 4:33 PM, Adeoluwa Odein wrote: > The same error. The sample were found on the following site --I copied > exactly what is written there: > 1. http://www.jython.org/archive/21/docs/zxjdbc.html The jython-users mailing list might be a better place to ask your question. Most people here are CPython users. http://sourceforge.net/mail/?group_id=12867 -- Terry Jan Reedy From gordon at panix.com Wed Jul 13 17:19:02 2011 From: gordon at panix.com (John Gordon) Date: Wed, 13 Jul 2011 21:19:02 +0000 (UTC) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: In <0730c5fb-3b65-45ce-9cc5-69d639f48281 at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > if you define the function in the execute() method, it works (as seen > on the page). But this is a stored procedure already residing on the > DB. A function/procedure outside of a package, actually works, but > then you lose access to private data; which is while I used a package. Did you try changing RS22 from a procedure to a function inside the package? -- 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 nberg at atmos.ucla.edu Wed Jul 13 17:19:21 2011 From: nberg at atmos.ucla.edu (Neil Berg) Date: Wed, 13 Jul 2011 14:19:21 -0700 Subject: losing-end-of-row values when manipulating CSV input In-Reply-To: <4E1E0B75.3000304@stoneleaf.us> References: <4E1E0B75.3000304@stoneleaf.us> Message-ID: Ethan, Thank you for this tip- you are correct that I saved the data as rich text. I remade the files in VI instead of TextEdit, which allowed me to write a true csv file and the script works as expected now. Thanks again, Neil On Jul 13, 2011, at 2:17 PM, Ethan Furman wrote: > Neil Berg wrote: >> Hello all, >> >> I am having an issue with my attempts to accurately filter some data from a CSV file I am importing. I have attached both a sample of the CSV data and my script. >> >> The attached CSV file contains two rows and 27 columns of data. The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. >> >> In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list". >> >> Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement. >> >> But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24. My script, however, is returning 23. I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line. I've tried several ways to remove this trailing "\", but to no success. >> >> Do you have any suggestions on how to fix this issue? >> >> Many thanks in advance, >> >> Neil Berg >> >> > Your 'csv' file isn't -- it looks like rich text. An actual csv file > looks more like this (which is probably what you're seeing in notepad, > but is not what is stored on disk): > > 8<------------------------------------------------------------------------------------ > BLS,4,19981101,37,m,36,34,36,35,34,34,35,36,38,39,43,42,42,42,38,36,34,32,33,33,35,34 > BLS,4,19981102,34,32,33,32,34,32,33,32,34,38,40,41,44,47,43,42,39,36,35,35,36,36,35,33 > 8<------------------------------------------------------------------------------------ > > Try saving in text-only format. > > ~Ethan~ From stratfordtenants at gmail.com Wed Jul 13 17:28:10 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:28:10 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: <65ea5860-caf7-4fc5-ab46-829ce29948d9@y13g2000yqy.googlegroups.com> On Jul 13, 5:19?pm, John Gordon wrote: > In <0730c5fb-3b65-45ce-9cc5-69d639f48... at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > > > if you define the function in the execute() method, it works (as seen > > on the page). ?But this is a stored procedure already residing on the > > DB. ?A function/procedure outside of a package, actually works, but > > then you lose access to private data; which is while I used a package. > > Did you try changing RS22 from a procedure to a function inside the > package? > > -- > 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" Correction, the previous actually works, and still gives me access to private data. So I will most likely use it. Basically, just call a function, outside a package. It resolves this entire dilemma. Implementing similar program in Perl DBI, works without any problem. Python/Jython seem quite difficult to work with Store Procedures, in my opinion. Thanks a lot. From stratfordtenants at gmail.com Wed Jul 13 17:28:38 2011 From: stratfordtenants at gmail.com (Adeoluwa Odein) Date: Wed, 13 Jul 2011 14:28:38 -0700 (PDT) Subject: python error PLS-00306: wrong number or types of arguments in References: <01efb6ac-deaa-4bdb-8b2d-b603bdddec57@n5g2000yqh.googlegroups.com> <9e937261-d05d-477a-90d2-a690e85e124d@h17g2000yqn.googlegroups.com> <86b9e6f2-e18e-41b9-92a2-86ea8d7b4592@f35g2000vbr.googlegroups.com> <0730c5fb-3b65-45ce-9cc5-69d639f48281@g2g2000vbl.googlegroups.com> Message-ID: On Jul 13, 5:19?pm, John Gordon wrote: > In <0730c5fb-3b65-45ce-9cc5-69d639f48... at g2g2000vbl.googlegroups.com> Adeoluwa Odein writes: > > > if you define the function in the execute() method, it works (as seen > > on the page). ?But this is a stored procedure already residing on the > > DB. ?A function/procedure outside of a package, actually works, but > > then you lose access to private data; which is while I used a package. > > Did you try changing RS22 from a procedure to a function inside the > package? > > -- > 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 same problem, if done inside a package. I just left it outside a package, and it works. From rosuav at gmail.com Wed Jul 13 17:40:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 07:40:19 +1000 Subject: "Python Wizard," with apologies to The Who In-Reply-To: <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> Message-ID: On Thu, Jul 14, 2011 at 5:31 AM, John Keisling wrote: > I very much appreciate that, coming from someone who clearly values > well-written poetry and lyrics as much as I do! I double majored in > math and English, and I always liked structured poetry. It's very > important to match not only the syllable count, but the meter too. I > also pride myself on never using the same rhyme twice in a song, which > even the original does not manage to do (they used "fall" twice). Having not known the original, I can't properly appreciate the parody, but I wholeheartedly concur with the above. Especially when you transmit your alternate words by email (as opposed to singing it yourself and posting on Youtube, for instance), you need them to scan perfectly so the reader isn't thrown off by anything. The other big pitfall is polysyllabic rhymes, quite common in Gilbert & Sullivan but probably not an issue here. (For instance, if the original rhymes "modern gunnery" with "in a nunnery", then you have to replace that with three-syllable words whose last two syllables are identical and whose first syllables rhyme. Not an easy task!) This appears to be an excellent parody, but others are better positioned to proclaim its quality than I. Chris Angelico From avfonarev at gmail.com Wed Jul 13 17:50:19 2011 From: avfonarev at gmail.com (Anton Fonarev) Date: Thu, 14 Jul 2011 01:50:19 +0400 Subject: What Programing Language are the Largest Website Written In? In-Reply-To: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: 2011/7/12 Xah Lee : > 23 yandex.ru (Russian) ? ? > As far as I know, the site is written in Perl. However, they are using lots of python in their products and for internal use. Anton. From emile at fenx.com Wed Jul 13 17:51:38 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 13 Jul 2011 14:51:38 -0700 Subject: I don't know list, I not good at list. In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> Message-ID: On 7/13/2011 2:13 PM Ellerbee, Edward said... > I've been beating my head against the desk trying to figure out a method > to accomplish this: > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list above) > in the format of > 25220[56] > 25224[678] this should get you started... >>> list1=['252205','252246','252206','252247','252248'] >>> D = {} >>> for ii in list1: D.setdefault(ii[:5],[]).append(ii[5]) ... >>> print D {'25224': ['6', '7', '8'], '25220': ['5', '6']} >>> Emile From python at mrabarnett.plus.com Wed Jul 13 17:58:50 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 13 Jul 2011 22:58:50 +0100 Subject: I don't know list, I not good at list. In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> Message-ID: <4E1E151A.4070006@mrabarnett.plus.com> > I've been beating my head against the desk trying to figure out a > method to accomplish this: > > Take a list (this example is 5 items, It could be 150 or more - i.e. > it's variable length depending on the city/local calling zones) > > The first 6 digits of phone numbers(NPA/NXX) in a local calling area. > I want to concatenate the last digit for insertion into a call > routing pattern. > > I tried this and failed miserably: > > list1=['252205','252246','252206','252247','252248'] > for item in list1: > try: > item1=list1[0] > item2=list1[1] > if item1[0:5] == item2[0:5]: > print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' > list1.pop(0) > else: > print item1 > list1.pop(0) > except: > try: > print item1 > list1.pop(0) > except: > pass > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list > above) in the format of > 25220[56] > 25224[678] > > I tried putting together a variable inserted into a regular > expression, and it doesn't seem to like: > Item1=list1[0] > Itemreg = re.compile(Item1[0:5]) > For stuff in itemreg.list1: > #do something > > Can somebody throw me a bone, code example or module to read on > python.org? I'm a n00b, so I'm still trying to understand functions > and classes. > > I thought the experts on this list might take pity on my pathetic > code skillz! > defaultdict comes in handy: >>> list1 = ['252205','252246','252206','252247','252248'] >>> from collections import defaultdict >>> d = defaultdict(set) >>> for item in list1: d[item[ : 5]].add(item[5 : ]) >>> d defaultdict(, {'25224': {'8', '7', '6'}, '25220': {'5', '6'}}) >>> for k, v in d.items(): print(k + "[" + "".join(v) + "]") 25224[876] 25220[56] From ryan at rfk.id.au Wed Jul 13 19:24:57 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 14 Jul 2011 09:24:57 +1000 Subject: PyCon Australia 2011: Schedule Announced Message-ID: <1310599497.11156.14.camel@rambutan> Hi Everyone, The official schedule for PyCon Australia 2011 has been announced! This year's conference will feature 3 fantastic keynotes, 7 introductory classroom sessions, and 26 presentations on topics as diverse as web programming, benchmarking, social issues and API design. PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Conference Schedule Announced 2. More Sponsors Announced Please pass this message on to those you feel may be interested. Conference Schedule Announced ============================= The detailed conference schedule has been completed and can now be viewed at the following URL: http://pycon-au.org/2011/conference/schedule/ There's even an iCal version for you to plug the schedule straight into your calendar of choice: http://pycon-au.org/2011/conference/schedule/ical/ Thanks again to all our presenters for some outstanding talk proposals this year. Standard Talks: A Python on the Couch (Mark Rees) Behaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in Python (Duncan Gray) Fun with App Engine 1.5.0 (Greg Darke) Hosting Python Web Applications (Graham Dumpleton) How Python Evolves (and How You Can Help Make It Happen) (Nick Coghlan) Infinite 8-bit Platformer (Chris McCormick) Networking Libraries in Python. (Senthil Kumaran) Pants - Network Programming Made Easy (Evan Davis) Say What You Mean: Meta-Programming a Declarative API (Ryan Kelly) State of CPython and Python Ecosystem (Senthil Kumaran) Sysadmins vs Developers, a take from the other side of the fence (Benjamin Smith) Teaching Python to the young and impressionable (Katie Bell) The NCSS Challenge: teaching programming via automated testing (Tim Dawborn) Weather field warping using Python. (Nathan Faggian) Zookeepr: Home-grown conference management software (Brianna Laugher) In-Depth Talks: Ah! I see you have the machine that goes "BING"! (Graeme Cross) Easy site migration using Diazo and Funnelweb (Adam Terrey) How to maintain big app stacks without losing your mind (Dylan Jay) Introduction to the Geospatial Web with GeoDjango (Javier Candeira) Pyramid: Lighter, faster, better web apps (Dylan Jay) Web micro-framework battle (Richard Jones) Discussion Panels: Panel: Python 3 (Nick Coghlan, Raymond Hettinger, Richard Jones) Panel: Python in the webs (Malcolm Tredinnick, Russell Keith-Magee, Dylan Jay, Richard Jones) Classroom Track: Python 101+ (Peter Lovett) Python's dark corners - the bad bits in Python and how to avoid them (Peter Lovett) Confessions of Joe Developer (Danny Greenfeld) Meta-matters: using decorators for better Python programming (Graeme Cross) Python for Science and Engineering, Part 1 (Edward Schofield) Python for Science and Engineering, Part 2 (Edward Schofield) The Zen of Python (Richard Jones) More Sponsors Announced ======================= We are delighted to announce that Bitbucket by Atlassian has joined us as a Silver Sponsor. Thanks once again to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Silver: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Arclight Silver: Bitbucket by Atlassian Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 From rantingrick at gmail.com Wed Jul 13 19:43:13 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 13 Jul 2011 16:43:13 -0700 (PDT) Subject: "Python Wizard," with apologies to The Who References: <8479eca3-843d-4857-a857-320da4a93965@u6g2000prc.googlegroups.com> <4e1cee94$0$30003$c3e8da3$5496439d@news.astraweb.com> <9d1facb5-f5a3-4f8a-8de3-fe9fd9906f60@g3g2000prf.googlegroups.com> Message-ID: On Jul 13, 4:40?pm, Chris Angelico wrote: > Having not known the original, I can't properly appreciate the parody, It's only a click away Chris... here let me youtube that for you... http://www.youtube.com/watch?v=4AKbUm8GrbM http://www.youtube.com/watch?v=SHhrZgojY1Q http://www.youtube.com/watch?v=IXWNSb4nUDY Here's one for my would be nemisis(es) http://www.youtube.com/watch?v=fi_rGnw_B9A From thinke365 at gmail.com Wed Jul 13 20:18:07 2011 From: thinke365 at gmail.com (think) Date: Thu, 14 Jul 2011 08:18:07 +0800 Subject: should i install python image library by myself? Message-ID: <201107140818034940258@gmail.com> when i type import image in the python interactive command, i am surprised to find that it does not work. the details are as follows: >>> import image Traceback (most recent call last): File "", line 1, in ? ImportError: No module named image i wonder the image library should be a buildin module, then why i cannot import it? what's wrong? or some version of python does not include image library as a buildin module? so can anybody recommend a version of python which include image libary, thank you ; ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From wobh at yahoo.com Wed Jul 13 20:53:49 2011 From: wobh at yahoo.com (William Clifford) Date: Wed, 13 Jul 2011 17:53:49 -0700 Subject: Lisp refactoring puzzle References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87y603nwys.fsf@pangea.home.gustad.com> <983mh1Fs7cU1@mid.individual.net> Message-ID: <86oc0xn0ma.fsf@gsosw-lego-spare1.domain.actdsltmp> Neil Cerutti writes: > On 2011-07-12, Petter Gustad wrote: >> Xah Lee writes: >> >>> it's funny, in all these supposedly modern high-level langs, they >>> don't provide even simple list manipulation functions such as union, >>> intersection, and the like. Not in perl, not in python, not in lisps. >> >> In Common Lisp you have: >> >> CL-USER> (union '(a b c) '(b c d)) >> (A B C D) >> CL-USER> (intersection '(a b c) '(b c d)) >> (C B) > > What's the rationale for providing them? Are the definitions > obvious for collections that a not sets? This seems like a good general question to me, although, I feel like the answer to this question specifically is "yes, obvious enough." A general purpose programming language ought to be general enough to allow expansion, but have enough "obvious" features, that one doesn't have to reinvent the wheel. I recently read somewhere that human languages "differ less in what they allow, and more in what they require" (paraphrase). I have little-to-no computer science expertise, but I sense that in computer languages with Turing equivalency this is exactly true. -- William Clifford From python at mrabarnett.plus.com Wed Jul 13 20:59:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 01:59:51 +0100 Subject: PyCon Australia 2011: Schedule Announced In-Reply-To: <1310599497.11156.14.camel@rambutan> References: <1310599497.11156.14.camel@rambutan> Message-ID: <4E1E3F87.5010101@mrabarnett.plus.com> On 14/07/2011 00:24, Ryan Kelly wrote: [snip] > > Ah! I see you have the machine that goes "BING"! (Graeme Cross) Surely it goes "PING"! From clp2 at rebertia.com Wed Jul 13 21:04:47 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 13 Jul 2011 18:04:47 -0700 Subject: should i install python image library by myself? In-Reply-To: <201107140818034940258@gmail.com> References: <201107140818034940258@gmail.com> Message-ID: On Wed, Jul 13, 2011 at 5:18 PM, think wrote: > when i?type import image in the python interactive command, i am surprised > to find that it does not work. the details are as follows: What led you to expect that exact command would work in the first place?? >>>>?import?image > Traceback?(most?recent?call?last): > ??File?"",?line?1,?in?? > ImportError:?No?module?named?image > > i wonder the image library should be a buildin module, then why i cannot > import it? > what's wrong? or some version of python does not include image library as a > buildin module? There is no standard library module by that name; no first-party versions of Python include such a module. Thus, it's no surprise that your import throws an exception. > so can anybody recommend a version of python which include image libary, I can only guess that your "image" library refers to either the "Image" (capitalization matters!) *submodule* of PIL (http://www.pythonware.com/products/pil/ ), or the "Image" class of Tkinter (http://docs.python.org/library/tkinter.html#images ). The former requires installation of PIL, and would then be correctly imported via: from PIL import Image The latter is typically built as part of a default Python installation and would be correctly imported via: from Tkinter import Image # Python 2.x or: from tkinter import Image # Python 3.x Cheers, Chris -- http://rebertia.com From python at mrabarnett.plus.com Wed Jul 13 21:04:54 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 02:04:54 +0100 Subject: should i install python image library by myself? In-Reply-To: <201107140818034940258@gmail.com> References: <201107140818034940258@gmail.com> Message-ID: <4E1E40B6.803@mrabarnett.plus.com> On 14/07/2011 01:18, think wrote: > when i type import image in the python interactive command, i am > surprised to find that it does not work. the details are as follows: > >>> import image > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named image > i wonder the image library should be a buildin module, then why i cannot > import it? > what's wrong? or some version of python does not include image library > as a buildin module? > so can anybody recommend a version of python which include image libary, > thank you ; ) > The usual image library used in Python is the Python Imaging Library ("PIL"). It isn't one of the standard modules. Have a look here: http://www.pythonware.com/products/pil/ From ian at excess.org Wed Jul 13 22:02:15 2011 From: ian at excess.org (Ian Ward) Date: Wed, 13 Jul 2011 22:02:15 -0400 Subject: ANN: Urwid 0.9.9.2 - Console UI Library Message-ID: <4E1E4E27.9090501@excess.org> Announcing Urwid 0.9.9.2 ------------------------ Urwid home page: http://excess.org/urwid/ Screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.2.tar.gz About this release: =================== This release is *not* the big, exciting, wow-look-at-all-those-new-features release that just might be coming out very soon. It does, however fix a number of bugs in the previous release. New in this release: ==================== * Fix for an Overlay get_cursor_coords(), and Text top-widget bug * Fix for a Padding rows() bug when used with width=PACK * Fix for a bug with large flow widgets used in an Overlay * Fix for a gpm_mev bug * Fix for Pile and GraphVScale when rendered with no contents * Fix for a Python 2.3 incompatibility (0.9.9 is the last release to claim support Python 2.3) About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, Unicode support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From greg.ewing at canterbury.ac.nz Wed Jul 13 23:12:41 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jul 2011 15:12:41 +1200 Subject: Lisp refactoring puzzle In-Reply-To: <87mxgilh15.fsf@mithlond.arda> References: <19f8eb5b-cc90-472a-8399-4a5787b6fecf@glegroupsg2000goo.googlegroups.com> <2c59f63a-b46f-4ea9-bc12-da4841687117@l28g2000yqc.googlegroups.com> <5cb297e4-6a39-461c-98c5-639e72e166af@p10g2000prf.googlegroups.com> <87mxgilh15.fsf@mithlond.arda> Message-ID: <98755cFolU1@mid.individual.net> Teemu Likonen wrote: > Please don't forget that the whole point of Lisps' (f x) syntax is that > code is also Lisp data. It's possible to design other syntaxes that have a similar property. Prolog, for example -- a Prolog program is expressed in terms of Prolog data structures, yet it manages to have things that look like fairly normal function calls and infix expressions. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 13 23:32:40 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jul 2011 15:32:40 +1200 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <9876asF7v0U1@mid.individual.net> Anthony Kong wrote: > So I have picked this topic for one of my presentation. It is because > functional programming technique is one of my favorite in my bag of python trick. I'm not sure it's a good idea to emphasise functional programming too much. Python doesn't really lend itself to a heavily functional style. While you *can* write Python code that way, it's not idiomatic, and you're likely to give beginners a distorted idea of how Python is normally written. -- Greg From steve+comp.lang.python at pearwood.info Thu Jul 14 00:05:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jul 2011 14:05:24 +1000 Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <9876asF7v0U1@mid.individual.net> Message-ID: <4e1e6b05$0$29973$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Jul 2011 01:32 pm Gregory Ewing wrote: > Anthony Kong wrote: > >> So I have picked this topic for one of my presentation. It is because >> functional programming technique is one of my favorite in my bag of >> python trick. > > I'm not sure it's a good idea to emphasise functional > programming too much. Python doesn't really lend itself > to a heavily functional style. While you *can* write > Python code that way, it's not idiomatic, and you're > likely to give beginners a distorted idea of how Python > is normally written. I think that's true for *purely* functional code, but functional idioms are very Pythonic. Iterators and generators, list comprehensions and generator expressions, itertools, using functions as first-class objects (including decorators) are all in a functional style. Python borrowed list comps from Haskell, just as it borrowed map from Lisp. If you want to claim that map is "not Pythonic", I won't get into a fight over it, but list comps certainly are! I guess it really depends on how you wish to define "functional". To my mind, even something as simple as "don't use global state, instead pass arguments to functions as needed" is a Good Trick learned from functional programming. -- Steven From nospam at torek.net Thu Jul 14 00:47:06 2011 From: nospam at torek.net (Chris Torek) Date: 14 Jul 2011 04:47:06 GMT Subject: difflib-like library supporting moved blocks detection? References: Message-ID: In article Vlastimil Brom wrote: >I'd like to ask about the availability of a text diff library, like >difflib, which would support the detection of moved text blocks. If you allow arbitrary moves, the "minimal edit distance" problem (string-to-string edit) becomes substantially harder. If you only allow insert, delete, or in-place-substitute, you have what is called the "Levenshtein distance" case. If you allow transpositions you get "Damerau-Levenshtein". These are both solveable with a dynamic programming algorithm. Once you allow move operations, though, the problem becomes NP-complete. See http://pages.cs.brandeis.edu/~shapird/publications/JDAmoves.pdf for instance. (They give an algorithm that produces "usually acceptable" results in polynomial time.) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From marco at minasithil.org Thu Jul 14 03:07:12 2011 From: marco at minasithil.org (marco) Date: Thu, 14 Jul 2011 09:07:12 +0200 Subject: [TWISTED] Howto Deferred Message-ID: Hello gals and guys, I'm an experienced Python user and I'd like to begin playing with Twisted. I started RTFM the tutorial advised on the official site and I found it really useful and well done. Now I'd like to practice a bit by coding a little program that reads strings from a serial device and redirects them remotely via TCP. For that sake I'm trying to use deferred. In the tutorial, a deferred class is instantiated at factory level, then used and destroyed. And here things get harder for me. Now, in my test program I need to manage data which comes in a "random" manner, and I thought about doing it in a few possible ways: 1. create a deferred at factory level and every time I read something from the serial port add some callbacks: class SerToTcpProtocol(Protocol): def dataReceived(self, data): # deferred is already instantiated and launched # self.factory.sendToTcp sends data to the TCP client self.factory.deferred.addCallback(self.factory.sendToTcp, data) 2. or, either, create a deferred at protocol level every time I receive something, then let the deferred do what I need and destroy it: class SerToTcpProtocol(Protocol): def dataReceived(self, data): d = defer.Deferred() d.addCallback(self.factory.sendToTcp, data) d.callback(data) 3. or again, use a deferred list: class SerToTcpProtocol(Protocol): def dataReceived(self, data): d = defer.Deferred() d.addCallback(self.factory.sendToTcp, data) self.factory.listDeferred.addCallback(lambda d) d.callback(data) Or I don't know.. hints are welcome. Thank you in advance and sorry for my english. From rosuav at gmail.com Thu Jul 14 03:57:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2011 17:57:41 +1000 Subject: [TWISTED] Howto Deferred In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 5:07 PM, marco wrote: > Now I'd like to practice a bit by coding a little program that reads > strings from a serial device and redirects them remotely via TCP. For > that sake I'm trying to use deferred. The obvious solution (to my mind) is two threads, one for each direction. On receipt of data, the thread immediately sends it on to the other end. I'm not familiar with deferred; it might work easily, or might need some fancy footwork to make it go. ChrisA From pavlovevidence at gmail.com Thu Jul 14 05:04:01 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 14 Jul 2011 02:04:01 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? In-Reply-To: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <427da0e8-55df-4013-a2e1-cf0bd47d5de7@glegroupsg2000goo.googlegroups.com> On Wednesday, July 13, 2011 5:39:16 AM UTC-7, Anthony Kong wrote: [snip] > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? Java is easily worst language I know of for support of functional programming (unless they added delegates or some other tacked-on type like that), so my advice would be to keep it light, for two reasons: 1. It won't take a lot to impress them 2. Too much will make them roll their eyes Thinking about it, one of the problems with demonstrating functional features is that it's not obvious how those features can simplify things. To get the benefit, you have to take a step back and redo the approach somewhat. Therefore, I'd recommend introducing these features as part of a demo on how a task in Python can be solved much more concisely than in Java. It's kind of an art to find good examples, though. Off the top of my head, I can think of using functools module to help with logging or to apply patches, whereas in Java they'd have to resort to a code weaver or lots of boilerplate. Carl Banks From tartley at tartley.com Thu Jul 14 06:31:55 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 14 Jul 2011 03:31:55 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> Message-ID: <92cbf295-ece7-4bd1-8d65-a7ddcfbd8571@gc3g2000vbb.googlegroups.com> On Jul 13, 1:39?pm, Anthony Kong wrote: > (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice) > > Hi, all, > > If you have read my previous posts to the group, you probably have some idea why I asked this question. > > I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work. > > > So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag ?of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages. > > > I think I will go through the following items: > > itertools module > functools module > concept of currying ('partial') > > I would therefore want to ask your input e.g. > > Is there any good example to illustrate the concept? > What is the most important features you think I should cover? > What will happen if you overdo it? > > Cheers I'd think you'd want to at least mention the relatively new 'lru_cache' decorator, for memoizing the return value expensive functions, providing they are deterministic / pure, etc. From tartley at tartley.com Thu Jul 14 06:33:55 2011 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 14 Jul 2011 03:33:55 -0700 (PDT) Subject: Functional style programming in python: what will you talk about if you have an hour on this topic? References: <2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com> <9876asF7v0U1@mid.individual.net> Message-ID: On Jul 14, 4:32?am, Gregory Ewing wrote: > Anthony Kong wrote: > > So I have picked this topic for one of my presentation. It is because > > functional programming technique is one of my favorite in my bag ?of python trick. > > I'm not sure it's a good idea to emphasise functional > programming too much. Python doesn't really lend itself > to a heavily functional style. While you *can* write > Python code that way, it's not idiomatic, and you're > likely to give beginners a distorted idea of how Python > is normally written. > > -- > Greg Maybe the talk would work well if not aimed at complete all-round beginners, but instead aimed at Pythonistas who are interested in functional programming, or functionistas who are py-curious (I think the same talk would work well for both groups) From calderone.jeanpaul at gmail.com Thu Jul 14 08:21:00 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 14 Jul 2011 05:21:00 -0700 (PDT) Subject: Howto Deferred References: Message-ID: <67bb6752-2df3-4b92-9441-f5d6f0a9ab87@u28g2000yqf.googlegroups.com> On Jul 14, 3:07?am, marco wrote: > Hello gals and guys, > > I'm an experienced Python user and I'd like to begin playing with > Twisted. > I started RTFM the tutorial advised on the official site and I found it > really useful and well done. > > Now I'd like to practice a bit by coding a little program that reads > strings from a serial device and redirects them remotely via TCP. For > that sake I'm trying to use deferred. > Deferreds probably aren't a good solution for this problem. They're useful for one-time events, but you have an event that repeats over and over again with different data. > In the tutorial, a deferred class is instantiated at factory level, then > used and destroyed. > > And here things get harder for me. > Now, in my test program I need to manage data which comes in a "random" > manner, and I thought about doing it in a few possible ways: > > 1. create a deferred at factory level and every time I read something > from the serial port add some callbacks: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? # deferred is already instantiated and launched > ? ? # self.factory.sendToTcp sends data to the TCP client > ? ? self.factory.deferred.addCallback(self.factory.sendToTcp, data) > Or you could do self.factory.sendToTcp(data) > 2. or, either, create a deferred at protocol level every time I receive > something, then let the deferred do what I need and destroy it: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? d = defer.Deferred() > ? ? d.addCallback(self.factory.sendToTcp, data) > ? ? d.callback(data) > Same here. :) > 3. or again, use a deferred list: > > class SerToTcpProtocol(Protocol): > > ? def dataReceived(self, data): > ? ? d = defer.Deferred() > ? ? d.addCallback(self.factory.sendToTcp, data) > ? ? self.factory.listDeferred.addCallback(lambda d) > ? ? d.callback(data) > I'm not sure what the listDeferred is there for. Deferreds are a good abstraction for "do one thing and then tell me what the result was". You have a different sort of thing here, where there isn't much of a result (sending to tcp probably always works until you lose your connection). A method call works well for that. Jean-Paul From EEllerbee at BBandT.com Thu Jul 14 09:05:05 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 09:05:05 -0400 Subject: I don't know list, I not good at list. In-Reply-To: <4E1E151A.4070006@mrabarnett.plus.com> References: <77AE044B1BF3944FAE2435F395F11B4B018599C6@clt-exmb02.bbtnet.com> <4E1E151A.4070006@mrabarnett.plus.com> Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859A67@clt-exmb02.bbtnet.com> Thank you all for the advice, let me spin this in a different way. I've built a program that goes to the NANPA website, scrapes area code/exchange (npa/nxx) digits for a specified area - be it carolina, alabama, texas, etc - drops it into a file, then massages the data and prints out the correct format to insert into a voice router. The code is ugly, but it works great. The thing I haven't been able to get my script to do is to reduce the amount of dial-peers. Hence the need to reduce the numbers to the least common denominator, and put it in the xxxxx[xx] format.If we had a set number of digits, we could build a dictionary(unless it's possible to do that dynamically). So, a couple assertions: 1. the data will always be 6 digit numbers (in a string format) 2. the data is in a txt file after being put there from my script 3. the data will never be the same (I'm going to use this for site conversions/new site builds e.g. today I might be dealing with 252-, 919- and 704- area codes, tomorrow might be 304- and 754- 4. I wanted a script to reduce the time taking to build the dial-peers manually. I'd previously spent 3-4 hours on gathering and processing data. The script I have so far pulls data and massages in about 6 seconds 5. I'm using python 2.7 - it seems like it had more module availability than 3 And a couple question: 1. Would lists be the best way to handle this data? Would it be better to process this data from a file? 2. Is there a way to determine the common (first-5 digits) denominator among a list (or file) of data? 3. and... Could those common numbers be inserted in a dict for processing? Sorry for the book! thanks Edward Ellerbee -----Original Message----- From: python-list-bounces+eellerbee=bbandt.com at python.org [mailto:python-list-bounces+eellerbee=bbandt.com at python.org] On Behalf Of MRAB Sent: Wednesday, July 13, 2011 5:59 PM To: python-list at python.org Subject: Re: I don't know list, I not good at list. > I've been beating my head against the desk trying to figure out a > method to accomplish this: > > Take a list (this example is 5 items, It could be 150 or more - i.e. > it's variable length depending on the city/local calling zones) > > The first 6 digits of phone numbers(NPA/NXX) in a local calling area. > I want to concatenate the last digit for insertion into a call > routing pattern. > > I tried this and failed miserably: > > list1=['252205','252246','252206','252247','252248'] > for item in list1: > try: > item1=list1[0] > item2=list1[1] > if item1[0:5] == item2[0:5]: > print item1[0:5] + '[' + item1[5:6] + item2[5:6] + ']' > list1.pop(0) > else: > print item1 > list1.pop(0) > except: > try: > print item1 > list1.pop(0) > except: > pass > > #----------------------------------------------------------------- > My intent is to have the end data come out (from the example list > above) in the format of > 25220[56] > 25224[678] > > I tried putting together a variable inserted into a regular > expression, and it doesn't seem to like: > Item1=list1[0] > Itemreg = re.compile(Item1[0:5]) > For stuff in itemreg.list1: > #do something > > Can somebody throw me a bone, code example or module to read on > python.org? I'm a n00b, so I'm still trying to understand functions > and classes. > > I thought the experts on this list might take pity on my pathetic > code skillz! > defaultdict comes in handy: >>> list1 = ['252205','252246','252206','252247','252248'] >>> from collections import defaultdict >>> d = defaultdict(set) >>> for item in list1: d[item[ : 5]].add(item[5 : ]) >>> d defaultdict(, {'25224': {'8', '7', '6'}, '25220': {'5', '6'}}) >>> for k, v in d.items(): print(k + "[" + "".join(v) + "]") 25224[876] 25220[56] -- http://mail.python.org/mailman/listinfo/python-list From fzadrozny at appcelerator.com Thu Jul 14 10:30:10 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Thu, 14 Jul 2011 11:30:10 -0300 Subject: PyDev 2.2.1 Released Message-ID: Hi All, PyDev 2.2.1 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Quick-outline * Parent methods may be shown with a 2nd Ctrl+O. * The initial node is selected with the current location in the file. Extract local refactoring * Option to replace duplicates. * Fixed issue where wrong grammar could be used. Others * Improved handling of Ctrl+Shift+T so that no keybinding conflict takes place (now it'll be only active on the PyDev views/editor). * PyLint markers always removed on a project clean. * If the standard library source files are not found, more options are presented. * If the completion popup is focused and shift is pressed on a context insensitive completion, a local import is done. * Fixed issue where a local import wasn't being added to the correct location. * Fixed error message in debugger when there was no caught/uncaught exception set in an empty workspace. * Performance improvements on hierarchy view. * Django commands may be deleted on dialog with backspace. What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From invalid at invalid.invalid Thu Jul 14 10:34:39 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 14 Jul 2011 14:34:39 +0000 (UTC) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: On 2011-07-13, Thorsten Kampe wrote: > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) >> On 2011-07-13, Thorsten Kampe wrote: >> >> >> and that that block is to be considered in relation to what was just >> >> said, before the colon. >> > >> > The indentation makes it abundantly clear to the human reader that >> > that indented block is to be considered in relation to what was just >> > said, before the indentation. > >> You would think so, but human readers like redundancy. > > I also like redundancy (and consistency). That's why I'd much more > prefer a "then" than a colon which is easily overlooked while reading > /and/ while writing. How is the "then" going to be consistent with other things that also introduce blocks (def, try, with, etc.). -- Grant Edwards grant.b.edwards Yow! ! I'm in a very at clever and adorable INSANE gmail.com ASYLUM!! From rosuav at gmail.com Thu Jul 14 10:38:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 00:38:32 +1000 Subject: Suppressing newline writing to file after variable In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> Message-ID: On Fri, Jul 15, 2011 at 12:04 AM, Ellerbee, Edward wrote: > Hey Chris, > > I was reading over this again, trying to understand the logic (I'm a > n00b) > > Could you explain this a bit? I'd like to build this emit function, but > I still don't have a firm grasp on functions. All of my code is line by > line. I'll convert it as a learn more. I'm responding on-list as I believe others will wish to weigh in (if only to point out some improvements to my code - it's hastily put together). Caution, post is long. Defining functions in Python is, broadly speaking, just a matter of collecting up a bunch of statements and giving it a name. Compare: if x>5: do_this() do_that() etc() with: def abcde(): do_this() do_that() etc() The first one does the three statements, in order, if and only if the condition is true. The second one gives a name to those three statements, so you can use it as a new statement: abcde() It'll do the same three things, every time you call it. It's effectively the same as putting the function's body in where you call it (that's an extremely sloppy explanation, but near enough). > So, I'd want this to go after the sort step, and before the format step. > I can figure that piece out, just trying to get this little block of > code to work. Yes, that would be the place to put it. Here's a reworked version that you can test in IDLE: def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result It incorporates some of the enhancements I mentioned in the original post. >>> combine(['252205','252206','252208'],5) ['25220[568]'] >>> combine(['252205','252215','252225'],4) ['2522[012]5'] Notice that the 'emit' function is now 'result.append()' - it builds up a list to return. You can now chain the calls; start with a list of numbers and then call combine() in a loop. # List of numbers from your previous post numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] numbers = combine(numbers,5) numbers = combine(numbers,4) numbers = combine(numbers,3) numbers = combine(numbers,2) numbers = combine(numbers,1) numbers = combine(numbers,0) If you do these statements one at a time in IDLE and inspect the 'numbers' list each time, you'll see the combinations sorting themselves out. (With this starting list, only the first two will have any effect.) The last set of calls can be turned into a for loop: for pos in range(5,-1,-1): numbers = combine(numbers,pos) In fact, you could actually take it out of being a function, if you wanted to: list_of_numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] for position in range(5,-1,-1): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) list_of_numbers = result That's what the function definition does - it takes a block of code and gives it a new name. (There's a lot more to it than that, thank you pedants I know, but in this simple example that's what it's doing.) Hope that's of use! Chris Angelico From EEllerbee at BBandT.com Thu Jul 14 10:53:23 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 10:53:23 -0400 Subject: Suppressing newline writing to file after variable In-Reply-To: References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com><77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com><77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> Holy cow, that's perfect! Thanks so much :) Would it be alright if I post my code on the list for critiquing? I'm learning python to supplement my voice engineering position - time consuming tasks that can be automated will take less time. Edward Ellerbee -----Original Message----- From: python-list-bounces+eellerbee=bbandt.com at python.org [mailto:python-list-bounces+eellerbee=bbandt.com at python.org] On Behalf Of Chris Angelico Sent: Thursday, July 14, 2011 10:39 AM To: python-list at python.org Subject: Re: Suppressing newline writing to file after variable On Fri, Jul 15, 2011 at 12:04 AM, Ellerbee, Edward wrote: > Hey Chris, > > I was reading over this again, trying to understand the logic (I'm a > n00b) > > Could you explain this a bit? I'd like to build this emit function, > but I still don't have a firm grasp on functions. All of my code is > line by line. I'll convert it as a learn more. I'm responding on-list as I believe others will wish to weigh in (if only to point out some improvements to my code - it's hastily put together). Caution, post is long. Defining functions in Python is, broadly speaking, just a matter of collecting up a bunch of statements and giving it a name. Compare: if x>5: do_this() do_that() etc() with: def abcde(): do_this() do_that() etc() The first one does the three statements, in order, if and only if the condition is true. The second one gives a name to those three statements, so you can use it as a new statement: abcde() It'll do the same three things, every time you call it. It's effectively the same as putting the function's body in where you call it (that's an extremely sloppy explanation, but near enough). > So, I'd want this to go after the sort step, and before the format step. > I can figure that piece out, just trying to get this little block of > code to work. Yes, that would be the place to put it. Here's a reworked version that you can test in IDLE: def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result It incorporates some of the enhancements I mentioned in the original post. >>> combine(['252205','252206','252208'],5) ['25220[568]'] >>> combine(['252205','252215','252225'],4) ['2522[012]5'] Notice that the 'emit' function is now 'result.append()' - it builds up a list to return. You can now chain the calls; start with a list of numbers and then call combine() in a loop. # List of numbers from your previous post numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] numbers = combine(numbers,5) numbers = combine(numbers,4) numbers = combine(numbers,3) numbers = combine(numbers,2) numbers = combine(numbers,1) numbers = combine(numbers,0) If you do these statements one at a time in IDLE and inspect the 'numbers' list each time, you'll see the combinations sorting themselves out. (With this starting list, only the first two will have any effect.) The last set of calls can be turned into a for loop: for pos in range(5,-1,-1): numbers = combine(numbers,pos) In fact, you could actually take it out of being a function, if you wanted to: list_of_numbers = ['252205', '252206', '252208', '252220', '252221', '252222', '252223', '919745', '919725', '919785', '704770', '704771', '704772', '704773', '704774', '704775', '704776', '704777', '704778', '704779', '704780', '704781', '704782', '704783', '704784', '704785', '704786', '704787', '704788', '704789', '704790', '704791', '704792', '704793', '704794', '704795', '704796', '704797', '704798', '704799'] for position in range(5,-1,-1): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) list_of_numbers = result That's what the function definition does - it takes a block of code and gives it a new name. (There's a lot more to it than that, thank you pedants I know, but in this simple example that's what it's doing.) Hope that's of use! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list From ozric at web.de Thu Jul 14 11:00:14 2011 From: ozric at web.de (Christian) Date: Thu, 14 Jul 2011 08:00:14 -0700 (PDT) Subject: String formatting - mysql insert Message-ID: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Hi, I get some problem when i like to set the table name dynamic. I'm appreciate for any help. Christian ### works #### newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s); """ , (rs[1],rs[2])) ### works not newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES (%s, %s); """ , (table_name,rs[1],rs[2])) ### works but is not really perfect: None from rs list result in "None" instead of NULL. newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES ('%s','%s'); """ % (table_name,rs[1],rs[2])) From rosuav at gmail.com Thu Jul 14 11:03:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 01:03:14 +1000 Subject: Suppressing newline writing to file after variable In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B016A29A2@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B08@clt-exmb02.bbtnet.com> <77AE044B1BF3944FAE2435F395F11B4B01859B8F@clt-exmb02.bbtnet.com> Message-ID: On Fri, Jul 15, 2011 at 12:53 AM, Ellerbee, Edward wrote: > Holy cow, that's perfect! > > Thanks so much :) > > Would it be alright if I post my code on the list for critiquing? I'm > learning python to supplement my voice engineering position - time > consuming tasks that can be automated will take less time. If it's not too long, sure! If it's more than can conveniently be read, post it on one of those code-sharing places like http://pastebin.com/ and post a link; then those who want to read it can do so, and those who would rather avoid it have that option too. ChrisA From wanderer at dialup4less.com Thu Jul 14 11:14:01 2011 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 14 Jul 2011 08:14:01 -0700 (PDT) Subject: An interesting beginner question: why we need colon at all in the python language? References: Message-ID: <147a626f-21e0-42f6-a939-50d0ee1e0303@g16g2000yqg.googlegroups.com> On Jul 14, 10:34?am, Grant Edwards wrote: > On 2011-07-13, Thorsten Kampe wrote: > > > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC)) > >> On 2011-07-13, Thorsten Kampe wrote: > > >> >> and that that block is to be considered in relation to what was just > >> >> said, before the colon. > > >> > The indentation makes it abundantly clear to the human reader that > >> > that indented block is to be considered in relation to what was just > >> > said, before the indentation. > > >> You would think so, but human readers like redundancy. > > > I also like redundancy (and consistency). That's why I'd much more > > prefer a "then" than a colon which is easily overlooked while reading > > /and/ while writing. > > How is the "then" going to be consistent with other things that also > introduce blocks (def, try, with, etc.). > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! ! ?I'm in a very > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? clever and adorable INSANE > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?ASYLUM!! But if you have the colon, why do you need the brackets or backslashes in an if statement. Why not if condition1 or condition2 or condition3: do_something() The statement ain't over til there's a colon. From rosuav at gmail.com Thu Jul 14 11:21:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2011 01:21:32 +1000 Subject: String formatting - mysql insert In-Reply-To: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: On Fri, Jul 15, 2011 at 1:00 AM, Christian wrote: > Hi, > > I get some problem ?when i like to set the table name dynamic. > I'm appreciate for any help. > > ### works but is not really perfect: None from rs list result in > "None" instead of NULL. > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES > ('%s','%s'); """ ?% ?(table_name,rs[1],rs[2])) I'll start with the easy one. This one is wrong for several reasons; firstly, it converts everything to strings (which is why a None comes out as 'None'), but secondly and more seriously, it cannot handle apostrophes or backslashes in your strings. SQL engines such as MySQL need strings to be properly escaped, and the execute() function will do that for you - but the % interpolation won't. > ### works not > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES ?(%s, > %s); """ , (table_name,rs[1],rs[2])) What's happening here is that the table name is being sent in apostrophes. Just as it puts quotes around your data, it also puts quotes around the table name - which you don't want. You're getting something like INSERT INTO 'foobar'_events, which MySQL doesn't like. I recommend a hybrid: newcur.execute ( ?""" INSERT INTO {0}_events (id1,id2) ? VALUES (%s,%s); """.format(table_name), (,rs[1],rs[2])) Note that I'm using the format() method rather than the % operator, specifically because it uses a different notation - {0} - and will leave the %s markers alone. This assumes that your table name is clean. If it comes from your own code, that's probably safe; but if it comes from user-supplied data, you WILL need to sanitize it (I recommend whitelisting valid characters eg letters and numbers, and keeping only those - and then imposing a length limit too) before giving it to .execute(). As far as I know, MySQL doesn't have facilities for dynamic table names, so your best bet is to make the SQL statement itself dynamic, as per this example. Hope that helps! Chris Angelico From noway at nohow.com Thu Jul 14 11:31:36 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 11:31:36 -0400 Subject: String formatting - mysql insert References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: On 07/14/2011 11:00 AM, Christian wrote: > Hi, > > I get some problem when i like to set the table name dynamic. > I'm appreciate for any help. > > Christian > > ### works #### > newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s); > """ , (rs[1],rs[2])) > > ### works not > newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES (%s, > %s); """ , (table_name,rs[1],rs[2])) > > ### works but is not really perfect: None from rs list result in > "None" instead of NULL. > newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES > ('%s','%s'); """ % (table_name,rs[1],rs[2])) You shouldn't use The bottom form at all since that is how injection attacks occur. The reason the second version doesn't work is because the the execute command escapes all of the arguments before replacing them. Example: sql = """SELECT * FROM table WHERE col = %s;""" cur.execute(sql, ('name',)) # The actual sql statement that gets executed is: # SELECT * FROM table WHERE col = 'name'; # Notice the single quotes. -- Bill From monkey at joemoney.net Thu Jul 14 13:00:07 2011 From: monkey at joemoney.net (monkeys paw) Date: Thu, 14 Jul 2011 13:00:07 -0400 Subject: How can I make a program automatically run once per day? In-Reply-To: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> Message-ID: <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> On 7/9/2011 10:01 PM, John Salerno wrote: > Thanks everyone! I probably should have said something like "Python, > if possible and efficient, otherwise any other method" ! :) > > I'll look into the Task Scheduler. Thanks again! You could use the below code. time.sleep(# seconds in a day) where i == 30 would run once a day for a month import time i=0 while (1): print 'hello' time.sleep(2) # Change this to number of seconds in a day if (i == 3): # make this 30 for a month break i = i + 1 From ian.g.kelly at gmail.com Thu Jul 14 13:13:57 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2011 11:13:57 -0600 Subject: How can I make a program automatically run once per day? In-Reply-To: <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> References: <54735121-6a94-4dcb-9f6b-e4fca4aad652@u42g2000yqm.googlegroups.com> <6uidnYUoaNs-vYLTnZ2dnUVZ_sidnZ2d@insightbb.com> Message-ID: On Thu, Jul 14, 2011 at 11:00 AM, monkeys paw wrote: > You could use the below code. time.sleep(# seconds in a day) > where i == 30 would run once a day for a month > > import time > i=0 > while (1): > ? ? ? ?print 'hello' > ? ? ? ?time.sleep(2) ? # Change this to number of seconds in a day > ? ? ? ?if (i == 3): ? ?# make this 30 for a month > ? ? ? ? ? ? ? ?break > ? ? ? ?i = i + 1 If the system ever gets rebooted during that month, then you would need to remember to manually restart the script. Or if the effective part of the script raises an exception, it could crash the whole script without some defensive coding. That's why it's better just to use the system scheduler service. From miki.tebeka at gmail.com Thu Jul 14 13:22:44 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 14 Jul 2011 10:22:44 -0700 (PDT) Subject: json decode issue Message-ID: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> Greetings, I'm trying to decode JSON output of a Java program (jackson) and having some issues. The cause of the problem is the following snippet: { "description": "... lives\uMOVE? OFFERS ", } Which causes ValueError: Invalid \uXXXX escape. Any ideas on how to fix this? Thanks, -- Miki From EEllerbee at BBandT.com Thu Jul 14 14:03:59 2011 From: EEllerbee at BBandT.com (Ellerbee, Edward) Date: Thu, 14 Jul 2011 14:03:59 -0400 Subject: Please critique my script Message-ID: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> I've been working on this for 3 weeks as a project while I'm learning python. It's ugly, only function in there is from a fellow lister, but it works perfectly and does what it is intended to do. I'd love to hear comments on how I could improve this code, what would be good to turn into a function/class etc. # The function of this script is to gather user data from the user to # build appropriate local dial-peers in a cisco voice gateway. # Data gathered from the user: # name of file to write dial-peers to # NPA # NXX # outbound port to send calls # question if home npa local calls are 7 digit # script navigates to nanpa.com, gathers the local calling area # and returns the data # the data is converted to beautiful soup (I had a problem with the xml format) # the data is parsed for the proper NPA/NXXs # list is sorted, duplicates removed # data from list is formatted and printed to the file specified #--------Import dependencies----------- import urllib2 from BeautifulSoup import BeautifulSoup import re #--------Define variables------------ count = 0 count2 = 0 count3 = 0 npalist = [] nxxlist = [] sortlist = [] sortedlist = [] npaReg = re.compile('(?<=)(...)(?=)') nxxReg = re.compile('(?<=)(...)(?=)') proxy = urllib2.ProxyHandler({'http': 'proxy.com:8080'}) # --actual proxy was removed for confidentiality-- opener = urllib2.build_opener(proxy) #----- function to concatenate numbers - thanks to Chris Angelico ----- def combine(list_of_numbers, position): lastprefix=tails=lastsuffix=None result=[] for cur in list_of_numbers: prefix=cur[:position]; tail=cur[position]; suffix=cur[position+1:] if prefix!=lastprefix or suffix!=lastsuffix: if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) lastprefix,tails,lastsuffix=prefix,"",suffix tails+=tail if lastprefix!=None: if len(tails)>1: result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) else: result.append(lastprefix+tails+lastsuffix) return result #-------Gather info from user-------- x = raw_input("please enter a filename: ") y = raw_input("please enter the npa: ") z = raw_input("please enter the nxx: ") p = raw_input("please enter the port: ") q = raw_input("Is home npa local dialing 7 digit?(y/n) ") #print x #-------Modify user data------------- o = open(x, 'w') y = str(y) z = str(z) p = str(p) pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa=" + y + "&nxx=" + z) print "Querying", pagedef #------Get info from NANPA.com ---------- urllib2.install_opener(opener) page = urllib2.urlopen(pagedef) soup = BeautifulSoup(page) soup = str(soup) #------Parse Gathered Data---------- for line in npaReg.findall(soup): npalist.insert(count,line) count = count + 1 for line2 in nxxReg.findall(soup): nxxlist.insert(count2,line2) count2 = count2 + 1 #-----Sort, remove duplicates, concatenate the last digits for similiar NPA/NXX ------ for makenewlist in range(0,count): sortlist.append(npalist.pop(0) + nxxlist.pop(0)) sortlist.sort() for sortednumber in sortlist: if sortednumber not in sortedlist: sortedlist.append(sortednumber) catlist = combine(sortedlist,5) catlist2 = combine(catlist,4) #------Print the dial-peers to file---- for line in catlist2: figureDpn = count3 + 1000 dpn = str(figureDpn) label = "dial-peer voice " + dpn o.write(label) o.write('\n') o.write("description *** local outbound dialpeer ***") o.write('\n') destpatt = "destination-pattern %s...." % line.rstrip() o.write(destpatt) o.write('\n') port = "port " + p o.write(port) o.write('\n') if line[0:3] == y and q == "y": o.write("forward-digits 7") o.write('\n') o.write('\n') count3 = count3 + 1 o.close() #------------------------------------------- Thanks! Edward Ellerbee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozric at web.de Thu Jul 14 14:10:48 2011 From: ozric at web.de (Christian) Date: Thu, 14 Jul 2011 11:10:48 -0700 (PDT) Subject: String formatting - mysql insert References: <721503a5-cecd-47e6-8a43-312e4680386a@n35g2000yqf.googlegroups.com> Message-ID: <21c17ab7-c768-415d-9b18-606ea6066847@l28g2000yqc.googlegroups.com> On 14 Jul., 17:31, Billy Mays wrote: > On 07/14/2011 11:00 AM, Christian wrote: > > > > > > > > > > > Hi, > > > I get some problem ?when i like to set the table name dynamic. > > I'm appreciate for any help. > > > Christian > > > ### works #### > > newcur.execute ( ?""" INSERT INTO events (id1,id2) ? VALUES ?(%s,%s); > > """ , (rs[1],rs[2])) > > > ### works not > > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES ?(%s, > > %s); """ , (table_name,rs[1],rs[2])) > > > ### works but is not really perfect: None from rs list result in > > "None" instead of NULL. > > newcur.execute ( ?""" INSERT INTO %s_events (id1,id2) ? VALUES > > ('%s','%s'); """ ?% ?(table_name,rs[1],rs[2])) > > You shouldn't use The bottom form at all since that is how injection > attacks occur. > > The reason the second version doesn't work is because the the execute > command escapes all of the arguments before replacing them. ?Example: > > sql = """SELECT * FROM table WHERE col = %s;""" > cur.execute(sql, ('name',)) > # The actual sql statement that gets executed is: > # SELECT * FROM table WHERE col = 'name'; > # Notice the single quotes. > > -- > Bill thanks you guys! From gerald.britton at gmail.com Thu Jul 14 14:44:04 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Thu, 14 Jul 2011 14:44:04 -0400 Subject: Please critique my script Message-ID: For me, there are some things I don't like much. One-character variable names stand out (tend to make the code hard to read). Violation of PEP 8 guidelines, especially wrt spacing. e.g. result.append("%s[%s]%s" % (lastprefix, tails, lastsuffix)) not result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) Similarly for many of the assignments and expressions. I see that you initialize count3 at line 39 but don't use it until line 123. I'd suggest that you move the initialization closer to its use. I think that you should move the call to open closer to where you're going to write to the file. In fact, you can do the thing a bit neater with a context manager like this: #------Print the dial-peers to file---- with open(x, 'w') as o: for line in catlist2: figureDpn = count3 + 1000 dpn = str(figureDpn) label = "dial-peer voice " + dpn o.write(label) o.write('\n') ... Note that if you use this approach you don't need a separate call to close(). Also, you can do all the writing in one call to write(), something like this: o.write( label + '\n' + "description *** local outbound dialpeer ***" + '\n' + destpatt + '\n' + "port " + p + '\n' "forward-digits 7" if line[0:3] == y and q == "y" else "" '\n' ) Which keeps the eye focused on the data being written (at least for me). -- Gerald Britton From python at mrabarnett.plus.com Thu Jul 14 15:12:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 20:12:05 +0100 Subject: Please critique my script In-Reply-To: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> References: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> Message-ID: <4E1F3F85.7020609@mrabarnett.plus.com> [snip] raw_input() returns a string, so there's no need for these 3 lines: > y = str(y) > z = str(z) > p = str(p) > pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa=" + y + "&nxx=" + z) > print "Querying", pagedef > > #------Get info from NANPA.com ---------- > urllib2.install_opener(opener) > page = urllib2.urlopen(pagedef) > soup = BeautifulSoup(page) > soup = str(soup) > > #------Parse Gathered Data---------- > for line in npaReg.findall(soup): > npalist.insert(count, line) > count = count + 1 > > for line2 in nxxReg.findall(soup): > nxxlist.insert(count2, line2) > count2 = count2 + 1 > enumerate will help you here: for count, line in enumerate(npaReg.findall(soup)): npalist.insert(count, line) for count2, line2 in enumerate(nxxReg.findall(soup)): nxxlist.insert(count2, line2) > #-----Sort, remove duplicates, concatenate the last digits for similiar NPA/NXX ------ > for makenewlist in range(0, count): > sortlist.append(npalist.pop(0) + nxxlist.pop(0)) > > sortlist.sort() > > for sortednumber in sortlist: > if sortednumber not in sortedlist: > sortedlist.append(sortednumber) > If you're going to sort them anyway (so you don't need to preserve the existing order), the easiest way to remove duplicates is to use a set: sortedlist = sorted(set(sortlist)) [snip] From python at mrabarnett.plus.com Thu Jul 14 15:20:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2011 20:20:20 +0100 Subject: json decode issue In-Reply-To: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> References: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> Message-ID: <4E1F4174.1070408@mrabarnett.plus.com> On 14/07/2011 18:22, Miki Tebeka wrote: > Greetings, > > I'm trying to decode JSON output of a Java program (jackson) and having some issues. > The cause of the problem is the following snippet: > { > "description": "... lives\uMOVE? OFFERS ", > } > Which causes ValueError: Invalid \uXXXX escape. > > Any ideas on how to fix this? > Is that valid JSON? If not, you'll either need to fix the program which generated it (or report it as a bug), or pre-process the JSON to correct the error, if you know what it should be. From noway at nohow.com Thu Jul 14 15:46:26 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 15:46:26 -0400 Subject: Possible File iteration bug Message-ID: I noticed that if a file is being continuously written to, the file generator does not notice it: def getLines(f): lines = [] for line in f: lines.append(line) return lines with open('/var/log/syslog', 'rb') as f: lines = getLines(f) # do some processing with lines # /var/log/syslog gets updated in the mean time # always returns an empty list, even though f has more data lines = getLines(f) I found a workaround by adding f.seek(0,1) directly before the last getLines() call, but is this the expected behavior? Calling f.tell() right after the first getLines() call shows that it isn't reset back to 0. Is this correct or a bug? -- Bill From ian.g.kelly at gmail.com Thu Jul 14 16:00:06 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2011 14:00:06 -0600 Subject: Possible File iteration bug In-Reply-To: References: Message-ID: On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: > def getLines(f): > ? ?lines = [] > ? ?for line in f: > ? ? ? ?lines.append(line) > ? ?return lines > > with open('/var/log/syslog', 'rb') as f: > ? ?lines = getLines(f) > ? ?# do some processing with lines > ? ?# /var/log/syslog gets updated in the mean time > > ? ?# always returns an empty list, even though f has more data > ? ?lines = getLines(f) > > > > > I found a workaround by adding f.seek(0,1) directly before the last > getLines() call, but is this the expected behavior? ?Calling f.tell() right > after the first getLines() call shows that it isn't reset back to 0. ?Is > this correct or a bug? This is expected. Part of the iterator protocol is that once an iterator raises StopIteration, it should continue to raise StopIteration on subsequent next() calls. From tjreedy at udel.edu Thu Jul 14 16:03:03 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jul 2011 16:03:03 -0400 Subject: json decode issue In-Reply-To: <4E1F4174.1070408@mrabarnett.plus.com> References: <87ac9918-c05c-482e-9789-ee90b1e9eb80@glegroupsg2000goo.googlegroups.com> <4E1F4174.1070408@mrabarnett.plus.com> Message-ID: On 7/14/2011 3:20 PM, MRAB wrote: > On 14/07/2011 18:22, Miki Tebeka wrote: >> Greetings, >> >> I'm trying to decode JSON output of a Java program (jackson) and >> having some issues. >> The cause of the problem is the following snippet: >> { >> "description": "... lives\uMOVE? OFFERS ", >> } >> Which causes ValueError: Invalid \uXXXX escape. >> >> Any ideas on how to fix this? >> > Is that valid JSON? If not, you'll either need to fix the program which > generated it (or report it as a bug), or pre-process the JSON to > correct the error, if you know what it should be. If you delete or double the backslash in that one particular spot, the string will parse, even if it is not correct. -- Terry Jan Reedy From noway at nohow.com Thu Jul 14 16:15:42 2011 From: noway at nohow.com (Billy Mays) Date: Thu, 14 Jul 2011 16:15:42 -0400 Subject: Possible File iteration bug References: Message-ID: On 07/14/2011 04:00 PM, Ian Kelly wrote: > On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: >> def getLines(f): >> lines = [] >> for line in f: >> lines.append(line) >> return lines >> >> with open('/var/log/syslog', 'rb') as f: >> lines = getLines(f) >> # do some processing with lines >> # /var/log/syslog gets updated in the mean time >> >> # always returns an empty list, even though f has more data >> lines = getLines(f) >> >> >> >> >> I found a workaround by adding f.seek(0,1) directly before the last >> getLines() call, but is this the expected behavior? Calling f.tell() right >> after the first getLines() call shows that it isn't reset back to 0. Is >> this correct or a bug? > > This is expected. Part of the iterator protocol is that once an > iterator raises StopIteration, it should continue to raise > StopIteration on subsequent next() calls. Is there any way to just create a new generator that clears its `closed` status? -- Bill From hniksic at xemacs.org Thu Jul 14 16:39:52 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 14 Jul 2011 22:39:52 +0200 Subject: Possible File iteration bug References: Message-ID: <878vs0wq93.fsf@xemacs.org> Billy Mays writes: > Is there any way to just create a new generator that clears its > closed` status? You can define getLines in terms of the readline file method, which does return new data when it is available. def getLines(f): lines = [] while True: line = f.readline() if line == '': break lines.append(line) return lines or, more succinctly: def getLines(f): return list(iter(f.readline, '')) From tjreedy at udel.edu Thu Jul 14 16:43:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jul 2011 16:43:12 -0400 Subject: Possible File iteration bug In-Reply-To: References: Message-ID: On 7/14/2011 3:46 PM, Billy Mays wrote: > I noticed that if a file is being continuously written to, the file > generator does not notice it: Because it does not look, as Ian explained. > def getLines(f): > lines = [] > for line in f: > lines.append(line) > return lines This nearly duplicates .readlines, except for using f an an iterator. Try the following (untested): with open('/var/log/syslog', 'rb') as f: lines = f.readlines() # do some processing with lines # /var/log/syslog gets updated in the mean time lines = f.readlines() People regularly do things like this with readline, so it is possible. If above does not work, try (untested): def getlines(f): lines = [] while True: l = f.readline() if l: lines.append(l) else: return lines -- Terry Jan Reedy From __peter__ at web.de Thu Jul 14 16:53:36 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jul 2011 22:53:36 +0200 Subject: Please critique my script References: <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> Message-ID: MRAB wrote: >> for line2 in nxxReg.findall(soup): >> nxxlist.insert(count2, line2) >> count2 = count2 + 1 >> > enumerate will help you here: > for count2, line2 in enumerate(nxxReg.findall(soup)): > nxxlist.insert(count2, line2) An insert() at the end of a list is usually spelt append() in Python ;) If you are looking for something less baroque nxxlist = nxxReg.findall(soup) will do, too. From lac at openend.se Thu Jul 14 16:59:01 2011 From: lac at openend.se (Laura Creighton) Date: Thu, 14 Jul 2011 22:59:01 +0200 Subject: PyCon Australia 2011: Schedule Announced In-Reply-To: Message from Ryan Kelly of "Thu, 14 Jul 2011 09:24:36 +1000." <1310599476.11156.13.camel@rambutan> References: <1310599476.11156.13.camel@rambutan> Message-ID: <201107142059.p6EKx1Ec031483@theraft.openend.se> Hi Ryan. Best of luck with the conference. >Thanks also to Linux Australia, who provide the overarching legal and >organisational structure for PyCon Australia. I want to talk to somebody from Linux Australia about this overarching legal and organisational structure. Do you have an email address of whom I should talk to? I think the structure that we have here in Europe could stand some refactoring, and I was talking with Stephen Thorne at Europython and what Linux Australia is doing looks very neat to me. There is nothing urgent about this, and in no way should this distract you from your conference, but sometime I would like to have an email. Thanks very much, Laura Creighton From brandon.harris at reelfx.com Thu Jul 14 18:15:40 2011 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 14 Jul 2011 17:15:40 -0500 Subject: Python threading/multiprocessing issue. Message-ID: <4E1F6A8C.30200@reelfx.com> I'm working on a tool that runs a number of process is separate thread. I've, up to this point, been using threading.Thread, but from what I read multiprocess will allow multiple processors to be used From the python docs on multiprocessing. I have run into an issue when modifying the thread object from the run method. Threading.thread allows me to change an attribute in the run method and it hold while multiprocessing.Process loses it. Here is an example illustrating the inconsistency that I've seen. ------------------------------------------------------------------------------ | import time import multiprocessing import threading def simple_process_call(): my_process = SimpleProcess() my_process.start() while not my_process.done.is_set(): pass print my_process.my_attribute class SimpleProcess(multiprocessing.Process): def __init__(self): super(SimpleProcess, self).__init__() self.my_attribute = 'Fail' self.done = multiprocessing.Event() def run(self): self.my_attribute = 'Success' time.sleep(5) self.done.set() def simple_thread_call(): my_thread = SimpleThread() my_thread.start() while not my_thread.done.is_set(): pass print my_thread.my_attribute class SimpleThread(threading.Thread): def __init__(self): super(SimpleThread, self).__init__() self.my_attribute = 'Fail' self.done = threading.Event() def run(self): self.my_attribute = 'Success' time.sleep(5) self.done.set() if __name__ == '__main__': # simple_process_call() simple_thread_call()| ------------------------------------------------------------------------------ The odd thing is that I can modify the multiprocessing.Event and it holds, but modifying any attribute on the class goes away. If I am super ignorant of something, please cure me of it. Thanks in advance! Brandon L. Harris -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Thu Jul 14 18:34:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 14 Jul 2011 15:34:50 -0700 (PDT) Subject: Multiplicity and Asininity in Tkinter Event API Message-ID: ############################################################ # Multiplicity and Asininity in Tkinter Event API! # ############################################################ The problems with Tkinter events are two fold: ------------------------------------------------------------ Problem 1: Number Of Sequences Is Obscene. ------------------------------------------------------------ The sheer number of exposed sequences and possible user combinations of sequences is overkill. You should never put the design of an API in the hands of users of said API. Designing rock solid API's is about giving users as much power as possible WITHOUT giving them too many choices. Unfortunately, not only did the authors of Tkinter give people choices, they gave them the power to create NEW choices... CRIKEY! ------------------------------------------------------------ Problem 2. No Uniform Naming Convention. ------------------------------------------------------------ The sequence names follow an intuitive naming convention. Not only that, but alias's exists for some of the combinations. Here are some examples... <1> | callback event inspection ------------------------------------------------------------ Examples Of "Possible" Sequence Combinations ------------------------------------------------------------ Bindings for a single letter: etc... Bindings for Mice: